Skip to content

Commit

Permalink
UBO-382 Allow to set preconfigured classification values during scopu…
Browse files Browse the repository at this point in the history
…s import (#443)

* UBO-382 Allow to set preconfigured classification values during scopus import

* UBO-382 Support custom scopus import status in rss-import-e-mail.xsl

* UBO-382 Simplified predicate
  • Loading branch information
Possommi authored Dec 11, 2024
1 parent 55e9530 commit d012ad7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.filter.ElementFilter;
import org.jdom2.filter.Filters;
import org.jdom2.xpath.XPathExpression;
import org.mycore.access.MCRAccessException;
import org.mycore.common.MCRConstants;
import org.mycore.common.MCRException;
Expand All @@ -16,9 +18,11 @@
import org.mycore.common.MCRSessionMgr;
import org.mycore.common.config.MCRConfiguration2;
import org.mycore.common.xml.MCRURIResolver;
import org.mycore.common.xml.MCRXMLFunctions;
import org.mycore.datamodel.metadata.MCRMetadataManager;
import org.mycore.datamodel.metadata.MCRObject;
import org.mycore.datamodel.metadata.MCRObjectID;
import org.mycore.frontend.MCRFrontendUtil;
import org.mycore.mods.MCRMODSWrapper;
import org.mycore.solr.MCRSolrClientFactory;
import org.mycore.solr.MCRSolrUtils;
Expand All @@ -31,6 +35,9 @@
import java.util.List;
import java.util.Locale;

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

class ScopusImporter {

private static final Logger LOGGER = LogManager.getLogger();
Expand All @@ -49,6 +56,8 @@ class ScopusImporter {

private static String MAIL_XSL;

private static XPathExpression<Element> MODS_XPATH = XPATH_FACTORY
.compile(".//mods:mods", Filters.element(), null, MODS_NAMESPACE);
private List<MCRObject> importedObjects = new ArrayList<>();

static {
Expand All @@ -57,7 +66,6 @@ class ScopusImporter {
IMPORT_URI = MCRConfiguration2.getString(prefix + "ImportURI").get();
PROJECT_ID = MCRConfiguration2.getString(prefix + "ProjectID").get();
STATUS = MCRConfiguration2.getString(prefix + "Status").get();

prefix += "Mail.";
MAIL_TO = MCRConfiguration2.getString(prefix + "To").get();
MAIL_PARAM = MCRConfiguration2.getString(prefix + "Param").get();
Expand Down Expand Up @@ -110,6 +118,8 @@ private static boolean shouldIgnore(Element publication) {
private final static SimpleDateFormat ID_BUILDER = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ROOT);

private MCRObject buildMCRObject(Element publicationXML) {
setPreconfiguredClasses(publicationXML);

MCRObject obj = new MCRObject(new Document(publicationXML));
MCRMODSWrapper wrapper = new MCRMODSWrapper(obj);
wrapper.setServiceFlag("status", STATUS);
Expand All @@ -119,6 +129,28 @@ private MCRObject buildMCRObject(Element publicationXML) {
return obj;
}

private void setPreconfiguredClasses(Element publicationXML) {
List<String> list = MCRConfiguration2.getString("UBO.Scopus.Importer.Default.Classifications")
.stream()
.flatMap(MCRConfiguration2::splitValue)
.toList();

list.forEach(classification -> {
String[] parts = classification.split(":");
if (parts.length == 2 && MCRXMLFunctions.isCategoryID(parts[0], parts[1])) {
Element e = MODS_XPATH.evaluateFirst(publicationXML);
if (e != null) {
Element c = new Element("classification", MODS_NAMESPACE);
c.setAttribute("valueURI",
MCRFrontendUtil.getBaseURL() + "classifications/" + parts[0] + "#" + parts[1]);
c.setAttribute("authorityURI",
MCRFrontendUtil.getBaseURL() + "classifications/" + parts[0]);
e.addContent(c);
}
}
});
}

private String getImportID() {
return ID_BUILDER.format(new Date(MCRSessionMgr.getCurrentSession().getLoginTime()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,7 @@ UBO.Scopus.API.URL=https://api.elsevier.com/content/
UBO.Scopus.Importer.Field2QueryID=id_scopus
UBO.Scopus.Importer.ImportURI.Scopus=%UBO.Scopus.API.URL%abstract/scopus_id/{0}?apikey=%UBO.Scopus.API.Key%
UBO.Scopus.Importer.ImportURI=xslStyle:mods2mycoreobject:enrich:scopus-import:xslStyle:import/scopus2mods,import/genre2genre,%UBO.SupportedMODSFilterName%:ratelimit:ScopusWeek:ratelimit:ScopusSecond:%UBO.Scopus.Importer.ImportURI.Scopus%
UBO.Scopus.Importer.Default.Classifications=
UBO.Scopus.Importer.ProjectID=%UBO.projectid.default%
UBO.Scopus.Importer.Status=imported
UBO.Scopus.Importer.Mail.To=%MCR.Mail.Address%
Expand Down
11 changes: 6 additions & 5 deletions ubo-common/src/main/resources/xsl/rss-import-e-mail.xsl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml version="1.0" encoding="UTF-8"?>

<!-- ============================================== -->
<!-- $Revision: 34514 $ $Date: 2016-02-04 19:27:24 +0100 (Do, 04 Feb 2016) $ -->
Expand Down Expand Up @@ -29,20 +29,21 @@
<xsl:param name="ServletsBaseURL" />
<xsl:param name="MCR.Mail.Address" />
<xsl:param name="UBO.Mail.From" />
<xsl:param name="UBO.Scopus.Importer.Status" />


<xsl:variable name="br"><xsl:text>
</xsl:text></xsl:variable>

<xsl:template match="/imported">
<xsl:template match="/*[contains(concat('imported ', $UBO.Scopus.Importer.Status), local-name())]">
<email>
<from><xsl:value-of select="$UBO.Mail.From" /></from>
<xsl:if test="string-length($MCR.Mail.Address)&gt;0">
<xsl:for-each select="str:tokenize($MCR.Mail.Address,',')" >
<to> <xsl:value-of select="." /> </to>
</xsl:for-each>
</xsl:if>
<subject>Universitätsbibliographie: <xsl:value-of select="@source" /> RSS Feed Import</subject>
<subject>Universitätsbibliographie: <xsl:value-of select="@source" /> RSS Feed Import</subject>
<body>
<xsl:text>
Liebe Kollegin, lieber Kollege,
Expand All @@ -66,9 +67,9 @@ die folgenden </xsl:text>
</xsl:for-each>
<xsl:text>

Mit freundlichen Grüßen
Mit freundlichen Grüßen

Ihre Universitätsbibliographie
Ihre Universitätsbibliographie
</xsl:text>
</body>
</email>
Expand Down

0 comments on commit d012ad7

Please sign in to comment.