Search in sources :

Example 46 with Issue

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

the class SlicingTest method buildInvalid.

@Test
public void buildInvalid() {
    Issue expectedIssue = Issue.builder().code(IssueType.INVALID).severity(IssueSeverity.ERROR).diagnostics("1 validation error").addLocation("Slicing.rules").detailsWithDisplay(OperationOutcomeCode.MSG_PARAM_INVALID, "Parameter 'rules' content is invalid [null]. Violation: may not be null.").build();
    exception.expect(ValidationException.class);
    exception.expectMessage("1 validation error");
    exception.expect(FhirExceptionIssueMatcher.issue(expectedIssue));
    Slicing.builder().build();
}
Also used : Issue(com.b2international.snowowl.fhir.core.model.Issue) FhirTest(com.b2international.snowowl.fhir.tests.FhirTest) Test(org.junit.Test)

Example 47 with Issue

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

the class ValidationException method toOperationOutcome.

/**
 * Creates an OperationOutcome representation from this exception. Useful when
 * the exception must be propagated through protocols where Java serialization
 * cannot be used (eg. HTTP), or the possible receiver cannot understand
 * serialized Java class and object byte sequences.
 *
 * @return {@link OperationOutcome} representation of this
 *         {@link FhirException}, never <code>null</code>.
 */
@Override
public OperationOutcome toOperationOutcome() {
    if (violations.isEmpty()) {
        throw new IllegalArgumentException("There are no violations to report.");
    }
    Builder outcomeBuilder = OperationOutcome.builder();
    for (ConstraintViolation<?> violation : violations) {
        String issueDetails = String.format(getOperationOutcomeCode().getDisplayName(), violation.getPropertyPath());
        StringBuilder builder = new StringBuilder(issueDetails);
        builder.append(" [");
        builder.append(violation.getInvalidValue());
        builder.append("]. Violation: ");
        builder.append(violation.getMessage());
        builder.append(".");
        Coding coding = Coding.builder().code(getOperationOutcomeCode().getCodeValue()).system(OperationOutcomeCode.CODE_SYSTEM_URI).display(builder.toString()).build();
        CodeableConcept codeableConcept = CodeableConcept.builder().addCoding(coding).text(builder.toString()).build();
        String location = violation.getRootBean().getClass().getSimpleName() + "." + violation.getPropertyPath().toString();
        Issue issue = Issue.builder().severity(IssueSeverity.ERROR).code(IssueType.INVALID).details(codeableConcept).diagnostics(getMessage()).addLocation(location).build();
        outcomeBuilder.addIssue(issue);
    }
    return outcomeBuilder.build();
}
Also used : Issue(com.b2international.snowowl.fhir.core.model.Issue) Coding(com.b2international.snowowl.fhir.core.model.dt.Coding) Builder(com.b2international.snowowl.fhir.core.model.OperationOutcome.Builder) CodeableConcept(com.b2international.snowowl.fhir.core.model.dt.CodeableConcept)

Aggregations

Issue (com.b2international.snowowl.fhir.core.model.Issue)47 Test (org.junit.Test)44 FhirTest (com.b2international.snowowl.fhir.tests.FhirTest)42 Builder (com.b2international.snowowl.fhir.core.model.Issue.Builder)18 Coding (com.b2international.snowowl.fhir.core.model.dt.Coding)6 ValidationException (com.b2international.snowowl.fhir.core.exceptions.ValidationException)5 OperationOutcomeCode (com.b2international.snowowl.fhir.core.codesystems.OperationOutcomeCode)4 OperationOutcome (com.b2international.snowowl.fhir.core.model.OperationOutcome)4 CodeableConcept (com.b2international.snowowl.fhir.core.model.dt.CodeableConcept)4 Fhir (com.b2international.snowowl.fhir.core.model.dt.Parameters.Fhir)4 Json (com.b2international.snowowl.fhir.core.model.dt.Parameters.Json)4 IssueSeverity (com.b2international.snowowl.fhir.core.codesystems.IssueSeverity)3 IssueType (com.b2international.snowowl.fhir.core.codesystems.IssueType)3 Parameters (com.b2international.snowowl.fhir.core.model.dt.Parameters)3 FhirExceptionIssueMatcher (com.b2international.snowowl.fhir.tests.FhirExceptionIssueMatcher)3 Optional (java.util.Optional)3 Assert.assertTrue (org.junit.Assert.assertTrue)3 BadRequestException (com.b2international.snowowl.fhir.core.exceptions.BadRequestException)2 LookupRequest (com.b2international.snowowl.fhir.core.model.codesystem.LookupRequest)2 Parameter (com.b2international.snowowl.fhir.core.model.dt.Parameter)2