Skip to content

Commit

Permalink
#550 Added template stub mycoreobject-mods-resolve-his-keys.xsl and d…
Browse files Browse the repository at this point in the history
…efined transformer mods-resolve-his-keys
  • Loading branch information
Possommi committed Jun 12, 2024
1 parent ddef6d3 commit 6a849e6
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,26 @@

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jdom2.Document;
import org.jdom2.JDOMException;
import org.jdom2.filter.Filters;
import org.mycore.common.config.MCRConfiguration2;
import org.mycore.common.content.MCRContent;
import org.mycore.common.content.transformer.MCRToJSONTransformer;
import org.xml.sax.SAXException;

import java.io.IOException;
import java.util.Optional;

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

public class PublicationHisResTransformer extends MCRToJSONTransformer {
private static final Logger LOGGER = LogManager.getLogger(PublicationHisResTransformer.class);

static final String HIS_IN_ONE_BASE_URL = MCRConfiguration2.getStringOrThrow("ThUniBib.HISinOne.BaseURL");

protected JsonObject toJSON(MCRContent source) throws IOException {
try {
Expand All @@ -59,13 +66,18 @@ protected JsonObject toJSON(MCRContent source) throws IOException {

private void addLanguages(JsonObject jsonObject, Document xml) {
final JsonArray languages = new JsonArray();
XPATH_FACTORY.compile("//mods:language/mods:languageTerm[@type='code']/text()", Filters.text(), null,
MODS_NAMESPACE)
.evaluate(xml)

XPATH_FACTORY.compile(
"//mods:language/mods:languageTerm[@authorityURI='" + HIS_IN_ONE_BASE_URL + "']/text()",
Filters.text(), null, MODS_NAMESPACE).evaluate(xml)
.forEach(text -> {
JsonObject item = new JsonObject();
item.addProperty("id", "TODO-GET-ID-FROM-HIS---" + text.getText());
languages.add(item);
try {
JsonObject item = new JsonObject();
item.addProperty("id", Integer.parseInt(text.getText()));
languages.add(item);
} catch (NumberFormatException e) {
LOGGER.error(e);
}
});

if (languages.size() > 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package de.uni_jena.thunibib.common.xml;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jdom2.Element;
import org.jdom2.transform.JDOMSource;
import org.mycore.common.xml.MCRFunctionResolver;

import javax.xml.transform.Source;
import javax.xml.transform.TransformerException;
import javax.xml.transform.URIResolver;

public class HISinOneResolver implements URIResolver {
public enum URI_PART {
language
}

private static Logger LOGGER = LogManager.getLogger(MCRFunctionResolver.class);

@Override
public Source resolve(String href, String base) throws TransformerException {
LOGGER.info("Resolving '{}'", href);

String[] parts = href.split(":");
String entity = parts[1];
String value = parts[2];

try {
switch (URI_PART.valueOf(entity)) {
case language:
return new JDOMSource(new Element("int").setText(String.valueOf(resolveLanguage(value))));
}
} catch (Exception e) {
throw new TransformerException(e);
}

throw new TransformerException("Unknown entity: " + entity);
}

private int resolveLanguage(String rfc5646) {
return 42;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

public class ThUniBibUtils {

protected static final Logger LOGGER = LogManager.getLogger(ThUniBibUtils.class);
private static final Logger LOGGER = LogManager.getLogger(ThUniBibUtils.class);

protected static final String LEAD_ID_NAME = "id_" + MCRConfiguration2.getString("MCR.user2.matching.lead_id")
.get();
Expand Down
24 changes: 21 additions & 3 deletions common/src/main/resources/config/thunibib-common/mycore.properties
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,31 @@ MCR.ORCID2.Genre.Mapping.Classification = ubogenre
UBO.ORCID2.InfoURL = %MCR.baseurl%faq.xml
MCR.Solr.Proxy.WhiteList = %MCR.Solr.Proxy.WhiteList%,/search,/search-all,/statistics-all

###############
# DBT Import
###############
MCR.ContentTransformer.import.DBTIdentifier2MODSCollection.Class = de.uni_jena.thunibib.impex.importer.DBTIdentifiers2MODSCollection
MCR.ContentTransformer.import.DBTList.Class = org.mycore.common.content.transformer.MCRTransformerPipe
MCR.ContentTransformer.import.DBTList.Steps = import.DBTIdentifier2MODSCollection,import.DBTList2MCRObj
MCR.ContentTransformer.import.DBTList.Filter = supportedmods
MCR.ContentTransformer.import.DBTList2MCRObj.Class = org.mycore.common.content.transformer.MCRXSLTransformer
MCR.ContentTransformer.import.DBTList2MCRObj.Stylesheet = xsl/import/dbt2mods-genre2uri.xsl,xsl/import-mods2mycoreobject.xsl

MCR.ContentTransformer.res-json.Class = de.uni_jena.thunibib.common.content.transformer.PublicationHisResTransformer
MCR.ContentTransformer.res-json-detailed.Class = org.mycore.common.content.transformer.MCRTransformerPipe
MCR.ContentTransformer.res-json-detailed.Steps = mods-xml-detailed,res-json
###############
# HISinOne
###############
ThUniBib.HISinOne.BaseURL = https://h1-demo.uni-jena.de/qisserver/
ThUniBib.HISinOne.ClientKey =
ThUniBib.HISinOne.ClientSecret =

# Transformer for converting mods to json format used by HISinOne
MCR.ContentTransformer.res-json.Class = de.uni_jena.thunibib.common.content.transformer.PublicationHisResTransformer
MCR.ContentTransformer.res-json-detailed.Class = org.mycore.common.content.transformer.MCRTransformerPipe
MCR.ContentTransformer.res-json-detailed.Steps = mods-xml-detailed,mods-resolve-his-keys,res-json

# This transformer maps values from the source mods to keys used in HISinOne
MCR.ContentTransformer.mods-resolve-his-keys.Class = org.mycore.common.content.transformer.MCRXSLTransformer
MCR.ContentTransformer.mods-resolve-his-keys.TransformerFactoryClass = net.sf.saxon.TransformerFactoryImpl
MCR.ContentTransformer.mods-resolve-his-keys.Stylesheet = xsl/mycoreobject-mods-resolve-his-keys.xsl

MCR.URIResolver.ModuleResolver.HISinOne = de.uni_jena.thunibib.common.xml.HISinOneResolver
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:mods="http://www.loc.gov/mods/v3"
xmlns:mcracl="http://www.mycore.de/xslt/acl"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
exclude-result-prefixes="mcracl fn xsl">

<xsl:include href="resource:xsl/functions/acl.xsl"/>

<xsl:output method="xml" indent="yes"/>

<xsl:param name="ThUniBib.HISinOne.BaseURL"/>

<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="mods:language">
<xsl:variable name="rfc5646" select="mods:languageTerm[@type='code'][@authority='rfc5646']"/>

<xsl:copy>
<xsl:copy-of select="*|@*"/>
<xsl:variable name="his-key" select="fn:document(concat('HISinOne:language:', $rfc5646))"/>

<xsl:if test="$his-key">
<mods:languageTerm authorityURI="{$ThUniBib.HISinOne.BaseURL}" type="code">
<xsl:value-of select="$his-key"/>
</mods:languageTerm>
</xsl:if>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

0 comments on commit 6a849e6

Please sign in to comment.