-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
Showing
14 changed files
with
298 additions
and
49 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
ubo-common/src/main/java/org/mycore/mods/enrichment/EnrichmentCommands.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.<configname></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); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
ubo-common/src/main/java/org/mycore/ubo/importer/ImportListJobAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.