Skip to content

Commit

Permalink
fix duplicate check on uuid+initiative+association (geonetwork#7567)
Browse files Browse the repository at this point in the history
* fix duplicate check on uuid+initiative+association

* added gmx:anchor option and unit tests

* Format / Update SchematronRulesIsoTest.java

---------

Co-authored-by: François Prunayre <[email protected]>
  • Loading branch information
joachimnielandt and fxprunayre authored Jan 4, 2024
1 parent c67946d commit 14dbaac
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ USA.
<sch:ns prefix="gml" uri="http://www.opengis.net/gml/3.2"/>
<sch:ns prefix="gml320" uri="http://www.opengis.net/gml"/>
<sch:ns prefix="gmd" uri="http://www.isotc211.org/2005/gmd"/>
<sch:ns prefix="gmx" uri="http://www.isotc211.org/2005/gmx"/>
<sch:ns prefix="srv" uri="http://www.isotc211.org/2005/srv"/>
<sch:ns prefix="gco" uri="http://www.isotc211.org/2005/gco"/>
<sch:ns prefix="geonet" uri="http://www.fao.org/geonetwork"/>
Expand Down Expand Up @@ -348,21 +349,19 @@ USA.
<sch:report test="gmd:aggregateDataSetName or gmd:aggregateDataSetIdentifier"
>$loc/strings/report.M23</sch:report>



<sch:let name="mdRefRef" value="gmd:aggregateDataSetIdentifier/*/gmd:code/*"/>
<sch:let name="mdRefRef" value="gmd:aggregateDataSetIdentifier/*/gmd:code/(gco:CharacterString|gmx:Anchor)"/>
<sch:let name="association" value="gmd:associationType/*/@codeListValue"/>
<sch:let name="initiative" value="gmd:initiativeType/*/@codeListValue"/>


<sch:let name="hasNoDuplicate"
value="count(../../*/gmd:MD_AggregateInformation[
gmd:aggregateDataSetIdentifier/*/gmd:code/* = $mdRefRef
gmd:aggregateDataSetIdentifier/*/gmd:code/(gco:CharacterString|gmx:Anchor) = $mdRefRef
and concat(
gmd:associationType/*/@codeListValue,
gmd:initiativeType/*/@codeListValue) =
concat($association, $initiative)]) = 1"/>
<sch:assert test="$hasNoDuplicate">$loc/strings/report.M23-dup</sch:assert>

</sch:rule>
</sch:pattern>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
import java.util.Arrays;
import java.util.Collections;

import static org.fao.geonet.constants.Geonet.Namespaces.GCO;
import static org.fao.geonet.constants.Geonet.Namespaces.GMD;
import static org.fao.geonet.constants.Geonet.Namespaces.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

/**
* Test some of the rules in the schematron-rules-iso.sch files in the iso19139 schema plugin.
*
* <p>
* Created by Jesse on 3/25/14.
*/
public class SchematronRulesIsoTest extends AbstractSchematronTest {
Expand Down Expand Up @@ -149,6 +149,88 @@ public void testMissingDataIdentificationCitationDateType() throws Exception {
testNoStringErrors(testMetadata, dateTypeEl);
}

@Test
public void testAggregationInfoCombinations() throws Exception {
final Element testMetadata = Xml.loadStream(SchematronRulesIsoTest.class.getResourceAsStream(INSPIRE_VALID_ISO19139_XML));
final Element mdDataIdentification = Xml.selectElement(testMetadata, "gmd:identificationInfo/gmd:MD_DataIdentification", Collections.singletonList(GMD));
assertNotNull(mdDataIdentification);

Element results = Xml.transform(testMetadata, getSchematronXsl(), params);
int errorsStart = countFailures(results);

// first we test cases that should not introduce failures
addDatasetIdentifier(mdDataIdentification, "uuid-1", null, "largerWorkCitation", null);
assertEquals(errorsStart, countFailures(Xml.transform(testMetadata, getSchematronXsl(), params)));
addDatasetIdentifier(mdDataIdentification, "uuid-2", null, "largerWorkCitation", null);
assertEquals(errorsStart, countFailures(Xml.transform(testMetadata, getSchematronXsl(), params)));
addDatasetIdentifier(mdDataIdentification, "uuid-2", null, "crossReference", null);
assertEquals(errorsStart, countFailures(Xml.transform(testMetadata, getSchematronXsl(), params)));
addDatasetIdentifier(mdDataIdentification, "uuid-3", null, "crossReference", "campaign");
assertEquals(errorsStart, countFailures(Xml.transform(testMetadata, getSchematronXsl(), params)));
addDatasetIdentifier(mdDataIdentification, "uuid-3", null, "crossReference", "collection");
assertEquals(errorsStart, countFailures(Xml.transform(testMetadata, getSchematronXsl(), params)));
addDatasetIdentifier(mdDataIdentification, "uuid-4", "href-4", "crossReference", "collection");
assertEquals(errorsStart, countFailures(Xml.transform(testMetadata, getSchematronXsl(), params)));

// adding duplicate uuid+initiativeType+associationType combinations should fail
Element bad = addDatasetIdentifier(mdDataIdentification, "uuid-1", null, "largerWorkCitation", null);
assertEquals(errorsStart + 2, countFailures(Xml.transform(testMetadata, getSchematronXsl(), params)));
bad.detach();
bad = addDatasetIdentifier(mdDataIdentification, "uuid-3", null, "crossReference", "campaign");
assertEquals(errorsStart + 2, countFailures(Xml.transform(testMetadata, getSchematronXsl(), params)));
bad.detach();
bad = addDatasetIdentifier(mdDataIdentification, "uuid-1", "href-1", "largerWorkCitation", null);
assertEquals(errorsStart + 2, countFailures(Xml.transform(testMetadata, getSchematronXsl(), params)));
bad.detach();
bad = addDatasetIdentifier(mdDataIdentification, "uuid-4", "href-4", "crossReference", "collection");
assertEquals(errorsStart + 2, countFailures(Xml.transform(testMetadata, getSchematronXsl(), params)));
bad.detach();
}

private static Element addDatasetIdentifier(Element parent, String uuid, String href, String associationType, String initiativeType) {
Element ai = new Element("aggregationInfo", GMD);
Element mdAi = new Element("MD_AggregateInformation", GMD);
Element adsi = new Element("aggregateDataSetIdentifier", GMD);
Element mdIdentifier = new Element("MD_Identifier", GMD);
Element code = new Element("code", GMD);

Element at = new Element("associationType", GMD);
Element dsAt = new Element("DS_AssociationTypeCode", GMD);
dsAt.setAttribute("codeListValue", associationType);
dsAt.setAttribute("codeList", "http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#DS_AssociationTypeCode");

at.addContent(dsAt);
ai.addContent(mdAi);
mdAi.addContent(adsi);
mdAi.addContent(at);
adsi.addContent(mdIdentifier);
mdIdentifier.addContent(code);

if (initiativeType != null) {
Element it = new Element("initiativeType", GMD);
Element dsIt = new Element("DS_InitiativeTypeCode", GMD);
dsIt.setAttribute("codeListValue", initiativeType);
dsIt.setAttribute("codeList", "http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#DS_InitiativeTypeCode");
it.addContent(dsIt);
mdAi.addContent(it);
}

if (href != null) {
Element anchor = new Element("Anchor", GMX);
anchor.setAttribute("href", href, XLINK);
anchor.setText(uuid);
code.addContent(anchor);
} else {
Element cs = new Element("CharacterString", GCO);
cs.setText(uuid);
code.addContent(cs);
}

parent.addContent(ai);

return ai;
}

private void testNoStringErrors(Element testMetadata, Element contact) throws Exception {
contact.setContent(Collections.emptyList());

Expand Down

0 comments on commit 14dbaac

Please sign in to comment.