@Test public void stationLocationOnlyTrajectoryTest() throws JAXBException, IOException, ValveException, DatatypeConfigurationException { String dotResponse = TestUtilities.getResourceAsString("trajectory1411.xml"); String soapQuery = TestUtilities.getResourceAsString("trajectoryGraphql/FullTrajectoryQuery1411.xml"); com.hashmapinc.tempus.WitsmlObjects.v1411.ObjTrajectorys trajQuery = WitsmlMarshal.deserialize(soapQuery, com.hashmapinc.tempus.WitsmlObjects.v1411.ObjTrajectorys.class); AbstractWitsmlObject trajQuerySingular = trajQuery.getTrajectory().get(0); com.hashmapinc.tempus.WitsmlObjects.v1411.ObjTrajectorys respTrajs = WitsmlMarshal.deserialize(dotResponse, com.hashmapinc.tempus.WitsmlObjects.v1411.ObjTrajectorys.class); AbstractWitsmlObject respTraj = respTrajs.getTrajectory().get(0); String respJson = respTraj.getJSONString("1.4.1.1"); Map<String,String> optionsIn = new HashMap<>(); optionsIn.put("returnElements", "station-location-only"); AbstractWitsmlObject resp = DotTranslator.translateQueryResponse(trajQuerySingular, respJson, optionsIn); com.hashmapinc.tempus.WitsmlObjects.v1411.ObjTrajectory resultTraj = (com.hashmapinc.tempus.WitsmlObjects.v1411.ObjTrajectory)resp; assertNull(resultTraj.getServiceCompany()); assertNull(resultTraj.getGridCorUsed()); assertNull(resultTraj.getAziRef()); assertNull(resultTraj.getMagDeclUsed()); assertNull(resultTraj.getAziVertSect()); assertNotNull(resultTraj.getName()); assertNotNull(resultTraj.getUid()); assertNotNull(resultTraj.getNameWell()); assertNotNull(resultTraj.getUidWell()); assertNotNull(resultTraj.getNameWellbore()); assertNotNull(resultTraj.getUidWellbore()); assertNotNull(resultTraj.getTrajectoryStation()); assertEquals(1, resultTraj.getTrajectoryStation().size()); }
public static AbstractWitsmlObject translateQueryResponse( AbstractWitsmlObject wmlObject, String jsonResponseString, Map<String, String> optionsIn ) throws ValveException, DatatypeConfigurationException { JSONObject queryJson; if ("1.4.1.1".equals(wmlObject.getVersion())) { queryJson = new JSONObject(wmlObject.getJSONString("1.4.1.1")); } else { queryJson = new JSONObject(wmlObject.getJSONString("1.3.1.1")); } JSONObject responseJson = new JSONObject(jsonResponseString); String result = responseJson.toString(); if ( "requested".equals(optionsIn.get("returnElements")) || "id-only".equals(optionsIn.get("returnElements")) ) { if ("id-only".equals(optionsIn.get("returnElements"))) { queryJson = QueryTemplateProvider.getIDOnly(wmlObject.getObjectType()); } result = JsonUtil.merge(queryJson, responseJson).toString(); } result = result.replaceAll("\"dtimTrajStart\":","\"dTimTrajStart\":"); result = result.replaceAll("\"dtimTrajEnd\":","\"dTimTrajEnd\":"); result = result.replaceAll("\"dtimStn\":","\"dTimStn\":"); LOG.finest("Converting DoT JSON response to valid XML string"); try { switch ( wmlObject.getObjectType() ) { case "well": return WitsmlMarshal.deserializeFromJSON( result, ObjWell.class); case "wellbore": return WitsmlMarshal.deserializeFromJSON( result, ObjWellbore.class); case "trajectory": ObjTrajectory traj = WitsmlMarshal.deserializeFromJSON(result, ObjTrajectory.class); if("station-location-only".equals(optionsIn.get("returnElements")) || "data-only".equals(optionsIn.get("returnElements"))) { return buildStationOnlyTrajectory(traj); } else if ("header-only".equals(optionsIn.get("returnElements"))) { traj.setTrajectoryStation(null); return traj; } return traj; case "log": if ("1.3.1.1".equals(wmlObject.getVersion())) { return WitsmlMarshal.deserializeFromJSON(result, com.hashmapinc.tempus.WitsmlObjects.v1311.ObjLog.class); } else { return WitsmlMarshal.deserializeFromJSON(result, ObjLog.class); } default: throw new ValveException("unsupported object type"); } } catch (IOException ioe) { throw new ValveException(ioe.getMessage()); } }
DotTranslator { public static AbstractWitsmlObject translateQueryResponse( AbstractWitsmlObject wmlObject, String jsonResponseString, Map<String, String> optionsIn ) throws ValveException, DatatypeConfigurationException { JSONObject queryJson; if ("1.4.1.1".equals(wmlObject.getVersion())) { queryJson = new JSONObject(wmlObject.getJSONString("1.4.1.1")); } else { queryJson = new JSONObject(wmlObject.getJSONString("1.3.1.1")); } JSONObject responseJson = new JSONObject(jsonResponseString); String result = responseJson.toString(); if ( "requested".equals(optionsIn.get("returnElements")) || "id-only".equals(optionsIn.get("returnElements")) ) { if ("id-only".equals(optionsIn.get("returnElements"))) { queryJson = QueryTemplateProvider.getIDOnly(wmlObject.getObjectType()); } result = JsonUtil.merge(queryJson, responseJson).toString(); } result = result.replaceAll("\"dtimTrajStart\":","\"dTimTrajStart\":"); result = result.replaceAll("\"dtimTrajEnd\":","\"dTimTrajEnd\":"); result = result.replaceAll("\"dtimStn\":","\"dTimStn\":"); LOG.finest("Converting DoT JSON response to valid XML string"); try { switch ( wmlObject.getObjectType() ) { case "well": return WitsmlMarshal.deserializeFromJSON( result, ObjWell.class); case "wellbore": return WitsmlMarshal.deserializeFromJSON( result, ObjWellbore.class); case "trajectory": ObjTrajectory traj = WitsmlMarshal.deserializeFromJSON(result, ObjTrajectory.class); if("station-location-only".equals(optionsIn.get("returnElements")) || "data-only".equals(optionsIn.get("returnElements"))) { return buildStationOnlyTrajectory(traj); } else if ("header-only".equals(optionsIn.get("returnElements"))) { traj.setTrajectoryStation(null); return traj; } return traj; case "log": if ("1.3.1.1".equals(wmlObject.getVersion())) { return WitsmlMarshal.deserializeFromJSON(result, com.hashmapinc.tempus.WitsmlObjects.v1311.ObjLog.class); } else { return WitsmlMarshal.deserializeFromJSON(result, ObjLog.class); } default: throw new ValveException("unsupported object type"); } } catch (IOException ioe) { throw new ValveException(ioe.getMessage()); } } }
DotTranslator { public static AbstractWitsmlObject translateQueryResponse( AbstractWitsmlObject wmlObject, String jsonResponseString, Map<String, String> optionsIn ) throws ValveException, DatatypeConfigurationException { JSONObject queryJson; if ("1.4.1.1".equals(wmlObject.getVersion())) { queryJson = new JSONObject(wmlObject.getJSONString("1.4.1.1")); } else { queryJson = new JSONObject(wmlObject.getJSONString("1.3.1.1")); } JSONObject responseJson = new JSONObject(jsonResponseString); String result = responseJson.toString(); if ( "requested".equals(optionsIn.get("returnElements")) || "id-only".equals(optionsIn.get("returnElements")) ) { if ("id-only".equals(optionsIn.get("returnElements"))) { queryJson = QueryTemplateProvider.getIDOnly(wmlObject.getObjectType()); } result = JsonUtil.merge(queryJson, responseJson).toString(); } result = result.replaceAll("\"dtimTrajStart\":","\"dTimTrajStart\":"); result = result.replaceAll("\"dtimTrajEnd\":","\"dTimTrajEnd\":"); result = result.replaceAll("\"dtimStn\":","\"dTimStn\":"); LOG.finest("Converting DoT JSON response to valid XML string"); try { switch ( wmlObject.getObjectType() ) { case "well": return WitsmlMarshal.deserializeFromJSON( result, ObjWell.class); case "wellbore": return WitsmlMarshal.deserializeFromJSON( result, ObjWellbore.class); case "trajectory": ObjTrajectory traj = WitsmlMarshal.deserializeFromJSON(result, ObjTrajectory.class); if("station-location-only".equals(optionsIn.get("returnElements")) || "data-only".equals(optionsIn.get("returnElements"))) { return buildStationOnlyTrajectory(traj); } else if ("header-only".equals(optionsIn.get("returnElements"))) { traj.setTrajectoryStation(null); return traj; } return traj; case "log": if ("1.3.1.1".equals(wmlObject.getVersion())) { return WitsmlMarshal.deserializeFromJSON(result, com.hashmapinc.tempus.WitsmlObjects.v1311.ObjLog.class); } else { return WitsmlMarshal.deserializeFromJSON(result, ObjLog.class); } default: throw new ValveException("unsupported object type"); } } catch (IOException ioe) { throw new ValveException(ioe.getMessage()); } }  }
DotTranslator { public static AbstractWitsmlObject translateQueryResponse( AbstractWitsmlObject wmlObject, String jsonResponseString, Map<String, String> optionsIn ) throws ValveException, DatatypeConfigurationException { JSONObject queryJson; if ("1.4.1.1".equals(wmlObject.getVersion())) { queryJson = new JSONObject(wmlObject.getJSONString("1.4.1.1")); } else { queryJson = new JSONObject(wmlObject.getJSONString("1.3.1.1")); } JSONObject responseJson = new JSONObject(jsonResponseString); String result = responseJson.toString(); if ( "requested".equals(optionsIn.get("returnElements")) || "id-only".equals(optionsIn.get("returnElements")) ) { if ("id-only".equals(optionsIn.get("returnElements"))) { queryJson = QueryTemplateProvider.getIDOnly(wmlObject.getObjectType()); } result = JsonUtil.merge(queryJson, responseJson).toString(); } result = result.replaceAll("\"dtimTrajStart\":","\"dTimTrajStart\":"); result = result.replaceAll("\"dtimTrajEnd\":","\"dTimTrajEnd\":"); result = result.replaceAll("\"dtimStn\":","\"dTimStn\":"); LOG.finest("Converting DoT JSON response to valid XML string"); try { switch ( wmlObject.getObjectType() ) { case "well": return WitsmlMarshal.deserializeFromJSON( result, ObjWell.class); case "wellbore": return WitsmlMarshal.deserializeFromJSON( result, ObjWellbore.class); case "trajectory": ObjTrajectory traj = WitsmlMarshal.deserializeFromJSON(result, ObjTrajectory.class); if("station-location-only".equals(optionsIn.get("returnElements")) || "data-only".equals(optionsIn.get("returnElements"))) { return buildStationOnlyTrajectory(traj); } else if ("header-only".equals(optionsIn.get("returnElements"))) { traj.setTrajectoryStation(null); return traj; } return traj; case "log": if ("1.3.1.1".equals(wmlObject.getVersion())) { return WitsmlMarshal.deserializeFromJSON(result, com.hashmapinc.tempus.WitsmlObjects.v1311.ObjLog.class); } else { return WitsmlMarshal.deserializeFromJSON(result, ObjLog.class); } default: throw new ValveException("unsupported object type"); } } catch (IOException ioe) { throw new ValveException(ioe.getMessage()); } }  static AbstractWitsmlObject get1311WitsmlObject(AbstractWitsmlObject wmlObj); static AbstractWitsmlObject translateQueryResponse( AbstractWitsmlObject wmlObject,
                                                               String jsonResponseString,
                                                               Map<String, String> optionsIn ); static AbstractWitsmlObject createFsRQueryResponse( String jsonResponseString,
                                                               AbstractWitsmlObject witsmlObject ); static String consolidateObjectsToXML(
            ArrayList<AbstractWitsmlObject> witsmlObjects,
            String version,
            String objectType
    ); }
DotTranslator { public static AbstractWitsmlObject translateQueryResponse( AbstractWitsmlObject wmlObject, String jsonResponseString, Map<String, String> optionsIn ) throws ValveException, DatatypeConfigurationException { JSONObject queryJson; if ("1.4.1.1".equals(wmlObject.getVersion())) { queryJson = new JSONObject(wmlObject.getJSONString("1.4.1.1")); } else { queryJson = new JSONObject(wmlObject.getJSONString("1.3.1.1")); } JSONObject responseJson = new JSONObject(jsonResponseString); String result = responseJson.toString(); if ( "requested".equals(optionsIn.get("returnElements")) || "id-only".equals(optionsIn.get("returnElements")) ) { if ("id-only".equals(optionsIn.get("returnElements"))) { queryJson = QueryTemplateProvider.getIDOnly(wmlObject.getObjectType()); } result = JsonUtil.merge(queryJson, responseJson).toString(); } result = result.replaceAll("\"dtimTrajStart\":","\"dTimTrajStart\":"); result = result.replaceAll("\"dtimTrajEnd\":","\"dTimTrajEnd\":"); result = result.replaceAll("\"dtimStn\":","\"dTimStn\":"); LOG.finest("Converting DoT JSON response to valid XML string"); try { switch ( wmlObject.getObjectType() ) { case "well": return WitsmlMarshal.deserializeFromJSON( result, ObjWell.class); case "wellbore": return WitsmlMarshal.deserializeFromJSON( result, ObjWellbore.class); case "trajectory": ObjTrajectory traj = WitsmlMarshal.deserializeFromJSON(result, ObjTrajectory.class); if("station-location-only".equals(optionsIn.get("returnElements")) || "data-only".equals(optionsIn.get("returnElements"))) { return buildStationOnlyTrajectory(traj); } else if ("header-only".equals(optionsIn.get("returnElements"))) { traj.setTrajectoryStation(null); return traj; } return traj; case "log": if ("1.3.1.1".equals(wmlObject.getVersion())) { return WitsmlMarshal.deserializeFromJSON(result, com.hashmapinc.tempus.WitsmlObjects.v1311.ObjLog.class); } else { return WitsmlMarshal.deserializeFromJSON(result, ObjLog.class); } default: throw new ValveException("unsupported object type"); } } catch (IOException ioe) { throw new ValveException(ioe.getMessage()); } }  static AbstractWitsmlObject get1311WitsmlObject(AbstractWitsmlObject wmlObj); static AbstractWitsmlObject translateQueryResponse( AbstractWitsmlObject wmlObject,
                                                               String jsonResponseString,
                                                               Map<String, String> optionsIn ); static AbstractWitsmlObject createFsRQueryResponse( String jsonResponseString,
                                                               AbstractWitsmlObject witsmlObject ); static String consolidateObjectsToXML(
            ArrayList<AbstractWitsmlObject> witsmlObjects,
            String version,
            String objectType
    );  }