protected ValidationException[] failed(String msg, Location location) { ValidationException ve = new ValidationException(msg, severity); ve.setError(getErrorCode()); ve.setLocation(location); return new ValidationException[] { ve }; }
public static ValidationException fromHL7Exception(HL7Exception e) { ValidationException ve = new ValidationException(e.getMessageWithoutLocation(), e); ve.setErrorCode(e.getErrorCode()); ve.setLocation(e.getLocation()); ve.setSeverity(e.getSeverity()); return ve; }
/** * @return <code>true</code> if default namespace is set properly */ private boolean hasCorrectNamespace(Document domDocumentToValidate, List<ValidationException> validationErrors) { String nsUri = domDocumentToValidate.getDocumentElement().getNamespaceURI(); boolean ok = DEFAULT_NS.equals(nsUri); if (!ok) { ValidationException e = new ValidationException( "The default namespace of the XML document is incorrect - should be " + DEFAULT_NS + " but was " + nsUri); validationErrors.add(e); log.error(e.getMessage()); } return ok; }
public static void profileViolatedWhen(boolean errorCondition, List<ValidationException> exceptions, ProfileValidationMessage validationErrorMessage, Object... details) { if (errorCondition) { ValidationException he = new ValidationException(String.format(validationErrorMessage.errorMessage(), details)); he.setError(validationErrorMessage.errorCode()); he.setSeverity(validationErrorMessage.severity()); exceptions.add(he); } }
private static void checkMSHField(String fieldNo, String profileValue, Terser terser, ProfileValidationMessage validationMessage, List<ValidationException> violations) { String mshValue; try { mshValue = mshField(fieldNo, terser); profileViolatedWhen(!Objects.equals(mshValue, profileValue), violations, validationMessage, mshValue, profileValue); } catch (HL7Exception e) { violations.add(new ValidationException("Could not obtain" + fieldNo, e)); } } }
public ValidationException(String message, Throwable cause, Severity severity) { super(message, cause); setSeverity(severity); }
public ValidationException[] apply(Message msg) { List<ValidationException> exceptions = new ArrayList<ValidationException>(); for (Iterator<Structure> iter = ReadOnlyMessageIterator .createPopulatedStructureIterator(msg, GenericSegment.class); iter.hasNext();) { String segmentName = iter.next().getName(); ValidationException ve = new ValidationException("Found unknown segment: " + segmentName); Location location = new Location().withSegmentName(segmentName); ve.setLocation(location); exceptions.add(ve); } return exceptions.toArray(new ValidationException[exceptions.size()]); }
/** * Populates the generated response based on the collected * {@link ValidationException}s. In case of exceptions, each exception will * cause an entry in one or more ERR segments. * * @param response response message to be populated * @throws HL7Exception */ protected void populateResponseMessage(Message response) throws HL7Exception { if (response == null) return; List<ValidationException> exceptions = getExceptions(); for (int i = 0; i < exceptions.size(); i++) { ValidationException ve = exceptions.get(i); // TODO respect minimumSeverity here? if (ve.getSeverity() == Severity.ERROR) { ve.populateResponse(response, getErrorAcknowledgementCode(), i); } } }
/** * @see ca.uhn.hl7v2.validation.ValidationExceptionHandler#hasFailed() */ public boolean hasFailed() { for (ValidationException ve : exceptions) { if (ve.getSeverity() == Severity.ERROR) return true; } return false; }
/** * If the validation failed, throws Exception or returns <code>false</code>, * depending on {link {@link #throwFirstException}. * * @throws HL7Exception if validation has failed and * {@link #throwFirstException} is true * @see ca.uhn.hl7v2.validation.DefaultValidationExceptionHandler#result() */ public Boolean result() throws HL7Exception { if (hasFailed() && throwFirstException) throw new HL7Exception(firstException.getMessage(), firstException); return !hasFailed(); }
private void testPrimitive(Primitive p, ValidationExceptionHandler<R> handler, Location l) { List<PrimitiveTypeRule> rules = new ArrayList<PrimitiveTypeRule>(); Message m = p.getMessage(); if (getValidationContext() != null) { rules.addAll(getValidationContext().getPrimitiveRules(m.getVersion(), p.getName(), p)); } for (PrimitiveTypeRule rule : rules) { ValidationException[] exceptions = rule.apply(p.getValue()); for (ValidationException ve : exceptions) { ve.setLocation(l); } if (exceptions.length > 0) { handler.onExceptions(exceptions); } } }
private ValidationException[] testAgainstProfile(Message message, String id) throws ProfileException, HL7Exception { HL7Exception[] exceptions; HapiContext context = message.getParser().getHapiContext(); Validator validator = context.getConformanceValidator(); try { ProfileStore profileStore = context.getProfileStore(); String profileString = profileStore.getProfile(id); if (profileString != null) { RuntimeProfile profile = getProfile(profileString); exceptions = validator.validate(message, profile.getMessage()); } else { throw new ProfileException("Unable to find the profile " + id); } } catch (IOException e) { throw new ProfileException("Error retreiving profile " + id, e); } ValidationException[] result = new ValidationException[exceptions.length]; for (int i = 0; i < exceptions.length; i++) { result[i] = ValidationException.fromHL7Exception(exceptions[i]); } return result; }
public static void profileNotHL7Compliant(List<ValidationException> exceptions, ProfileValidationMessage validationErrorMessage, Object... details) { ValidationException he = new ValidationException(String.format(validationErrorMessage.errorMessage(), details)); he.setError(validationErrorMessage.errorCode()); he.setSeverity(validationErrorMessage.severity()); exceptions.add(he); }
public boolean handleError(DOMError error) { validationErrors.add(new ValidationException(getSeverity(error) + error.getMessage())); return true; }
public ValidationException(Throwable cause, Severity severity) { super(cause); setSeverity(severity); }
public ValidationException[] apply(Message msg) { List<ValidationException> exceptions = new ArrayList<ValidationException>(); for (Iterator<Structure> iter = ReadOnlyMessageIterator .createPopulatedStructureIterator(msg, GenericSegment.class); iter.hasNext();) { String segmentName = iter.next().getName(); ValidationException ve = new ValidationException("Found unknown segment: " + segmentName); Location location = new Location().withSegmentName(segmentName); ve.setLocation(location); exceptions.add(ve); } return exceptions.toArray(new ValidationException[exceptions.size()]); }
/** * Populates the generated response based on the collected * {@link ValidationException}s. In case of exceptions, each exception will * cause an entry in one or more ERR segments. * * @param response response message to be populated * @throws HL7Exception */ protected void populateResponseMessage(Message response) throws HL7Exception { if (response == null) return; List<ValidationException> exceptions = getExceptions(); for (int i = 0; i < exceptions.size(); i++) { ValidationException ve = exceptions.get(i); // TODO respect minimumSeverity here? if (ve.getSeverity() == Severity.ERROR) { ve.populateResponse(response, getErrorAcknowledgementCode(), i); } } }
/** * @see ca.uhn.hl7v2.validation.ValidationExceptionHandler#hasFailed() */ public boolean hasFailed() { for (ValidationException ve : exceptions) { if (ve.getSeverity() == Severity.ERROR) return true; } return false; }
/** * If the validation failed, throws Exception or returns <code>false</code>, * depending on {link {@link #throwFirstException}. * * @throws HL7Exception if validation has failed and * {@link #throwFirstException} is true * @see ca.uhn.hl7v2.validation.DefaultValidationExceptionHandler#result() */ public Boolean result() throws HL7Exception { if (hasFailed() && throwFirstException) throw new HL7Exception(firstException.getMessage(), firstException); return !hasFailed(); }
private void testPrimitive(Primitive p, ValidationExceptionHandler<R> handler, Location l) { List<PrimitiveTypeRule> rules = new ArrayList<PrimitiveTypeRule>(); Message m = p.getMessage(); if (getValidationContext() != null) { rules.addAll(getValidationContext().getPrimitiveRules(m.getVersion(), p.getName(), p)); } for (PrimitiveTypeRule rule : rules) { ValidationException[] exceptions = rule.apply(p.getValue()); for (ValidationException ve : exceptions) { ve.setLocation(l); } if (exceptions.length > 0) { handler.onExceptions(exceptions); } } }