Skip to content

Commit

Permalink
Merge pull request #3753 from Kathrin-Huber/use_noWorkflow_on_automat…
Browse files Browse the repository at this point in the history
…ic_processes

respect noWorkflow in automatic generated processes
  • Loading branch information
Kathrin-Huber authored Jun 17, 2020
2 parents 702c69c + 3790c4c commit 4aa79e3
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<String> divisionsWithNoWorkflow = ServiceManager.getRulesetService()
.openRuleset(getMainProcess().getRuleset()).getDivisionsWithNoWorkflow();
if (divisionsWithNoWorkflow.contains(processDataTab.getDocType())) {
this.getMainProcess().getTasks().clear();
}
}

/**
* Save links between child processes and main process.
*
Expand Down Expand Up @@ -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());
}
}
Expand Down Expand Up @@ -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());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -546,14 +547,16 @@ 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);

ProcessGenerator processGenerator = new ProcessGenerator();
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());
Expand All @@ -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<String, IncludedStructuralElement> yearToCreate = yearsIterator.next();
String yearTitle = getYearTitle(yearToCreate.getKey());
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -466,8 +467,8 @@ private static Map<String, String> getMetadataEntries(Collection<Metadata> 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<IndividualIssue> individualIssuesForProcess = processesToCreate.get(index);
Expand Down Expand Up @@ -608,7 +609,8 @@ private String dateMark(String scheme, LocalDate date) {
}

private void prepareTheAppropriateYearProcess(String yearMark, Map<String, String> genericFields)
throws DAOException, DataException, ProcessGenerationException, IOException, CommandException {
throws DAOException, DataException, ProcessGenerationException, IOException, CommandException,
RulesetNotFoundException {

if (yearMark.equals(currentYear)) {
return;
Expand All @@ -620,10 +622,11 @@ private void prepareTheAppropriateYearProcess(String yearMark, Map<String, Strin
}
}

private void saveAndCloseCurrentYearProcess() throws DataException, IOException {
private void saveAndCloseCurrentYearProcess() throws DataException, IOException, RulesetNotFoundException {
final long begin = System.nanoTime();

metsService.saveWorkpiece(yearWorkpiece, yearMetadataFileUri);
ImportService.checkTasks(yearProcess, yearWorkpiece.getRootElement().getType());
processService.save(yearProcess);

this.yearProcess = null;
Expand Down Expand Up @@ -737,11 +740,12 @@ private IncludedStructuralElement getOrCreateIncludedStructuralElement(
return createdChild;
}

private void finish() throws DataException, IOException {
private void finish() throws DataException, IOException, RulesetNotFoundException {
final long begin = System.nanoTime();

saveAndCloseCurrentYearProcess();
metsService.saveWorkpiece(overallWorkpiece, overallMetadataFileUri);
ImportService.checkTasks(overallProcess, overallWorkpiece.getRootElement().getType());
processService.save(overallProcess);

if (logger.isTraceEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ public static void processProcessChildren(Process mainProcess, LinkedList<TempPr
Template template, RulesetManagementInterface managementInterface,
String acquisitionStage, List<Locale.LanguageRange> 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!");
Expand Down Expand Up @@ -1020,16 +1020,33 @@ public static void updateTasks(Process process) {
public static void processTempProcess(TempProcess tempProcess, Template template,
RulesetManagementInterface managementInterface, String acquisitionStage,
List<Locale.LanguageRange> priorityList)
throws InvalidMetadataValueException, NoSuchMetadataFieldException, ProcessGenerationException {
throws InvalidMetadataValueException, NoSuchMetadataFieldException, ProcessGenerationException, IOException,
RulesetNotFoundException {
List<ProcessDetail> 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);
}

/**
* Checks if an imported Process should be created with Tasks and removes them if not,
* depending on the configuration of the doctype.
* @param process the process to check.
* @param docType the doctype to check in the ruleset.
*/
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<String> 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
Expand Down

0 comments on commit 4aa79e3

Please sign in to comment.