Skip to content

Commit

Permalink
Add parameter to control execption handling during EAD collection import
Browse files Browse the repository at this point in the history
  • Loading branch information
solth committed Nov 15, 2024
1 parent 41c5e21 commit 75dd227
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -126,6 +128,7 @@ public void run() {
setAuthenticatedUser();
List<Integer> 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();
Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions Kitodo/src/main/resources/kitodo_config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 75dd227

Please sign in to comment.