From 4b0e20d3ffc53b354cc86a78c24a0f351853559b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Prunayre?= Date: Fri, 9 Aug 2024 06:47:44 +0200 Subject: [PATCH] Standard / ISO19139 / Fix removal of online source when multiple transfer options block are used. (#8281) * Standard / ISO19139 / Fix removal of online source when multiple transfer options block are used. Follow up of https://github.com/geonetwork/core-geonetwork/pull/7431 * Fix online resource update/delete so that it supports multiple gmd:MD_DigitalTransferOptions blocks. --------- Co-authored-by: Ian Allen --- .../plugin/iso19139/extract-relations.xsl | 5 ++-- .../plugin/iso19139/index-fields/index.xsl | 6 ++-- .../plugin/iso19139/process/onlinesrc-add.xsl | 28 +++++++++++++------ .../iso19139/process/onlinesrc-remove.xsl | 22 +++++++++++---- 4 files changed, 39 insertions(+), 22 deletions(-) diff --git a/schemas/iso19139/src/main/plugin/iso19139/extract-relations.xsl b/schemas/iso19139/src/main/plugin/iso19139/extract-relations.xsl index 10e10352ab8..7aa2b12d7a1 100644 --- a/schemas/iso19139/src/main/plugin/iso19139/extract-relations.xsl +++ b/schemas/iso19139/src/main/plugin/iso19139/extract-relations.xsl @@ -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"> @@ -110,7 +109,7 @@ - + - + <xsl:apply-templates mode="get-iso19139-localized-string" diff --git a/schemas/iso19139/src/main/plugin/iso19139/index-fields/index.xsl b/schemas/iso19139/src/main/plugin/iso19139/index-fields/index.xsl index d2fdc3f4a78..15f081abb99 100644 --- a/schemas/iso19139/src/main/plugin/iso19139/index-fields/index.xsl +++ b/schemas/iso19139/src/main/plugin/iso19139/index-fields/index.xsl @@ -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" @@ -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)"/> @@ -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) diff --git a/schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-add.xsl b/schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-add.xsl index 0afe80eaa3d..e9c86757ca4 100644 --- a/schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-add.xsl +++ b/schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-add.xsl @@ -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 --> @@ -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 != ''"> diff --git a/schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-remove.xsl b/schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-remove.xsl index 718f483eced..5ea7b210773 100644 --- a/schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-remove.xsl +++ b/schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-remove.xsl @@ -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()">