From 26124057654707e17bcf6d861ac13390651720a8 Mon Sep 17 00:00:00 2001 From: Arved Solth Date: Fri, 15 Nov 2024 12:38:38 +0100 Subject: [PATCH] Add parameter to control execption handling during EAD collection import --- .../java/org/kitodo/config/enums/ParameterCore.java | 8 +++++++- .../production/thread/ImportEadProcessesThread.java | 12 +++++++++++- Kitodo/src/main/resources/kitodo_config.properties | 7 +++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Kitodo/src/main/java/org/kitodo/config/enums/ParameterCore.java b/Kitodo/src/main/java/org/kitodo/config/enums/ParameterCore.java index bfd38c605bb..6ddd98b8d52 100644 --- a/Kitodo/src/main/java/org/kitodo/config/enums/ParameterCore.java +++ b/Kitodo/src/main/java/org/kitodo/config/enums/ParameterCore.java @@ -665,7 +665,13 @@ public enum ParameterCore implements ParameterInterface { * Optional parameter controlling how many processes are to be displayed and processed in the metadata import mask. * When more data records are imported the import process is moved to a background task. Default value is 5. */ - MAX_NUMBER_OF_PROCESSES_FOR_IMPORT_MASK(new Parameter<>("maxNumberOfProcessesForImportMask", 5)); + MAX_NUMBER_OF_PROCESSES_FOR_IMPORT_MASK(new Parameter<>("maxNumberOfProcessesForImportMask", 5)), + + /* + * Optional parameter controlling whether the import of all elements from an uploaded EAD XML file should be + * canceled when an exception occurs or not. Defaults to 'false'. + */ + STOP_EAD_COLLECTION_IMPORT_ON_EXCEPTION(new Parameter<>("stopEadCollectionImportOnException", false)); private final Parameter parameter; diff --git a/Kitodo/src/main/java/org/kitodo/production/thread/ImportEadProcessesThread.java b/Kitodo/src/main/java/org/kitodo/production/thread/ImportEadProcessesThread.java index 465e113752f..a9cd0c309f5 100644 --- a/Kitodo/src/main/java/org/kitodo/production/thread/ImportEadProcessesThread.java +++ b/Kitodo/src/main/java/org/kitodo/production/thread/ImportEadProcessesThread.java @@ -45,6 +45,8 @@ import org.kitodo.api.MetadataEntry; import org.kitodo.api.dataeditor.rulesetmanagement.FunctionalMetadata; import org.kitodo.api.dataeditor.rulesetmanagement.RulesetManagementInterface; +import org.kitodo.config.ConfigCore; +import org.kitodo.config.enums.ParameterCore; import org.kitodo.constants.StringConstants; import org.kitodo.data.database.beans.Client; import org.kitodo.data.database.beans.ImportConfiguration; @@ -126,6 +128,7 @@ public void run() { setAuthenticatedUser(); List newProcessIds = new ArrayList<>(); int newParentId = 0; + boolean stopOnError = ConfigCore.getBooleanParameter(ParameterCore.STOP_EAD_COLLECTION_IMPORT_ON_EXCEPTION); try { int numberOfElements = XMLUtils.getNumberOfEADElements(xmlString, eadLevel); XMLInputFactory inputFactory = XMLInputFactory.newInstance(); @@ -197,7 +200,14 @@ public void run() { inProcessElement = false; String content = event.toString(); stringBuilder.append(removeDefaultNamespaceUri(content)); - newProcessIds.add(parseXmlStringToProcessedTempProcess(stringBuilder.toString()).getProcess().getId()); + try { + newProcessIds.add(parseXmlStringToProcessedTempProcess(stringBuilder.toString()).getProcess().getId()); + } catch (Exception e) { + logger.error(e.getMessage(), e); + if (stopOnError) { + throw new ProcessGenerationException("Unable to create process. Cause: " + e.getMessage()); + } + } stringBuilder = new StringBuilder(); } else { if (inParentProcessElement || inProcessElement) { diff --git a/Kitodo/src/main/resources/kitodo_config.properties b/Kitodo/src/main/resources/kitodo_config.properties index b776b50e21c..7046d14c150 100644 --- a/Kitodo/src/main/resources/kitodo_config.properties +++ b/Kitodo/src/main/resources/kitodo_config.properties @@ -796,3 +796,10 @@ security.secret.ldapManagerPassword= # informing the user that the processes will be imported using a background task and the progress can be tracked via the # task manager. maxNumberOfProcessesForImportMask=5 + +# The parameter 'stopEadCollectionImportOnException' can be used to control how Kitodo should handle potential +# exceptions occurring during the import of EAD collections. When set to 'true', the import of an upload EAD XML file +# will be canceled and all new processes created from the uploaded file up to this point are removed. If set to 'false', +# the import will skip the current EAD element that caused the exception and continue with the next element. +# Defaults to 'false'. +stopEadCollectionImportOnException=false