private String toDescription() { StringBuilder b = new StringBuilder(100); if (myMessages.size() > 0) { if (myMessages.get(0).getSeverity() != null) { b.append(myMessages.get(0).getSeverity().name()); b.append(" - "); } b.append(myMessages.get(0).getMessage()); b.append(" - "); b.append(myMessages.get(0).getLocationString()); } else { b.append("No issues"); } return b.toString(); }
@Override public String lookup(String theKey) { if ("line".equals(theKey)) { return toString(myMessage.getLocationLine()); } if ("col".equals(theKey)) { return toString(myMessage.getLocationCol()); } if ("message".equals(theKey)) { return toString(myMessage.getMessage()); } if ("location".equals(theKey)) { return toString(myMessage.getLocationString()); } if ("severity".equals(theKey)) { return myMessage.getSeverity() != null ? myMessage.getSeverity().name() : null; } return ""; }
/** * Populate an operation outcome with the results of the validation */ public void populateOperationOutcome(IBaseOperationOutcome theOperationOutcome) { for (SingleValidationMessage next : myMessages) { String location; if (isNotBlank(next.getLocationString())) { location = next.getLocationString(); } else if (next.getLocationLine() != null || next.getLocationCol() != null) { location = "Line[" + next.getLocationLine() + "] Col[" + next.getLocationCol() + "]"; } else { location = null; } String severity = next.getSeverity() != null ? next.getSeverity().getCode() : null; OperationOutcomeUtil.addIssue(myCtx, theOperationOutcome, severity, next.getMessage(), location, Constants.OO_INFOSTATUS_PROCESSING); } if (myMessages.isEmpty()) { String message = myCtx.getLocalizer().getMessage(ValidationResult.class, "noIssuesDetected"); OperationOutcomeUtil.addIssue(myCtx, theOperationOutcome, "information", message, null, "informational"); } }
b.append(next.getSeverity()).append(ansi().fg(Color.WHITE)).append(" - "); if (isNotBlank(next.getLocationString())) { b.append(ansi().fg(Color.WHITE)).append(next.getLocationString());
public void validationIntro() { // START SNIPPET: validationIntro FhirContext ctx = FhirContext.forDstu3(); // Ask the context for a validator FhirValidator validator = ctx.newValidator(); // Create some modules and register them IValidatorModule module1 = new SchemaBaseValidator(ctx); validator.registerValidatorModule(module1); IValidatorModule module2 = new SchematronBaseValidator(ctx); validator.registerValidatorModule(module2); // Pass a resource in to be validated. The resource can // be an IBaseResource instance, or can be a raw String // containing a serialized resource as text. Patient resource = new Patient(); ValidationResult result = validator.validateWithResult(resource); String resourceText = "<Patient.....>"; ValidationResult result2 = validator.validateWithResult(resourceText); // The result object now contains the validation results for (SingleValidationMessage next : result.getMessages()) { System.out.println(next.getLocationString() + " " + next.getMessage()); } // END SNIPPET: validationIntro }
for (SingleValidationMessage next : messages) { System.out.println("Message:"); System.out.println(" * Location: " + next.getLocationString()); System.out.println(" * Severity: " + next.getSeverity()); System.out.println(" * Message : " + next.getMessage());
System.out.println(" Next issue " + next.getSeverity() + " - " + next.getLocationString() + " - " + next.getMessage());
private String toDescription() { StringBuilder b = new StringBuilder(100); if (myMessages.size() > 0) { if (myMessages.get(0).getSeverity() != null) { b.append(myMessages.get(0).getSeverity().name()); b.append(" - "); } b.append(myMessages.get(0).getMessage()); b.append(" - "); b.append(myMessages.get(0).getLocationString()); } else { b.append("No issues"); } return b.toString(); }
@Override public String lookup(String theKey) { if ("line".equals(theKey)) { return toString(myMessage.getLocationLine()); } if ("col".equals(theKey)) { return toString(myMessage.getLocationCol()); } if ("message".equals(theKey)) { return toString(myMessage.getMessage()); } if ("location".equals(theKey)) { return toString(myMessage.getLocationString()); } if ("severity".equals(theKey)) { return myMessage.getSeverity() != null ? myMessage.getSeverity().name() : null; } return ""; }
/** * Populate an operation outcome with the results of the validation */ public void populateOperationOutcome(IBaseOperationOutcome theOperationOutcome) { for (SingleValidationMessage next : myMessages) { String location; if (isNotBlank(next.getLocationString())) { location = next.getLocationString(); } else if (next.getLocationLine() != null || next.getLocationCol() != null) { location = "Line[" + next.getLocationLine() + "] Col[" + next.getLocationCol() + "]"; } else { location = null; } String severity = next.getSeverity() != null ? next.getSeverity().getCode() : null; OperationOutcomeUtil.addIssue(myCtx, theOperationOutcome, severity, next.getMessage(), location, Constants.OO_INFOSTATUS_PROCESSING); } if (myMessages.isEmpty()) { String message = myCtx.getLocalizer().getMessage(ValidationResult.class, "noIssuesDetected"); OperationOutcomeUtil.addIssue(myCtx, theOperationOutcome, "information", message, null, "informational"); } }
/** * Runs validation on a given resource, logs the results, and returns the response. * @param theResource the resource to be validated * @return ValidationResult */ public ValidationResult validate(IBaseResource theResource) { ValidationResult result = validator.validateWithResult(theResource); // Do we have any errors or fatal errors? // Show the issues for (SingleValidationMessage next : result.getMessages()) { switch (next.getSeverity()) { case ERROR: logger.error(next.getLocationString() + " - " + next.getMessage()); break; case INFORMATION: logger.info(next.getLocationString() + " - " + next.getMessage()); break; case WARNING: logger.warn(next.getLocationString() + " - " + next.getMessage()); break; case FATAL: logger.error(next.getLocationString() + " - " + next.getMessage()); break; default: logger.debug(next.getLocationString() + " - " + next.getMessage()); } } return result; } }