Skip to content

Commit

Permalink
Updated resource logic to use 2 new field called idx and hash and rev…
Browse files Browse the repository at this point in the history
…ert id back to the old method. This will ensure backward compatibility

Also update xslt for add and remove thumbnail/onlines recources
  • Loading branch information
ianwallen committed Oct 27, 2023
1 parent acc3540 commit f4a8b82
Show file tree
Hide file tree
Showing 9 changed files with 329 additions and 187 deletions.
105 changes: 59 additions & 46 deletions schemas/iso19139/src/main/plugin/iso19139/extract-relations.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down Expand Up @@ -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')]]"
Expand All @@ -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"/>
</title>
<type>thumbnail</type>
</item>
Expand All @@ -121,47 +127,54 @@

<xsl:if test="count(*/descendant::*[name(.) = 'gmd:onLine']/*[gmd:linkage/gmd:URL!='']) > 0">
<onlines>
<xsl:for-each select="*/descendant::*[name(.) = 'gmd:onLine']/*[gmd:linkage/gmd:URL!='']">
<item>
<xsl:variable name="langCode">
<xsl:value-of select="concat('#', upper-case(util:twoCharLangCode($lang, 'EN')))"/>
</xsl:variable>
<xsl:variable name="url" select="gmd:linkage/gmd:URL"/>
<xsl:variable name="uid" select="uuid:randomUUID()"/>
<id>
<xsl:value-of select="$uid"/>
</id>
<title>
<xsl:apply-templates mode="get-iso19139-localized-string"
select="gmd:name"/>
</title>
<url>
<value lang="{$mainLanguage}">
<xsl:for-each select="*/descendant::*[name(.) = 'gmd:onLine']">
<xsl:if test="gmd:CI_OnlineResource[gmd:linkage/gmd:URL!='']">
<item>
<xsl:variable name="langCode">
<xsl:value-of select="concat('#', upper-case(util:twoCharLangCode($lang, 'EN')))"/>
</xsl:variable>
<xsl:variable name="url" select="gmd:CI_OnlineResource/gmd:linkage/gmd:URL"/>
<id>
<xsl:value-of select="$url"/>
</value>
</url>
<function>
<xsl:value-of select="gmd:function/*/@codeListValue"/>
</function>
<applicationProfile>
<xsl:value-of select="gmd:applicationProfile/*/text()"/>
</applicationProfile>
<description>
<xsl:apply-templates mode="get-iso19139-localized-string"
select="gmd:description"/>
</description>
<protocol>
<xsl:value-of select="gn-fn-rel:translate(gmd:protocol, $langCode)"/>
</protocol>
<mimeType>
<xsl:value-of select="if (*/gmx:MimeFileType)
then */gmx:MimeFileType/@type
else if (starts-with(gmd:protocol/gco:CharacterString, 'WWW:DOWNLOAD:'))
then replace(gmd:protocol/gco:CharacterString, 'WWW:DOWNLOAD:', '')
else ''"/>
</mimeType>
<type>onlinesrc</type>
</item>
</id>
<idx>
<xsl:value-of select="position()"/>
</idx>
<hash>
<xsl:value-of select="util:md5Hex(exslt:node-set(.))"/>
</hash>
<title>
<xsl:apply-templates mode="get-iso19139-localized-string"
select="gmd:CI_OnlineResource/gmd:name"/>
</title>
<url>
<value lang="{$mainLanguage}">
<xsl:value-of select="$url"/>
</value>
</url>
<function>
<xsl:value-of select="gmd:CI_OnlineResource/gmd:function/*/@codeListValue"/>
</function>
<applicationProfile>
<xsl:value-of select="gmd:CI_OnlineResource/gmd:applicationProfile/*/text()"/>
</applicationProfile>
<description>
<xsl:apply-templates mode="get-iso19139-localized-string"
select="gmd:CI_OnlineResource/gmd:description"/>
</description>
<protocol>
<xsl:value-of select="gn-fn-rel:translate(gmd:CI_OnlineResource/gmd:protocol, $langCode)"/>
</protocol>
<mimeType>
<xsl:value-of select="if (gmd:CI_OnlineResource/*/gmx:MimeFileType)
then gmd:CI_OnlineResource/*/gmx:MimeFileType/@type
else if (starts-with(gmd:CI_OnlineResource/gmd:protocol/gco:CharacterString, 'WWW:DOWNLOAD:'))
then replace(gmd:CI_OnlineResource/gmd:protocol/gco:CharacterString, 'WWW:DOWNLOAD:', '')
else ''"/>
</mimeType>
<type>onlinesrc</type>
</item>
</xsl:if>
</xsl:for-each>
</onlines>
</xsl:if>
Expand Down
169 changes: 97 additions & 72 deletions schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-add.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<!-- Main properties for the link.
Expand All @@ -52,98 +55,120 @@ Insert is made in first transferOptions found.
in this one. -->
<xsl:param name="extra_metadata_uuid"/>

<!-- Target element to update. The key is based on the concatenation
of URL+Protocol+Name -->
<!-- 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+Protocol+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"/>
<xsl:param name="resourceHash"/>
<xsl:param name="resourceIdx"/>

<xsl:variable name="update_flag">
<xsl:value-of select="boolean($updateKey != '' or $resourceHash != '' or $resourceIdx != '')"/>
</xsl:variable>

<xsl:variable name="mainLang">
<xsl:value-of
select="(gmd:MD_Metadata|*[@gco:isoType='gmd:MD_Metadata'])/gmd:language/gmd:LanguageCode/@codeListValue"/>
</xsl:variable>

<xsl:template match="gmd:MD_Metadata|*[@gco:isoType='gmd:MD_Metadata']">
<!-- 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:copy>
<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>
<xsl:apply-templates
select="gmd:distributionInfo/gmd:MD_Distribution/gmd:distributionFormat"/>
<xsl:apply-templates
select="gmd:distributionInfo/gmd:MD_Distribution/gmd:distributor"/>
<gmd:transferOptions>
<gmd:MD_DigitalTransferOptions>
<xsl:apply-templates
select="gmd:distributionInfo/gmd:MD_Distribution/
gmd:transferOptions[1]/gmd:MD_DigitalTransferOptions/gmd:unitsOfDistribution"/>
<xsl:apply-templates
select="gmd:distributionInfo/gmd:MD_Distribution/
gmd:transferOptions[1]/gmd:MD_DigitalTransferOptions/gmd:transferSize"/>
<xsl:apply-templates
select="gmd:distributionInfo/gmd:MD_Distribution/
gmd:transferOptions[1]/gmd:MD_DigitalTransferOptions/gmd:onLine"/>


<xsl:if test="$updateKey = ''">
<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"/>
</xsl:if>
</gmd:MD_DigitalTransferOptions>
</gmd:transferOptions>
</gmd:MD_Distribution>
</gmd:distributionInfo>
</xsl:if>
</xsl:copy>
</xsl:template>

<xsl:apply-templates
select="gmd:distributionInfo/gmd:MD_Distribution/
gmd:transferOptions[1]/gmd:MD_DigitalTransferOptions/gmd:offLine"/>
<!-- <gmd:MD_Distribution> does not exist-->
<xsl:template match="*/gmd:distributionInfo[$update_flag = false()]">
<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>
</xsl:copy>
</xsl:template>

<!-- <gmd:transferOptions> does not exist-->
<xsl:template match="*/gmd:distributionInfo/gmd:MD_Distribution[$update_flag = false()]">
<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>
</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: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>
</xsl:copy>
</xsl:template>

<xsl:apply-templates
select="gmd:distributionInfo/gmd:MD_Distribution/
gmd:transferOptions[position() > 1]"/>

</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"/>
<!-- Add new gmd:gmd:onLine-->
<xsl:template match="*/gmd:distributionInfo/gmd:MD_Distribution/gmd:transferOptions[1]/gmd:MD_DigitalTransferOptions[$update_flag = false()]">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
<xsl:call-template name="createOnlineSrc"/>
</xsl:copy>
</xsl:template>

<!-- End of inserting gmd:onLine -->


<!-- Updating the link matching the update key. -->
<xsl:template match="gmd:onLine[$updateKey != '' and
normalize-space($updateKey) = concat(
<!-- Updating the gmd:onLine based on update parameters -->
<xsl:template
priority="2"
match="*[$update_flag = true() and gmd:onLine]">
<xsl:for-each select="gmd:onLine">
<xsl:choose>
<xsl:when test="($resourceIdx = '' or position() = xs:integer($resourceIdx))
and ($resourceHash != '' or normalize-space($updateKey) = concat(
gmd:CI_OnlineResource/gmd:linkage/gmd:URL,
gmd:CI_OnlineResource/gmd:protocol/*,
gmd:CI_OnlineResource/gmd:name/gco:CharacterString)
]">
<xsl:call-template name="createOnlineSrc"/>
gmd:CI_OnlineResource/gmd:name/gco:CharacterString))
and ($resourceHash = '' or util: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:apply-templates select="* except gmd:onLine" />

</xsl:template>


Expand All @@ -170,7 +195,7 @@ Insert is made in first transferOptions found.

<xsl:if test="$url">
<!-- In case the protocol is an OGC protocol
the name parameter may contains a list of layers
the name parameter may contain a list of layers
separated by comma.
In that case on one online element is added per
layer/featureType.
Expand Down
Loading

0 comments on commit f4a8b82

Please sign in to comment.