From 2ee59be5b4acc76207105dd7d559d764404e7ce5 Mon Sep 17 00:00:00 2001 From: Kathrin Huber Date: Wed, 10 Jun 2020 14:06:31 +0200 Subject: [PATCH] respect noWorkflow in automatic generated processes --- .../forms/createprocess/CreateProcessForm.java | 17 ++++++----------- .../migration/NewspaperProcessesMigrator.java | 9 +++++++-- .../process/NewspaperProcessesGenerator.java | 14 +++++++++----- .../production/services/data/ImportService.java | 15 +++++++++++++-- 4 files changed, 35 insertions(+), 20 deletions(-) diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/CreateProcessForm.java b/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/CreateProcessForm.java index 936f7143042..6f4468572a9 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/CreateProcessForm.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/CreateProcessForm.java @@ -364,7 +364,7 @@ private void createProcessHierarchy() && !this.titleRecordLinkTab.getSelectedInsertionPosition().isEmpty()) { this.processes = new LinkedList<>(Collections.singletonList(this.processes.get(0))); } - checkTasks(); + ImportService.checkTasks(this.getMainProcess(), processDataTab.getDocType()); processAncestors(); processChildren(); // main process and it's ancestors need to be saved so they have IDs before creating their process directories @@ -406,15 +406,6 @@ private void createProcessHierarchy() ServiceManager.getProcessService().save(getMainProcess()); } - private void checkTasks() throws IOException, RulesetNotFoundException { - // remove tasks from process, if doctype is configured not to use a workflow - Collection divisionsWithNoWorkflow = ServiceManager.getRulesetService() - .openRuleset(getMainProcess().getRuleset()).getDivisionsWithNoWorkflow(); - if (divisionsWithNoWorkflow.contains(processDataTab.getDocType())) { - this.getMainProcess().getTasks().clear(); - } - } - /** * Save links between child processes and main process. * @@ -448,7 +439,7 @@ private void processChildren() { ImportService.processProcessChildren(getMainProcess(), this.childProcesses, template, rulesetManagementInterface, acquisitionStage, priorityList); } catch (DataException | InvalidMetadataValueException | NoSuchMetadataFieldException - | ProcessGenerationException e) { + | ProcessGenerationException | IOException | RulesetNotFoundException e) { Helper.setErrorMessage("Unable to attach child documents to process: " + e.getMessage()); } } @@ -479,6 +470,10 @@ private void processAncestors() throws ProcessGenerationException { acquisitionStage, priorityList); } catch (InvalidMetadataValueException | NoSuchMetadataFieldException e) { throw new ProcessGenerationException("Error creating process hierarchy: invalid metadata found!"); + } catch (IOException e) { + throw new ProcessGenerationException("Error reading Ruleset: " + tempProcess.getProcess().getRuleset().getTitle()); + } catch (RulesetNotFoundException e) { + throw new ProcessGenerationException("Ruleset not found:" + tempProcess.getProcess().getRuleset().getTitle()); } } } diff --git a/Kitodo/src/main/java/org/kitodo/production/migration/NewspaperProcessesMigrator.java b/Kitodo/src/main/java/org/kitodo/production/migration/NewspaperProcessesMigrator.java index 1b7ae542c9a..e920ce0648f 100644 --- a/Kitodo/src/main/java/org/kitodo/production/migration/NewspaperProcessesMigrator.java +++ b/Kitodo/src/main/java/org/kitodo/production/migration/NewspaperProcessesMigrator.java @@ -54,6 +54,7 @@ import org.kitodo.production.process.ProcessGenerator; import org.kitodo.production.services.ServiceManager; import org.kitodo.production.services.data.BatchService; +import org.kitodo.production.services.data.ImportService; import org.kitodo.production.services.data.ProcessService; import org.kitodo.production.services.dataeditor.DataEditorService; import org.kitodo.production.services.dataformat.MetsService; @@ -546,7 +547,8 @@ private static String getCompletedDate(IncludedStructuralElement includedStructu * @throws IOException * An error has occurred in the disk drive. */ - public void createOverallProcess() throws ProcessGenerationException, IOException, DataException, DAOException, CommandException { + public void createOverallProcess() throws ProcessGenerationException, IOException, DataException, DAOException, + CommandException, RulesetNotFoundException { final long begin = System.nanoTime(); logger.info("Creating overall process {}...", title); @@ -554,6 +556,7 @@ public void createOverallProcess() throws ProcessGenerationException, IOExceptio processGenerator.generateProcess(templateId, projectId); overallProcess = processGenerator.getGeneratedProcess(); overallProcess.setTitle(getTitle()); + ImportService.checkTasks(overallProcess, overallWorkpiece.getRootElement().getType()); processService.save(overallProcess); ServiceManager.getFileService().createProcessLocation(overallProcess); overallWorkpiece.setId(overallProcess.getId().toString()); @@ -579,7 +582,8 @@ public void createOverallProcess() throws ProcessGenerationException, IOExceptio * @throws DAOException * if a process cannot be load from the database */ - public void createNextYearProcess() throws ProcessGenerationException, IOException, DataException, DAOException, CommandException { + public void createNextYearProcess() throws ProcessGenerationException, IOException, DataException, DAOException, + CommandException, RulesetNotFoundException { final long begin = System.nanoTime(); Entry yearToCreate = yearsIterator.next(); String yearTitle = getYearTitle(yearToCreate.getKey()); @@ -588,6 +592,7 @@ public void createNextYearProcess() throws ProcessGenerationException, IOExcepti processGenerator.generateProcess(templateId, projectId); Process yearProcess = processGenerator.getGeneratedProcess(); yearProcess.setTitle(yearTitle); + ImportService.checkTasks(yearProcess, yearToCreate.getValue().getType()); processService.save(yearProcess); MetadataEditor.addLink(overallWorkpiece.getRootElement(), yearProcess.getId()); diff --git a/Kitodo/src/main/java/org/kitodo/production/process/NewspaperProcessesGenerator.java b/Kitodo/src/main/java/org/kitodo/production/process/NewspaperProcessesGenerator.java index 27edcbfbd1d..debe61b3253 100644 --- a/Kitodo/src/main/java/org/kitodo/production/process/NewspaperProcessesGenerator.java +++ b/Kitodo/src/main/java/org/kitodo/production/process/NewspaperProcessesGenerator.java @@ -61,6 +61,7 @@ import org.kitodo.production.model.bibliography.course.IndividualIssue; import org.kitodo.production.process.field.AdditionalField; import org.kitodo.production.services.ServiceManager; +import org.kitodo.production.services.data.ImportService; import org.kitodo.production.services.data.ProcessService; import org.kitodo.production.services.data.RulesetService; import org.kitodo.production.services.dataformat.MetsService; @@ -466,8 +467,8 @@ private static Map getMetadataEntries(Collection metad return metadataEntries; } - private void createProcess(int index) - throws DAOException, DataException, IOException, ProcessGenerationException, CommandException { + private void createProcess(int index) throws DAOException, DataException, IOException, ProcessGenerationException, + CommandException, RulesetNotFoundException { final long begin = System.nanoTime(); List individualIssuesForProcess = processesToCreate.get(index); @@ -608,7 +609,8 @@ private String dateMark(String scheme, LocalDate date) { } private void prepareTheAppropriateYearProcess(String yearMark, Map genericFields) - throws DAOException, DataException, ProcessGenerationException, IOException, CommandException { + throws DAOException, DataException, ProcessGenerationException, IOException, CommandException, + RulesetNotFoundException { if (yearMark.equals(currentYear)) { return; @@ -620,10 +622,11 @@ private void prepareTheAppropriateYearProcess(String yearMark, Map priorityList) throws DataException, InvalidMetadataValueException, NoSuchMetadataFieldException, - ProcessGenerationException { + ProcessGenerationException, IOException, RulesetNotFoundException { for (TempProcess tempProcess : childProcesses) { if (Objects.isNull(tempProcess) || Objects.isNull(tempProcess.getProcess())) { logger.error("Child process " + (childProcesses.indexOf(tempProcess) + 1) + " is null => Skip!"); @@ -1020,16 +1020,27 @@ public static void updateTasks(Process process) { public static void processTempProcess(TempProcess tempProcess, Template template, RulesetManagementInterface managementInterface, String acquisitionStage, List priorityList) - throws InvalidMetadataValueException, NoSuchMetadataFieldException, ProcessGenerationException { + throws InvalidMetadataValueException, NoSuchMetadataFieldException, ProcessGenerationException, IOException, + RulesetNotFoundException { List processDetails = transformToProcessDetails(tempProcess, managementInterface, acquisitionStage, priorityList); String docType = tempProcess.getWorkpiece().getRootElement().getType(); createProcessTitle(tempProcess, managementInterface, acquisitionStage, priorityList, processDetails); Process process = tempProcess.getProcess(); addProperties(tempProcess.getProcess(), template, processDetails, docType, tempProcess.getProcess().getTitle()); + checkTasks(process, docType); updateTasks(process); } + public static void checkTasks(Process process, String docType) throws IOException, RulesetNotFoundException { + // remove tasks from process, if doctype is configured not to use a workflow + Collection divisionsWithNoWorkflow = ServiceManager.getRulesetService() + .openRuleset(process.getRuleset()).getDivisionsWithNoWorkflow(); + if (divisionsWithNoWorkflow.contains(docType)) { + process.getTasks().clear(); + } + } + /** * Imports a process and saves it to database. * @param ppn the ppn to import