Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  UBO-335 add lang parameter to translate resource url
  UBO-334 Support mods:genre with authorityURI and valueURI in mods-filter-supported.xsl (#395)
  UBO-249 Fixed i18n ubo.import.list.form.headline (#394)
  UBO-249 Imports via list should be able to get concurrently executed (#393)
  UBO-333 FSU040THUL-3541 Renamed solr fields 'person_aut_corresp*' to 'corresponding_aut*' (#392)
  UBO-332 Added missing tooltip for statistics button (#391)
  UBO-331 added new enrichment command in new command group (#390)
  UBO-330 Fixed NPE in PublicationEventHandler (#389)
  • Loading branch information
kkrebs committed Jun 15, 2024
2 parents ebd7315 + addccd5 commit b5494a7
Show file tree
Hide file tree
Showing 14 changed files with 298 additions and 49 deletions.
Original file line number Diff line number Diff line change
@@ -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
* <code>MCR.MODS.EnrichmentResolver.DataSources.&lt;configname&gt;</code>.
*/
@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);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> 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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ private void handleName(Element modsNameElement) {
.ifPresent(trueValue -> {
List<Element> 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);
});
}
Expand Down
76 changes: 58 additions & 18 deletions ubo-common/src/main/resources/META-INF/resources/import-list.xed
Original file line number Diff line number Diff line change
@@ -1,15 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>

<webpage lastModified="$Date: 2009-07-09 12:25:56 +0200 (Do, 09 Jul 2009) $" id="dozbib.import.list">
<title xml:lang="de">Literaturliste importieren</title>
<webpage lastModified="$Date: 2009-07-09 12:25:56 +0200 (Do, 09 Jul 2009) $" id="dozbib.import.list" xmlns:i18n="http://www.mycore.org/i18n">
<title>
<i18n:de>
Literaturliste importieren
</i18n:de>
<i18n:en>
Import bibliography
</i18n:en>
</title>

<xed:form xmlns:xed="http://www.mycore.de/xeditor">
<xed:if test="$list-submitted = 'true'" xmlns:xed="http://www.mycore.de/xeditor">
<article class="card mb-3">
<div class="card-body">
<xed:output i18n="ubo.import.list.submission.success" />
</div>
</article>
</xed:if>
</xed:form>

<article class="card">
<div class="card-body">
<p>
Über dieses Formular können Sie eine Literaturliste im
<a href="http://artis.imag.fr/~Xavier.Decoret/resources/xdkbibtex/bibtex_summary.html">BibTeX Format</a>,
alle Publikationen einer gegebenen ORCID oder eine CSV-Datei importieren.
<i18n:de>
Über dieses Formular können Sie eine Literaturliste im
<a href="http://artis.imag.fr/~Xavier.Decoret/resources/xdkbibtex/bibtex_summary.html">BibTeX Format</a>,
alle Publikationen einer gegebenen ORCID oder eine CSV-Datei importieren.
</i18n:de>
<i18n:en>
Using this form you can import a bibliography in
<a href="http://artis.imag.fr/~Xavier.Decoret/resources/xdkbibtex/bibtex_summary.html">BibTeX format</a>,
all publications of a given ORCID or a CSV file.
</i18n:en>
</p>

<xed:form xmlns:xed="http://www.mycore.de/xeditor" method="post" role="form">
<xed:bind xpath="/import">

Expand All @@ -25,11 +50,13 @@
</xed:if>

<fieldset>
<legend>Literaturliste importieren</legend>
<legend>
<xed:output i18n="ubo.import.list.form.headline" />:
</legend>

<xed:repeat xpath="subject" max="5">
<div class="form-group form-inline">
<label for="subject" class="mycore-form-label">
<label for="subject" class="mycore-form-label text-nowrap">
<xed:output i18n="ubo.subject" />:
</label>
<select class="autocomplete {$xed-validation-marker} col-7 form-control custom-select">
Expand All @@ -44,7 +71,7 @@

<xed:bind xpath="origin">
<div class="form-group form-inline">
<label for="{generate-id()}" class="mycore-form-label">
<label for="{generate-id()}" class="mycore-form-label text-nowrap">
<xed:output i18n="ubo.department" />:
</label>
<select id="{generate-id()}" class="autocomplete {$xed-validation-marker} col-7 form-control custom-select">
Expand All @@ -56,17 +83,21 @@

<xed:bind xpath="@sourceType">
<div class="form-group form-inline">
<label for="{generate-id()}" class="mycore-form-label">Quell-Format:</label>
<select id="{generate-id()}" class="form-control col-7 mr-1 custom-select" onchange="toggleEnrichment(this)">
<label for="{generate-id()}" class="mycore-form-label text-nowrap">
<xed:output i18n="ubo.import.list.label.sourceFormat" />:
</label>
<select id="{generate-id()}" class="form-control col-7 mr-1 custom-select" onchange="UBOImportList.toggleEnrichment(this)">
<xed:include uri="xslStyle:items2options:classification:editor:-1:children:importSourceType" />
</select>
</div>
</xed:bind>

<xed:bind xpath="@targetType">
<div class="form-group form-inline">
<label for="{generate-id()}" class="mycore-form-label">Ausgabe-Format:</label>
<select id="{generate-id()}" class="form-control col custom-select">
<label for="{generate-id()}" class="mycore-form-label text-nowrap">
<xed:output i18n="ubo.import.list.label.outputFormat" />:
</label>
<select id="import-list-output-format-select" class="form-control col-7 custom-select">
<option value="preview-html">Vorschau (HTML)</option>
<option value="preview-mods-raw">Vorschau (MODS)</option>
<option value="import">direkt importieren</option>
Expand All @@ -76,7 +107,9 @@

<xed:bind xpath="@enrich" initially="false">
<div class="form-group form-inline">
<label class="mycore-form-label">aus externen Datenquellen anreichern:</label>
<label class="mycore-form-label text-nowrap">
<xed:output i18n="ubo.import.list.label.enrich" />:
</label>
<input type="radio" value="true" class="form-control ml-2 mr-2" id="enrich-yes" /><label for="enrich-yes">Ja</label>
<input type="radio" value="false" class="form-control ml-4 mr-2" id="enrich-no" /><label for="enrich-no" >Nein</label>
</div>
Expand All @@ -85,20 +118,27 @@
<xed:bind xpath="source">
<div class="form-group form-inline">
<textarea id="{xed:generate-id()}" class="{$xed-validation-marker} form-control col" type="text"
placeholder="BibTeX Quellcode bzw. ORCID bzw. PPN/CSV-Literaturliste hierhin kopieren" rows="10"
oninput="toggleSubmit()"/>
placeholder="{i18n:ubo.import.list.textarea.placeholder}" rows="10"
oninput="UBOImportList.toggleSubmit()"/>
</div>
<xed:validate required="true" display="global" />
</xed:bind>

<div>
<div class="form-group form-inline">
<button id="submitBtn" class="btn btn-sm btn-primary" disabled="disabled" type="submit" xed:target="servlet" xed:href="DozBibImportServlet">
<xed:output i18n="button.submit" />
</button>
</div>

<xed:bind xpath="@async" initially="false">
<div class="form-group form-inline ml-3" title="{i18n:ubo.import.list.tooltip.async}">
<input type="checkbox" value="true" class="form-check-input my-auto" id="async-yes" onchange="UBOImportList.toggleSelect('import-list-output-format-select', 'import')"/>
<label class="my-auto">
<xed:output i18n="ubo.import.list.label.async" />
</label>
</div>
</xed:bind>
</div>
</fieldset>

</xed:bind>
</xed:form>

Expand Down
Loading

0 comments on commit b5494a7

Please sign in to comment.