/** * @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; }
/** * @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; }
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 boolean handleError(DOMError error) { validationErrors.add(new ValidationException(getSeverity(error) + error.getMessage())); return true; }
public boolean handleError(DOMError error) { validationErrors.add(new ValidationException(getSeverity(error) + error.getMessage())); return true; }
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()]); }
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()]); }
protected ValidationException[] failed(Exception e, Location location) { if (e instanceof ValidationException) return new ValidationException[] { (ValidationException) e }; ValidationException ve = new ValidationException(e.getMessage(), e, severity); ve.setError(getErrorCode()); ve.setLocation(location); return new ValidationException[] { ve }; }
protected ValidationException[] failed(Exception e, Location location) { if (e instanceof ValidationException) return new ValidationException[] { (ValidationException) e }; ValidationException ve = new ValidationException(e.getMessage(), e, severity); ve.setError(getErrorCode()); ve.setLocation(location); return new ValidationException[] { ve }; }
/** * Tests for extra components (i.e. any not defined in the profile) */ protected List<ValidationException> checkUndefinedComponents(Composite comp, int numInProfile) { List<ValidationException> exList = new ArrayList<>(); StringBuilder extra = new StringBuilder(); for (int i = numInProfile; i < comp.getComponents().length; i++) { try { String s = comp.getComponent(i).encode(); if (s.length() > 0) { extra.append(s).append(enc.getComponentSeparator()); } } catch (HL7Exception de) { exList.add(new ValidationException(de)); } } profileViolatedWhen(extra.toString().length() > 0, exList, COMPONENT_NOT_DEFINED_IN_PROFILE, extra.toString()); return exList; }
public ValidationException[] apply(Message msg) { List<ValidationException> exceptions = new ArrayList<ValidationException>(); ValidationException ve = new ValidationException("Invalid version: " + msg.getVersion()); Location location = new Location() .withSegmentName("MSH") .withField(12); ve.setLocation(location); ve.setError(ErrorCode.UNSUPPORTED_VERSION_ID); exceptions.add(ve); return exceptions.toArray(new ValidationException[exceptions.size()]); }
public ValidationException[] apply(Message msg) { List<ValidationException> exceptions = new ArrayList<ValidationException>(); ValidationException ve = new ValidationException("Invalid version: " + msg.getVersion()); Location location = new Location() .withSegmentName("MSH") .withField(12); ve.setLocation(location); ve.setError(ErrorCode.UNSUPPORTED_VERSION_ID); exceptions.add(ve); return exceptions.toArray(new ValidationException[exceptions.size()]); }
public ValidationException[] apply(Message message) { try { ValidatingMessageVisitor visitor = visitorFactory.create(); MessageVisitors.visit(message, visitor); return visitor.getValidationExceptions(); } catch (HL7Exception e) { return new ValidationException[] { new ValidationException(e) }; } } }
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); } }
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); }
protected ValidationException[] failed(String msg, Location location) { ValidationException ve = new ValidationException(msg, severity); ve.setError(getErrorCode()); ve.setLocation(location); return new ValidationException[] { ve }; }
protected ValidationException[] failed(String msg, Location location) { ValidationException ve = new ValidationException(msg, severity); ve.setError(getErrorCode()); ve.setLocation(location); return new ValidationException[] { ve }; }
public ValidationException[] apply(Message message) { try { ValidatingMessageVisitor visitor = visitorFactory.create(); MessageVisitors.visit(message, visitor); return visitor.getValidationExceptions(); } catch (HL7Exception e) { return new ValidationException[] { new ValidationException(e) }; } } }
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; }
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; }