From 921063403eed3cd425f6ab4352be371de2e5c8c5 Mon Sep 17 00:00:00 2001 From: Possommi Date: Wed, 29 May 2024 08:33:08 +0200 Subject: [PATCH 1/8] UBO-330 Fixed NPE in PublicationEventHandler (#389) * UBO-330 Fixed NPE in PublicationEventHandler * UBO-330 Simplified filter condition --- .../org/mycore/ubo/publication/PublicationEventHandler.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ubo-common/src/main/java/org/mycore/ubo/publication/PublicationEventHandler.java b/ubo-common/src/main/java/org/mycore/ubo/publication/PublicationEventHandler.java index 0b0089c9..92f80d94 100644 --- a/ubo-common/src/main/java/org/mycore/ubo/publication/PublicationEventHandler.java +++ b/ubo-common/src/main/java/org/mycore/ubo/publication/PublicationEventHandler.java @@ -175,9 +175,9 @@ private void handleName(Element modsNameElement) { .ifPresent(trueValue -> { List elementsToRemove = modsNameElement.getChildren("nameIdentifier", MCRConstants.MODS_NAMESPACE) - .stream() - .filter(element -> element.getAttributeValue("type").equals(leadIDName)) - .collect(Collectors.toList()); + .stream() + .filter(element -> leadIDName.equals(element.getAttributeValue("type"))) + .collect(Collectors.toList()); elementsToRemove.forEach(modsNameElement::removeContent); }); } From 4e1e5c86e429b030aee896088423cd43c6abe1d0 Mon Sep 17 00:00:00 2001 From: erodde <155449327+erodde@users.noreply.github.com> Date: Wed, 29 May 2024 15:04:21 +0200 Subject: [PATCH 2/8] UBO-331 added new enrichment command in new command group (#390) --- .../mods/enrichment/EnrichmentCommands.java | 38 +++++++++++++++++++ .../config/ubo-common/mycore.properties | 1 + 2 files changed, 39 insertions(+) create mode 100644 ubo-common/src/main/java/org/mycore/mods/enrichment/EnrichmentCommands.java diff --git a/ubo-common/src/main/java/org/mycore/mods/enrichment/EnrichmentCommands.java b/ubo-common/src/main/java/org/mycore/mods/enrichment/EnrichmentCommands.java new file mode 100644 index 00000000..fcf14058 --- /dev/null +++ b/ubo-common/src/main/java/org/mycore/mods/enrichment/EnrichmentCommands.java @@ -0,0 +1,38 @@ +package org.mycore.mods.enrichment; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.jdom2.Element; +import org.mycore.access.MCRAccessException; +import org.mycore.common.MCRException; +import org.mycore.datamodel.metadata.MCRMetadataManager; +import org.mycore.datamodel.metadata.MCRObject; +import org.mycore.datamodel.metadata.MCRObjectID; +import org.mycore.frontend.cli.annotation.MCRCommand; +import org.mycore.frontend.cli.annotation.MCRCommandGroup; +import org.mycore.mods.MCRMODSWrapper; + +/** + * Enriches a MODS file by its ID and a given enrichment configuration, compare + * MCR.MODS.EnrichmentResolver.DataSources.<configname>. + */ +@MCRCommandGroup(name = "Enrichment Commands") +public class EnrichmentCommands { + + private final static Logger LOGGER = LogManager.getLogger(); + + @MCRCommand(syntax = "enrich {0} with config {1}", + help = "Enriches existing MODS metadata {0} with a given enrichment configuration {1}", order = 40) + public static void enrichMods(String modsId, String configID) { + try { + MCRObject obj = MCRMetadataManager.retrieveMCRObject(MCRObjectID.getInstance(modsId)); + Element mods = new MCRMODSWrapper(obj).getMODS(); + MCREnricher enricher = new MCREnricher(configID); + enricher.enrich(mods); + MCRMetadataManager.update(obj); + } catch (MCRException | MCRAccessException e) { + LOGGER.error("Error while trying to enrich {} with configuration {}: ", modsId, configID, e); + } + } + +} diff --git a/ubo-common/src/main/resources/config/ubo-common/mycore.properties b/ubo-common/src/main/resources/config/ubo-common/mycore.properties index 869b833f..6982a2c6 100644 --- a/ubo-common/src/main/resources/config/ubo-common/mycore.properties +++ b/ubo-common/src/main/resources/config/ubo-common/mycore.properties @@ -240,6 +240,7 @@ UBO.CreatorRoles=cre aut tch pht prg MCR.CLI.Classes.Internal.DozBib=org.mycore.ubo.DozBibCommands MCR.CLI.Classes.Internal.Relations=org.mycore.ubo.relations.ParentChildRelationChecker MCR.CLI.Classes.Internal.UBOExport=org.mycore.ubo.export.MCRExportCommands +MCR.CLI.Classes.Internal.Enrichment=org.mycore.mods.enrichment.EnrichmentCommands # MyCoRe command line interface configuration MCR.CommandLineInterface.SystemName=UBO From e39392f57461797b5f90c5f4adcd86c31c4dc954 Mon Sep 17 00:00:00 2001 From: Possommi Date: Fri, 31 May 2024 08:26:54 +0200 Subject: [PATCH 3/8] UBO-332 Added missing tooltip for statistics button (#391) * UBO-332 Added missing tooltip for statistics button * UBO-332 Improved tooltip text for statistics button --- .../src/main/resources/config/ubo-common/messages_de.properties | 1 + .../src/main/resources/config/ubo-common/messages_en.properties | 1 + ubo-common/src/main/resources/xsl/response.xsl | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ubo-common/src/main/resources/config/ubo-common/messages_de.properties b/ubo-common/src/main/resources/config/ubo-common/messages_de.properties index 4540ea57..66ae19ed 100644 --- a/ubo-common/src/main/resources/config/ubo-common/messages_de.properties +++ b/ubo-common/src/main/resources/config/ubo-common/messages_de.properties @@ -120,6 +120,7 @@ button.selectPerson = Person ausw\u00E4hlen button.show = anzeigen button.statistics = Statistik button.statisticsShow = Statistik anzeigen +button.statistics.tooltip = Statistiken auf Basis dieser Trefferliste anzeigen button.structure = Struktur button.structureBlank = \ Struktur button.submit = Abschicken diff --git a/ubo-common/src/main/resources/config/ubo-common/messages_en.properties b/ubo-common/src/main/resources/config/ubo-common/messages_en.properties index 3d15f3eb..8084ad9a 100644 --- a/ubo-common/src/main/resources/config/ubo-common/messages_en.properties +++ b/ubo-common/src/main/resources/config/ubo-common/messages_en.properties @@ -120,6 +120,7 @@ button.selectPerson = Select person button.show = show button.statistics = Statistics button.statisticsShow = Show statistics +button.statistics.tooltip = Show statistics based on this result list button.structure = Structure button.structureBlank = \ Structure button.submit = Submit diff --git a/ubo-common/src/main/resources/xsl/response.xsl b/ubo-common/src/main/resources/xsl/response.xsl index 8d642dcb..1e3893fa 100644 --- a/ubo-common/src/main/resources/xsl/response.xsl +++ b/ubo-common/src/main/resources/xsl/response.xsl @@ -250,7 +250,7 @@
- + From eae966688e057a426f23dc54b4b39bdb2f280493 Mon Sep 17 00:00:00 2001 From: Possommi Date: Mon, 3 Jun 2024 09:43:12 +0200 Subject: [PATCH 4/8] UBO-333 FSU040THUL-3541 Renamed solr fields 'person_aut_corresp*' to 'corresponding_aut*' (#392) * UBO-333 FSU040THUL-3541 Made add-copy-field:source:person_* less greedy by changing it to add-copy-field:source:person_??? * UBO-333 FSU040THUL-3541 Made add-copy-field:source:person_* less greedy by changing it to add-copy-field:source:person_??? * UBO-333 FSU040THUL-3541 Renamed solr fields "person_aut_corresp*" to "corresponding_aut*" --- .../resources/config/ubo-common/solr/main/solr-schema.json | 4 ++-- ubo-common/src/main/resources/xsl/ubo-solr.xsl | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ubo-common/src/main/resources/config/ubo-common/solr/main/solr-schema.json b/ubo-common/src/main/resources/config/ubo-common/solr/main/solr-schema.json index 17bdb80d..15f534cd 100644 --- a/ubo-common/src/main/resources/config/ubo-common/solr/main/solr-schema.json +++ b/ubo-common/src/main/resources/config/ubo-common/solr/main/solr-schema.json @@ -232,7 +232,7 @@ }, { "add-field": { - "name": "person_aut_corresp", + "name": "corresponding_aut", "type": "ubo_name", "multiValued": true, "indexed": true, @@ -241,7 +241,7 @@ }, { "add-field": { - "name": "person_aut_corresp_id", + "name": "corresponding_aut_id", "type": "ubo_id", "multiValued": true, "indexed": true, diff --git a/ubo-common/src/main/resources/xsl/ubo-solr.xsl b/ubo-common/src/main/resources/xsl/ubo-solr.xsl index e675deff..06195dd6 100644 --- a/ubo-common/src/main/resources/xsl/ubo-solr.xsl +++ b/ubo-common/src/main/resources/xsl/ubo-solr.xsl @@ -161,12 +161,12 @@ - + - + From f65baa3e9e374b7c09ec2c198fa2797c3ac3fbca Mon Sep 17 00:00:00 2001 From: Possommi Date: Thu, 6 Jun 2024 08:36:17 +0200 Subject: [PATCH 5/8] UBO-249 Imports via list should be able to get concurrently executed (#393) * UBO-249 Added ImportListJobAction * UBO-249 Use MCRTranslation in import-list.xed * UBO-249 Toggle output format drop down when user checks #async-yes checkbox * UBO-249 Redirect to import-list.xed when id list has been submitted and user requested an asynchronous import * UBO-249 Provide tooltip for checkbox * UBO-249 Moved functions in ImportList.js to javascript object * UBO-249 Added ubo.import.list.textarea.placeholder to be used in import-list.xed * UBO-249 Removed obsolete if condition * UBO-249 Build xml from InputStream --- .../ubo/importer/DozBibImportServlet.java | 33 +++-- .../ubo/importer/ImportListJobAction.java | 115 ++++++++++++++++++ .../META-INF/resources/import-list.xed | 76 +++++++++--- .../META-INF/resources/js/ImportList.js | 42 ++++--- .../config/ubo-common/messages_de.properties | 10 ++ .../config/ubo-common/messages_en.properties | 10 ++ 6 files changed, 247 insertions(+), 39 deletions(-) create mode 100644 ubo-common/src/main/java/org/mycore/ubo/importer/ImportListJobAction.java diff --git a/ubo-common/src/main/java/org/mycore/ubo/importer/DozBibImportServlet.java b/ubo-common/src/main/java/org/mycore/ubo/importer/DozBibImportServlet.java index 52447452..61fdf4db 100644 --- a/ubo-common/src/main/java/org/mycore/ubo/importer/DozBibImportServlet.java +++ b/ubo-common/src/main/java/org/mycore/ubo/importer/DozBibImportServlet.java @@ -9,25 +9,29 @@ package org.mycore.ubo.importer; -import java.io.IOException; -import java.net.URLEncoder; -import java.nio.charset.StandardCharsets; - -import javax.xml.transform.TransformerException; - import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.jdom2.Document; import org.jdom2.Element; +import org.jdom2.output.XMLOutputter; import org.mycore.access.MCRAccessException; import org.mycore.common.content.MCRJDOMContent; +import org.mycore.frontend.MCRFrontendUtil; import org.mycore.frontend.servlets.MCRServlet; import org.mycore.frontend.servlets.MCRServletJob; +import org.mycore.services.queuedjob.MCRJob; +import org.mycore.services.queuedjob.MCRJobQueue; import org.mycore.ubo.AccessControl; import org.mycore.ubo.DozBibEntryServlet; import org.mycore.ubo.importer.evaluna.EvalunaImportJob; +import org.mycore.user2.MCRUserManager; import org.xml.sax.SAXException; +import javax.xml.transform.TransformerException; +import java.io.IOException; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; + @SuppressWarnings("serial") public class DozBibImportServlet extends MCRServlet { @@ -47,8 +51,23 @@ public void doGetPost(MCRServletJob job) throws Exception { private void handleImportJob(HttpServletRequest req, HttpServletResponse res) throws Exception { Document doc = (Document) (req.getAttribute("MCRXEditorSubmission")); - Element formInput = doc.detachRootElement(); + String doAsync = doc.getRootElement().getAttributeValue("async"); + if ("true".equals(doAsync)) { + MCRJob job = new MCRJob(ImportListJobAction.class); + job.setParameter(ImportListJobAction.EDITOR_SUBMISSION_PARAMETER, new XMLOutputter().outputString(doc)); + job.setParameter(ImportListJobAction.USER_ID_PARAMETER, MCRUserManager.getCurrentUser().getUserName()); + MCRJobQueue.getInstance(ImportListJobAction.class).offer(job); + String referer = req.getHeader("Referer"); + if (referer != null) { + res.sendRedirect(referer+"&list-submitted=true"); + } else { + res.sendRedirect(MCRFrontendUtil.getBaseURL()); + } + return; + } + + Element formInput = doc.detachRootElement(); ImportJob importJob = buildImportJob(formInput); importJob.transform(formInput); diff --git a/ubo-common/src/main/java/org/mycore/ubo/importer/ImportListJobAction.java b/ubo-common/src/main/java/org/mycore/ubo/importer/ImportListJobAction.java new file mode 100644 index 00000000..c17166b0 --- /dev/null +++ b/ubo-common/src/main/java/org/mycore/ubo/importer/ImportListJobAction.java @@ -0,0 +1,115 @@ +package org.mycore.ubo.importer; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.jdom2.Document; +import org.jdom2.Element; +import org.jdom2.input.SAXBuilder; +import org.mycore.common.MCRMailer; +import org.mycore.common.config.MCRConfiguration2; +import org.mycore.frontend.MCRFrontendUtil; +import org.mycore.services.i18n.MCRTranslation; +import org.mycore.services.queuedjob.MCRJob; +import org.mycore.services.queuedjob.MCRJobAction; +import org.mycore.ubo.importer.evaluna.EvalunaImportJob; +import org.mycore.user2.MCRUser; +import org.mycore.user2.MCRUserManager; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.util.Optional; +import java.util.concurrent.ExecutionException; + +/** + * Allows to execute a list import asynchronously. It executes the same tasks as in {@link DozBibImportServlet}. + * + * @author shermann (Silvio Hermann) + * */ +public class ImportListJobAction extends MCRJobAction { + + public static String EDITOR_SUBMISSION_PARAMETER = "xEditorSubmission"; + public static String USER_ID_PARAMETER = "userName"; + public static String IMPORT_JOB_ID_PARAMETER = "importJobId"; + + protected static final Logger LOGGER = LogManager.getLogger(ImportListJobAction.class); + + protected static final Optional DEFAULT_EMAIL_FROM = MCRConfiguration2.getString("UBO.Mail.From"); + + public ImportListJobAction() { + } + + public ImportListJobAction(MCRJob mcrJob) { + super(mcrJob); + } + + @Override + public void execute() throws ExecutionException { + String xEditorSubmission = job.getParameter(ImportListJobAction.EDITOR_SUBMISSION_PARAMETER); + + if (xEditorSubmission == null) { + LOGGER.error("No {} parameter provided", ImportListJobAction.EDITOR_SUBMISSION_PARAMETER); + return; + } + + try (InputStream inputStream = new ByteArrayInputStream(xEditorSubmission.getBytes(StandardCharsets.UTF_8))) { + Document doc = new SAXBuilder().build(inputStream); + Element formInput = doc.detachRootElement(); + + String sourceType = formInput.getAttributeValue("sourceType"); + ImportJob importJob = "Evaluna".equals(sourceType) ? new EvalunaImportJob() : new ListImportJob(sourceType); + importJob.transform(formInput); + job.setParameter(IMPORT_JOB_ID_PARAMETER, importJob.getID()); + + if ("true".equals(formInput.getAttributeValue("enrich"))) { + importJob.enrich(); + } + + importJob.saveAndIndex(); + sendMail(importJob); + } catch (Exception e) { + LOGGER.error("Could not transform form input", e); + } + } + + private void sendMail(ImportJob importJob) { + String userName = job.getParameter(ImportListJobAction.USER_ID_PARAMETER); + MCRUser mcrUser = MCRUserManager.getUser(userName); + String eMailAddress = mcrUser.getEMailAddress(); + + if (eMailAddress == null) { + LOGGER.warn("Cannot send e-mail to user {} as user has no e-mail address", userName); + return; + } + + if (ImportListJobAction.DEFAULT_EMAIL_FROM.isEmpty()) { + LOGGER.warn("Cannot send e-mail to user {} as property UBO.Mail.From is not set", userName); + return; + } + + String subject = MCRTranslation.translate("ubo.import.list.email.subject", importJob.getID()); + MCRMailer.send(DEFAULT_EMAIL_FROM.get(), eMailAddress, subject, getBody(importJob)); + } + + private String getBody(ImportJob importJob) { + String url = MCRFrontendUtil.getBaseURL() + "servlets/solr/select?fq=%2BobjectType%3Amods&q=importID%3A%22" + + URLEncoder.encode(importJob.getID(), StandardCharsets.UTF_8) + "%22"; + return MCRTranslation.translate("ubo.import.list.email.body", url); + } + + @Override + public boolean isActivated() { + return true; + } + + @Override + public String name() { + return getClass().getSimpleName(); + } + + @Override + public void rollback() { + LOGGER.warn("Rolling back in {} is not implemented", ImportListJobAction.class.getName()); + } +} diff --git a/ubo-common/src/main/resources/META-INF/resources/import-list.xed b/ubo-common/src/main/resources/META-INF/resources/import-list.xed index 2a4ea4c9..e2869a64 100644 --- a/ubo-common/src/main/resources/META-INF/resources/import-list.xed +++ b/ubo-common/src/main/resources/META-INF/resources/import-list.xed @@ -1,15 +1,40 @@ - - Literaturliste importieren + + + <i18n:de> + Literaturliste importieren + </i18n:de> + <i18n:en> + Import bibliography + </i18n:en> + + + + +
+
+ +
+
+
+

- Über dieses Formular können Sie eine Literaturliste im - BibTeX Format, - alle Publikationen einer gegebenen ORCID oder eine CSV-Datei importieren. + + Über dieses Formular können Sie eine Literaturliste im + BibTeX Format, + alle Publikationen einer gegebenen ORCID oder eine CSV-Datei importieren. + + + Using this form you can import a bibliography in + BibTeX format, + all publications of a given ORCID or a CSV file. +

+ @@ -25,11 +50,13 @@
- Literaturliste importieren + + : +
-