public ValidationResult(FhirContext theCtx, List<SingleValidationMessage> theMessages) { boolean successful = true; myCtx = theCtx; myMessages = theMessages; for (SingleValidationMessage next : myMessages) { next.getSeverity(); if (next.getSeverity() == null || next.getSeverity().ordinal() > ResultSeverityEnum.WARNING.ordinal()) { successful = false; } } myIsSuccessful = successful; }
/** * Should the validator validate the resource against the base schema (the schema provided with the FHIR distribution itself) * * @return Returns a referens to <code>this<code> for method chaining */ public synchronized FhirValidator setValidateAgainstStandardSchema(boolean theValidateAgainstStandardSchema) { addOrRemoveValidator(theValidateAgainstStandardSchema, SchemaBaseValidator.class, new SchemaBaseValidator(myContext)); return this; }
/** * If the validation produces a result with at least the given severity, a header with the name * specified by {@link #setResponseOutcomeHeaderName(String)} will be added containing a JSON encoded * OperationOutcome resource containing the validation results. */ public ResultSeverityEnum getAddResponseOutcomeHeaderOnSeverity() { return myAddResponseOutcomeHeaderOnSeverity != null ? ResultSeverityEnum.values()[myAddResponseOutcomeHeaderOnSeverity] : null; }
private void addIssue(SAXParseException theException, ResultSeverityEnum theSeverity) { SingleValidationMessage message = new SingleValidationMessage(); message.setLocationLine(theException.getLineNumber()); message.setLocationCol(theException.getColumnNumber()); message.setMessage(theException.getLocalizedMessage()); message.setSeverity(theSeverity); myContext.addValidationMessage(message); }
@Override ValidationResult doValidate(FhirValidator theValidator, String theRequest) { return theValidator.validateWithResult(theRequest); }
/** * Validates a resource instance returning a {@link ca.uhn.fhir.validation.ValidationResult} which contains the results. * * @param theResource * the resource to validate * @return the results of validation * @since 1.1 */ public ValidationResult validateWithResult(String theResource) { Validate.notNull(theResource, "theResource must not be null"); applyDefaultValidators(); IValidationContext<IBaseResource> ctx = ValidationContext.forText(myContext, theResource); for (IValidatorModule next : myValidators) { next.validateResource(ctx); } return ctx.toResult(); }
/** * If the validation produces a result with at least the given severity, a header with the name * specified by {@link #setResponseOutcomeHeaderName(String)} will be added containing a JSON encoded * OperationOutcome resource containing the validation results. */ public void setAddResponseOutcomeHeaderOnSeverity(ResultSeverityEnum theAddResponseOutcomeHeaderOnSeverity) { myAddResponseOutcomeHeaderOnSeverity = theAddResponseOutcomeHeaderOnSeverity != null ? theAddResponseOutcomeHeaderOnSeverity.ordinal() : null; }
@Override public void error(SAXParseException theException) { addIssue(theException, ResultSeverityEnum.ERROR); }
public static <T extends IBaseResource> IValidationContext<T> forResource(final FhirContext theContext, final T theResource) { return new ValidationContext<T>(theContext, theResource, new IEncoder() { @Override public String encode() { return theContext.newXmlParser().encodeResourceToString(theResource); } @Override public EncodingEnum getEncoding() { return EncodingEnum.XML; } }); }
/** * Create a new validator instance. * <p> * Note on thread safety: Validators are thread safe, you may use a single validator * in multiple threads. (This is in contrast to parsers) * </p> */ public FhirValidator newValidator() { return new FhirValidator(this); }
@Override public String getResourceAsString() { if (myResourceAsString == null) { myResourceAsString = myEncoder.encode(); } return myResourceAsString; }
@Override public void validateResource(IValidationContext<IBaseResource> theContext) { doValidate(theContext, "fhir-single.xsd"); }
private ValidationContext(FhirContext theContext, T theResource, IEncoder theEncoder, List<SingleValidationMessage> theMessages) { super(theContext, theMessages); myResource = theResource; myEncoder = theEncoder; if (theEncoder != null) { myResourceAsStringEncoding = theEncoder.getEncoding(); } else { myResourceAsStringEncoding = null; } }
/** * Should the validator validate the resource against the base schema (the schema provided with the FHIR distribution itself) */ public synchronized boolean isValidateAgainstStandardSchema() { return haveValidatorOfType(SchemaBaseValidator.class); }
@Override public ValidationResult toResult() { return new ValidationResult(myFhirContext, myMessages); }
@Override ValidationResult doValidate(FhirValidator theValidator, IBaseResource theRequest) { return theValidator.validateWithResult(theRequest); }
/** * Sets the minimum severity at which an issue detected by the validator will fail/reject the request. Default is * {@link ResultSeverityEnum#ERROR}. Set to <code>null</code> to disable this behaviour. */ public void setFailOnSeverity(ResultSeverityEnum theSeverity) { myFailOnSeverity = theSeverity != null ? theSeverity.ordinal() : null; }
@Override public void warning(SAXParseException theException) { addIssue(theException, ResultSeverityEnum.WARNING); }
/** * Sets the minimum severity at which an issue detected by the validator will result in a header being added to the * response. Default is {@link ResultSeverityEnum#INFORMATION}. Set to <code>null</code> to disable this behaviour. * * @see #setResponseHeaderName(String) * @see #setResponseHeaderValue(String) */ public void setAddResponseHeaderOnSeverity(ResultSeverityEnum theSeverity) { myAddResponseIssueHeaderOnSeverity = theSeverity != null ? theSeverity.ordinal() : null; }
@Override public void fatalError(SAXParseException theException) { addIssue(theException, ResultSeverityEnum.FATAL); }