@Test public void shouldCreateTrajectoryWithUid() throws Exception { ObjTrajectory traj = new ObjTrajectory(); traj.setUid("traj-a"); traj.setName("traj-a"); traj.setUidWellbore("wellbore-a"); traj.setUidWell("well-a"); String payload = ((AbstractWitsmlObject) traj).getJSONString("1.4.1.1"); String endpoint = this.url + this.trajectoryPath + traj.getUid(); HttpRequestWithBody req = Unirest.put(endpoint); req.header("Content-Type", "application/json"); req.body(payload); req.queryString("uidWellbore", traj.getUidWellbore()); req.queryString("uidWell", traj.getUidWell()); HttpResponse<String> resp = mock(HttpResponse.class); when(resp.getBody()).thenReturn("{\"uid\": \"" + traj.getUid() + "\"}"); when(resp.getStatus()).thenReturn(200); when(this.mockClient.makeRequest(argThat(someReq -> ( someReq.getHttpMethod().name().equals(req.getHttpMethod().name()) && someReq.getUrl().equals(req.getUrl()) && someReq.getHeaders().containsKey("Content-Type") )), eq("goodUsername"), eq("goodPassword"), anyString())).thenReturn(resp); String actualUid = this.delegator.createObject( traj, "goodUsername", "goodPassword", "exchangeID", this.mockClient ); String expectedUid = traj.getUid(); assertEquals(expectedUid, actualUid); }
public String createObject(AbstractWitsmlObject witsmlObj, String username, String password, String exchangeID, DotClient client) throws ValveException, ValveAuthException, UnirestException, JsonProcessingException { String objectType = witsmlObj.getObjectType(); if ("log".equals(objectType)) { String response = createLogObject(witsmlObj, username, password, exchangeID, client); return response; } if ("fluidsReport".equalsIgnoreCase(objectType)) { String response = createFluidsReportObject(witsmlObj, username, password, exchangeID, client); return response; } String uid = witsmlObj.getUid(); String endpoint = this.getEndpoint(objectType); String payload = witsmlObj.getJSONString("1.4.1.1"); HttpRequestWithBody request; if (null == uid || uid.isEmpty()) { request = Unirest.post(endpoint); } else { request = Unirest.put(endpoint + uid); } if ("wellbore".equals(objectType)) { request.queryString("uidWell", witsmlObj.getParentUid()); } else if ("trajectory".equals(objectType)) { request.queryString("uidWellbore", witsmlObj.getParentUid()); request.queryString("uidWell", witsmlObj.getGrandParentUid()); } request.header("Content-Type", "application/json"); request.body(payload); HttpResponse<String> response = client.makeRequest(request, username, password, exchangeID); int status = response.getStatus(); if (201 == status || 200 == status) { return (null == uid || uid.isEmpty()) ? new JsonNode(response.getBody()).getObject().getString("uid") : uid; } else { throw new ValveException(response.getBody()); } }
DotDelegator { public String createObject(AbstractWitsmlObject witsmlObj, String username, String password, String exchangeID, DotClient client) throws ValveException, ValveAuthException, UnirestException, JsonProcessingException { String objectType = witsmlObj.getObjectType(); if ("log".equals(objectType)) { String response = createLogObject(witsmlObj, username, password, exchangeID, client); return response; } if ("fluidsReport".equalsIgnoreCase(objectType)) { String response = createFluidsReportObject(witsmlObj, username, password, exchangeID, client); return response; } String uid = witsmlObj.getUid(); String endpoint = this.getEndpoint(objectType); String payload = witsmlObj.getJSONString("1.4.1.1"); HttpRequestWithBody request; if (null == uid || uid.isEmpty()) { request = Unirest.post(endpoint); } else { request = Unirest.put(endpoint + uid); } if ("wellbore".equals(objectType)) { request.queryString("uidWell", witsmlObj.getParentUid()); } else if ("trajectory".equals(objectType)) { request.queryString("uidWellbore", witsmlObj.getParentUid()); request.queryString("uidWell", witsmlObj.getGrandParentUid()); } request.header("Content-Type", "application/json"); request.body(payload); HttpResponse<String> response = client.makeRequest(request, username, password, exchangeID); int status = response.getStatus(); if (201 == status || 200 == status) { return (null == uid || uid.isEmpty()) ? new JsonNode(response.getBody()).getObject().getString("uid") : uid; } else { throw new ValveException(response.getBody()); } } }
DotDelegator { public String createObject(AbstractWitsmlObject witsmlObj, String username, String password, String exchangeID, DotClient client) throws ValveException, ValveAuthException, UnirestException, JsonProcessingException { String objectType = witsmlObj.getObjectType(); if ("log".equals(objectType)) { String response = createLogObject(witsmlObj, username, password, exchangeID, client); return response; } if ("fluidsReport".equalsIgnoreCase(objectType)) { String response = createFluidsReportObject(witsmlObj, username, password, exchangeID, client); return response; } String uid = witsmlObj.getUid(); String endpoint = this.getEndpoint(objectType); String payload = witsmlObj.getJSONString("1.4.1.1"); HttpRequestWithBody request; if (null == uid || uid.isEmpty()) { request = Unirest.post(endpoint); } else { request = Unirest.put(endpoint + uid); } if ("wellbore".equals(objectType)) { request.queryString("uidWell", witsmlObj.getParentUid()); } else if ("trajectory".equals(objectType)) { request.queryString("uidWellbore", witsmlObj.getParentUid()); request.queryString("uidWell", witsmlObj.getGrandParentUid()); } request.header("Content-Type", "application/json"); request.body(payload); HttpResponse<String> response = client.makeRequest(request, username, password, exchangeID); int status = response.getStatus(); if (201 == status || 200 == status) { return (null == uid || uid.isEmpty()) ? new JsonNode(response.getBody()).getObject().getString("uid") : uid; } else { throw new ValveException(response.getBody()); } } DotDelegator(Map<String, String> config); }
DotDelegator { public String createObject(AbstractWitsmlObject witsmlObj, String username, String password, String exchangeID, DotClient client) throws ValveException, ValveAuthException, UnirestException, JsonProcessingException { String objectType = witsmlObj.getObjectType(); if ("log".equals(objectType)) { String response = createLogObject(witsmlObj, username, password, exchangeID, client); return response; } if ("fluidsReport".equalsIgnoreCase(objectType)) { String response = createFluidsReportObject(witsmlObj, username, password, exchangeID, client); return response; } String uid = witsmlObj.getUid(); String endpoint = this.getEndpoint(objectType); String payload = witsmlObj.getJSONString("1.4.1.1"); HttpRequestWithBody request; if (null == uid || uid.isEmpty()) { request = Unirest.post(endpoint); } else { request = Unirest.put(endpoint + uid); } if ("wellbore".equals(objectType)) { request.queryString("uidWell", witsmlObj.getParentUid()); } else if ("trajectory".equals(objectType)) { request.queryString("uidWellbore", witsmlObj.getParentUid()); request.queryString("uidWell", witsmlObj.getGrandParentUid()); } request.header("Content-Type", "application/json"); request.body(payload); HttpResponse<String> response = client.makeRequest(request, username, password, exchangeID); int status = response.getStatus(); if (201 == status || 200 == status) { return (null == uid || uid.isEmpty()) ? new JsonNode(response.getBody()).getObject().getString("uid") : uid; } else { throw new ValveException(response.getBody()); } } DotDelegator(Map<String, String> config); void deleteObject(AbstractWitsmlObject witsmlObj, String username, String password, String exchangeID,
			DotClient client); void performElementDelete(AbstractWitsmlObject witsmlObj, String username, String password,
			String exchangeID, DotClient client); void updateObject(AbstractWitsmlObject witsmlObj, String username, String password, String exchangeID,
			DotClient client); String updateFluidsReport(AbstractWitsmlObject witsmlObj, String username, String password,
			String exchangeID, DotClient client); void updateLog(AbstractWitsmlObject witsmlObj, String username, String password, String exchangeID,
			DotClient client, String payload); String getUuid(AbstractWitsmlObject witsmlObj, String uid, DotClient client, String username,
			String password, String exchangeID); String createObject(AbstractWitsmlObject witsmlObj, String username, String password, String exchangeID,
			DotClient client); String createFluidsReportObject(AbstractWitsmlObject witsmlObj, String username, String password,
			String exchangeID, DotClient client); String createLogObject(AbstractWitsmlObject witsmlObj, String username, String password, String exchangeID,
			DotClient client); static short mnemonicsChecks( String channelPayload,
										 String dataPayload,
										 String version ); HttpResponse<String> performPost(String payload, String endpoint, HashMap<String, String> requestParams,
			DotClient client, String username, String password, String exchangeID); String[] getMappedPayloads4Log(String version, String payload, AbstractWitsmlObject witsmlObj); AbstractWitsmlObject getObject(AbstractWitsmlObject witsmlObject, String username, String password,
			String exchangeID, DotClient client, Map<String, String> optionsIn); ArrayList<AbstractWitsmlObject> search(AbstractWitsmlObject witsmlObject, String username, String password,
			String exchangeID, DotClient client, Map<String, String> optionsIn); }
DotDelegator { public String createObject(AbstractWitsmlObject witsmlObj, String username, String password, String exchangeID, DotClient client) throws ValveException, ValveAuthException, UnirestException, JsonProcessingException { String objectType = witsmlObj.getObjectType(); if ("log".equals(objectType)) { String response = createLogObject(witsmlObj, username, password, exchangeID, client); return response; } if ("fluidsReport".equalsIgnoreCase(objectType)) { String response = createFluidsReportObject(witsmlObj, username, password, exchangeID, client); return response; } String uid = witsmlObj.getUid(); String endpoint = this.getEndpoint(objectType); String payload = witsmlObj.getJSONString("1.4.1.1"); HttpRequestWithBody request; if (null == uid || uid.isEmpty()) { request = Unirest.post(endpoint); } else { request = Unirest.put(endpoint + uid); } if ("wellbore".equals(objectType)) { request.queryString("uidWell", witsmlObj.getParentUid()); } else if ("trajectory".equals(objectType)) { request.queryString("uidWellbore", witsmlObj.getParentUid()); request.queryString("uidWell", witsmlObj.getGrandParentUid()); } request.header("Content-Type", "application/json"); request.body(payload); HttpResponse<String> response = client.makeRequest(request, username, password, exchangeID); int status = response.getStatus(); if (201 == status || 200 == status) { return (null == uid || uid.isEmpty()) ? new JsonNode(response.getBody()).getObject().getString("uid") : uid; } else { throw new ValveException(response.getBody()); } } DotDelegator(Map<String, String> config); void deleteObject(AbstractWitsmlObject witsmlObj, String username, String password, String exchangeID,
			DotClient client); void performElementDelete(AbstractWitsmlObject witsmlObj, String username, String password,
			String exchangeID, DotClient client); void updateObject(AbstractWitsmlObject witsmlObj, String username, String password, String exchangeID,
			DotClient client); String updateFluidsReport(AbstractWitsmlObject witsmlObj, String username, String password,
			String exchangeID, DotClient client); void updateLog(AbstractWitsmlObject witsmlObj, String username, String password, String exchangeID,
			DotClient client, String payload); String getUuid(AbstractWitsmlObject witsmlObj, String uid, DotClient client, String username,
			String password, String exchangeID); String createObject(AbstractWitsmlObject witsmlObj, String username, String password, String exchangeID,
			DotClient client); String createFluidsReportObject(AbstractWitsmlObject witsmlObj, String username, String password,
			String exchangeID, DotClient client); String createLogObject(AbstractWitsmlObject witsmlObj, String username, String password, String exchangeID,
			DotClient client); static short mnemonicsChecks( String channelPayload,
										 String dataPayload,
										 String version ); HttpResponse<String> performPost(String payload, String endpoint, HashMap<String, String> requestParams,
			DotClient client, String username, String password, String exchangeID); String[] getMappedPayloads4Log(String version, String payload, AbstractWitsmlObject witsmlObj); AbstractWitsmlObject getObject(AbstractWitsmlObject witsmlObject, String username, String password,
			String exchangeID, DotClient client, Map<String, String> optionsIn); ArrayList<AbstractWitsmlObject> search(AbstractWitsmlObject witsmlObject, String username, String password,
			String exchangeID, DotClient client, Map<String, String> optionsIn);  }