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
  • Loading branch information
Possommi committed Dec 11, 2024
1 parent 55e9530 commit 0184ad4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
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,27 @@ 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])) {
MODS_XPATH.evaluate(publicationXML).forEach(element -> {
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]);
publicationXML.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

0 comments on commit 0184ad4

Please sign in to comment.