From 5b28bd54894d43a616545bf6c7ff0b71bc595b4b Mon Sep 17 00:00:00 2001 From: Silvio Hermann Date: Wed, 12 Jun 2024 09:41:05 +0200 Subject: [PATCH] #550 Added template stub mycoreobject-mods-resolve-his-keys.xsl and defined transformer mods-resolve-his-keys --- .../PublicationHisResTransformer.java | 24 +++++++++--- .../thunibib/common/xml/HISinOneResolver.java | 39 +++++++++++++++++++ .../uni_jena/thunibib/user/ThUniBibUtils.java | 2 +- .../config/thunibib-common/mycore.properties | 24 ++++++++++-- .../mycoreobject-mods-resolve-his-keys.xsl | 35 +++++++++++++++++ 5 files changed, 114 insertions(+), 10 deletions(-) create mode 100644 common/src/main/java/de/uni_jena/thunibib/common/xml/HISinOneResolver.java create mode 100644 common/src/main/resources/xsl/mycoreobject-mods-resolve-his-keys.xsl diff --git a/common/src/main/java/de/uni_jena/thunibib/common/content/transformer/PublicationHisResTransformer.java b/common/src/main/java/de/uni_jena/thunibib/common/content/transformer/PublicationHisResTransformer.java index a4e0310a2..8c05aa3ec 100644 --- a/common/src/main/java/de/uni_jena/thunibib/common/content/transformer/PublicationHisResTransformer.java +++ b/common/src/main/java/de/uni_jena/thunibib/common/content/transformer/PublicationHisResTransformer.java @@ -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 { @@ -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) { diff --git a/common/src/main/java/de/uni_jena/thunibib/common/xml/HISinOneResolver.java b/common/src/main/java/de/uni_jena/thunibib/common/xml/HISinOneResolver.java new file mode 100644 index 000000000..080c31854 --- /dev/null +++ b/common/src/main/java/de/uni_jena/thunibib/common/xml/HISinOneResolver.java @@ -0,0 +1,39 @@ +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]; + + switch (URI_PART.valueOf(entity)) { + case language: + return new JDOMSource(new Element("int").setText(String.valueOf(resolveLanguage(value)))); + } + + throw new TransformerException("Unknown entity: " + entity); + } + + private int resolveLanguage(String rfc5646) { + return 42; + } +} diff --git a/common/src/main/java/de/uni_jena/thunibib/user/ThUniBibUtils.java b/common/src/main/java/de/uni_jena/thunibib/user/ThUniBibUtils.java index e4fadb506..ee5f20053 100644 --- a/common/src/main/java/de/uni_jena/thunibib/user/ThUniBibUtils.java +++ b/common/src/main/java/de/uni_jena/thunibib/user/ThUniBibUtils.java @@ -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(); diff --git a/common/src/main/resources/config/thunibib-common/mycore.properties b/common/src/main/resources/config/thunibib-common/mycore.properties index d4730ae80..360864b75 100644 --- a/common/src/main/resources/config/thunibib-common/mycore.properties +++ b/common/src/main/resources/config/thunibib-common/mycore.properties @@ -131,6 +131,9 @@ 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 @@ -138,6 +141,21 @@ MCR.ContentTransformer.import.DBTList.Filter = supportedmod 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 diff --git a/common/src/main/resources/xsl/mycoreobject-mods-resolve-his-keys.xsl b/common/src/main/resources/xsl/mycoreobject-mods-resolve-his-keys.xsl new file mode 100644 index 000000000..dacbb385f --- /dev/null +++ b/common/src/main/resources/xsl/mycoreobject-mods-resolve-his-keys.xsl @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +