From acc3540c4fca1e37e78602b8b97fa1e3c67ed758 Mon Sep 17 00:00:00 2001 From: WANGF Date: Thu, 12 Oct 2023 14:00:34 -0400 Subject: [PATCH 01/15] Passing the index into remove process xslt for iso 19139 --- .../src/main/plugin/iso19139/extract-relations.xsl | 4 +++- .../plugin/iso19139/process/onlinesrc-remove.xsl | 7 ++++--- .../components/edit/onlinesrc/OnlineSrcService.js | 12 +++++++++++- .../edit/onlinesrc/partials/onlinesrcList.html | 2 +- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/schemas/iso19139/src/main/plugin/iso19139/extract-relations.xsl b/schemas/iso19139/src/main/plugin/iso19139/extract-relations.xsl index 2b27b5e2140..dd87f5281bf 100644 --- a/schemas/iso19139/src/main/plugin/iso19139/extract-relations.xsl +++ b/schemas/iso19139/src/main/plugin/iso19139/extract-relations.xsl @@ -34,6 +34,7 @@ xmlns:gmx="http://www.isotc211.org/2005/gmx" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:util="java:org.fao.geonet.util.XslUtil" + xmlns:uuid="java:java.util.UUID" xmlns:gn-fn-rel="http://geonetwork-opensource.org/xsl/functions/relations" version="2.0" exclude-result-prefixes="#all"> @@ -126,8 +127,9 @@ + - + <xsl:apply-templates mode="get-iso19139-localized-string" 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 f11cd771f49..e945099369a 100644 --- a/schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-remove.xsl +++ b/schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-remove.xsl @@ -30,6 +30,7 @@ Stylesheet used to remove a reference to a online resource. xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> + <xsl:param name="resourceIndex"/> <xsl:param name="url"/> <xsl:param name="name"/> @@ -42,12 +43,12 @@ Stylesheet used to remove a reference to a online resource. <!-- Remove geonet:* elements. --> <xsl:template - match="geonet:*|gmd:onLine[normalize-space(gmd:CI_OnlineResource/gmd:linkage/gmd:URL) = $url and normalize-space(gmd:CI_OnlineResource/gmd:name/gco:CharacterString) = normalize-space($name)]" + match="geonet:*|gmd:onLine[normalize-space(gmd:CI_OnlineResource/gmd:linkage/gmd:URL) = $url and normalize-space(gmd:CI_OnlineResource/gmd:name/gco:CharacterString) = normalize-space($name)][number($resourceIndex)]" priority="2"/> <xsl:template - match="geonet:*|gmd:onLine[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]" + match="geonet:*|gmd:onLine[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][number($resourceIndex)]" priority="2"/> <xsl:template - match="geonet:*|gmd:onLine[normalize-space(gmd:CI_OnlineResource/gmd:linkage/gmd:URL) = $url and normalize-space(gmd:CI_OnlineResource/gmd:protocol/*) = 'WWW:DOWNLOAD-1.0-http--download']" + match="geonet:*|gmd:onLine[normalize-space(gmd:CI_OnlineResource/gmd:linkage/gmd:URL) = $url and normalize-space(gmd:CI_OnlineResource/gmd:protocol/*) = 'WWW:DOWNLOAD-1.0-http--download'][number($resourceIndex)]" priority="2"/> </xsl:stylesheet> diff --git a/web-ui/src/main/resources/catalog/components/edit/onlinesrc/OnlineSrcService.js b/web-ui/src/main/resources/catalog/components/edit/onlinesrc/OnlineSrcService.js index 6d0003da1dd..faafd0e186c 100644 --- a/web-ui/src/main/resources/catalog/components/edit/onlinesrc/OnlineSrcService.js +++ b/web-ui/src/main/resources/catalog/components/edit/onlinesrc/OnlineSrcService.js @@ -712,7 +712,16 @@ * * @param {Object} onlinesrc the online resource to remove */ - removeOnlinesrc: function (onlinesrc) { + removeOnlinesrc: function (onlinesrc, onlines) { + //Passing the index of the xml/xpath into the remove process xsl + var xslIndex = -1; + for (var i = 0; i < onlines.length; i++) { + if (onlinesrc.id === onlines[i].id) { + xslIndex = i+1; + break; + } + } + var url = onlinesrc.lUrl || onlinesrc.url; if ( url.match(".*/api/records/' + gnCurrentEdit.uuid + '/attachments/.*") != null @@ -724,6 +733,7 @@ this, setParams("onlinesrc-remove", { id: gnCurrentEdit.id, + resourceIndex: xslIndex, url: url, name: $filter("gnLocalized")(onlinesrc.title) }) diff --git a/web-ui/src/main/resources/catalog/components/edit/onlinesrc/partials/onlinesrcList.html b/web-ui/src/main/resources/catalog/components/edit/onlinesrc/partials/onlinesrcList.html index bde4ba3f9aa..b326c7a2b1b 100644 --- a/web-ui/src/main/resources/catalog/components/edit/onlinesrc/partials/onlinesrcList.html +++ b/web-ui/src/main/resources/catalog/components/edit/onlinesrc/partials/onlinesrcList.html @@ -219,7 +219,7 @@ aria-label="{{'remove' | translate}} {{resource.title | gnLocalized: lang}}" data-ng-if="readonly !== true" data-gn-confirm-click="{{'removeOnlinesrcConfirm' | translate:{url: resource.lUrl} }}" - data-gn-click-and-spin="onlinesrcService.removeOnlinesrc(resource)" + data-gn-click-and-spin="onlinesrcService.removeOnlinesrc(resource, relations.onlines)" > <i class="fa fa-times text-danger"></i> </a> From f4a8b82ca53ce777c28ea66f417c59a762613798 Mon Sep 17 00:00:00 2001 From: Ian Allen <ianwallen@hotmail.com> Date: Fri, 27 Oct 2023 16:16:38 -0300 Subject: [PATCH 02/15] Updated resource logic to use 2 new field called idx and hash and revert id back to the old method. This will ensure backward compatibility Also update xslt for add and remove thumbnail/onlines recources --- .../plugin/iso19139/extract-relations.xsl | 105 ++++++----- .../plugin/iso19139/process/onlinesrc-add.xsl | 169 ++++++++++-------- .../iso19139/process/onlinesrc-remove.xsl | 57 ++++-- .../plugin/iso19139/process/thumbnail-add.xsl | 79 ++++---- .../iso19139/process/thumbnail-remove.xsl | 29 ++- .../records/model/related/RelatedItem.java | 40 +++++ .../edit/onlinesrc/OnlineSrcDirective.js | 13 +- .../edit/onlinesrc/OnlineSrcService.js | 22 +-- .../onlinesrc/partials/onlinesrcList.html | 2 +- 9 files changed, 329 insertions(+), 187 deletions(-) diff --git a/schemas/iso19139/src/main/plugin/iso19139/extract-relations.xsl b/schemas/iso19139/src/main/plugin/iso19139/extract-relations.xsl index dd87f5281bf..1aaa8d06b8d 100644 --- a/schemas/iso19139/src/main/plugin/iso19139/extract-relations.xsl +++ b/schemas/iso19139/src/main/plugin/iso19139/extract-relations.xsl @@ -34,7 +34,7 @@ xmlns:gmx="http://www.isotc211.org/2005/gmx" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:util="java:org.fao.geonet.util.XslUtil" - xmlns:uuid="java:java.util.UUID" + xmlns:exslt="http://exslt.org/common" xmlns:gn-fn-rel="http://geonetwork-opensource.org/xsl/functions/relations" version="2.0" exclude-result-prefixes="#all"> @@ -86,7 +86,7 @@ </xsl:template> <!-- Relation contained in the metadata record has to be returned - It could be document or thumbnails + It could be a document or thumbnails --> <xsl:template mode="relation" match="metadata[gmd:MD_Metadata or *[contains(@gco:isoType, 'MD_Metadata')]]" @@ -100,18 +100,24 @@ <xsl:if test="count(*/descendant::*[name(.) = 'gmd:graphicOverview']/*) > 0"> <thumbnails> - <xsl:for-each select="*/descendant::*[name(.) = 'gmd:graphicOverview']/*"> + <xsl:for-each select="*/descendant::*[name(.) = 'gmd:graphicOverview']"> <item> <id> - <xsl:value-of select="gmd:fileName/gco:CharacterString"/> + <xsl:value-of select="gmd:MD_BrowseGraphic/gmd:fileName/gco:CharacterString"/> </id> + <idx> + <xsl:value-of select="position()"/> + </idx> + <hash> + <xsl:value-of select="util:md5Hex(exslt:node-set(.))"/> + </hash> <url> <xsl:apply-templates mode="get-iso19139-localized-string" - select="gmd:fileName"/> + select="gmd:MD_BrowseGraphic/gmd:fileName"/> </url> <title> <xsl:apply-templates mode="get-iso19139-localized-string" - select="gmd:fileDescription"/> + select="gmd:MD_BrowseGraphic/gmd:fileDescription"/> thumbnail @@ -121,47 +127,54 @@ - - - - - - - - - - - - <xsl:apply-templates mode="get-iso19139-localized-string" - select="gmd:name"/> - - - + + + + + + + + - - - - - - - - - - - - - - - - - - onlinesrc - + + + + + + + + + <xsl:apply-templates mode="get-iso19139-localized-string" + select="gmd:CI_OnlineResource/gmd:name"/> + + + + + + + + + + + + + + + + + + + + + + onlinesrc + + 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 6947108375b..09deafe2af6 100644 --- a/schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-add.xsl +++ b/schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-add.xsl @@ -30,6 +30,9 @@ Insert is made in first transferOptions found. xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:gmx="http://www.isotc211.org/2005/gmx" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:xs="http://www.w3.org/2001/XMLSchema" + xmlns:util="java:org.fao.geonet.util.XslUtil" + xmlns:exslt="http://exslt.org/common" version="2.0"> - + + + + + + + - + + + - - - - - - - - - - - - - - - + + + + + + - + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - + + + + + + + - - + + + - + gmd:CI_OnlineResource/gmd:name/gco:CharacterString)) + and ($resourceHash = '' or util:md5Hex(exslt:node-set(.)) = $resourceHash)"> + + + + + + + + + + @@ -170,7 +195,7 @@ Insert is made in first transferOptions found. + + + - + + + + + + + + + + + + + + + + + + - - - - + + + diff --git a/schemas/iso19139/src/main/plugin/iso19139/process/thumbnail-add.xsl b/schemas/iso19139/src/main/plugin/iso19139/process/thumbnail-add.xsl index 16b975a837c..83553d4543c 100644 --- a/schemas/iso19139/src/main/plugin/iso19139/process/thumbnail-add.xsl +++ b/schemas/iso19139/src/main/plugin/iso19139/process/thumbnail-add.xsl @@ -27,6 +27,9 @@ xmlns:srv="http://www.isotc211.org/2005/srv" xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:geonet="http://www.fao.org/geonetwork" + xmlns:xs="http://www.w3.org/2001/XMLSchema" + xmlns:util="java:org.fao.geonet.util.XslUtil" + xmlns:exslt="http://exslt.org/common" exclude-result-prefixes="#all" version="2.0"> @@ -41,55 +44,51 @@ - + + + - + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - + + + - + */gmd:fileDescription/gco:CharacterString)) + and ($resourceHash = '' or util:md5Hex(exslt:node-set(.)) = $resourceHash)"> + + + + + + + + + + + + + match="*[gmd:graphicOverview]"> + + + + + + + + + + + + + - + diff --git a/services/src/main/java/org/fao/geonet/api/records/model/related/RelatedItem.java b/services/src/main/java/org/fao/geonet/api/records/model/related/RelatedItem.java index c24ebd29d9c..a8b9b4491d2 100644 --- a/services/src/main/java/org/fao/geonet/api/records/model/related/RelatedItem.java +++ b/services/src/main/java/org/fao/geonet/api/records/model/related/RelatedItem.java @@ -40,6 +40,8 @@ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "relatedItem", propOrder = { "id", + "idx", + "hash", "url", "title", "type" @@ -52,6 +54,8 @@ public abstract class RelatedItem { protected String id; + protected String idx; + protected String hash; protected MultilingualValue url; protected String type; @@ -76,6 +80,42 @@ public void setId(String value) { this.id = value; } + /** + * Gets the value of the idx property. + * + * @return possible object is {@link String } + */ + public String getIdx() { + return idx; + } + + /** + * Sets the value of the idx property. + * + * @param value allowed object is {@link String } + */ + public void setIdx(String value) { + this.idx = value; + } + + /** + * Gets the value of the hasg property. + * + * @return possible object is {@link String } + */ + public String getHash() { + return hash; + } + + /** + * Sets the value of the hash property. + * + * @param value allowed object is {@link String } + */ + public void setHash(String value) { + this.hash = value; + } + /** * Gets the value of the url property. * diff --git a/web-ui/src/main/resources/catalog/components/edit/onlinesrc/OnlineSrcDirective.js b/web-ui/src/main/resources/catalog/components/edit/onlinesrc/OnlineSrcDirective.js index 636ad8006ef..0856013bf6b 100644 --- a/web-ui/src/main/resources/catalog/components/edit/onlinesrc/OnlineSrcDirective.js +++ b/web-ui/src/main/resources/catalog/components/edit/onlinesrc/OnlineSrcDirective.js @@ -964,6 +964,8 @@ } } scope.editingKey = [keyUrl, linkToEdit.protocol, keyName].join(""); + scope.editingIdx = linkToEdit.idx; + scope.editingHash = linkToEdit.hash; scope.OGCProtocol = checkIsOgc(linkToEdit.protocol); @@ -1012,6 +1014,8 @@ }; } else { scope.editingKey = null; + scope.editingIdx = null; + scope.editingHash = null; scope.params.linkType = typeConfig; scope.params.protocol = null; scope.params.mimeType = ""; @@ -1203,6 +1207,8 @@ if (scope.isEditing) { processParams.updateKey = scope.editingKey; + processParams.resourceIdx = scope.editingIdx; + processParams.resourceHash = scope.editingHash; } // Add list of layers for WMS @@ -1944,7 +1950,12 @@ * @returns {boolean} */ scope.canEnableLinkButton = function (selectRecords) { - if (selectRecords.length < 1) return false; + if ( + !selectRecords || + !Array.isArray(selectRecords) || + selectRecords.length < 1 + ) + return false; // Check if the metadata titles are defined for (var i = 0; i < selectRecords.length; i++) { diff --git a/web-ui/src/main/resources/catalog/components/edit/onlinesrc/OnlineSrcService.js b/web-ui/src/main/resources/catalog/components/edit/onlinesrc/OnlineSrcService.js index faafd0e186c..9f76534f31f 100644 --- a/web-ui/src/main/resources/catalog/components/edit/onlinesrc/OnlineSrcService.js +++ b/web-ui/src/main/resources/catalog/components/edit/onlinesrc/OnlineSrcService.js @@ -682,17 +682,21 @@ this, setParams("thumbnail-remove", { id: gnCurrentEdit.id, - thumbnail_url: thumb.id + thumbnail_url: thumb.id, + resourceIdx: thumb.idx, + resourceHash: thumb.hash }) ); } - // It is an uploaded tumbnail + // It is an uploaded thumbnail else { return runService( "removeThumbnail", { type: thumb.title === "thumbnail" ? "small" : "large", id: gnCurrentEdit.id, + resourceIdx: thumb.idx, + resourceHash: thumb.hash, version: gnCurrentEdit.version }, this @@ -712,16 +716,7 @@ * * @param {Object} onlinesrc the online resource to remove */ - removeOnlinesrc: function (onlinesrc, onlines) { - //Passing the index of the xml/xpath into the remove process xsl - var xslIndex = -1; - for (var i = 0; i < onlines.length; i++) { - if (onlinesrc.id === onlines[i].id) { - xslIndex = i+1; - break; - } - } - + removeOnlinesrc: function (onlinesrc) { var url = onlinesrc.lUrl || onlinesrc.url; if ( url.match(".*/api/records/' + gnCurrentEdit.uuid + '/attachments/.*") != null @@ -733,7 +728,8 @@ this, setParams("onlinesrc-remove", { id: gnCurrentEdit.id, - resourceIndex: xslIndex, + resourceHash: onlinesrc.hash, + resourceIdx: onlinesrc.idx, url: url, name: $filter("gnLocalized")(onlinesrc.title) }) diff --git a/web-ui/src/main/resources/catalog/components/edit/onlinesrc/partials/onlinesrcList.html b/web-ui/src/main/resources/catalog/components/edit/onlinesrc/partials/onlinesrcList.html index b326c7a2b1b..bde4ba3f9aa 100644 --- a/web-ui/src/main/resources/catalog/components/edit/onlinesrc/partials/onlinesrcList.html +++ b/web-ui/src/main/resources/catalog/components/edit/onlinesrc/partials/onlinesrcList.html @@ -219,7 +219,7 @@ aria-label="{{'remove' | translate}} {{resource.title | gnLocalized: lang}}" data-ng-if="readonly !== true" data-gn-confirm-click="{{'removeOnlinesrcConfirm' | translate:{url: resource.lUrl} }}" - data-gn-click-and-spin="onlinesrcService.removeOnlinesrc(resource, relations.onlines)" + data-gn-click-and-spin="onlinesrcService.removeOnlinesrc(resource)" > From af6ad789a89856760d88cee9fffd9e3818002b0b Mon Sep 17 00:00:00 2001 From: Ian Allen Date: Mon, 30 Oct 2023 09:05:42 -0300 Subject: [PATCH 03/15] Add missing that was causing bugs. --- .../plugin/iso19139/process/onlinesrc-add.xsl | 43 +++++++++--------- .../iso19139/process/onlinesrc-remove.xsl | 45 ++++++++++--------- .../plugin/iso19139/process/thumbnail-add.xsl | 45 ++++++++++--------- .../iso19139/process/thumbnail-remove.xsl | 37 +++++++-------- 4 files changed, 87 insertions(+), 83 deletions(-) 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 09deafe2af6..49e29081235 100644 --- a/schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-add.xsl +++ b/schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-add.xsl @@ -62,9 +62,9 @@ Insert is made in first transferOptions found. resourceIdx is the index location of the object to be removed - can be used when duplicate entries exists to ensure the correct one is removed. --> - - - + + + @@ -151,24 +151,25 @@ Insert is made in first transferOptions found. - - - - - - - - - - - - - + + + + + + + + + + + + + + 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 d0736747f26..e160b45f77d 100644 --- a/schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-remove.xsl +++ b/schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-remove.xsl @@ -44,34 +44,35 @@ Stylesheet used to remove a reference to a online resource. onlinesrc-remove?url=http://geonetwork.org/resource.txt&name=test --> - - - - + + + + - - - - - - - - - - - + + - + + + + + + + + + + + diff --git a/schemas/iso19139/src/main/plugin/iso19139/process/thumbnail-add.xsl b/schemas/iso19139/src/main/plugin/iso19139/process/thumbnail-add.xsl index 83553d4543c..e89645a6f20 100644 --- a/schemas/iso19139/src/main/plugin/iso19139/process/thumbnail-add.xsl +++ b/schemas/iso19139/src/main/plugin/iso19139/process/thumbnail-add.xsl @@ -50,9 +50,9 @@ resourceHash is hash value of the object to be removed which will ensure the correct value is removed. It will override the usage of updateKey resourceIdx is the index location of the object to be removed - can be used when duplicate entries exists to ensure the correct one is removed. --> - - - + + + @@ -70,25 +70,26 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - + + + - - - - - - - - - - - - + + + + + + + + + + + + + From bdc8c671b7bb869741d13d534af019918baaad48 Mon Sep 17 00:00:00 2001 From: WANGF Date: Tue, 28 Nov 2023 16:47:55 -0500 Subject: [PATCH 04/15] unit test fix --- .../src/main/plugin/iso19139/process/onlinesrc-add.xsl | 4 ++-- .../src/main/plugin/iso19139/process/onlinesrc-remove.xsl | 4 ++-- .../src/main/plugin/iso19139/process/thumbnail-add.xsl | 4 ++-- .../src/main/plugin/iso19139/process/thumbnail-remove.xsl | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) 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 49e29081235..14086fe2858 100644 --- a/schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-add.xsl +++ b/schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-add.xsl @@ -31,7 +31,7 @@ Insert is made in first transferOptions found. xmlns:gmx="http://www.isotc211.org/2005/gmx" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" - xmlns:util="java:org.fao.geonet.util.XslUtil" + xmlns:digestUtils="java:org.apache.commons.codec.digest.DigestUtils" xmlns:exslt="http://exslt.org/common" version="2.0"> @@ -161,7 +161,7 @@ Insert is made in first transferOptions found. gmd:CI_OnlineResource/gmd:linkage/gmd:URL, gmd:CI_OnlineResource/gmd:protocol/*, gmd:CI_OnlineResource/gmd:name/gco:CharacterString))) - and ($resourceHash = '' or util:md5Hex(exslt:node-set(.)) = $resourceHash)"> + and ($resourceHash = '' or digestUtils:md5Hex(exslt:node-set(.)) = $resourceHash)"> 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 e160b45f77d..c944c895e58 100644 --- a/schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-remove.xsl +++ b/schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-remove.xsl @@ -29,7 +29,7 @@ Stylesheet used to remove a reference to a online resource. xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" - xmlns:util="java:org.fao.geonet.util.XslUtil" + xmlns:digestUtils="java:org.apache.commons.codec.digest.DigestUtils" xmlns:exslt="http://exslt.org/common" version="2.0"> @@ -64,7 +64,7 @@ Stylesheet used to remove a reference to a online resource. 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 util:md5Hex(exslt:node-set(.)) = $resourceHash)"> + and ($resourceHash = '' or digestUtils:md5Hex(exslt:node-set(.)) = $resourceHash)"> diff --git a/schemas/iso19139/src/main/plugin/iso19139/process/thumbnail-add.xsl b/schemas/iso19139/src/main/plugin/iso19139/process/thumbnail-add.xsl index e89645a6f20..5ce2fe12ce8 100644 --- a/schemas/iso19139/src/main/plugin/iso19139/process/thumbnail-add.xsl +++ b/schemas/iso19139/src/main/plugin/iso19139/process/thumbnail-add.xsl @@ -28,7 +28,7 @@ xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:geonet="http://www.fao.org/geonetwork" xmlns:xs="http://www.w3.org/2001/XMLSchema" - xmlns:util="java:org.fao.geonet.util.XslUtil" + xmlns:digestUtils="java:org.apache.commons.codec.digest.DigestUtils" xmlns:exslt="http://exslt.org/common" exclude-result-prefixes="#all" version="2.0"> @@ -81,7 +81,7 @@ */gmd:fileName/gmd:PT_FreeText/gmd:textGroup/gmd:LocalisedCharacterString[@locale = '#DE'], */gmd:fileDescription/gmd:PT_FreeText/gmd:textGroup/gmd:LocalisedCharacterString[@locale = '#DE'], */gmd:fileDescription/gco:CharacterString))) - and ($resourceHash = '' or util:md5Hex(exslt:node-set(.)) = $resourceHash)"> + and ($resourceHash = '' or digestUtils:md5Hex(exslt:node-set(.)) = $resourceHash)"> diff --git a/schemas/iso19139/src/main/plugin/iso19139/process/thumbnail-remove.xsl b/schemas/iso19139/src/main/plugin/iso19139/process/thumbnail-remove.xsl index 02e55657664..2a55921581b 100644 --- a/schemas/iso19139/src/main/plugin/iso19139/process/thumbnail-remove.xsl +++ b/schemas/iso19139/src/main/plugin/iso19139/process/thumbnail-remove.xsl @@ -27,7 +27,7 @@ xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:geonet="http://www.fao.org/geonetwork" exclude-result-prefixes="#all" - xmlns:util="java:org.fao.geonet.util.XslUtil" + xmlns:digestUtils="java:org.apache.commons.codec.digest.DigestUtils" xmlns:exslt="http://exslt.org/common" version="2.0"> @@ -55,7 +55,7 @@ + and ($resourceHash = '' or digestUtils:md5Hex(exslt:node-set(.)) = $resourceHash)"> From fba52da5b05aac2cbc4fcd39855fa28fbfef5d03 Mon Sep 17 00:00:00 2001 From: Ian Allen Date: Mon, 15 Jan 2024 12:15:47 -0400 Subject: [PATCH 05/15] Fix issues based on code review. - Fix issue with ordering of elements. - Fix issue with md5Hex not working --- .../plugin/iso19139/extract-relations.xsl | 12 +- .../plugin/iso19139/process/onlinesrc-add.xsl | 139 +++++++++++------- .../iso19139/process/onlinesrc-remove.xsl | 26 +--- .../plugin/iso19139/process/thumbnail-add.xsl | 54 ++++--- .../iso19139/process/thumbnail-remove.xsl | 22 +-- 5 files changed, 135 insertions(+), 118 deletions(-) diff --git a/schemas/iso19139/src/main/plugin/iso19139/extract-relations.xsl b/schemas/iso19139/src/main/plugin/iso19139/extract-relations.xsl index 1aaa8d06b8d..fdc58f1b90a 100644 --- a/schemas/iso19139/src/main/plugin/iso19139/extract-relations.xsl +++ b/schemas/iso19139/src/main/plugin/iso19139/extract-relations.xsl @@ -98,9 +98,9 @@ - + - + @@ -109,7 +109,7 @@ - + - + - + @@ -141,7 +141,7 @@ - + <xsl:apply-templates mode="get-iso19139-localized-string" 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 14086fe2858..d03cb13a19d 100644 --- a/schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-add.xsl +++ b/schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-add.xsl @@ -25,6 +25,11 @@ <!-- Processing to insert or update an online resource element. Insert is made in first transferOptions found. + +Note: It assumes that it will be adding new items in + the first /gmd:distributionInfo + and first /gmd:MD_Distribution + and first /gmd:transferOptions --> <xsl:stylesheet xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:gco="http://www.isotc211.org/2005/gco" @@ -77,70 +82,101 @@ Insert is made in first transferOptions found. <!-- Add new gmd:onLine and consider cases where parent elements don't exist --> <!-- <gmd:distributionInfo> does not exist--> - <xsl:template match="gmd:MD_Metadata[$update_flag = false()]|*[@gco:isoType='gmd:MD_Metadata' and $update_flag = false()]"> + <xsl:template match="gmd:MD_Metadata[not(gmd:distributionInfo) and $update_flag = false()]|*[@gco:isoType='gmd:MD_Metadata' and not(gmd:distributionInfo) and $update_flag = false()]"> <xsl:copy> - <xsl:apply-templates select="node()|@*"/> - <xsl:if test="not(gmd:distributionInfo)"> - <gmd:distributionInfo> - <gmd:MD_Distribution> - <gmd:transferOptions> - <gmd:MD_DigitalTransferOptions> - <xsl:call-template name="createOnlineSrc"/> - </gmd:MD_DigitalTransferOptions> - </gmd:transferOptions> - </gmd:MD_Distribution> - </gmd:distributionInfo> - </xsl:if> + <xsl:apply-templates select="@*"/> + <xsl:apply-templates + select="gmd:fileIdentifier| + gmd:language| + gmd:characterSet| + gmd:parentIdentifier| + gmd:hierarchyLevel| + gmd:hierarchyLevelName| + gmd:contact| + gmd:dateStamp| + gmd:metadataStandardName| + gmd:metadataStandardVersion| + gmd:dataSetURI| + gmd:locale| + gmd:spatialRepresentationInfo| + gmd:referenceSystemInfo| + gmd:metadataExtensionInfo| + gmd:identificationInfo| + gmd:contentInfo"/> + + <gmd:distributionInfo> + <gmd:MD_Distribution> + <gmd:transferOptions> + <gmd:MD_DigitalTransferOptions> + <xsl:call-template name="createOnlineSrc"/> + </gmd:MD_DigitalTransferOptions> + </gmd:transferOptions> + </gmd:MD_Distribution> + </gmd:distributionInfo> + + + <xsl:apply-templates + select="gmd:dataQualityInfo| + gmd:portrayalCatalogueInfo| + gmd:metadataConstraints| + gmd:applicationSchemaInfo| + gmd:metadataMaintenance| + gmd:series| + gmd:describes| + gmd:propertyType| + gmd:featureType| + gmd:featureAttribute"/> </xsl:copy> </xsl:template> <!-- <gmd:MD_Distribution> does not exist--> - <xsl:template match="*/gmd:distributionInfo[$update_flag = false()]"> + <xsl:template match="*/gmd:distributionInfo[not(gmd:MD_Distribution) and $update_flag = false() and position() = 1]"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> - <xsl:if test="not(gmd:MD_Distribution)"> - <gmd:MD_Distribution> - <gmd:transferOptions> - <gmd:MD_DigitalTransferOptions> - <xsl:call-template name="createOnlineSrc"/> - </gmd:MD_DigitalTransferOptions> - </gmd:transferOptions> - </gmd:MD_Distribution> - </xsl:if> + <gmd:MD_Distribution> + <gmd:transferOptions> + <gmd:MD_DigitalTransferOptions> + <xsl:call-template name="createOnlineSrc"/> + </gmd:MD_DigitalTransferOptions> + </gmd:transferOptions> + </gmd:MD_Distribution> </xsl:copy> </xsl:template> <!-- <gmd:transferOptions> does not exist--> - <xsl:template match="*/gmd:distributionInfo/gmd:MD_Distribution[$update_flag = false()]"> + <xsl:template match="*/gmd:distributionInfo[1]/gmd:MD_Distribution[not(gmd:transferOptions) and $update_flag = false() and position() = 1]"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> - <xsl:if test="not(gmd:transferOptions)"> - <gmd:transferOptions> - <gmd:MD_DigitalTransferOptions> - <xsl:call-template name="createOnlineSrc"/> - </gmd:MD_DigitalTransferOptions> - </gmd:transferOptions> - </xsl:if> + <gmd:transferOptions> + <gmd:MD_DigitalTransferOptions> + <xsl:call-template name="createOnlineSrc"/> + </gmd:MD_DigitalTransferOptions> + </gmd:transferOptions> </xsl:copy> </xsl:template> <!-- <gmd:MD_DigitalTransferOptions> does not exist--> - <xsl:template match="*/gmd:distributionInfo/gmd:MD_Distribution/gmd:transferOptions[$update_flag = false()][1]"> + <xsl:template match="*/gmd:distributionInfo[1]/gmd:MD_Distribution[1]/gmd:transferOptions[not(gmd:MD_DigitalTransferOptions) and $update_flag = false() and position() = 1]"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> - <xsl:if test="not(gmd:MD_DigitalTransferOptions)"> - <gmd:MD_DigitalTransferOptions> - <xsl:call-template name="createOnlineSrc"/> - </gmd:MD_DigitalTransferOptions> - </xsl:if> + <gmd:MD_DigitalTransferOptions> + <xsl:call-template name="createOnlineSrc"/> + </gmd:MD_DigitalTransferOptions> </xsl:copy> </xsl:template> <!-- Add new gmd:gmd:onLine--> - <xsl:template match="*/gmd:distributionInfo/gmd:MD_Distribution/gmd:transferOptions[1]/gmd:MD_DigitalTransferOptions[$update_flag = false()]"> + <xsl:template match="*/gmd:distributionInfo[1]/gmd:MD_Distribution[1]/gmd:transferOptions[1]/gmd:MD_DigitalTransferOptions[$update_flag = false() and position() = 1]"> <xsl:copy> - <xsl:apply-templates select="node()|@*"/> + <xsl:apply-templates select="@*"/> + <xsl:apply-templates + select="gmd:unitsOfDistribution| + gmd:transferSize| + gmd:onLine"/> + <xsl:call-template name="createOnlineSrc"/> + + <xsl:apply-templates select="gmd:offLine"/> </xsl:copy> </xsl:template> @@ -148,28 +184,17 @@ Insert is made in first transferOptions found. <!-- 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 --> <xsl:template - priority="2" - match="*[$update_flag = true() and gmd:onLine]"> - <xsl:copy> - <xsl:apply-templates select="@*|node() except gmd:onLine" /> - - <xsl:for-each select="gmd:onLine"> - <xsl:choose> - <xsl:when test="($resourceIdx = '' or position() = xs:integer($resourceIdx)) - and ($resourceHash != '' or ($updateKey != '' and normalize-space($updateKey) = concat( + 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(exslt:node-set(.)) = $resourceHash)"> - <xsl:call-template name="createOnlineSrc"/> - </xsl:when> - <xsl:otherwise> - <xsl:apply-templates select="."/> - </xsl:otherwise> - </xsl:choose> - </xsl:for-each> - </xsl:copy> + and ($resourceHash = '' or digestUtils:md5Hex(string(exslt:node-set(.))) = $resourceHash)]" + priority="2"> + <xsl:call-template name="createOnlineSrc"/> </xsl:template> 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 c944c895e58..2a4fac88081 100644 --- a/schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-remove.xsl +++ b/schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-remove.xsl @@ -50,30 +50,16 @@ Stylesheet used to remove a reference to a online resource. <xsl:param name="name" select="''"/> <!-- 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 --> <xsl:template - priority="2" - match="*[gmd:onLine]"> - <xsl:copy> - <xsl:apply-templates select="@*|node() except gmd:onLine" /> - - <xsl:for-each select="gmd:onLine"> - <xsl:choose> - <xsl:when test="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) + match="*//gmd:MD_DigitalTransferOptions/gmd:onLine + [gmd:CI_OnlineResource[gmd:linkage/gmd:URL!=''] and ($resourceIdx = '' or position() = 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) 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(exslt:node-set(.)) = $resourceHash)"> - <!-- Remove the thumbnail --> - </xsl:when> - <xsl:otherwise> - <xsl:apply-templates select="."/> - </xsl:otherwise> - </xsl:choose> - </xsl:for-each> - </xsl:copy> - </xsl:template> + and ($resourceHash = '' or digestUtils:md5Hex(string(exslt:node-set(.))) = $resourceHash)]" + priority="2"/> <!-- Do a copy of every node and attribute --> <xsl:template match="@*|node()"> diff --git a/schemas/iso19139/src/main/plugin/iso19139/process/thumbnail-add.xsl b/schemas/iso19139/src/main/plugin/iso19139/process/thumbnail-add.xsl index 5ce2fe12ce8..f4bb3eea6d9 100644 --- a/schemas/iso19139/src/main/plugin/iso19139/process/thumbnail-add.xsl +++ b/schemas/iso19139/src/main/plugin/iso19139/process/thumbnail-add.xsl @@ -61,35 +61,53 @@ <!-- Add new gmd:graphicOverview --> <xsl:template match="gmd:identificationInfo/*[$update_flag = false()]"> <xsl:copy> - <xsl:apply-templates select="node()|@*"/> + <xsl:copy-of select="@*"/> + <xsl:apply-templates select="gmd:citation"/> + <xsl:apply-templates select="gmd:abstract"/> + <xsl:apply-templates select="gmd:purpose"/> + <xsl:apply-templates select="gmd:credit"/> + <xsl:apply-templates select="gmd:status"/> + <xsl:apply-templates select="gmd:pointOfContact"/> + <xsl:apply-templates select="gmd:resourceMaintenance"/> + <xsl:call-template name="fill"/> + + <xsl:apply-templates select="gmd:graphicOverview"/> + + <xsl:apply-templates select="gmd:resourceFormat"/> + <xsl:apply-templates select="gmd:descriptiveKeywords"/> + <xsl:apply-templates select="gmd:resourceSpecificUsage"/> + <xsl:apply-templates select="gmd:resourceConstraints"/> + <xsl:apply-templates select="gmd:aggregationInfo"/> + <xsl:apply-templates select="gmd:spatialRepresentationType"/> + <xsl:apply-templates select="gmd:spatialResolution"/> + <xsl:apply-templates select="gmd:language"/> + <xsl:apply-templates select="gmd:characterSet"/> + <xsl:apply-templates select="gmd:topicCategory"/> + <xsl:apply-templates select="gmd:environmentDescription"/> + <xsl:apply-templates select="gmd:extent"/> + <xsl:apply-templates select="gmd:supplementalInformation"/> + + <xsl:apply-templates select="srv:*"/> + + <xsl:apply-templates select="*[namespace-uri()!='http://www.isotc211.org/2005/gmd' and + namespace-uri()!='http://www.isotc211.org/2005/srv']"/> </xsl:copy> </xsl:template> <!-- Updating the gmd:graphicOverview 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 --> <xsl:template priority="2" - match="*[$update_flag = true() and gmd:graphicOverview]"> - <xsl:copy> - <xsl:apply-templates select="@*|node() except gmd:graphicOverview" /> - - <xsl:for-each select="gmd:graphicOverview"> - <xsl:choose> - <xsl:when test="($resourceIdx = '' or position() = xs:integer($resourceIdx)) - and ($resourceHash != '' or ($updateKey != '' and normalize-space($updateKey) = concat( + match="*//gmd:graphicOverview + [$resourceIdx = '' or position() = xs:integer($resourceIdx)] + [ ($resourceHash != '' or ($updateKey != '' and normalize-space($updateKey) = concat( */gmd:fileName/gco:CharacterString, */gmd:fileName/gmd:PT_FreeText/gmd:textGroup/gmd:LocalisedCharacterString[@locale = '#DE'], */gmd:fileDescription/gmd:PT_FreeText/gmd:textGroup/gmd:LocalisedCharacterString[@locale = '#DE'], */gmd:fileDescription/gco:CharacterString))) - and ($resourceHash = '' or digestUtils:md5Hex(exslt:node-set(.)) = $resourceHash)"> - <xsl:call-template name="fill"/> - </xsl:when> - <xsl:otherwise> - <xsl:apply-templates select="."/> - </xsl:otherwise> - </xsl:choose> - </xsl:for-each> - </xsl:copy> + and ($resourceHash = '' or digestUtils:md5Hex(string(exslt:node-set(.))) = $resourceHash)]"> + <xsl:call-template name="fill"/> </xsl:template> <!-- TMP TO REMOVE when gco:characterString is added in multilingual elements diff --git a/schemas/iso19139/src/main/plugin/iso19139/process/thumbnail-remove.xsl b/schemas/iso19139/src/main/plugin/iso19139/process/thumbnail-remove.xsl index 2a55921581b..5495b43e19e 100644 --- a/schemas/iso19139/src/main/plugin/iso19139/process/thumbnail-remove.xsl +++ b/schemas/iso19139/src/main/plugin/iso19139/process/thumbnail-remove.xsl @@ -46,25 +46,13 @@ <xsl:param name="resourceIdx" select="''"/> <!-- Remove the thumbnail define in thumbnail_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 --> <xsl:template priority="4" - match="*[gmd:graphicOverview]"> - <xsl:copy> - <xsl:apply-templates select="@*|node() except gmd:graphicOverview" /> - <xsl:for-each select="gmd:graphicOverview"> - <xsl:choose> - <xsl:when test="($resourceIdx = '' or position() = xs:integer($resourceIdx)) - and ($resourceHash != '' or ($thumbnail_url != '' and normalize-space(gmd:MD_BrowseGraphic/gmd:fileName/gco:CharacterString) = normalize-space($thumbnail_url))) - and ($resourceHash = '' or digestUtils:md5Hex(exslt:node-set(.)) = $resourceHash)"> - <!-- Remove the thumbnail --> - </xsl:when> - <xsl:otherwise> - <xsl:apply-templates select="."/> - </xsl:otherwise> - </xsl:choose> - </xsl:for-each> - </xsl:copy> - </xsl:template> + match="*//gmd:graphicOverview + [$resourceIdx = '' or position() = xs:integer($resourceIdx)] + [ ($resourceHash != '' or ($thumbnail_url != '' and normalize-space(gmd:MD_BrowseGraphic/gmd:fileName/gco:CharacterString) = normalize-space($thumbnail_url))) + and ($resourceHash = '' or digestUtils:md5Hex(string(exslt:node-set(.))) = $resourceHash)]"/> <!-- Do a copy of every node and attribute --> <xsl:template match="@*|node()"> From e6df4e694f60007c77cd1d61ab9799e46b76d6f9 Mon Sep 17 00:00:00 2001 From: wangf1122 <74916635+wangf1122@users.noreply.github.com> Date: Tue, 23 Jan 2024 10:41:57 -0500 Subject: [PATCH 06/15] Update schemas/iso19139/src/main/plugin/iso19139/process/thumbnail-remove.xsl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jose García <josegar74@gmail.com> --- .../src/main/plugin/iso19139/process/thumbnail-remove.xsl | 1 + 1 file changed, 1 insertion(+) diff --git a/schemas/iso19139/src/main/plugin/iso19139/process/thumbnail-remove.xsl b/schemas/iso19139/src/main/plugin/iso19139/process/thumbnail-remove.xsl index 5495b43e19e..fe53ec5a305 100644 --- a/schemas/iso19139/src/main/plugin/iso19139/process/thumbnail-remove.xsl +++ b/schemas/iso19139/src/main/plugin/iso19139/process/thumbnail-remove.xsl @@ -29,6 +29,7 @@ xmlns:geonet="http://www.fao.org/geonetwork" exclude-result-prefixes="#all" xmlns:digestUtils="java:org.apache.commons.codec.digest.DigestUtils" xmlns:exslt="http://exslt.org/common" + exclude-result-prefixes="#all" version="2.0"> <!-- From cf723fee088d8086f280b43020e4d592d9388635 Mon Sep 17 00:00:00 2001 From: wangf1122 <74916635+wangf1122@users.noreply.github.com> Date: Tue, 23 Jan 2024 10:42:08 -0500 Subject: [PATCH 07/15] Update schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-add.xsl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jose García <josegar74@gmail.com> --- .../iso19139/src/main/plugin/iso19139/process/onlinesrc-add.xsl | 1 + 1 file changed, 1 insertion(+) 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 d03cb13a19d..155986cfc5e 100644 --- a/schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-add.xsl +++ b/schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-add.xsl @@ -38,6 +38,7 @@ Note: It assumes that it will be adding new items in xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:digestUtils="java:org.apache.commons.codec.digest.DigestUtils" xmlns:exslt="http://exslt.org/common" + exclude-result-prefixes="#all" version="2.0"> <!-- Main properties for the link. From 8aa2802fcea2e0f887db6204a1157e7406744bf8 Mon Sep 17 00:00:00 2001 From: wangf1122 <74916635+wangf1122@users.noreply.github.com> Date: Tue, 23 Jan 2024 10:42:26 -0500 Subject: [PATCH 08/15] Update schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-remove.xsl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jose García <josegar74@gmail.com> --- .../src/main/plugin/iso19139/process/onlinesrc-remove.xsl | 1 + 1 file changed, 1 insertion(+) 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 2a4fac88081..ce6d98bae3d 100644 --- a/schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-remove.xsl +++ b/schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-remove.xsl @@ -31,6 +31,7 @@ Stylesheet used to remove a reference to a online resource. xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:digestUtils="java:org.apache.commons.codec.digest.DigestUtils" xmlns:exslt="http://exslt.org/common" + exclude-result-prefixes="#all" version="2.0"> <!-- From 8eb4c1d3f74c629ada3ae6924cb32631d5a5394f Mon Sep 17 00:00:00 2001 From: wangf1122 <74916635+wangf1122@users.noreply.github.com> Date: Tue, 23 Jan 2024 13:16:52 -0500 Subject: [PATCH 09/15] Update schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-remove.xsl Co-authored-by: Ian <ianwallen@hotmail.com> --- .../src/main/plugin/iso19139/process/onlinesrc-remove.xsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 ce6d98bae3d..194eb2c530f 100644 --- a/schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-remove.xsl +++ b/schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-remove.xsl @@ -54,7 +54,7 @@ Stylesheet used to remove a reference to a online resource. <!-- 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 --> <xsl:template match="*//gmd:MD_DigitalTransferOptions/gmd:onLine - [gmd:CI_OnlineResource[gmd:linkage/gmd:URL!=''] and ($resourceIdx = '' or position() = xs:integer($resourceIdx))] + [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) 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')) From f1975e39655875caf0ed7f01aa4280c23db1db91 Mon Sep 17 00:00:00 2001 From: wangf1122 <74916635+wangf1122@users.noreply.github.com> Date: Tue, 23 Jan 2024 13:17:07 -0500 Subject: [PATCH 10/15] Update schemas/iso19139/src/main/plugin/iso19139/process/thumbnail-remove.xsl Co-authored-by: Ian <ianwallen@hotmail.com> --- .../src/main/plugin/iso19139/process/thumbnail-remove.xsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/schemas/iso19139/src/main/plugin/iso19139/process/thumbnail-remove.xsl b/schemas/iso19139/src/main/plugin/iso19139/process/thumbnail-remove.xsl index fe53ec5a305..6eef3263ced 100644 --- a/schemas/iso19139/src/main/plugin/iso19139/process/thumbnail-remove.xsl +++ b/schemas/iso19139/src/main/plugin/iso19139/process/thumbnail-remove.xsl @@ -51,7 +51,7 @@ <xsl:template priority="4" match="*//gmd:graphicOverview - [$resourceIdx = '' or position() = xs:integer($resourceIdx)] + [$resourceIdx = '' or (count(preceding::gmd:graphicOverview) + 1) = xs:integer($resourceIdx)] [ ($resourceHash != '' or ($thumbnail_url != '' and normalize-space(gmd:MD_BrowseGraphic/gmd:fileName/gco:CharacterString) = normalize-space($thumbnail_url))) and ($resourceHash = '' or digestUtils:md5Hex(string(exslt:node-set(.))) = $resourceHash)]"/> From 892a8b42f85f8750f5d664e3ac33f141fa959ffc Mon Sep 17 00:00:00 2001 From: WANGF <feifei.wang@dfo-mpo.gc.ca> Date: Mon, 19 Feb 2024 15:06:27 -0500 Subject: [PATCH 11/15] Add hash and index to search indexing. Remove thumbnail hash and indexing as the backend file/store will get deleted. --- .../java/org/fao/geonet/util/XslUtil.java | 7 +++ .../plugin/iso19139/extract-relations.xsl | 4 +- .../plugin/iso19139/index-fields/index.xsl | 3 ++ .../plugin/iso19139/process/onlinesrc-add.xsl | 4 +- .../iso19139/process/onlinesrc-remove.xsl | 4 +- .../plugin/iso19139/process/thumbnail-add.xsl | 46 ++++++------------- .../iso19139/process/thumbnail-remove.xsl | 23 ++-------- .../metadataactions/RelatedDirective.js | 2 + 8 files changed, 36 insertions(+), 57 deletions(-) diff --git a/core/src/main/java/org/fao/geonet/util/XslUtil.java b/core/src/main/java/org/fao/geonet/util/XslUtil.java index 256129da48b..ffbc69cd4bf 100644 --- a/core/src/main/java/org/fao/geonet/util/XslUtil.java +++ b/core/src/main/java/org/fao/geonet/util/XslUtil.java @@ -1300,6 +1300,13 @@ public static String md5Hex(String str) { return org.apache.commons.codec.digest.DigestUtils.md5Hex(str); } + public static String md5HexIgnoreWhiteSpaces(String str) { + str = org.apache.commons.lang3.StringUtils.remove(str, '\n'); + str = org.apache.commons.lang3.StringUtils.remove(str, ' '); + + return org.apache.commons.codec.digest.DigestUtils.md5Hex(str); + } + public static String encodeForURL(String str) { try { return DefaultEncoder.getInstance().encodeForURL(str); diff --git a/schemas/iso19139/src/main/plugin/iso19139/extract-relations.xsl b/schemas/iso19139/src/main/plugin/iso19139/extract-relations.xsl index fdc58f1b90a..6d5099e171a 100644 --- a/schemas/iso19139/src/main/plugin/iso19139/extract-relations.xsl +++ b/schemas/iso19139/src/main/plugin/iso19139/extract-relations.xsl @@ -109,7 +109,7 @@ <xsl:value-of select="position()"/> </idx> <hash> - <xsl:value-of select="util:md5Hex(string(exslt:node-set(.)))"/> + <xsl:value-of select="util:md5HexIgnoreWhiteSpaces(string(exslt:node-set(.)))"/> </hash> <url> <xsl:apply-templates mode="get-iso19139-localized-string" @@ -141,7 +141,7 @@ <xsl:value-of select="position()"/> </idx> <hash> - <xsl:value-of select="util:md5Hex(string(exslt:node-set(.)))"/> + <xsl:value-of select="util:md5HexIgnoreWhiteSpaces(string(exslt:node-set(.)))"/> </hash> <title> <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 edd84c35951..e885ed65eef 100644 --- a/schemas/iso19139/src/main/plugin/iso19139/index-fields/index.xsl +++ b/schemas/iso19139/src/main/plugin/iso19139/index-fields/index.xsl @@ -34,6 +34,7 @@ xmlns:gn-fn-index="http://geonetwork-opensource.org/xsl/functions/index" xmlns:index="java:org.fao.geonet.kernel.search.EsSearchManager" xmlns:util="java:org.fao.geonet.util.XslUtil" + xmlns:exslt="http://exslt.org/common" xmlns:date-util="java:org.fao.geonet.utils.DateUtil" xmlns:daobs="http://daobs.org" xmlns:saxon="http://saxon.sf.net/" @@ -1105,6 +1106,8 @@ <atomfeed><xsl:value-of select="gmd:linkage/gmd:URL"/></atomfeed> </xsl:if> <link type="object">{ + "hash": "<xsl:value-of select="util:md5HexIgnoreWhiteSpaces(string(exslt:node-set(.)))"/>", + "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) then util:escapeForJson(*/gmx:MimeFileType/@type) 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 155986cfc5e..2463f327f97 100644 --- a/schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-add.xsl +++ b/schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-add.xsl @@ -36,7 +36,7 @@ Note: It assumes that it will be adding new items in xmlns:gmx="http://www.isotc211.org/2005/gmx" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" - xmlns:digestUtils="java:org.apache.commons.codec.digest.DigestUtils" + xmlns:util="java:org.fao.geonet.util.XslUtil" xmlns:exslt="http://exslt.org/common" exclude-result-prefixes="#all" version="2.0"> @@ -193,7 +193,7 @@ Note: It assumes that it will be adding new items in 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)]" + and ($resourceHash = '' or util:md5HexIgnoreWhiteSpaces(string(exslt:node-set(.))) = $resourceHash)]" priority="2"> <xsl:call-template name="createOnlineSrc"/> </xsl:template> 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 194eb2c530f..e91d90e3fe6 100644 --- a/schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-remove.xsl +++ b/schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-remove.xsl @@ -29,7 +29,7 @@ Stylesheet used to remove a reference to a online resource. xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" - xmlns:digestUtils="java:org.apache.commons.codec.digest.DigestUtils" + xmlns:util="java:org.fao.geonet.util.XslUtil" xmlns:exslt="http://exslt.org/common" exclude-result-prefixes="#all" version="2.0"> @@ -59,7 +59,7 @@ Stylesheet used to remove a reference to a online resource. 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(.))) = $resourceHash)]" + and ($resourceHash = '' or util:md5HexIgnoreWhiteSpaces(string(exslt:node-set(.))) = $resourceHash)]" priority="2"/> <!-- Do a copy of every node and attribute --> diff --git a/schemas/iso19139/src/main/plugin/iso19139/process/thumbnail-add.xsl b/schemas/iso19139/src/main/plugin/iso19139/process/thumbnail-add.xsl index f4bb3eea6d9..16b975a837c 100644 --- a/schemas/iso19139/src/main/plugin/iso19139/process/thumbnail-add.xsl +++ b/schemas/iso19139/src/main/plugin/iso19139/process/thumbnail-add.xsl @@ -27,9 +27,6 @@ xmlns:srv="http://www.isotc211.org/2005/srv" xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:geonet="http://www.fao.org/geonetwork" - xmlns:xs="http://www.w3.org/2001/XMLSchema" - xmlns:digestUtils="java:org.apache.commons.codec.digest.DigestUtils" - xmlns:exslt="http://exslt.org/common" exclude-result-prefixes="#all" version="2.0"> @@ -44,22 +41,11 @@ <xsl:param name="thumbnail_desc" select="''"/> <xsl:param name="thumbnail_type" select="''"/> - <!-- Target element to update. - updateKey is used to identify the resource name to be updated - it is for backwards compatibility. Will not be used if resourceHash is set. - The key is based on the concatenation of URL+Name - resourceHash is hash value of the object to be removed which will ensure the correct value is removed. It will override the usage of updateKey - resourceIdx is the index location of the object to be removed - can be used when duplicate entries exists to ensure the correct one is removed. ---> - <xsl:param name="updateKey" select="''"/> - <xsl:param name="resourceHash" select="''"/> - <xsl:param name="resourceIdx" select="''"/> - - <xsl:variable name="update_flag"> - <xsl:value-of select="boolean($updateKey != '' or $resourceHash != '' or $resourceIdx != '')"/> - </xsl:variable> - - <!-- Add new gmd:graphicOverview --> - <xsl:template match="gmd:identificationInfo/*[$update_flag = false()]"> + <!-- Target element to update. The key is based on the concatenation + of URL+Name --> + <xsl:param name="updateKey"/> + + <xsl:template match="gmd:identificationInfo/*"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:apply-templates select="gmd:citation"/> @@ -70,7 +56,9 @@ <xsl:apply-templates select="gmd:pointOfContact"/> <xsl:apply-templates select="gmd:resourceMaintenance"/> - <xsl:call-template name="fill"/> + <xsl:if test="$updateKey = ''"> + <xsl:call-template name="fill"/> + </xsl:if> <xsl:apply-templates select="gmd:graphicOverview"/> @@ -95,18 +83,12 @@ </xsl:copy> </xsl:template> - <!-- Updating the gmd:graphicOverview 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 --> - <xsl:template - priority="2" - match="*//gmd:graphicOverview - [$resourceIdx = '' or position() = xs:integer($resourceIdx)] - [ ($resourceHash != '' or ($updateKey != '' and normalize-space($updateKey) = concat( - */gmd:fileName/gco:CharacterString, - */gmd:fileName/gmd:PT_FreeText/gmd:textGroup/gmd:LocalisedCharacterString[@locale = '#DE'], - */gmd:fileDescription/gmd:PT_FreeText/gmd:textGroup/gmd:LocalisedCharacterString[@locale = '#DE'], - */gmd:fileDescription/gco:CharacterString))) - and ($resourceHash = '' or digestUtils:md5Hex(string(exslt:node-set(.))) = $resourceHash)]"> + + <xsl:template match="gmd:graphicOverview[concat( + */gmd:fileName/gco:CharacterString, + */gmd:fileName/gmd:PT_FreeText/gmd:textGroup/gmd:LocalisedCharacterString[@locale = '#DE'], + */gmd:fileDescription/gmd:PT_FreeText/gmd:textGroup/gmd:LocalisedCharacterString[@locale = '#DE'], + */gmd:fileDescription/gco:CharacterString) = normalize-space($updateKey)]"> <xsl:call-template name="fill"/> </xsl:template> diff --git a/schemas/iso19139/src/main/plugin/iso19139/process/thumbnail-remove.xsl b/schemas/iso19139/src/main/plugin/iso19139/process/thumbnail-remove.xsl index 6eef3263ced..a856ed23dd1 100644 --- a/schemas/iso19139/src/main/plugin/iso19139/process/thumbnail-remove.xsl +++ b/schemas/iso19139/src/main/plugin/iso19139/process/thumbnail-remove.xsl @@ -25,37 +25,22 @@ <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:gco="http://www.isotc211.org/2005/gco" - xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:geonet="http://www.fao.org/geonetwork" exclude-result-prefixes="#all" - xmlns:digestUtils="java:org.apache.commons.codec.digest.DigestUtils" - xmlns:exslt="http://exslt.org/common" - exclude-result-prefixes="#all" version="2.0"> <!-- Usage: - thumbnail_url is the url to be removed - it is for backwards compatibility. Will not be used if resourceHash is set. - resourceHash is hash value of the object to be removed which will ensure the correct value is removed. It will override the usage of thumbnail_url - resourceIdx is the index location of the object to be removed - can be used when duplicate entries exists to ensure the correct one is removed. - - example: thumbnail-from-url-remove?thumbnail_url=http://geonetwork.org/thumbnails/image.png --> - <xsl:param name="thumbnail_url" select="''"/> - <xsl:param name="resourceHash" select="''"/> - <xsl:param name="resourceIdx" select="''"/> + <xsl:param name="thumbnail_url"/> <!-- Remove the thumbnail define in thumbnail_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 --> <xsl:template - priority="4" - match="*//gmd:graphicOverview - [$resourceIdx = '' or (count(preceding::gmd:graphicOverview) + 1) = xs:integer($resourceIdx)] - [ ($resourceHash != '' or ($thumbnail_url != '' and normalize-space(gmd:MD_BrowseGraphic/gmd:fileName/gco:CharacterString) = normalize-space($thumbnail_url))) - and ($resourceHash = '' or digestUtils:md5Hex(string(exslt:node-set(.))) = $resourceHash)]"/> + priority="2" + match="gmd:graphicOverview[normalize-space(gmd:MD_BrowseGraphic/gmd:fileName/gco:CharacterString) = normalize-space($thumbnail_url)]"/> - <!-- Do a copy of every node and attribute --> + <!-- Do a copy of every nodes and attributes --> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> diff --git a/web-ui/src/main/resources/catalog/components/metadataactions/RelatedDirective.js b/web-ui/src/main/resources/catalog/components/metadataactions/RelatedDirective.js index 04bba86d128..b269d685f16 100644 --- a/web-ui/src/main/resources/catalog/components/metadataactions/RelatedDirective.js +++ b/web-ui/src/main/resources/catalog/components/metadataactions/RelatedDirective.js @@ -400,6 +400,8 @@ scope.convertLinkToEdit = function (link) { var convertedLink = { id: link.url, + idx: link.idx, + hash: link.hash, url: convertLangProperties(link.urlObject), type: getType(link.function), title: convertLangProperties(link.nameObject), From 90f7b0aeb1a7327b8c3cd9118d690f431eaef36a Mon Sep 17 00:00:00 2001 From: WANGF <feifei.wang@dfo-mpo.gc.ca> Date: Tue, 20 Feb 2024 15:53:00 -0500 Subject: [PATCH 12/15] Fix unit test --- .../iso19139/src/main/plugin/iso19139/extract-relations.xsl | 6 +++--- .../src/main/plugin/iso19139/index-fields/index.xsl | 4 ++-- .../src/main/plugin/iso19139/process/onlinesrc-add.xsl | 4 ++-- .../src/main/plugin/iso19139/process/onlinesrc-remove.xsl | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/schemas/iso19139/src/main/plugin/iso19139/extract-relations.xsl b/schemas/iso19139/src/main/plugin/iso19139/extract-relations.xsl index 6d5099e171a..96a6bf0c0cc 100644 --- a/schemas/iso19139/src/main/plugin/iso19139/extract-relations.xsl +++ b/schemas/iso19139/src/main/plugin/iso19139/extract-relations.xsl @@ -33,7 +33,7 @@ xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:gmx="http://www.isotc211.org/2005/gmx" 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" @@ -109,7 +109,7 @@ <xsl:value-of select="position()"/> </idx> <hash> - <xsl:value-of select="util:md5HexIgnoreWhiteSpaces(string(exslt:node-set(.)))"/> + <xsl:value-of select="digestUtils:md5Hex(string(exslt:node-set(normalize-space(.))))"/> </hash> <url> <xsl:apply-templates mode="get-iso19139-localized-string" @@ -141,7 +141,7 @@ <xsl:value-of select="position()"/> </idx> <hash> - <xsl:value-of select="util:md5HexIgnoreWhiteSpaces(string(exslt:node-set(.)))"/> + <xsl:value-of select="digestUtils:md5Hex(string(exslt:node-set(normalize-space(.))))"/> </hash> <title> <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 e885ed65eef..93c5038a705 100644 --- a/schemas/iso19139/src/main/plugin/iso19139/index-fields/index.xsl +++ b/schemas/iso19139/src/main/plugin/iso19139/index-fields/index.xsl @@ -33,7 +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:util="java:org.fao.geonet.util.XslUtil" + xmlns:digestUtils="java:org.apache.commons.codec.digest.DigestUtils" xmlns:exslt="http://exslt.org/common" xmlns:date-util="java:org.fao.geonet.utils.DateUtil" xmlns:daobs="http://daobs.org" @@ -1106,7 +1106,7 @@ <atomfeed><xsl:value-of select="gmd:linkage/gmd:URL"/></atomfeed> </xsl:if> <link type="object">{ - "hash": "<xsl:value-of select="util:md5HexIgnoreWhiteSpaces(string(exslt:node-set(.)))"/>", + "hash": "<xsl:value-of select="digestUtils:md5Hex(string(exslt:node-set(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 2463f327f97..ddf0ad7bc50 100644 --- a/schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-add.xsl +++ b/schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-add.xsl @@ -36,7 +36,7 @@ Note: It assumes that it will be adding new items in xmlns:gmx="http://www.isotc211.org/2005/gmx" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" - xmlns:util="java:org.fao.geonet.util.XslUtil" + xmlns:digestUtils="java:org.apache.commons.codec.digest.DigestUtils" xmlns:exslt="http://exslt.org/common" exclude-result-prefixes="#all" version="2.0"> @@ -193,7 +193,7 @@ Note: It assumes that it will be adding new items in gmd:CI_OnlineResource/gmd:linkage/gmd:URL, gmd:CI_OnlineResource/gmd:protocol/*, gmd:CI_OnlineResource/gmd:name/gco:CharacterString))) - and ($resourceHash = '' or util:md5HexIgnoreWhiteSpaces(string(exslt:node-set(.))) = $resourceHash)]" + and ($resourceHash = '' or digestUtils:md5Hex(string(exslt:node-set(normalize-space(.)))) = $resourceHash)]" priority="2"> <xsl:call-template name="createOnlineSrc"/> </xsl:template> 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 e91d90e3fe6..66ce59c5310 100644 --- a/schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-remove.xsl +++ b/schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-remove.xsl @@ -29,7 +29,7 @@ Stylesheet used to remove a reference to a online resource. xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" - xmlns:util="java:org.fao.geonet.util.XslUtil" + xmlns:digestUtils="java:org.apache.commons.codec.digest.DigestUtils" xmlns:exslt="http://exslt.org/common" exclude-result-prefixes="#all" version="2.0"> @@ -59,7 +59,7 @@ Stylesheet used to remove a reference to a online resource. 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 util:md5HexIgnoreWhiteSpaces(string(exslt:node-set(.))) = $resourceHash)]" + and ($resourceHash = '' or digestUtils:md5Hex(string(exslt:node-set(normalize-space(.)))) = $resourceHash)]" priority="2"/> <!-- Do a copy of every node and attribute --> From b9f1d5dfb46069fef4f814aed1fa389d4edea5aa Mon Sep 17 00:00:00 2001 From: WANGF <feifei.wang@dfo-mpo.gc.ca> Date: Tue, 20 Feb 2024 15:59:22 -0500 Subject: [PATCH 13/15] Remove unwanted method in XslUtils --- core/src/main/java/org/fao/geonet/util/XslUtil.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/core/src/main/java/org/fao/geonet/util/XslUtil.java b/core/src/main/java/org/fao/geonet/util/XslUtil.java index ffbc69cd4bf..256129da48b 100644 --- a/core/src/main/java/org/fao/geonet/util/XslUtil.java +++ b/core/src/main/java/org/fao/geonet/util/XslUtil.java @@ -1300,13 +1300,6 @@ public static String md5Hex(String str) { return org.apache.commons.codec.digest.DigestUtils.md5Hex(str); } - public static String md5HexIgnoreWhiteSpaces(String str) { - str = org.apache.commons.lang3.StringUtils.remove(str, '\n'); - str = org.apache.commons.lang3.StringUtils.remove(str, ' '); - - return org.apache.commons.codec.digest.DigestUtils.md5Hex(str); - } - public static String encodeForURL(String str) { try { return DefaultEncoder.getInstance().encodeForURL(str); From fff34dbb600757e67a3080d18a2c8ed8d118b4ae Mon Sep 17 00:00:00 2001 From: WANGF <feifei.wang@dfo-mpo.gc.ca> Date: Wed, 21 Feb 2024 09:11:06 -0500 Subject: [PATCH 14/15] fix unit test --- schemas/iso19139/src/main/plugin/iso19139/index-fields/index.xsl | 1 + 1 file changed, 1 insertion(+) 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 93c5038a705..b535ae1dc5a 100644 --- a/schemas/iso19139/src/main/plugin/iso19139/index-fields/index.xsl +++ b/schemas/iso19139/src/main/plugin/iso19139/index-fields/index.xsl @@ -35,6 +35,7 @@ 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" xmlns:saxon="http://saxon.sf.net/" From d630326d25de3cbd9aaa9197b492a6372b8a3add Mon Sep 17 00:00:00 2001 From: WANGF <feifei.wang@dfo-mpo.gc.ca> Date: Tue, 5 Mar 2024 10:38:41 -0500 Subject: [PATCH 15/15] code review comment --- schemas/iso19139/src/main/plugin/iso19139/extract-relations.xsl | 1 + .../iso19139/src/main/plugin/iso19139/process/onlinesrc-add.xsl | 1 + .../src/main/plugin/iso19139/process/onlinesrc-remove.xsl | 1 + 3 files changed, 3 insertions(+) diff --git a/schemas/iso19139/src/main/plugin/iso19139/extract-relations.xsl b/schemas/iso19139/src/main/plugin/iso19139/extract-relations.xsl index 96a6bf0c0cc..10e10352ab8 100644 --- a/schemas/iso19139/src/main/plugin/iso19139/extract-relations.xsl +++ b/schemas/iso19139/src/main/plugin/iso19139/extract-relations.xsl @@ -33,6 +33,7 @@ xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:gmx="http://www.isotc211.org/2005/gmx" 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" 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 ddf0ad7bc50..0afe80eaa3d 100644 --- a/schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-add.xsl +++ b/schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-add.xsl @@ -186,6 +186,7 @@ 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))] 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 66ce59c5310..718f483eced 100644 --- a/schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-remove.xsl +++ b/schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-remove.xsl @@ -52,6 +52,7 @@ 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))]