Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix serial migration #4356

Merged
merged 13 commits into from
Apr 23, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ private void createProcessHierarchy()
&& !this.titleRecordLinkTab.getSelectedInsertionPosition().isEmpty()) {
this.processes = new LinkedList<>(Collections.singletonList(this.processes.get(0)));
}
ImportService.checkTasks(this.getMainProcess(), processDataTab.getDocType());
ProcessService.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
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.kitodo.api.Metadata;
import org.kitodo.api.MetadataEntry;
import org.kitodo.api.dataformat.IncludedStructuralElement;
import org.kitodo.api.dataformat.Workpiece;
Expand Down Expand Up @@ -165,7 +166,7 @@ public void run() {
* @param process
* process to migrate
*/
private void migrate(Process process) throws IOException, ProcessGenerationException, DataException, DAOException, CommandException {
void migrate(Process process) throws IOException, ProcessGenerationException, DataException, DAOException, CommandException {
logger.info("Starting to convert process {} (ID {})...", process.getTitle(), process.getId());
long begin = System.nanoTime();
migrateMetadataFiles(process);
Expand Down Expand Up @@ -227,13 +228,16 @@ private static Optional<String> getParentRecordId(Process process) throws IOExce
* current number of the child process
*/
private List<Integer> createParentProcess(Process childProcess)
throws ProcessGenerationException, IOException, DataException, CommandException {
throws ProcessGenerationException, IOException, DataException, CommandException, DAOException {

processGenerator.generateProcess(childProcess.getTemplate().getId(), childProcess.getProject().getId());
Process parentProcess = processGenerator.getGeneratedProcess();
processService.save(parentProcess);
fileService.createProcessLocation(parentProcess);
createParentMetsFile(childProcess);
checkTaskAndId(parentProcess);
processService.save(parentProcess);
parentProcess = ServiceManager.getProcessService().getById(parentProcess.getId());
ArrayList<Integer> parentData = new ArrayList<>();
parentData.add(parentProcess.getId());
URI metadataFilePath = fileService.getMetadataFilePath(childProcess);
Expand All @@ -242,6 +246,33 @@ private List<Integer> createParentProcess(Process childProcess)
return parentData;
}

private void checkTaskAndId(Process parentProcess) throws IOException {
URI parentMetadataFilePath = fileService.getMetadataFilePath(parentProcess, true, true);
Workpiece workpiece = ServiceManager.getMetsService().loadWorkpiece(parentMetadataFilePath);
ProcessService.checkTasks(parentProcess, workpiece.getRootElement().getType());
Collection<Metadata> metadata = workpiece.getRootElement().getMetadata();
String shortedTitle = "";
String catalogIdentifier = "";
for (Metadata metadatum : metadata) {
if (metadatum.getKey().equals("TSL_ATS")) {
shortedTitle = ((MetadataEntry) metadatum).getValue();
}
if (metadatum.getKey().equals("CatalogIDDigital")) {
catalogIdentifier = ((MetadataEntry) metadatum).getValue();
}
}
String title = "";
if (!shortedTitle.isEmpty()) {
title += shortedTitle + '_';
}
if (!catalogIdentifier.isEmpty()) {
title += catalogIdentifier;
}
parentProcess.setTitle(title);
workpiece.setId(parentProcess.getId().toString());
ServiceManager.getMetsService().saveWorkpiece(workpiece,parentMetadataFilePath);
}

/**
* Links parent process and child process in the database. The processes are
* saved.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,13 @@
import org.kitodo.data.exceptions.DataException;
import org.kitodo.exceptions.CommandException;
import org.kitodo.exceptions.ProcessGenerationException;
import org.kitodo.production.dto.BatchDTO;
import org.kitodo.production.dto.ProcessDTO;
import org.kitodo.production.helper.tasks.NewspaperMigrationTask;
import org.kitodo.production.helper.tasks.TaskManager;
import org.kitodo.production.metadata.MetadataEditor;
import org.kitodo.production.process.NewspaperProcessesGenerator;
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 @@ -550,7 +547,7 @@ public void createOverallProcess() throws ProcessGenerationException, IOExceptio
processGenerator.generateProcess(templateId, projectId);
overallProcess = processGenerator.getGeneratedProcess();
overallProcess.setTitle(getTitle());
ImportService.checkTasks(overallProcess, overallWorkpiece.getRootElement().getType());
ProcessService.checkTasks(overallProcess, overallWorkpiece.getRootElement().getType());
processService.saveToDatabase(overallProcess);
ServiceManager.getFileService().createProcessLocation(overallProcess);
overallWorkpiece.setId(overallProcess.getId().toString());
Expand Down Expand Up @@ -586,7 +583,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.checkTasks(yearProcess, yearToCreate.getValue().getType());
processService.saveToDatabase(yearProcess);

MetadataEditor.addLink(overallWorkpiece.getRootElement(), yearProcess.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
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 @@ -657,7 +656,7 @@ private void saveAndCloseCurrentYearProcess() throws DataException, IOException
final long begin = System.nanoTime();

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

this.yearProcess = null;
Expand Down Expand Up @@ -723,7 +722,7 @@ private void createNewYearProcess(String yearMark, Map<String, String> genericFi

String title = makeTitle(yearTitleDefinition.orElse("+'_'+#YEAR"), genericFields);
getGeneratedProcess().setTitle(title);
ImportService.checkTasks(getGeneratedProcess(), yearType);
ProcessService.checkTasks(getGeneratedProcess(), yearType);
processService.save(getGeneratedProcess());
processService.refresh(getGeneratedProcess());

Expand Down Expand Up @@ -788,7 +787,7 @@ private void finish() throws DataException, IOException {
overallProcess.getTitle());
}
metsService.saveWorkpiece(overallWorkpiece, overallMetadataFileUri);
ImportService.checkTasks(overallProcess, overallWorkpiece.getRootElement().getType());
ProcessService.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 @@ -1119,25 +1119,10 @@ public static void processTempProcess(TempProcess tempProcess, Template template
createProcessTitle(tempProcess, managementInterface, acquisitionStage, priorityList, processDetails);
Process process = tempProcess.getProcess();
addProperties(tempProcess.getProcess(), template, processDetails, docType, tempProcess.getProcess().getTitle());
checkTasks(process, docType);
ProcessService.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 {
// 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
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,21 @@ public static void emptyCache() {
RULESET_CACHE_FOR_CREATE_FROM_CALENDAR.clear();
}

/**
* 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 {
// 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();
}
}

@Override
public Long countDatabaseRows() throws DAOException {
return countDatabaseRows("SELECT COUNT(*) FROM Process");
Expand Down
Loading