Search in sources :

Example 1 with Builder

use of com.b2international.snowowl.fhir.core.model.OperationOutcome.Builder 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)1 Builder (com.b2international.snowowl.fhir.core.model.OperationOutcome.Builder)1 CodeableConcept (com.b2international.snowowl.fhir.core.model.dt.CodeableConcept)1 Coding (com.b2international.snowowl.fhir.core.model.dt.Coding)1