Search in sources :

Example 6 with BatchRequest

use of com.b2international.snowowl.fhir.core.model.BatchRequest in project snow-owl by b2ihealthcare.

the class FhirParametersRequestEntryProcessor method doProcess.

@Override
public void doProcess(ArrayNode arrayNode, HttpServletRequest request) throws JsonMappingException, JsonProcessingException {
    BatchRequest batchRequest = requestEntry.getRequest();
    Code requestMethod = batchRequest.getMethod();
    if (!requestMethod.equals(HttpVerb.POST.getCode())) {
        createInvalidMethodResponse(arrayNode, requestMethod);
        return;
    }
    HttpHeaders headers = getHeaders(request);
    RestTemplate restTemplate = getRestTemplate();
    StringBuilder uriBuilder = new StringBuilder(request.getScheme()).append("://").append(request.getServerName()).append(":").append(request.getLocalPort()).append(request.getRequestURI()).append(batchRequest.getUrl().getUriValue());
    // TODO: change the RequestEntry to accommodate resources for non-operation bulk support
    HttpEntity<?> httpEntity = new HttpEntity<>(requestEntry.getRequestResource(), headers);
    ResponseEntity<String> response = restTemplate.exchange(uriBuilder.toString(), HttpMethod.POST, httpEntity, String.class);
    String json = response.getBody();
    ObjectNode resourceNode = (ObjectNode) objectMapper.readTree(json);
    addResponse(arrayNode, resourceNode, String.valueOf(response.getStatusCode().value()));
}
Also used : BatchRequest(com.b2international.snowowl.fhir.core.model.BatchRequest) HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) RestTemplate(org.springframework.web.client.RestTemplate) Code(com.b2international.snowowl.fhir.core.model.dt.Code)

Aggregations

BatchRequest (com.b2international.snowowl.fhir.core.model.BatchRequest)6 Bundle (com.b2international.snowowl.fhir.core.model.Bundle)3 Entry (com.b2international.snowowl.fhir.core.model.Entry)3 OperationOutcomeEntry (com.b2international.snowowl.fhir.core.model.OperationOutcomeEntry)3 ParametersRequestEntry (com.b2international.snowowl.fhir.core.model.ParametersRequestEntry)3 ParametersResponseEntry (com.b2international.snowowl.fhir.core.model.ParametersResponseEntry)3 ResourceRequestEntry (com.b2international.snowowl.fhir.core.model.ResourceRequestEntry)3 ResourceResponseEntry (com.b2international.snowowl.fhir.core.model.ResourceResponseEntry)3 Code (com.b2international.snowowl.fhir.core.model.dt.Code)3 FhirTest (com.b2international.snowowl.fhir.tests.FhirTest)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 Test (org.junit.Test)3 HttpEntity (org.springframework.http.HttpEntity)3 HttpHeaders (org.springframework.http.HttpHeaders)3 RestTemplate (org.springframework.web.client.RestTemplate)3 Link (com.b2international.snowowl.fhir.core.model.Link)2 LookupRequest (com.b2international.snowowl.fhir.core.model.codesystem.LookupRequest)2 Fhir (com.b2international.snowowl.fhir.core.model.dt.Parameters.Fhir)2 Json (com.b2international.snowowl.fhir.core.model.dt.Parameters.Json)2 FhirResource (com.b2international.snowowl.fhir.core.model.FhirResource)1