hashmapinc / Drillflow

A dockerized WITSML API Server that is agnostic of the backend.
Apache License 2.0
17 stars 13 forks source link

Fix bad merging for nested objects in Well #218

Closed randypitcherii closed 5 years ago

randypitcherii commented 5 years ago

Chris to provide actual/expected for unit testing

randypitcherii commented 5 years ago

@cherrera2001 - this is the card for the bad merging issue you found

cherrera2001 commented 5 years ago

ok...so this seems to be working for wellbore, but not well...the assumption is that wellbore is a significantly simpler object, thus it does not have the complex sub-objects that well does...therefore it is not subject to the deep inspection of the merge function for JSONObject types and JSONArray types.

With that being said the actual behavior that is occurring is the following (note everything below was done using the WATT and version 1.3.1.1 of the API:

Assume that well with uid=uid12333 has already been created with the following elements present:

<name>Well hm1223</name>
<nameLegal>Company Legal Name</nameLegal>
<numLicense>Company License Number</numLicense>
<numGovt>Govt-Number</numGovt>
<field>FunctionalTest</field>
<country>US</country>
<state>TX</state>
<county>Montgomery</county>
<region>Region Name</region>
<district>District Name</district>
<block>Block Name</block>
<timeZone>-06:00</timeZone>
<operator>Operating Company</operator>

Created with the query:

<wells xmlns="http://www.witsml.org/schemas/131" version="1.3.1.1">
<well  uid="uid12333">
        <name>Well hm1223</name>
        <nameLegal>Company Legal Name</nameLegal>
        <numLicense>Company License Number</numLicense>
        <numGovt>Govt-Number</numGovt>
        <dTimLicense>2001-05-15T13:20:00.000</dTimLicense>
        <field>FunctionalTest</field>
        <country>US</country>
        <state>TX</state>
        <county>Montgomery</county>
        <region>Region Name</region>
        <district>District Name</district>
        <block>Block Name</block>
        <timeZone>-06:00</timeZone>
        <operator>Operating Company</operator>
</well>
</wells>

When executing a GetFromStore request against the DrillFlow WITSML API with the following query:

<?xml version="1.0" encoding="UTF-8"?>
<wells version="1.3.1.1" xmlns="http://www.witsml.org/schemas/131">
    <well uid="uid12333">
        <name></name>
        <nameLegal></nameLegal>
        <numLicense></numLicense>
        <numGovt></numGovt>
        <dTimLicense></dTimLicense>
        <field></field>
        <country></country>
        <state></state>
        <county></county>
        <region></region>
        <district></district>
        <block></block>
        <timeZone></timeZone>
        <operator></operator>
        <operatorDiv></operatorDiv>
        <pcInterest uom=""></pcInterest>
        <numAPI></numAPI>
        <statusWell></statusWell>
        <purposeWell></purposeWell>
        <fluidWell></fluidWell>
        <directionWell></directionWell>
        <dTimSpud></dTimSpud>
        <dTimPa></dTimPa>
        <wellheadElevation uom=""></wellheadElevation>
        <wellDatum uid="" defaultMeasuredDepth="" defaultVerticalDepth="" defaultElevation="">
            <name></name>
            <code></code>
            <datumName></datumName>
            <kind></kind>
            <wellbore>
                <wellboreReference></wellboreReference>
                <wellParent></wellParent>
            </wellbore>
            <rig>
                <rigReference></rigReference>
                <wellboreParent></wellboreParent>
                <wellParent></wellParent>
            </rig>
            <elevation uom="" datum=""></elevation>
            <measuredDepth uom="" datum=""></measuredDepth>
            <comment></comment>
        </wellDatum>
        <groundElevation uom="" datum=""></groundElevation>
        <waterDepth uom="" datum=""></waterDepth>
        <wellLocation>
            <wellCRS uidRef=""></wellCRS>
            <latitude uom=""></latitude>
            <longitude uom=""></longitude>
            <easting uom=""></easting>
            <northing uom=""></northing>
            <westing uom=""></westing>
            <southing uom=""></southing>
            <projectedX uom=""></projectedX>
            <projectedY uom=""></projectedY>
            <localX uom=""></localX>
            <localY uom=""></localY>
            <original></original>
            <description></description>
        </wellLocation>
        <referencePoint uid="">
            <name></name>
            <type></type>
            <elevation uom="" datum=""></elevation>
            <measuredDepth uom="" datum=""></measuredDepth>
            <location>
                <wellCRS uidRef=""></wellCRS>
                <latitude uom=""></latitude>
                <longitude uom=""></longitude>
                <easting uom=""></easting>
                <northing uom=""></northing>
                <westing uom=""></westing>
                <southing uom=""></southing>
                <projectedX uom=""></projectedX>
                <projectedY uom=""></projectedY>
                <localX uom=""></localX>
                <localY uom=""></localY>
                <original></original>
                <description></description>
            </location>
            <description></description>
        </referencePoint>
        <wellCRS uid="">
            <name></name>
            <mapProjection>
                <nameCRS namingSystem="" code=""></nameCRS>
                <projectionCode></projectionCode>
                <projectedFrom uidRef=""></projectedFrom>
                <stdParallel1 uom=""></stdParallel1>
                <stdParallel2 uom=""></stdParallel2>
                <centralMeridian uom=""></centralMeridian>
                <originLatitude uom=""></originLatitude>
                <originLongitude uom=""></originLongitude>
                <latitude1 uom=""></latitude1>
                <longitude1 uom=""></longitude1>
                <latitude2 uom=""></latitude2>
                <longitude2 uom=""></longitude2>
                <latitudeForScale uom=""></latitudeForScale>
                <longitudeForScale uom=""></longitudeForScale>
                <trueScaleLatitude uom=""></trueScaleLatitude>
                <spheroidRadius uom=""></spheroidRadius>
                <scaleFactor></scaleFactor>
                <methodVariant></methodVariant>
                <perspectiveHeight uom=""></perspectiveHeight>
                <zone></zone>
                <NADType></NADType>
                <falseEasting uom=""></falseEasting>
                <falseNorthing uom=""></falseNorthing>
                <bearing uom=""></bearing>
                <hemisphere></hemisphere>
                <description></description>
                <parameter index="" name="" uom="" description=""></parameter>
            </mapProjection>
            <geographic>
                <nameCRS namingSystem="" code=""></nameCRS>
                <geodeticDatumCode></geodeticDatumCode>
                <xTranslation uom=""></xTranslation>
                <yTranslation uom=""></yTranslation>
                <zTranslation uom=""></zTranslation>
                <xRotation uom=""></xRotation>
                <yRotation uom=""></yRotation>
                <zRotation uom=""></zRotation>
                <scaleFactor></scaleFactor>
                <ellipsoidCode></ellipsoidCode>
                <ellipsoidSemiMajorAxis uom=""></ellipsoidSemiMajorAxis>
                <ellipsoidInverseFlattening></ellipsoidInverseFlattening>
            </geographic>
            <localCRS>
                <usesWellAsOrigin></usesWellAsOrigin>
                <origin></origin>
                <originDescription></originDescription>
                <yAxisAzimuth uom=""></yAxisAzimuth>
                <yAxisDescription></yAxisDescription>
                <xRotationCounterClockwise></xRotationCounterClockwise>
            </localCRS>
            <description></description>
        </wellCRS>
        <commonData>
            <dTimCreation></dTimCreation>
            <dTimLastChange></dTimLastChange>
            <itemState></itemState>
            <comments></comments>
        </commonData>
    </well>
</wells>

Which is a query for a specific well with uid=uid12333 for all possible elements within the schema.

This query results in a REST query being generated by the DoT valve to the following URL:

_${VALVE_BASE_URL}_/_wellbore.path_/uid12333

with a null body

This results in a response with the following JSON body:

{
    "country": "US",
    "numLicense": "Company License Number",
    "commonData": {
        "dTimLastChange": "2019-01-07T14:53:50.3274906+00:00",
        "dTimCreation": "2019-01-03T16:34:23.924594+00:00"
    },
    "county": "Montgomery",
    "timeZone": "-06:00",
    "operator": "Operating Company",
    "referencePoint": [],
    "uid": "uid12333",
    "wellLocation": [],
    "field": "FunctionalTest",
    "wellCRS": [],
    "nameLegal": "Company Legal Name",
    "district": "District Name",
    "name": "Well hm1223",
    "numGovt": "Govt-Number",
    "block": "Block Name",
    "state": "TX",
    "region": "Region Name",
    "wellDatum": []
}

The above JSON also represents the src value of the merge function.

This is then passed into the merge function with the dest value being:

{
    "country": "",
    "numLicense": "",
    "county": "",
    "waterDepth": {
        "uom": null,
        "value": null
    },
    "operator": "",
    "pcInterest": {
        "uom": "",
        "value": null
    },
    "objectType": "well",
    "uid": "uid12333",
    "nameLegal": "",
    "block": "",
    "state": "",
    "operatorDiv": "",
    "groundElevation": {
        "datum": "",
        "uom": null,
        "value": null
    },
    "commonData": {
        "comments": "",
        "acquisitionTimeZone": [],
        "extensionNameValue": []
    },
    "timeZone": "",
    "numAPI": "",
    "version": "1.4.1.1",
    "referencePoint": [
        {
            "elevation": {
                "datum": "",
                "uom": null,
                "value": null
            },
            "uid": "",
            "measuredDepth": {
                "datum": "",
                "uom": null,
                "value": null
            },
            "name": "",
            "description": "",
            "location": [
                {
                    "southing": {
                        "uom": "",
                        "value": null
                    },
                    "easting": {
                        "uom": "",
                        "value": null
                    },
                    "latitude": {
                        "uom": "",
                        "value": null
                    },
                    "description": "",
                    "extensionNameValue": [],
                    "northing": {
                        "uom": "",
                        "value": null
                    },
                    "uid": null,
                    "projectedX": {
                        "uom": "",
                        "value": null
                    },
                    "wellCRS": {
                        "value": "",
                        "uidRef": ""
                    },
                    "projectedY": {
                        "uom": "",
                        "value": null
                    },
                    "localY": {
                        "uom": "",
                        "value": null
                    },
                    "westing": {
                        "uom": "",
                        "value": null
                    },
                    "localX": {
                        "uom": "",
                        "value": null
                    },
                    "longitude": {
                        "uom": "",
                        "value": null
                    }
                }
            ],
            "type": "",
            "extensionNameValue": []
        }
    ],
    "wellLocation": [
        {
            "southing": {
                "uom": "",
                "value": null
            },
            "easting": {
                "uom": "",
                "value": null
            },
            "latitude": {
                "uom": "",
                "value": null
            },
            "description": "",
            "extensionNameValue": [],
            "northing": {
                "uom": "",
                "value": null
            },
            "uid": null,
            "projectedX": {
                "uom": "",
                "value": null
            },
            "wellCRS": {
                "value": "",
                "uidRef": ""
            },
            "projectedY": {
                "uom": "",
                "value": null
            },
            "localY": {
                "uom": "",
                "value": null
            },
            "westing": {
                "uom": "",
                "value": null
            },
            "localX": {
                "uom": "",
                "value": null
            },
            "longitude": {
                "uom": "",
                "value": null
            }
        }
    ],
    "wellheadElevation": {
        "datum": null,
        "uom": null,
        "value": null
    },
    "field": "",
    "wellCRS": [
        {
            "uid": "",
            "localCRS": {
                "yaxisAzimuth": {
                    "uom": "",
                    "northDirection": null,
                    "value": null
                },
                "origin": {
                    "value": "",
                    "uidRef": null
                },
                "yaxisDescription": "",
                "originDescription": ""
            },
            "geographic": {
                "ztranslation": {
                    "uom": "",
                    "value": null
                },
                "xtranslation": {
                    "uom": "",
                    "value": null
                },
                "yrotation": {
                    "uom": "",
                    "value": null
                },
                "scaleFactor": null,
                "ellipsoidCode": null,
                "geodeticDatumCode": null,
                "ellipsoidSemiMajorAxis": {
                    "uom": "",
                    "value": null
                },
                "ytranslation": {
                    "uom": "",
                    "value": null
                },
                "nameCRS": {
                    "namingSystem": "",
                    "code": "",
                    "value": ""
                },
                "ellipsoidInverseFlattening": null,
                "xrotation": {
                    "uom": "",
                    "value": null
                },
                "zrotation": {
                    "uom": "",
                    "value": null
                }
            },
            "mapProjection": {
                "latitudeForScale": {
                    "uom": "",
                    "value": null
                },
                "originLatitude": {
                    "uom": "",
                    "value": null
                },
                "projectionCode": null,
                "falseNorthing": {
                    "uom": "",
                    "value": null
                },
                "description": "",
                "latitude1": {
                    "uom": "",
                    "value": null
                },
                "latitude2": {
                    "uom": "",
                    "value": null
                },
                "zone": "",
                "parameter": [
                    {
                        "uid": null,
                        "uom": "",
                        "name": "",
                        "index": 0,
                        "description": "",
                        "value": ""
                    }
                ],
                "hemisphere": null,
                "spheroidRadius": {
                    "uom": "",
                    "value": null
                },
                "longitudeForScale": {
                    "uom": "",
                    "value": null
                },
                "nadtype": null,
                "stdParallel1": {
                    "uom": "",
                    "value": null
                },
                "trueScaleLatitude": {
                    "uom": "",
                    "value": null
                },
                "projectedFrom": {
                    "value": "",
                    "uidRef": ""
                },
                "perspectiveHeight": {
                    "uom": "",
                    "value": null
                },
                "bearing": {
                    "uom": "",
                    "value": null
                },
                "scaleFactor": null,
                "centralMeridian": {
                    "uom": "",
                    "value": null
                },
                "methodVariant": null,
                "stdParallel2": {
                    "uom": "",
                    "value": null
                },
                "longitude2": {
                    "uom": "",
                    "value": null
                },
                "longitude1": {
                    "uom": "",
                    "value": null
                },
                "originLongitude": {
                    "uom": "",
                    "value": null
                },
                "nameCRS": {
                    "namingSystem": "",
                    "code": "",
                    "value": ""
                },
                "falseEasting": {
                    "uom": "",
                    "value": null
                }
            },
            "name": "",
            "description": "",
            "extensionNameValue": []
        }
    ],
    "district": "",
    "name": "",
    "numGovt": "",
    "region": "",
    "wellDatum": [
        {
            "elevation": {
                "datum": "",
                "uom": null,
                "value": null
            },
            "rig": {
                "wellboreParent": {
                    "value": "",
                    "uidRef": null
                },
                "rigReference": {
                    "value": "",
                    "uidRef": null
                },
                "wellParent": {
                    "value": "",
                    "uidRef": null
                }
            },
            "uid": "",
            "wellbore": {
                "wellParent": {
                    "value": "",
                    "uidRef": null
                },
                "wellboreReference": {
                    "value": "",
                    "uidRef": null
                }
            },
            "datumName": {
                "namingSystem": null,
                "code": null,
                "value": ""
            },
            "kind": [
                ""
            ],
            "measuredDepth": {
                "datum": "",
                "uom": null,
                "value": null
            },
            "name": "",
            "comment": "",
            "extensionNameValue": []
        }
    ]
}

Once converted to XML via the WOL...this then results in the following XML response to the GetFromStore request:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<wells version="1.3.1.1" xmlns="http://www.witsml.org/schemas/131">
<well uid="uid12333">
<name>Well hm1223</name>
<nameLegal>Company Legal Name</nameLegal>
<numLicense>Company License Number</numLicense>
<numGovt>Govt-Number</numGovt>
<field>FunctionalTest</field>
<country>US</country>
<state>TX</state>
<county>Montgomery</county>
<region>Region Name</region>
<district>District Name</district>
<block>Block Name</block>
<timeZone>-06:00</timeZone>
<operator>Operating Company</operator>
<wellDatum uid="">
<name>
</name>
<datumName>
</datumName>
<kind>
</kind>
<wellbore>
<wellboreReference>
</wellboreReference>
<wellParent>
</wellParent>
</wellbore>
<rig>
<rigReference>
</rigReference>
<wellboreParent>
</wellboreParent>
<wellParent>
</wellParent>
</rig>
<elevation datum="" />
<measuredDepth datum="" />
<comment>
</comment>
</wellDatum>
<wellLocation>
<wellCRS uidRef="">
</wellCRS>
<latitude uom="" />
<longitude uom="" />
<easting uom="" />
<northing uom="" />
<westing uom="" />
<southing uom="" />
<projectedX uom="" />
<projectedY uom="" />
<localX uom="" />
<localY uom="" />
<description>
</description>
</wellLocation>
<referencePoint uid="">
<name>
</name>
<type>
</type>
<elevation datum="" />
<measuredDepth datum="" />
<location>
<wellCRS uidRef="">
</wellCRS>
<latitude uom="" />
<longitude uom="" />
<easting uom="" />
<northing uom="" />
<westing uom="" />
<southing uom="" />
<projectedX uom="" />
<projectedY uom="" />
<localX uom="" />
<localY uom="" />
<description>
</description>
</location>
<description>
</description>
</referencePoint>
<wellCRS uid="">
<name>
</name>
<mapProjection>
<nameCRS namingSystem="" code="">
</nameCRS>
<projectedFrom uidRef="">
</projectedFrom>
<stdParallel1 uom="" />
<stdParallel2 uom="" />
<centralMeridian uom="" />
<originLatitude uom="" />
<originLongitude uom="" />
<latitude1 uom="" />
<longitude1 uom="" />
<latitude2 uom="" />
<longitude2 uom="" />
<latitudeForScale uom="" />
<longitudeForScale uom="" />
<trueScaleLatitude uom="" />
<spheroidRadius uom="" />
<perspectiveHeight uom="" />
<zone>
</zone>
<falseEasting uom="" />
<falseNorthing uom="" />
<bearing uom="" />
<description>
</description>
<parameter index="0" name="" uom="" description="">
</parameter>
</mapProjection>
<geographic>
<nameCRS namingSystem="" code="">
</nameCRS>
<xTranslation uom="" />
<yTranslation uom="" />
<zTranslation uom="" />
<xRotation uom="" />
<yRotation uom="" />
<zRotation uom="" />
<ellipsoidSemiMajorAxis uom="" />
</geographic>
<localCRS>
<origin>
</origin>
<originDescription>
</originDescription>
<yAxisAzimuth uom="" />
<yAxisDescription>
</yAxisDescription>
</localCRS>
<description>
</description>
</wellCRS>
</well>
</wells>

The Expected response should be:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<wells version="1.3.1.1" xmlns="http://www.witsml.org/schemas/131">
<well uid="uid12333">
<name>Well hm1223</name>
<nameLegal>Company Legal Name</nameLegal>
<numLicense>Company License Number</numLicense>
<numGovt>Govt-Number</numGovt>
<field>FunctionalTest</field>
<country>US</country>
<state>TX</state>
<county>Montgomery</county>
<region>Region Name</region>
<district>District Name</district>
<block>Block Name</block>
<timeZone>-06:00</timeZone>
<operator>Operating Company</operator>
</well>
</wells>
randypitcherii commented 5 years ago

Thanks for the detailed behavior, Chris.

I've fixed the core issue, which was our poorly-done JSONArray merging.