Skip to content

Commit

Permalink
check online resource url for duplications (#369)
Browse files Browse the repository at this point in the history
* check online resource url for duplications

* Revert "check online resource url for duplications"

This reverts commit 8f9510d

* refactor resource duplication check by xsl in schematron

* change error message

* Error message with lang, url information

* review

* update getDuplicatedResource validation function
  • Loading branch information
wangf1122 authored Apr 19, 2024
1 parent d5798a0 commit 002796e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
<ServiceNamespace>srv:SV_ServiceIdentification is misplaced for gmd:MD_ScopeCode: </ServiceNamespace>
<MissingContactMail>Contact - Electronic mail address is required</MissingContactMail>

<requireCitation>Citation</requireCitation>
<alert.requiredCitation>Data Identification Citation is a required element</alert.requiredCitation>
<hasDuplicatedOnlineResource>Duplicated Online Resource URLs for the same language are not allowed. The following duplicate(s) (language; URL) were identified:</hasDuplicatedOnlineResource>

</strings>
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
<ServiceNamespace>srv:SV_ServiceIdentification est mal placé pour gmd:MD_ScopeCode: </ServiceNamespace>
<MissingContactMail>Contact - Adresse de courrier électronique obligatoire</MissingContactMail>

<requireCitation>Citation</requireCitation>
<alert.requiredCitation>La citation d’identification des données est un élément obligatoire</alert.requiredCitation>
<hasDuplicatedOnlineResource>Les URL de ressources en ligne dupliquées pour la même langue ne sont pas autorisées. Les doublons suivants (langue ; URL) ont été identifiés :</hasDuplicatedOnlineResource>

</strings>
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,37 @@
</xsl:for-each>
</xsl:function>


<xsl:function xmlns:sch="http://purl.oclc.org/dsdl/schematron"
name="geonet:getDuplicateResources"
as="xs:string">
<xsl:param name="elements" as="element()*"/>

<!-- Find groups of elements with duplicates -->
<xsl:variable name="duplicateResourcesElements">
<xsl:for-each-group select="$elements"
group-by="concat(gmd:linkage/gmd:URL/text(), '|', tokenize(gmd:description/gco:CharacterString/text(), ';')[3])">
<xsl:if test="count(current-group()) &gt; 1">
<xsl:sequence select="."/>
</xsl:if>
</xsl:for-each-group>
</xsl:variable>

<!-- Iterate over duplicate groups and generate the list of duplicates -->
<xsl:variable name="duplicateResources">
<xsl:for-each select="$duplicateResourcesElements/*">
<xsl:if test="position() &gt; 1">
<xsl:text>, </xsl:text>
</xsl:if>
<xsl:value-of select="concat(' ', tokenize(gmd:description/gco:CharacterString/text(), ';')[3], ';')"/>
<xsl:value-of select="gmd:linkage/gmd:URL/text()"/>
</xsl:for-each>
</xsl:variable>

<!-- Return the results -->
<xsl:value-of select="$duplicateResources"/>
</xsl:function>

<!--- Metadata pattern -->
<sch:pattern>
<sch:title>$loc/strings/Metadata</sch:title>
Expand Down Expand Up @@ -520,6 +551,8 @@
<sch:let name="mapRESTCount" value="count(gmd:transferOptions/gmd:MD_DigitalTransferOptions/gmd:onLine[@xlink:role='urn:xml:lang:eng-CAN' and translate(gmd:CI_OnlineResource/gmd:protocol/gco:CharacterString, $uppercase, $smallcase) = 'esri rest: map service']) +
count(gmd:transferOptions/gmd:MD_DigitalTransferOptions/gmd:onLine[@xlink:role='urn:xml:lang:fra-CAN' and translate(gmd:CI_OnlineResource/gmd:protocol/gco:CharacterString, $uppercase, $smallcase) = 'esri rest: map service'])" />

<sch:let name="onlineResources" value="gmd:transferOptions/gmd:MD_DigitalTransferOptions/gmd:onLine/gmd:CI_OnlineResource" />

<sch:assert test="$mapRESTCount &lt;= 2">$loc/strings/MapResourcesRESTNumber</sch:assert>
<sch:assert test="$mapRESTCount = 0 or $mapRESTCount = 2 or $mapRESTCount &gt; 2">$loc/strings/MapResourcesREST</sch:assert>

Expand All @@ -528,6 +561,11 @@

<sch:assert test="$mapWMSCount &lt;= 2">$loc/strings/MapResourcesWMSNumber</sch:assert>
<sch:assert test="$mapWMSCount = 0 or $mapWMSCount = 2 or $mapWMSCount &gt; 2">$loc/strings/MapResourcesWMS</sch:assert>

<sch:let name="duplicatedResource" value="geonet:getDuplicateResources($onlineResources)" />
<sch:let name="locMsg" value="geonet:appendLocaleMessage($loc/strings/hasDuplicatedOnlineResource, $duplicatedResource)" />

<sch:assert test="not(string($duplicatedResource))">$locMsg</sch:assert>
</sch:rule>

<!-- Distribution - Format -->
Expand Down

0 comments on commit 002796e

Please sign in to comment.