Skip to content

Commit

Permalink
Add hash and index to search indexing. Remove thumbnail hash and inde…
Browse files Browse the repository at this point in the history
…xing as the backend file/store will get deleted.
  • Loading branch information
wangf1122 committed Feb 19, 2024
1 parent 2ae75c4 commit 892a8b4
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 57 deletions.
7 changes: 7 additions & 0 deletions core/src/main/java/org/fao/geonet/util/XslUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down Expand Up @@ -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 -->
Expand Down
46 changes: 14 additions & 32 deletions schemas/iso19139/src/main/plugin/iso19139/process/thumbnail-add.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -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">

Expand All @@ -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"/>
Expand All @@ -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"/>

Expand All @@ -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>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 892a8b4

Please sign in to comment.