Skip to content

Commit

Permalink
Added validation for customUnit as described in #355.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbjones committed May 2, 2020
1 parent 4fcce3c commit 137892f
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 11 deletions.
Binary file modified lib/eml.jar
Binary file not shown.
13 changes: 12 additions & 1 deletion src/main/java/org/ecoinformatics/eml/EMLValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ public boolean validate() {
}
}


// Elements which contain an `annotation` child element MUST contain an
// `id` attribute, unless the containing `annotation` element contains a
// `references` attribute
Expand Down Expand Up @@ -154,6 +153,18 @@ public boolean validate() {
//}
}

// If a customUnit is referenced in a document, it must have a
// corresponding STMML unit definition in the document with a matching
// @id
ArrayList<String> unitIdentifiers = getXPathValues("//*[local-name() = 'unitList']/*[local-name() = 'unit']/@id");
ArrayList<String> unitReferences = getXPathValues("//unit/customUnit");
for (String s : unitReferences) {
if (!unitIdentifiers.contains(s)) {
errors.add("Invalid: Custom unit definition missing: " + s);
isValid = false;
}
}

// TODO: When `references` is used, the `system` attribute MUST have the
// same value in both the target and source elements, or it must be
// absent in both. For now, we have decided to not enforce this
Expand Down
11 changes: 9 additions & 2 deletions src/test/resources/eml-datasetWithAccessUnitsLiteralLayout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,13 @@ Clip strips are 10cm wide and 3m long.
</attributeList>
</dataTable>
</dataset>
<additionalMetadata><metadata>
<unitList><unit id="g/sample"></unit></unitList></metadata></additionalMetadata>
<additionalMetadata>
<metadata>
<unitList xmlns:stmml="http://www.xml-cml.org/schema/stmml-1.1"
xsi:schemaLocation="http://www.xml-cml.org/schema/stmml-1.1 ../../../xsd/stmml.xsd">
<!--note that the unitTypes here are taken from the eml-unitDictionary.xml-->
<unit name="g/sample" unitType="arealMassDensity" id="g/sample" parentSI="kilogramsPerSquareMeter" multiplierToSI=".001"/>
</unitList>
</metadata>
</additionalMetadata>
</eml:eml>
13 changes: 8 additions & 5 deletions src/test/resources/eml-datasetWithCitation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -359,10 +359,13 @@
</metadata>
</additionalMetadata>
<additionalMetadata>
<metadata>
<unitList>
<unit id="gramsPerSquareMeter"/>
<unit id="speciesPerSquareMeter"/>
</unitList></metadata>
<metadata>
<stmml:unitList xmlns:stmml="http://www.xml-cml.org/schema/stmml-1.1"
xsi:schemaLocation="http://www.xml-cml.org/schema/stmml-1.1 ../../../xsd/stmml.xsd">
<!--note that the unitTypes here are taken from the eml-unitDictionary.xml-->
<stmml:unit name="gramsPerSquareMeter" unitType="arealMassDensity" id="gramsPerSquareMeter" parentSI="kilogramsPerSquareMeter" multiplierToSI=".001"/>
<stmml:unit name="speciesPerSquareMeter" unitType="arealDensity" id="speciesPerSquareMeter" parentSI="numberPerSquareMeter" multiplierToSI="1"/>
</stmml:unitList>
</metadata>
</additionalMetadata>
</eml:eml>
8 changes: 5 additions & 3 deletions src/test/resources/test2008.cdr958608.1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ Clip strips are 10cm wide and 3m long.
<measurementScale>
<ratio>
<unit>
<customUnit>g/sample</customUnit>
<customUnit>g/sample</customUnit>
</unit>
<numericDomain>
<numberType>real</numberType>
Expand All @@ -528,8 +528,10 @@ Clip strips are 10cm wide and 3m long.
</dataset>
<additionalMetadata>
<metadata>
<unitList>
<unit id="g/sample"/>
<unitList xmlns:stmml="http://www.xml-cml.org/schema/stmml-1.1"
xsi:schemaLocation="http://www.xml-cml.org/schema/stmml-1.1 ../../../xsd/stmml.xsd">
<!--note that the unitTypes here are taken from the eml-unitDictionary.xml-->
<unit name="g/sample" unitType="arealMassDensity" id="g/sample" parentSI="kilogramsPerSquareMeter" multiplierToSI=".001"/>
</unitList>
</metadata>
</additionalMetadata>
Expand Down

0 comments on commit 137892f

Please sign in to comment.