Skip to content

Commit

Permalink
Fix online resource update/delete so that it supports multiple gmd:MD…
Browse files Browse the repository at this point in the history
…_DigitalTransferOptions blocks. (#393)
  • Loading branch information
tylerjmchugh authored Aug 20, 2024
1 parent 097c317 commit 3f7ed80
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
6 changes: 4 additions & 2 deletions src/main/plugin/iso19139.ca.HNAP/index-fields/index.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:gn-fn-index="http://geonetwork-opensource.org/xsl/functions/index"
xmlns:index="java:org.fao.geonet.kernel.search.EsSearchManager"
xmlns:digestUtils="java:org.apache.commons.codec.digest.DigestUtils"
xmlns:util="java:org.fao.geonet.util.XslUtil"
xmlns:date-util="java:org.fao.geonet.utils.DateUtil"
xmlns:daobs="http://daobs.org"
Expand Down Expand Up @@ -941,8 +942,7 @@
<xsl:copy-of select="gn-fn-index:add-multilingual-field('orderingInstructions', ., $allLanguages)"/>
</xsl:for-each>

<xsl:for-each select="gmd:transferOptions/*/
gmd:onLine/*[gmd:linkage/gmd:URL != '']">
<xsl:for-each select=".//gmd:onLine/*[gmd:linkage/gmd:URL != '']">

<xsl:variable name="transferGroup"
select="count(ancestor::gmd:transferOptions/preceding-sibling::gmd:transferOptions)"/>
Expand All @@ -966,6 +966,8 @@
<atomfeed><xsl:value-of select="gmd:linkage/gmd:URL"/></atomfeed>
</xsl:if>
<link type="object">{
"hash": "<xsl:value-of select="digestUtils:md5Hex(normalize-space(.))"/>",
"idx": <xsl:value-of select="position()"/>,
"protocol":"<xsl:value-of select="gn-fn-index:json-escape((gmd:protocol/*/text())[1])"/>",
"mimeType":"<xsl:value-of select="if (*/gmx:MimeFileType)
then gn-fn-index:json-escape(*/gmx:MimeFileType/@type)
Expand Down
32 changes: 21 additions & 11 deletions src/main/plugin/iso19139.ca.HNAP/process/onlinesrc-add.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -186,19 +186,29 @@ Note: It assumes that it will be adding new items in
<!-- Updating the gmd:onLine based on update parameters -->
<!-- Note: first part of the match needs to match the xsl:for-each select from extract-relations.xsl in order to get the position() to match -->
<!-- The unique identifier is marked with resourceIdx which is the position index and resourceHash which is hash code of the current node (combination of url, resource name, and description) -->
<xsl:template
match="*//gmd:MD_DigitalTransferOptions/gmd:onLine
[gmd:CI_OnlineResource[gmd:linkage/gmd:URL!=''] and ($resourceIdx = '' or position() = xs:integer($resourceIdx))]
[($resourceHash != '' or ($updateKey != '' and normalize-space($updateKey) = concat(
gmd:CI_OnlineResource/gmd:linkage/gmd:URL,
gmd:CI_OnlineResource/gmd:protocol/*,
gmd:CI_OnlineResource/gmd:name/gco:CharacterString)))
and ($resourceHash = '' or digestUtils:md5Hex(string(exslt:node-set(.))) = $resourceHash)]"
priority="2">
<xsl:call-template name="createOnlineSrc"/>
<!-- Template to match all gmd:onLine elements -->
<xsl:template match="//gmd:MD_DigitalTransferOptions/gmd:onLine" priority="2">
<!-- Calculate the global position of the current gmd:onLine element -->
<xsl:variable name="position" select="count(//gmd:MD_DigitalTransferOptions/gmd:onLine[current() >> .]) + 1" />

<xsl:choose>
<xsl:when test="gmd:CI_OnlineResource[gmd:linkage/gmd:URL != ''] and
($resourceIdx = '' or $position = xs:integer($resourceIdx)) and
($resourceHash != '' or ($updateKey != '' and normalize-space($updateKey) = concat(
gmd:CI_OnlineResource/gmd:linkage/gmd:URL,
gmd:CI_OnlineResource/gmd:protocol/*,
gmd:CI_OnlineResource/gmd:name/gco:CharacterString)))
and ($resourceHash = '' or digestUtils:md5Hex(normalize-space(.)) = $resourceHash)">
<xsl:call-template name="createOnlineSrc"/>
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>


<xsl:template name="createOnlineSrc">
<!-- Add all online source from the target metadata to the
current one -->
Expand Down

0 comments on commit 3f7ed80

Please sign in to comment.