From 4a889def798d2a1bac660fd2540b0a3bd9e264c0 Mon Sep 17 00:00:00 2001 From: Silvio Hermann Date: Tue, 3 Dec 2024 13:26:01 +0100 Subject: [PATCH] UBO-378 Load existing configs via uri resolver --- .../ubo/importer/DozBibImportServlet.java | 5 +- .../ubo/importer/EnrichmentConfigMgr.java | 61 ++++++------------- .../ubo/importer/ImportListJobAction.java | 5 +- .../META-INF/resources/import-list.xed | 13 +--- .../main/resources/xsl/enrichers2options.xsl | 19 ++++++ 5 files changed, 41 insertions(+), 62 deletions(-) create mode 100644 ubo-common/src/main/resources/xsl/enrichers2options.xsl 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 e1d5bc46..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,9 +74,8 @@ private void handleImportJob(HttpServletRequest req, HttpServletResponse res) th boolean enrich = "true".equals(formInput.getAttributeValue("enrich")); if (enrich) { - String dataSources = EnrichmentConfigMgr.instance().getDataSource(formInput); - if (dataSources != null) { - String enricherId = EnrichmentConfigMgr.instance().getOrCreateEnrichmentConfig(dataSources); + String enricherId = EnrichmentConfigMgr.getEnricherId(formInput); + if (enricherId != null) { importJob.enrich(enricherId); } else { importJob.enrich(); 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 index 51fcad84..b4ee2187 100644 --- a/ubo-common/src/main/java/org/mycore/ubo/importer/EnrichmentConfigMgr.java +++ b/ubo-common/src/main/java/org/mycore/ubo/importer/EnrichmentConfigMgr.java @@ -3,69 +3,42 @@ import org.jdom2.Element; import org.mycore.common.config.MCRConfiguration2; -import java.nio.charset.StandardCharsets; -import java.util.HashMap; import java.util.Optional; -import java.util.UUID; /** - * Class handles dynamically created enrichment resolver configurations. + * Class handles retrieves the enricher id from the form input of import-list.xed. * * @author shermann (Silvio Hermann) */ public class EnrichmentConfigMgr { - - private final HashMap dynamicEnrichmentConfigIds = new HashMap<>(); - - private static EnrichmentConfigMgr INSTANCE; + static final String DEFAULT_CONFIG_ID = "import-list-custom"; private EnrichmentConfigMgr() { } /** - * Creates and returns a singleton instance of this class. - * - * @return the instance - */ - public static EnrichmentConfigMgr instance() { - if (INSTANCE != null) { - return INSTANCE; - } - INSTANCE = new EnrichmentConfigMgr(); - return INSTANCE; - } - - /** - * Creates and registers an enrichment configuration id. - * - * @param dataSources the data source - * - * @return the enrichment configuration id for the given data source - * */ - public String getOrCreateEnrichmentConfig(String dataSources) { - if (dynamicEnrichmentConfigIds.containsKey(dataSources)) { - return dynamicEnrichmentConfigIds.get(dataSources); - } - - String id = UUID.nameUUIDFromBytes(dataSources.getBytes(StandardCharsets.UTF_8)).toString(); - String property = "MCR.MODS.EnrichmentResolver.DataSources." + id; - MCRConfiguration2.set(property, dataSources); - dynamicEnrichmentConfigIds.put(dataSources, id); - return id; - } - - /** - * Retrieves the first DataSource text content from the import list form element. + * Retrieves the enricher id from the import list form element. * * @param formInput the form input (usually provided by import-list.xed) * - * @return the first DataSource text or null + * @return the enricher id (maybe of type custom) text or null */ - public String getDataSource(Element formInput) { + public static String getEnricherId(Element formInput) { Optional dataSource = formInput.getChildren("DataSources") .stream() .filter(element -> !element.getText().isEmpty()) .findFirst(); - return dataSource.isPresent() ? dataSource.get().getText() : null; + + String enricherId = dataSource.isPresent() ? dataSource.get().getText() : null; + if (enricherId != null) { + if (MCRConfiguration2.getString("MCR.MODS.EnrichmentResolver.DataSources." + enricherId).isPresent()) { + return enricherId; + } else { + String property = "MCR.MODS.EnrichmentResolver.DataSources." + DEFAULT_CONFIG_ID; + MCRConfiguration2.set(property, dataSource.get().getText()); + return DEFAULT_CONFIG_ID; + } + } + return null; } } 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 154718c7..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,9 +61,8 @@ public void execute() throws ExecutionException { job.setParameter(IMPORT_JOB_ID_PARAMETER, importJob.getID()); if ("true".equals(formInput.getAttributeValue("enrich"))) { - String dataSources = EnrichmentConfigMgr.instance().getDataSource(formInput); - if (dataSources != null) { - String enricherId = EnrichmentConfigMgr.instance().getOrCreateEnrichmentConfig(dataSources); + String enricherId = EnrichmentConfigMgr.getEnricherId(formInput); + if (enricherId != null) { importJob.enrich(enricherId); } else { importJob.enrich(); 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 d81481c4..7cc5194f 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 @@ -147,18 +147,7 @@ - - - - + diff --git a/ubo-common/src/main/resources/xsl/enrichers2options.xsl b/ubo-common/src/main/resources/xsl/enrichers2options.xsl new file mode 100644 index 00000000..f4cd37d0 --- /dev/null +++ b/ubo-common/src/main/resources/xsl/enrichers2options.xsl @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + +