Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UBO-349 FSU040THUL-3962 Avoid same destatis category from ORIGIN.xml is outputted multiple times #409

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions ubo-common/src/main/java/org/mycore/ubo/DozBibXMLFunctions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package org.mycore.ubo;

import org.jdom2.Document;
import org.jdom2.JDOMException;
import org.jdom2.filter.Filters;
import org.mycore.datamodel.classifications2.MCRCategory;
import org.mycore.datamodel.classifications2.MCRCategoryDAO;
import org.mycore.datamodel.classifications2.MCRCategoryDAOFactory;
import org.mycore.datamodel.classifications2.MCRCategoryID;
import org.mycore.datamodel.classifications2.MCRLabel;
import org.mycore.datamodel.common.MCRXMLMetadataManager;
import org.mycore.datamodel.metadata.MCRObject;
import org.mycore.datamodel.metadata.MCRObjectID;
import org.xml.sax.SAXException;

import java.io.IOException;
import java.util.List;

import static org.mycore.common.MCRConstants.MODS_NAMESPACE;
import static org.mycore.common.MCRConstants.XPATH_FACTORY;

/**
* Collections of methods to be used in XSLT-1 stylesheets.
*
* @author shermann (Silvio Hermann)
* */
public class DozBibXMLFunctions {

/**
* Retrieves a list of {@link MCRCategory}s having an <code>x-destatis</code> {@link MCRLabel}.
*
* @param mcrid the id of the {@link org.mycore.datamodel.metadata.MCRObject}
*
* @return a list of {@link MCRCategory}s having an <code>x-destatis</code> {@link MCRLabel}
* @throws IOException
* @throws JDOMException
* @throws SAXException
*/
public static List<MCRCategory> getDestatisCategories(MCRObjectID mcrid)
throws IOException, JDOMException, SAXException {

Document xml = MCRXMLMetadataManager.instance().retrieveXML(mcrid);
MCRCategoryDAO dao = MCRCategoryDAOFactory.getInstance();

return XPATH_FACTORY.compile(
"//mods:mods/mods:classification[contains(@authorityURI,'ORIGIN')]", Filters.element(),
null, MODS_NAMESPACE).evaluate(xml)
.stream()
.filter(element -> element.getAttributeValue("valueURI") != null)
.map(element -> element.getAttributeValue("valueURI"))
.map(valueURI -> valueURI.substring(valueURI.indexOf("#") + 1))
.map(categId -> dao.getCategory(MCRCategoryID.fromString("ORIGIN:" + categId), 0))
.filter(mcrCategory -> mcrCategory.getLabel("x-destatis").isPresent())
.toList();
}

/**
* Creates a list of unique destatis category identifiers as string.
*
* @param mcrid the id of the {@link MCRObject}
*
* @return a {@link String} of destatis identifiers separated by blanks
* @throws IOException
* @throws JDOMException
* @throws SAXException
*/
public static String getUniqueDestatisCategories(String mcrid) throws IOException, JDOMException, SAXException {
List<String> list = DozBibXMLFunctions.getDestatisCategories(MCRObjectID.getInstance(mcrid))
.stream()
.map(mcrCategory -> mcrCategory.getLabel("x-destatis"))
.map(mcrLabel -> mcrLabel.get())
.distinct()
.map(mcrLabel -> mcrLabel.getText())
.toList();
return String.join(" ", list);
}
}
40 changes: 19 additions & 21 deletions ubo-common/src/main/resources/xsl/mods-display.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
xmlns:mcr="http://www.mycore.org/"
xmlns:i18n="xalan://org.mycore.services.i18n.MCRTranslation"
xmlns:mcrxsl="xalan://org.mycore.common.xml.MCRXMLFunctions"
exclude-result-prefixes="xsl xalan xlink i18n encoder mcr mcrxsl check cerif">
xmlns:dozbib="xalan://org.mycore.ubo.DozBibXMLFunctions"
exclude-result-prefixes="dozbib xsl xalan xlink i18n encoder mcr mcrxsl check cerif">

<xsl:include href="shelfmark-normalization.xsl" />
<xsl:include href="output-category.xsl" />
Expand Down Expand Up @@ -90,27 +91,24 @@
</xsl:template>

<!-- Derive destatis from origin if fachreferate is not set -->
<xsl:template match="mods:classification[contains(@authorityURI,'ORIGIN') and not (../mods:classification[contains(@authorityURI,'fachreferate')])]" mode="label-info-destatis">
<xsl:variable name="origin-value" select="substring-after(@valueURI, '#')"/>
<xsl:variable name="destatis-attr" select="$origin//category[@ID = $origin-value]/label[@xml:lang = 'x-destatis']/@text"/>

<xsl:if test="string-length($destatis-attr) &gt; 0">
<xsl:variable name="destatis-categories">
<xsl:call-template name="Tokenizer">
<xsl:with-param name="string" select="$destatis-attr" />
<xsl:template name="label-info-destatis">
<xsl:if test="not (//mods:mods/mods:classification[contains(@authorityURI,'fachreferate')])">
<xsl:variable name="destatis-categories">
<xsl:call-template name="Tokenizer">
<xsl:with-param name="string" select="dozbib:getUniqueDestatisCategories(//mycoreobject/@ID)" />
</xsl:call-template>
</xsl:variable>

<xsl:for-each select="xalan:nodeset($destatis-categories)/token">
<span class="label-info badge badge-secondary mr-1 ubo-hover-pointer"
title="{i18n:translate('facets.facet.subject')}"
onclick="location.assign('{$WebApplicationBaseURL}servlets/solr/select?sort=modified+desc&amp;q={encoder:encode(concat($fq, '+subject:&quot;', ., '&quot;'))}')">
<xsl:call-template name="output.category">
<xsl:with-param name="classID" select="'fachreferate'" />
<xsl:with-param name="categID" select="." />
</xsl:call-template>
</xsl:variable>

<xsl:for-each select="xalan:nodeset($destatis-categories)/token">
<span class="label-info badge badge-secondary mr-1 ubo-hover-pointer"
title="{i18n:translate('facets.facet.subject')}"
onclick="location.assign('{$WebApplicationBaseURL}servlets/solr/select?sort=modified+desc&amp;q={encoder:encode(concat($fq, '+subject:&quot;', ., '&quot;'))}')">
<xsl:call-template name="output.category">
<xsl:with-param name="classID" select="'fachreferate'" />
<xsl:with-param name="categID" select="." />
</xsl:call-template>
</span>
</xsl:for-each>
</span>
</xsl:for-each>
</xsl:if>
</xsl:template>

Expand Down
2 changes: 1 addition & 1 deletion ubo-common/src/main/resources/xsl/mycoreobject.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@
<div class="row">
<div class="col">
<xsl:apply-templates select="mods:classification[contains(@authorityURI,'fachreferate')]" mode="label-info" />
<xsl:apply-templates select="mods:classification[contains(@authorityURI,'ORIGIN')]" mode="label-info-destatis" />
<xsl:call-template name="label-info-destatis"/>
<xsl:apply-templates select="mods:classification[contains(@authorityURI,'ORIGIN')]" mode="label-info" />
</div>
</div>
Expand Down
Loading