/** * Validates the given specialised archetype including specialised validation to its stated parent archetype * * @param archetype * @param parentArchetype * @param reportConstraintsOnFunctionalPropertiesAsInfo if set to true, constraints on functional properties such as "is_integral" as part of DV_PROPORTION and "offset" in EVENT are reported as info only. If set to false (default), they are reported as errors. * @return list of validation errors or empty list if valid */ public List<ValidationError> validate(Archetype archetype, Archetype parentArchetype, boolean reportConstraintsOnCommonFunctionalPropertiesAsInfo) throws RMInspectionException { List<ValidationError> errors = new ArrayList<ValidationError>(); // normal non-specialised validation first. errors.addAll(validate(archetype, reportConstraintsOnCommonFunctionalPropertiesAsInfo)); int childSpecialisationDepth = StringUtils.countMatches(archetype.getArchetypeId().domainConcept(), "-"); checkSpecialisedObjectConstraints(archetype, parentArchetype, childSpecialisationDepth, errors); checkSpecialisationHierarchyOfAllAtAndAcCodesInTheDefinition(archetype, childSpecialisationDepth, errors); log.debug("-- Error size:" +errors.size()); for (ValidationError error : errors) { log.debug("Error: " + error.getType() + " "+ error.getText()); } return errors; }
/** * Checks for unused codes in the ontology * * @param defList * @param errors * @param archetype */ private void checkForUnusedCodes(List<OntologyDefinitions> defList, List<ValidationError> errors, Archetype archetype, Set<String> actuallyUsedCodes) { int specialisationDepth = StringUtils.countMatches(archetype.getArchetypeId().domainConcept(), "-"); // now check for each code if it exists in the definition ValidationError error = null; for (OntologyDefinitions defs : defList) { for (ArchetypeTerm term : defs.getDefinitions()) { if (!actuallyUsedCodes.contains(term.getCode())) { // at the moment, we only want to report on unused codes // that are on the same specialisation depth as this archetype. if (specialisationDepth == StringUtils.countMatches(term.getCode(), ".")) { error = new ValidationError(ErrorType.WOUC, null, term.getCode(), defs.getLanguage()); errors.add(error); } } } } }