Search in sources :

Example 6 with OperationOutcome

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

the class OperationOutcomeTest method serialize.

@Test
public void serialize() throws JsonProcessingException {
    OperationOutcome operationOutcome = OperationOutcome.builder().addIssue(Issue.builder().severity(IssueSeverity.ERROR).code(IssueType.REQUIRED).addLocation("location").build()).build();
    JsonPath jsonPath = JsonPath.from(objectMapper.writeValueAsString(operationOutcome));
    assertThat(jsonPath.getString("resourceType"), equalTo("OperationOutcome"));
    jsonPath.setRoot("issue[0]");
    assertThat(jsonPath.getString("severity"), equalTo("error"));
    assertThat(jsonPath.getString("code"), equalTo("required"));
    assertThat(jsonPath.getList("location"), equalTo(Lists.newArrayList("location")));
}
Also used : OperationOutcome(com.b2international.snowowl.fhir.core.model.OperationOutcome) JsonPath(io.restassured.path.json.JsonPath) FhirTest(com.b2international.snowowl.fhir.tests.FhirTest) Test(org.junit.Test)

Example 7 with OperationOutcome

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

the class AbstractFhirController method handle.

@ExceptionHandler
@ResponseStatus(HttpStatus.UNAUTHORIZED)
@ResponseBody
public ResponseEntity<OperationOutcome> handle(final UnauthorizedException ex) {
    FhirException fhirException = FhirException.createFhirError(ex.getMessage(), OperationOutcomeCode.MSG_AUTH_REQUIRED);
    OperationOutcome body = fhirException.toOperationOutcome();
    HttpHeaders headers = new HttpHeaders();
    headers.add("WWW-Authenticate", "Basic");
    headers.add("WWW-Authenticate", "Bearer");
    return new ResponseEntity<>(body, headers, HttpStatus.UNAUTHORIZED);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) FhirException(com.b2international.snowowl.fhir.core.exceptions.FhirException) OperationOutcome(com.b2international.snowowl.fhir.core.model.OperationOutcome) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

OperationOutcome (com.b2international.snowowl.fhir.core.model.OperationOutcome)7 FhirTest (com.b2international.snowowl.fhir.tests.FhirTest)5 Test (org.junit.Test)5 Issue (com.b2international.snowowl.fhir.core.model.Issue)4 Bundle (com.b2international.snowowl.fhir.core.model.Bundle)2 OperationOutcomeEntry (com.b2international.snowowl.fhir.core.model.OperationOutcomeEntry)2 FhirException (com.b2international.snowowl.fhir.core.exceptions.FhirException)1 BatchResponse (com.b2international.snowowl.fhir.core.model.BatchResponse)1 Entry (com.b2international.snowowl.fhir.core.model.Entry)1 Link (com.b2international.snowowl.fhir.core.model.Link)1 ParametersRequestEntry (com.b2international.snowowl.fhir.core.model.ParametersRequestEntry)1 ParametersResponseEntry (com.b2international.snowowl.fhir.core.model.ParametersResponseEntry)1 ResourceRequestEntry (com.b2international.snowowl.fhir.core.model.ResourceRequestEntry)1 ResourceResponseEntry (com.b2international.snowowl.fhir.core.model.ResourceResponseEntry)1 LookupResult (com.b2international.snowowl.fhir.core.model.codesystem.LookupResult)1 CodeableConcept (com.b2international.snowowl.fhir.core.model.dt.CodeableConcept)1 Coding (com.b2international.snowowl.fhir.core.model.dt.Coding)1 Parameters (com.b2international.snowowl.fhir.core.model.dt.Parameters)1 Fhir (com.b2international.snowowl.fhir.core.model.dt.Parameters.Fhir)1 Json (com.b2international.snowowl.fhir.core.model.dt.Parameters.Json)1