Skip to content

Commit

Permalink
Standard / Formatter / Citation improvements (#7434)
Browse files Browse the repository at this point in the history
* Standard / Formatter / Citation improvements

* Improve list of contact (when multiple individual names or when same contact with multiple roles)
* Cleanup layout (avoid extra space/add missing ones)
* Add formatter parameter to customize author and publisher roles (eg. http://localhost:8080/geonetwork/srv/api/records/uuid/formatters/citation?format=text&authorRoles=author,processor&publisherRoles=publisher,custodian)
* Add test

* Update services/src/test/java/org/fao/geonet/api/records/formatters/FormatterApiTest.java

Co-authored-by: Jose García <[email protected]>

* Jose's feedbacks.

---------

Co-authored-by: Jose García <[email protected]>
  • Loading branch information
fxprunayre and josegar74 authored Oct 27, 2023
1 parent d88a609 commit a7c0dee
Show file tree
Hide file tree
Showing 19 changed files with 3,000 additions and 124 deletions.
16 changes: 14 additions & 2 deletions core/src/test/java/org/fao/geonet/AbstractCoreIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,21 @@ public MockHttpSession loginAsAnonymous() {
}


private static Element getSample(String resource) throws IOException, JDOMException {
final URL resourceUrl = AbstractCoreIntegrationTest.class.getResource(resource);
return Xml.loadStream(resourceUrl.openStream());
}

public Element getSampleMetadataXml() throws IOException, JDOMException {
final URL resource = AbstractCoreIntegrationTest.class.getResource("kernel/valid-metadata.iso19139.xml");
return Xml.loadStream(resource.openStream());
return getSample("kernel/valid-metadata.iso19139.xml");
}

public Element getSampleISO19139MetadataXml() throws IOException, JDOMException {
return getSample("kernel/metadata.iso19139.xml");
}

public Element getSampleISO19115MetadataXml() throws IOException, JDOMException {
return getSample("kernel/metadata.iso19115-3.xml");
}

/**
Expand Down
1,555 changes: 1,555 additions & 0 deletions core/src/test/resources/org/fao/geonet/kernel/metadata.iso19115-3.xml

Large diffs are not rendered by default.

1,054 changes: 1,054 additions & 0 deletions core/src/test/resources/org/fao/geonet/kernel/metadata.iso19139.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -18,41 +18,57 @@
<xsl:import href="../../layout/utility-tpl-multilingual.xsl"/>
<xsl:import href="../../layout/utility-fn.xsl"/>

<xsl:template name="get-iso19115-3.2018-citation">
<xsl:param name="metadata" as="node()"/>
<xsl:param name="language" as="xs:string"/>

<xsl:variable name="langId"
select="gn-fn-iso19115-3.2018:getLangId($metadata, $language)"/>
<xsl:function name="gn-fn-iso19115-3.2018:get-author-list">
<xsl:param name="authors" as="node()*"/>
<xsl:param name="langId" as="xs:string"/>

<!-- Who is the creator of the data set? This can be an individual, a group of individuals, or an organization. -->
<xsl:variable name="authorRoles"
select="('custodian', 'author')"/>
<xsl:variable name="authors"
select="$metadata/mdb:identificationInfo/*/mri:pointOfContact/
*[cit:role/*/@codeListValue = $authorRoles]"/>
<xsl:variable name="authorsNameAndOrgList">
<xsl:variable name="authorsNameAndOrgListTmp"
as="node()*">
<xsl:for-each select="$authors">
<author>
<xsl:variable name="name"
select=".//cit:individual/*/cit:name[1]"/>

<xsl:for-each select="$name">
<xsl:call-template name="get-iso19115-3.2018-localised">
<xsl:with-param name="langId" select="$langId"/>
</xsl:call-template>
</xsl:for-each>
<xsl:if test="normalize-space($name) != ''">(</xsl:if>
select=".//cit:individual/*/cit:name"/>

<xsl:variable name="listOfNames">
<xsl:for-each select="$name">
<xsl:call-template name="get-iso19115-3.2018-localised">
<xsl:with-param name="langId" select="$langId"/>
</xsl:call-template>
<xsl:if test="position() != last()">, </xsl:if>
</xsl:for-each>
</xsl:variable>

<xsl:value-of select="$listOfNames"/>
<xsl:if test="normalize-space($listOfNames) != ''"> (</xsl:if>
<xsl:for-each select="cit:party/*/cit:name">
<xsl:call-template name="get-iso19115-3.2018-localised">
<xsl:with-param name="langId" select="$langId"/>
</xsl:call-template>
</xsl:for-each>
<xsl:if test="normalize-space($name) != ''">)</xsl:if>
<xsl:if test="normalize-space($listOfNames) != ''">)</xsl:if>
</author>
</xsl:for-each>
</xsl:variable>

<xsl:for-each-group select="$authorsNameAndOrgListTmp" group-by=".">
<xsl:copy-of select="."/>
</xsl:for-each-group>
</xsl:function>

<xsl:template name="get-iso19115-3.2018-citation">
<xsl:param name="metadata" as="node()"/>
<xsl:param name="language" as="xs:string"/>

<xsl:variable name="langId"
select="gn-fn-iso19115-3.2018:getLangId($metadata, $language)"/>

<xsl:variable name="authors"
select="$metadata/mdb:identificationInfo/*/mri:pointOfContact/
*[cit:role/*/@codeListValue = $authorRolesList]"/>
<xsl:variable name="authorsNameAndOrgList"
select="gn-fn-iso19115-3.2018:get-author-list($authors, $langId)"/>


<!-- What name is the data set called? -->
<xsl:variable name="title"
select="$metadata/mdb:identificationInfo/*/mri:citation/*/cit:title"/>
Expand Down Expand Up @@ -84,36 +100,12 @@

<xsl:variable name="lastPublicationDate"
select="$publicationDates[1]"/>

<!-- What entity is responsible for producing and/or distributing the data set? Also, is there a physical location associated with the publisher? -->
<xsl:variable name="publisherRoles"
select="('publisher')"/>
<xsl:variable name="publishers"
<xsl:variable name="publishers" as="node()*"
select="$metadata/mdb:identificationInfo/*/mri:pointOfContact/
*[cit:role/*/@codeListValue = $publisherRoles]"/>

<xsl:variable name="publishersNameAndOrgList">
<xsl:for-each select="$publishers">
<author>
<xsl:variable name="name"
select=".//cit:individual/*/cit:name[1]"/>

<xsl:for-each select="$name">
<xsl:call-template name="get-iso19115-3.2018-localised">
<xsl:with-param name="langId" select="$langId"/>
</xsl:call-template>
</xsl:for-each>
<xsl:if test="normalize-space($name) != ''">(</xsl:if>
<xsl:for-each select="cit:party/*/cit:name">
<xsl:call-template name="get-iso19115-3.2018-localised">
<xsl:with-param name="langId" select="$langId"/>
</xsl:call-template>
</xsl:for-each>
<xsl:if test="normalize-space($name) != ''">)</xsl:if>
</author>
</xsl:for-each>
</xsl:variable>
*[cit:role/*/@codeListValue = $publisherRolesList]"/>

<xsl:variable name="publishersNameAndOrgList" as="node()*"
select="gn-fn-iso19115-3.2018:get-author-list($publishers, $langId)"/>

<!-- Electronic Retrieval Location -->
<xsl:variable name="doiInResourceIdentifier"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@
<xsl:param name="format"
select="'html'"/>

<!-- Who is the creator of the data set? This can be an individual, a group of individuals, or an organization. -->
<xsl:param name="authorRoles"
select="'custodian,author'"/>
<xsl:variable name="authorRolesList"
select="tokenize($authorRoles, ',')"/>

<!-- What entity is responsible for producing and/or distributing the data set? Also, is there a physical location associated with the publisher? -->
<xsl:param name="publisherRoles"
select="'publisher'"/>
<xsl:variable name="publisherRolesList"
select="tokenize($publisherRoles, ',')"/>

<xsl:variable name="formats" as="node()*">
<format key="html"/>
<format key="text"/>
Expand All @@ -36,33 +48,35 @@
select="count(authorsNameAndOrgList/*) > 0"/>
<xsl:variable name="hasPublisher"
select="count(publishersNameAndOrgList/*) > 0"/>
<textResponse>
<xsl:value-of select="concat(
<textResponse><xsl:value-of select="normalize-space(concat(
(if ($hasAuthor)
then string-join(authorsNameAndOrgList/*, ', ')
else ''),
(if ($hasAuthor)
then ' '
else ''),
(if (lastPublicationDate != '')
then concat(' (', substring(lastPublicationDate, 1, 4), '). ')
then concat('(', substring(lastPublicationDate, 1, 4), '). ')
else if ($hasAuthor) then '. ' else ''),
translatedTitle,
normalize-space(translatedTitle),
'. ',
(if ($hasPublisher)
then concat(string-join(publishersNameAndOrgList/*, ', '), '. ')
else ''),
if (doiUrl != '') then doiUrl else landingPageUrl)"/>
if (doiUrl != '') then doiUrl else landingPageUrl))"/>
</textResponse>
</xsl:template>


<xsl:template mode="citation" match="citation[lower-case($format) = 'bibtex']">
<!-- https://en.wikipedia.org/wiki/BibTeX -->
<textResponse>@data{<xsl:value-of select="uuid"/>,
author = {<xsl:value-of select="string-join(authorsNameAndOrgList/*, ' and ')"/>},
publisher = {<xsl:value-of select="string-join(publishersNameAndOrgList/*, ' and ')"/>},
title = {<xsl:value-of select="translatedTitle"/>},
<xsl:if test="lastPublicationDate != ''">year = {<xsl:value-of select="substring(lastPublicationDate, 1, 4)"/>},</xsl:if>
<xsl:if test="doi != ''">doi = {<xsl:value-of select="doi"/>},</xsl:if>
url = {<xsl:value-of select="if (doiUrl != '') then doiUrl else landingPageUrl"/>}
author = {<xsl:value-of select="normalize-space(string-join(authorsNameAndOrgList/*, ', '))"/>},
publisher = {<xsl:value-of select="normalize-space(string-join(publishersNameAndOrgList/*, ', '))"/>},
title = {<xsl:value-of select="normalize-space(translatedTitle)"/>},
<xsl:if test="lastPublicationDate != ''">year = {<xsl:value-of select="substring(lastPublicationDate, 1, 4)"/>},</xsl:if>
<xsl:if test="doi != ''">doi = {<xsl:value-of select="doi"/>},</xsl:if>
url = {<xsl:value-of select="if (doiUrl != '') then doiUrl else landingPageUrl"/>}
}</textResponse>
</xsl:template>

Expand All @@ -73,12 +87,12 @@
<!-- TODO: add support for MAP, DBASE, CTLG, AGGR? -->
<xsl:text>TY - </xsl:text><xsl:value-of select="'DATA'"/><xsl:text>&#13;&#10;</xsl:text>
<xsl:for-each select="authorsNameAndOrgList/*[. != '']">
<xsl:text>AU - </xsl:text><xsl:value-of select="."/><xsl:text>&#13;&#10;</xsl:text>
<xsl:text>AU - </xsl:text><xsl:value-of select="normalize-space(.)"/><xsl:text>&#13;&#10;</xsl:text>
</xsl:for-each>
<xsl:text>TI - </xsl:text><xsl:value-of select="translatedTitle"/><xsl:text>&#13;&#10;</xsl:text>
<xsl:text>TI - </xsl:text><xsl:value-of select="normalize-space(translatedTitle)"/><xsl:text>&#13;&#10;</xsl:text>
<!-- TODO: LA, ET -->
<xsl:for-each select="publishersNameAndOrgList/*[. != '']">
<xsl:text>PB - </xsl:text><xsl:value-of select="."/><xsl:text>&#13;&#10;</xsl:text>
<xsl:text>PB - </xsl:text><xsl:value-of select="normalize-space(.)"/><xsl:text>&#13;&#10;</xsl:text>
</xsl:for-each>
<xsl:for-each select="keyword[. != '']">
<xsl:text>KW - </xsl:text><xsl:value-of select="."/><xsl:text>&#13;&#10;</xsl:text>
Expand Down Expand Up @@ -114,23 +128,24 @@
else if ($hasAuthor) then '.'
else ''"/>

<div><xsl:copy-of select="translatedTitle/(text()|*)"/>.</div>
<span><xsl:copy-of select="translatedTitle/(text()|*)"/>.</span>

<xsl:call-template name="citation-contact">
<xsl:with-param name="contact" select="publishersNameAndOrgList"/>
</xsl:call-template>
<br/>
<br></br>

<xsl:variable name="url"
select="if (doiUrl != '') then doiUrl else landingPageUrl"/>
<a href="{$url}">
<xsl:value-of select="$url"/>
</a>
<br/>
<br></br>

<xsl:if test="additionalCitation != ''">
<br/>
<br></br>
<em><xsl:value-of select="$schemaStrings/citationAdditional"/></em>
<br/>
<br></br>
<xsl:value-of select="additionalCitation"/>
</xsl:if>
</p>
Expand All @@ -150,6 +165,7 @@
</span>
</xsl:for-each>
<xsl:if test="position() != last()">, </xsl:if>
<xsl:if test="position() = last()">&#160;</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,12 @@
<xsl:import href="../../layout/utility-tpl-multilingual.xsl"/>
<xsl:import href="../../layout/utility-fn.xsl"/>

<xsl:template name="get-iso19139-citation">
<xsl:param name="metadata" as="node()"/>
<xsl:param name="language" as="xs:string"/>

<xsl:variable name="langId"
select="gn-fn-iso19139:getLangId($metadata, $language)"/>
<xsl:function name="gn-fn-iso19139:get-author-list">
<xsl:param name="authors" as="node()*"/>
<xsl:param name="langId" as="xs:string"/>


<!-- Who is the creator of the data set? This can be an individual, a group of individuals, or an organization. -->
<xsl:variable name="authorRoles"
select="('author')"/>
<xsl:variable name="authors"
select="$metadata/gmd:identificationInfo/*/gmd:pointOfContact/
*[gmd:role/*/@codeListValue = $authorRoles]"/>
<xsl:variable name="authorsNameAndOrgList">
<xsl:variable name="authorsNameAndOrgListTmp"
as="node()*">
<xsl:for-each select="$authors">
<author>
<xsl:variable name="name"
Expand All @@ -58,6 +49,25 @@
</xsl:for-each>
</xsl:variable>

<xsl:for-each-group select="$authorsNameAndOrgListTmp" group-by=".">
<xsl:copy-of select="."/>
</xsl:for-each-group>
</xsl:function>


<xsl:template name="get-iso19139-citation">
<xsl:param name="metadata" as="node()"/>
<xsl:param name="language" as="xs:string"/>

<xsl:variable name="langId"
select="gn-fn-iso19139:getLangId($metadata, $language)"/>

<xsl:variable name="authors"
select="$metadata/gmd:identificationInfo/*/gmd:pointOfContact/
*[gmd:role/*/@codeListValue = $authorRolesList]"/>
<xsl:variable name="authorsNameAndOrgList" as="node()*"
select="gn-fn-iso19139:get-author-list($authors, $langId)"/>

<!-- What name is the data set called? -->
<xsl:variable name="title"
select="$metadata/gmd:identificationInfo/*/gmd:citation/*/gmd:title"/>
Expand Down Expand Up @@ -90,35 +100,11 @@
<xsl:variable name="lastPublicationDate"
select="$publicationDates[1]"/>

<!-- What entity is responsible for producing and/or distributing the data set? Also, is there a physical location associated with the publisher? -->
<xsl:variable name="publisherRoles"
select="('publisher')"/>
<xsl:variable name="publishers"
select="$metadata/gmd:identificationInfo/*/gmd:pointOfContact/
*[gmd:role/*/@codeListValue = $publisherRoles]"/>

<xsl:variable name="publishersNameAndOrgList">
<xsl:for-each select="$publishers">
<author>
<xsl:variable name="name"
select=".//gmd:individualName[1]"/>

<xsl:for-each select="$name">
<xsl:call-template name="localised">
<xsl:with-param name="langId" select="$langId"/>
</xsl:call-template>
</xsl:for-each>
<xsl:if test="normalize-space($name) != ''">(</xsl:if>
<xsl:for-each select=".//gmd:organisationName">
<xsl:call-template name="localised">
<xsl:with-param name="langId" select="$langId"/>
</xsl:call-template>
</xsl:for-each>
<xsl:if test="normalize-space($name) != ''">)</xsl:if>
</author>
</xsl:for-each>
</xsl:variable>

*[gmd:role/*/@codeListValue = $publisherRolesList]"/>
<xsl:variable name="publishersNameAndOrgList" as="node()*"
select="gn-fn-iso19139:get-author-list($publishers, $langId)"/>

<!-- Electronic Retrieval Location -->
<xsl:variable name="doiInResourceIdentifier"
Expand All @@ -129,7 +115,7 @@
or contains(*/@xlink:href, 'doi.org')]/*/(@xlink:href|text()))[1]"/>

<xsl:variable name="doiProtocolRegex"
select="'(DOI|WWW:LINK-1.0-http--metadata-URL)'"/>
select="'(DOI|WWW:LINK-1.0-http--metadata-URL)'"/>

<xsl:variable name="doiInOnline"
select="//gmd:distributionInfo//gmd:onLine/*[
Expand Down
Loading

0 comments on commit a7c0dee

Please sign in to comment.