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();
}
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();
}
Aggregations