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 219f1051..9fb9affe 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 @@ -74,7 +74,12 @@ private void handleImportJob(HttpServletRequest req, HttpServletResponse res) th boolean enrich = "true".equals(formInput.getAttributeValue("enrich")); if (enrich) { - importJob.enrich(); + String enricherId = EnrichmentConfigMgr.getEnricherId(formInput); + if (enricherId != null) { + importJob.enrich(enricherId); + } else { + importJob.enrich(); + } } String targetType = formInput.getAttributeValue("targetType"); diff --git a/ubo-common/src/main/java/org/mycore/ubo/importer/EnrichmentConfigMgr.java b/ubo-common/src/main/java/org/mycore/ubo/importer/EnrichmentConfigMgr.java new file mode 100644 index 00000000..89f0c039 --- /dev/null +++ b/ubo-common/src/main/java/org/mycore/ubo/importer/EnrichmentConfigMgr.java @@ -0,0 +1,48 @@ +package org.mycore.ubo.importer; + +import org.jdom2.Element; +import org.mycore.common.config.MCRConfiguration2; + +import java.util.Optional; + +/** + * Class retrieves the enricher id from the form input of import-list.xed. + * + * @author shermann (Silvio Hermann) + */ +public class EnrichmentConfigMgr { + static final String DEFAULT_CONFIG_ID = "custom"; + + private EnrichmentConfigMgr() { + } + + /** + * Retrieves the enricher id from the import list form element. + * If the value of the DataSource element is a valid enrichment config id that id is returned. Otherwise, + * it assumed a list of enrichment sources e.g. GBV Unpaywall ... is provided. In that case a new + * configuration with id custom is created and the returned id will be custom. + * + * @param formInput the form input (usually provided by import-list.xed) + * + * @return the enricher id or null + */ + public static String getEnricherId(Element formInput) { + Optional dataSource = formInput.getChildren("DataSources") + .stream() + .filter(element -> !element.getText().isEmpty()) + .findFirst(); + + if (dataSource.isEmpty()) { + return null; + } + + String dataSrcTxt = dataSource.get().getText(); + if (MCRConfiguration2.getString("MCR.MODS.EnrichmentResolver.DataSources." + dataSrcTxt).isPresent()) { + return dataSrcTxt; + } else { + String property = "MCR.MODS.EnrichmentResolver.DataSources." + DEFAULT_CONFIG_ID; + MCRConfiguration2.set(property, dataSrcTxt); + return DEFAULT_CONFIG_ID; + } + } +} diff --git a/ubo-common/src/main/java/org/mycore/ubo/importer/ImportJob.java b/ubo-common/src/main/java/org/mycore/ubo/importer/ImportJob.java index a3f1fdef..327246d9 100644 --- a/ubo-common/src/main/java/org/mycore/ubo/importer/ImportJob.java +++ b/ubo-common/src/main/java/org/mycore/ubo/importer/ImportJob.java @@ -81,6 +81,13 @@ public void transform(MCRContent source) throws IOException, JDOMException, SAXE } } + public void enrich(String configId){ + for (Document publication : publications) { + MCREnricher enricher = new MCREnricher(configId); + enricher.enrich(getContainedMODS(publication)); + } + } + public void enrich() { for (Document publication : publications) { MCREnricher enricher = new MCREnricher(ENRICHER_CONFIG_ID); 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 index 54e23c3c..2379aaaa 100644 --- a/ubo-common/src/main/java/org/mycore/ubo/importer/ImportListJobAction.java +++ b/ubo-common/src/main/java/org/mycore/ubo/importer/ImportListJobAction.java @@ -61,7 +61,12 @@ public void execute() throws ExecutionException { job.setParameter(IMPORT_JOB_ID_PARAMETER, importJob.getID()); if ("true".equals(formInput.getAttributeValue("enrich"))) { - importJob.enrich(); + String enricherId = EnrichmentConfigMgr.getEnricherId(formInput); + if (enricherId != null) { + importJob.enrich(enricherId); + } else { + importJob.enrich(); + } } try { @@ -80,7 +85,7 @@ private void sendMail(ImportJob importJob) { String userName = job.getParameter(ImportListJobAction.USER_ID_PARAMETER); MCRUser mcrUser = MCRUserManager.getUser(userName); - if(mcrUser == null) { + if (mcrUser == null) { LOGGER.error("User {} not found", userName); return; } diff --git a/ubo-common/src/main/resources/META-INF/resources/enrichmentDebugger.xed b/ubo-common/src/main/resources/META-INF/resources/enrichmentDebugger.xed index da2ef9e9..7f30c7b7 100644 --- a/ubo-common/src/main/resources/META-INF/resources/enrichmentDebugger.xed +++ b/ubo-common/src/main/resources/META-INF/resources/enrichmentDebugger.xed @@ -13,7 +13,7 @@
- + 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 2f2b016c..14f55627 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 @@ -55,7 +55,7 @@ -
+
@@ -69,7 +69,7 @@ -
+
@@ -85,7 +85,7 @@
-
+
@@ -100,7 +100,7 @@ -
+
@@ -137,6 +137,26 @@
+
+ + + + + + +
+