Skip to content

Commit

Permalink
Add validation check to ensure that the description/details are prese…
Browse files Browse the repository at this point in the history
…nt for the original language as well as all translations.
  • Loading branch information
gardes committed Apr 1, 2022
1 parent dc5e3a0 commit 214a170
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Set;
import java.util.StringTokenizer;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
Expand Down Expand Up @@ -1142,17 +1143,14 @@ public void checkArchetypeDefinitionTypename(Archetype archetype,
}
}

/**
* Checks if languages listed in translation section are provided in
* term_definition and constraint_definition sections
/** Checks if languages listed in translation section are provided in
* term_definition and constraint_definition sections.
* Also checks if the respective language is present in the description details.
* <p>
* TODO: how about missing individual term_def/constraint_def translations?
*
* @param archetype
* @return errors
*/
public void checkOntologyTranslation(Archetype archetype,
List<ValidationError> errors) {
* @return errors */
public void checkOntologyTranslation(Archetype archetype, List<ValidationError> errors) {
Set<String> languages = archetype.languagesAvailable();
String primaryLang = archetype.getOriginalLanguage().getCodeString();

Expand All @@ -1164,21 +1162,28 @@ public void checkOntologyTranslation(Archetype archetype,

Set<String> termDefLangs = retrieveLanguageSet(termDefList);
Set<String> constraintDefLangs = retrieveLanguageSet(constraintDefList);
ValidationError error;

ValidationError error = null;
for (String lang : languages) {
// Checks if for all available languages, there are also equivalents in the description/details - if there are description/details at all.
// This is important to prevent inconsistencies and is also relevant for the primary language.
if (archetype.getDescription() != null && archetype.getDescription().getDetails() != null && !archetype.getDescription().getDetails().containsKey(lang)) {
error = new ValidationError(ErrorType.VOTM, "DESCRIPTIONDETAILS", lang);
errors.add(error);
}

if (primaryLang.equals(lang)) {
continue;
}

if (!termDefLangs.contains(lang)) {
error = new ValidationError(ErrorType.VOTM, "TERM",
lang);
error = new ValidationError(ErrorType.VOTM, "TERM", lang);
errors.add(error);
}

if (!constraintDefList.isEmpty()
&& !constraintDefLangs.contains(lang)) {
error = new ValidationError(ErrorType.VOTM, "CONSTRAINT",
lang);
error = new ValidationError(ErrorType.VOTM, "CONSTRAINT", lang);
errors.add(error);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ VONLC_TERM_TEXT=Archetype code {0} is missing in language {1}.
VONLC_CONSTRAINT_TEXT=Constraint code {0} is missing in language {1}.
VOTM_TERM_TEXT=Archetype term definition missing for language {0}.
VOTM_CONSTRAINT_TEXT=Code constraint definition missing for language {0}.
VOTM_DESCRIPTIONDETAILS_TEXT=Description Details are missing for language {0}.
VONSD_TEXT=Ontology code [{0}] has specialisation level greater than {1}.
VCARM_TEXT=Unknown attribute [{0}] of parent RM type [{1}] at path {2}.
VSAM_MULTIPLE_TEXT=Multiplicity (Multiple) of attribute at {0} does not conform to multiplicity (Single) of the attribute at {1} in the parent archetype.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ VONLC_TERM_TEXT=(de)Archetype code {0} is missing in language {1}.
VONLC_CONSTRAINT_TEXT=(de)Constraint code {0} is missing in language {1}.
VOTM_TERM_TEXT=(de)Archetype term definition missing for language {0}.
VOTM_CONSTRAINT_TEXT=(de)Code constraint definition missing for language {0}.
VOTM_DESCRIPTIONDETAILS_TEXT=(en)Description Details are missing for language {0}.
VONSD_TEXT=(de)Ontology code [{0}] has specialisation level greater than {1}.
VCARM_TEXT=(de)Unknown attribute [{0}] of parent RM type [{1}] at path {2}.
VSAM_MULTIPLE_TEXT=(de)Multiplicity (Multiple) of attribute at {0} does not conform to multiplicity (Single) of the attribute at {1} in the parent archetype.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ VONLC_TERM_TEXT=(ru)Archetype code {0} is missing in language {1}.
VONLC_CONSTRAINT_TEXT=(ru)Constraint code {0} is missing in language {1}.
VOTM_TERM_TEXT=(ru)Archetype term definition missing for language {0}.
VOTM_CONSTRAINT_TEXT=(ru)Code constraint definition missing for language {0}.
VOTM_DESCRIPTIONDETAILS_TEXT=(ru)Description Details are missing for language {0}.
VONSD_TEXT=(ru)Ontology code [{0}] has specialisation level greater than {1}.
VCARM_TEXT=(ru)Unknown attribute [{0}] of parent RM type [{1}] at path {2}.
VSAM_MULTIPLE_TEXT=(ru)Multiplicity (Multiple) of attribute at {0} does not conform to multiplicity (Single) of the attribute at {1} in the parent archetype.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,53 +1,59 @@
package org.openehr.am.validation;

public class OntologyTranslationCheckTest extends ArchetypeValidationTestBase {

public void testTranslationCheckWithNoTranslation() throws Exception {
checkTranslation("adl-test-ENTRY.ontology_translation.v1");
assertEquals("expected no validation error", 0, errors.size());
}

public void testTranslationCheckWithoutConstraintDef() throws Exception {
checkTranslation("adl-test-ENTRY.ontology_translation.v7");
assertEquals("expected no validation error", 0, errors.size());
}

public void testTranslationCheckWithMissingTermAndConstraintTranslation()
throws Exception {
checkTranslation("adl-test-ENTRY.ontology_translation.v2");
assertEquals("expected validation error", 2, errors.size());
assertFirstErrorType(ErrorType.VOTM);
assertSecondErrorType(ErrorType.VOTM);
}

public void testTranslationCheckWithMissingTermTranslation()
throws Exception {
checkTranslation("adl-test-ENTRY.ontology_translation.v3");
assertEquals("expected validation error", 1, errors.size());
assertFirstErrorType(ErrorType.VOTM);
}

public void testTranslationCheckWithMissingConstraintTranslation()
throws Exception {
checkTranslation("adl-test-ENTRY.ontology_translation.v4");
assertEquals("expected validation error", 1, errors.size());
assertFirstErrorType(ErrorType.VOTM);
}

public void testTranslationCheckWithCompleteTranslation() throws Exception {
checkTranslation("adl-test-ENTRY.ontology_translation.v5");
assertEquals("expected no validation error", 0, errors.size());
}

public void testTranslationCheckWithTwoMissingTranslation() throws Exception {
checkTranslation("adl-test-ENTRY.ontology_translation.v6");
assertEquals("expected validation error", 2, errors.size());
assertFirstErrorType(ErrorType.VOTM);
assertSecondErrorType(ErrorType.VOTM);
}

private void checkTranslation(String name) throws Exception {
archetype = loadArchetype(name);
validator.checkOntologyTranslation(archetype, errors);
}
}
package org.openehr.am.validation;

public class OntologyTranslationCheckTest extends ArchetypeValidationTestBase {

public void testTranslationCheckWithNoTranslation() throws Exception {
checkTranslation("adl-test-ENTRY.ontology_translation.v1");
assertEquals("expected no validation error", 0, errors.size());
}

public void testTranslationCheckWithoutConstraintDef() throws Exception {
checkTranslation("adl-test-ENTRY.ontology_translation.v7");
assertEquals("expected no validation error", 0, errors.size());
}

public void testTranslationCheckWithMissingTermAndConstraintTranslation()
throws Exception {
checkTranslation("adl-test-ENTRY.ontology_translation.v2");
assertEquals("expected validation error", 2, errors.size());
assertFirstErrorType(ErrorType.VOTM);
assertSecondErrorType(ErrorType.VOTM);
}

public void testTranslationCheckWithMissingTermTranslation()
throws Exception {
checkTranslation("adl-test-ENTRY.ontology_translation.v3");
assertEquals("expected validation error", 1, errors.size());
assertFirstErrorType(ErrorType.VOTM);
}

public void testTranslationCheckWithMissingConstraintTranslation()
throws Exception {
checkTranslation("adl-test-ENTRY.ontology_translation.v4");
assertEquals("expected validation error", 1, errors.size());
assertFirstErrorType(ErrorType.VOTM);
}

public void testTranslationCheckWithCompleteTranslation() throws Exception {
checkTranslation("adl-test-ENTRY.ontology_translation.v5");
assertEquals("expected no validation error", 0, errors.size());
}

public void testTranslationCheckWithTwoMissingTranslation() throws Exception {
checkTranslation("adl-test-ENTRY.ontology_translation.v6");
assertEquals("expected validation error", 2, errors.size());
assertFirstErrorType(ErrorType.VOTM);
assertSecondErrorType(ErrorType.VOTM);
}

public void testTranslationCheckWithoutMatchingDescriptionDetails() throws Exception {
checkTranslation("adl-test-ENTRY.ontology_translation.v8");
assertEquals("expected validation error", 1, errors.size());
assertFirstErrorType(ErrorType.VOTM);
}

private void checkTranslation(String name) throws Exception {
archetype = loadArchetype(name);
validator.checkOntologyTranslation(archetype, errors);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
archetype
adl-test-ENTRY.ontology_translation.v7

concept
[at0000] -- empty definition test

language
original_language = <[ISO_639-1::en]>
translations = <
["de"] = <
language = <[ISO_639-1::de]>
author = <
["name"] = <"Jasmin Buck, Sebastian Garde">
["organisation"] = <"University of Heidelberg, Central Queensland University">
>
>
>
description
original_author = <
["name"] = <"Tester test">
>
details = <
["en"] = <
language = <[ISO_639-1::de]>
purpose = <"Test">
use = <"To test a missing German details equivalent.">
>

>
lifecycle_state = <"draft">
definition
ELEMENT[at0000] matches { -- Diagnosis
value matches {
DV_CODED_TEXT matches {
defining_code matches {*}
}
}
}

ontology
term_definitions = <
["en"] = <
items = <
["at0000"] = <
text = <"most minimal">;
description = <"most minimal">
>
>
>
["de"] = <
items = <
["at0000"] = <
text = <"most minimal">;
description = <"most minimal">
>
>
>
>

0 comments on commit 214a170

Please sign in to comment.