Skip to content

Commit

Permalink
Standard / ISO19139 / Fix removal of online source when multiple tran…
Browse files Browse the repository at this point in the history
…sfer options block are used. (#8281)

* Standard / ISO19139 / Fix removal of online source when multiple
transfer options block are used.

Follow up of #7431

* Fix online resource update/delete so that it supports multiple gmd:MD_DigitalTransferOptions blocks.

---------

Co-authored-by: Ian Allen <[email protected]>
  • Loading branch information
fxprunayre and ianwallen committed Aug 9, 2024
1 parent aa52573 commit 4b0e20d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:util="java:org.fao.geonet.util.XslUtil"
xmlns:digestUtils="java:org.apache.commons.codec.digest.DigestUtils"
xmlns:exslt="http://exslt.org/common"
xmlns:gn-fn-rel="http://geonetwork-opensource.org/xsl/functions/relations"
version="2.0"
exclude-result-prefixes="#all">
Expand Down Expand Up @@ -110,7 +109,7 @@
<xsl:value-of select="position()"/>
</idx>
<hash>
<xsl:value-of select="digestUtils:md5Hex(string(exslt:node-set(normalize-space(.))))"/>
<xsl:value-of select="digestUtils:md5Hex(normalize-space(.))"/>
</hash>
<url>
<xsl:apply-templates mode="get-iso19139-localized-string"
Expand Down Expand Up @@ -142,7 +141,7 @@
<xsl:value-of select="position()"/>
</idx>
<hash>
<xsl:value-of select="digestUtils:md5Hex(string(exslt:node-set(normalize-space(.))))"/>
<xsl:value-of select="digestUtils:md5Hex(normalize-space(.))"/>
</hash>
<title>
<xsl:apply-templates mode="get-iso19139-localized-string"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
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:exslt="http://exslt.org/common"
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 @@ -1122,8 +1121,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 @@ -1147,7 +1145,7 @@
<atomfeed><xsl:value-of select="gmd:linkage/gmd:URL"/></atomfeed>
</xsl:if>
<link type="object">{
"hash": "<xsl:value-of select="digestUtils:md5Hex(string(exslt:node-set(normalize-space(.))))"/>",
"hash": "<xsl:value-of select="digestUtils:md5Hex(normalize-space(.))"/>",
"idx": <xsl:value-of select="position()"/>,
"protocol":"<xsl:value-of select="util:escapeForJson((gmd:protocol/*/text())[1])"/>",
"mimeType":"<xsl:value-of select="if (*/gmx:MimeFileType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,19 +187,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(
<!-- 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(string(exslt:node-set(normalize-space(.)))) = $resourceHash)]"
priority="2">
<xsl:call-template name="createOnlineSrc"/>
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 Expand Up @@ -243,7 +253,7 @@ Note: It assumes that it will be adding new items in
</gmd:URL>
</gmd:linkage>
<gmd:protocol>
<xsl:call-template name="setProtocol"/>
<xsl:call-template name="setProtocol"/>
</gmd:protocol>

<xsl:if test="$applicationProfile != ''">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,25 @@ Stylesheet used to remove a reference to a online resource.
<!-- Remove the gmd:onLine define in url parameter -->
<!-- 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 (count(preceding::gmd:onLine) + 1) = xs:integer($resourceIdx))]
[($resourceHash != '' or ($url != null and (normalize-space(gmd:CI_OnlineResource/gmd:linkage/gmd:URL) = $url and normalize-space(gmd:CI_OnlineResource/gmd:name/gco:CharacterString) = normalize-space($name)
<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:if test="not(
gmd:CI_OnlineResource[gmd:linkage/gmd:URL != ''] and
($resourceIdx = '' or $position = xs:integer($resourceIdx)) and
($resourceHash != '' or ($url != null and (normalize-space(gmd:CI_OnlineResource/gmd:linkage/gmd:URL) = $url and normalize-space(gmd:CI_OnlineResource/gmd:name/gco:CharacterString) = normalize-space($name)
or normalize-space(gmd:CI_OnlineResource/gmd:linkage/gmd:URL) = $url and count(gmd:CI_OnlineResource/gmd:name/gmd:PT_FreeText/gmd:textGroup[gmd:LocalisedCharacterString = $name]) > 0
or normalize-space(gmd:CI_OnlineResource/gmd:linkage/gmd:URL) = $url and normalize-space(gmd:CI_OnlineResource/gmd:protocol/*) = 'WWW:DOWNLOAD-1.0-http--download'))
)
and ($resourceHash = '' or digestUtils:md5Hex(string(exslt:node-set(normalize-space(.)))) = $resourceHash)]"
priority="2"/>
and ($resourceHash = '' or digestUtils:md5Hex(normalize-space(.)) = $resourceHash)
)">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:if>
</xsl:template>

<!-- Do a copy of every node and attribute -->
<xsl:template match="@*|node()">
Expand Down

0 comments on commit 4b0e20d

Please sign in to comment.