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 workflow creation on migration #3811

Merged
merged 4 commits into from
Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -303,14 +303,15 @@ public String createNewWorkflow() {
TasksToWorkflowConverter templateConverter = new TasksToWorkflowConverter();
List<Task> processTasks = blueprintProcess.getTasks();
processTasks.sort(Comparator.comparingInt(Task::getOrdering));
String workflowTitle = "ChangeME_" + Helper.generateRandomString(3);

try {
templateConverter.convertTasksToWorkflowFile("ChangeME", processTasks);
templateConverter.convertTasksToWorkflowFile(workflowTitle, processTasks);
} catch (IOException e) {
Helper.setErrorMessage(e.getLocalizedMessage(), logger, e);
}

workflowToUse = new Workflow("ChangeME");
workflowToUse = new Workflow(workflowTitle);
workflowToUse.setClient(blueprintProcess.getProject().getClient());
workflowToUse.setStatus(WorkflowStatus.DRAFT);
workflowToUse.getTemplates().add(null);
Expand All @@ -337,6 +338,7 @@ public void setRedirectFromWorkflow(Integer workflowId) {
if (Objects.nonNull(workflowId) && workflowId != 0) {
// showPopup for Template
try {
workflowToUse = ServiceManager.getWorkflowService().getById(workflowId);
createTemplates();
} catch (DAOException e) {
Helper.setErrorMessage(ERROR_READING, new Object[] {ObjectType.TEMPLATE.getTranslationSingular() },
Expand Down
19 changes: 19 additions & 0 deletions Kitodo/src/main/java/org/kitodo/production/forms/WorkflowForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,25 @@ public String saveAndRedirect() {
}
}

/**
* Cancel Workflow creation.
* @return redirectPath
*/
public String cancel() {
if (migration) {
try {
ServiceManager.getWorkflowService().remove(workflow);
} catch (DataException e) {
Helper.setErrorMessage(ERROR_DELETING, new Object[] {this.workflow.getTitle(), e.getMessage() }, logger,
e);
return this.stayOnCurrentPage;
}
return MIGRATION_FORM_PATH;
}

return "projects?keepPagination=true";
}

private boolean hasMultipleSructureTreeConfiguration() throws WorkflowException, IOException {
Map<String, String> requestParameterMap = FacesContext.getCurrentInstance().getExternalContext()
.getRequestParameterMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,22 @@ private String createWorkflow(String title, List<Task> tasks) {
}

private void convertTasksToXmlWorkflow(StringBuilder diagram, List<Task> tasks) {
for (Task task : tasks) {
if (task.getOrdering().equals(1)) {
diagram.append(XmlGenerator.generateTask(task, "StartEvent_1", "Task_" + task.getOrdering()));
for (int i = 0; i < tasks.size(); i++) {
int diagramOrder = i + 1;
if (i == 0) {
diagram.append(
XmlGenerator.generateTask(tasks.get(i), "StartEvent_1", diagramOrder));
} else {
diagram.append(XmlGenerator.generateTask(task));
diagram.append(XmlGenerator.generateTask(tasks.get(i), diagramOrder));
}
}
}

private void convertTasksToWorkflowCoordinates(StringBuilder diagram, List<Task> tasks) {
int diagramStart = 498;

for (Task task : tasks) {
diagram.append(XmlGenerator.generateTaskShape(task.getOrdering(), diagramStart));
for (int i = 1; i <= tasks.size(); i++) {
diagram.append(XmlGenerator.generateTaskShape(i, diagramStart));
diagramStart = diagramStart + BOX_DISTANCE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.apache.commons.lang3.StringUtils;
import org.kitodo.data.database.beans.Role;
import org.kitodo.data.database.beans.Task;
import org.kitodo.data.database.enums.TaskStatus;

class XmlGenerator {

Expand All @@ -35,8 +36,8 @@ private XmlGenerator() {
* for generating
* @return generated task
*/
static String generateTask(Task task) {
return generateTask(task, "Task_" + (task.getOrdering() - 1), "Task_" + task.getOrdering());
static String generateTask(Task task, int order) {
return generateTask(task, "Task_" + (order - 1), order);
}

/**
Expand All @@ -46,25 +47,23 @@ static String generateTask(Task task) {
* for generating
* @param sourceReference
* for sequence flow
* @param targetReference
* for sequence flow
* @return generated task
*/
static String generateTask(Task task, String sourceReference, String targetReference) {
static String generateTask(Task task, String sourceReference, int ordering) {
StringBuilder taskBuilder = new StringBuilder();

openTask(taskBuilder, task);

taskBuilder.append("id=\"Task_");
taskBuilder.append(task.getOrdering());
taskBuilder.append(ordering);
taskBuilder.append(QUOTES);

taskBuilder.append("name=\"");
taskBuilder.append(task.getTitle());
taskBuilder.append(QUOTES);

generateTemplateTaskProperty(taskBuilder, "editType", task.getEditType().getValue());
generateTemplateTaskProperty(taskBuilder, "processingStatus", task.getProcessingStatus().getValue());
generateTemplateTaskProperty(taskBuilder, "processingStatus",
task.getProcessingStatus().equals(TaskStatus.DONE) ? TaskStatus.DONE.getValue()
: TaskStatus.LOCKED.getValue());
generateTemplateTaskProperty(taskBuilder, "concurrent", task.isConcurrent());
generateTemplateTaskProperty(taskBuilder, "typeMetadata", task.isTypeMetadata());
generateTemplateTaskProperty(taskBuilder, "separateStructure", task.isSeparateStructure());
Expand All @@ -86,17 +85,15 @@ static String generateTask(Task task, String sourceReference, String targetRefer
taskBuilder.deleteCharAt(taskBuilder.length() - 1);
taskBuilder.append(QUOTES);
}

if (StringUtils.isNotBlank(task.getScriptName()) || StringUtils.isNotBlank(task.getScriptPath())) {
generateTemplateTaskProperty(taskBuilder, "scriptName", task.getScriptName());
generateTemplateTaskProperty(taskBuilder, "scriptPath", task.getScriptPath());
}

taskBuilder.append(">\n");

generateSequences(taskBuilder, task.getOrdering());
generateSequences(taskBuilder, ordering);
closeTask(taskBuilder, task);
generateSequenceFlow(taskBuilder, task.getOrdering(), sourceReference, targetReference);
generateSequenceFlow(taskBuilder, ordering, sourceReference);

return taskBuilder.toString();
}
Expand Down Expand Up @@ -149,14 +146,13 @@ private static void generateSequences(StringBuilder taskBuilder, Integer orderin
taskBuilder.append("</bpmn2:outgoing>\n");
}

private static void generateSequenceFlow(StringBuilder taskBuilder, Integer ordering, String sourceReference,
String targetReference) {
private static void generateSequenceFlow(StringBuilder taskBuilder, Integer ordering, String sourceReference) {
taskBuilder.append(" <bpmn2:sequenceFlow id=\"SequenceFlow_");
taskBuilder.append(ordering);
taskBuilder.append("\" sourceRef=\"");
taskBuilder.append(sourceReference);
taskBuilder.append("\" targetRef=\"");
taskBuilder.append(targetReference);
taskBuilder.append("Task_");
taskBuilder.append(SLASH_END_LINE);
}

Expand Down
5 changes: 2 additions & 3 deletions Kitodo/src/main/webapp/pages/workflowEdit.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@
actionListener="#{WorkflowForm.setSaveDisabled(false)}"
update="save"
style="display:none;"/>
<p:button value="#{isViewMode ? msgs.close : msgs.cancel}"
onclick="setConfirmUnload(false);"
outcome="projects?keepPagination=true"
<p:commandButton value="#{isViewMode ? msgs.close : msgs.cancel}"
action="#{WorkflowForm.cancel()}"
icon="fa fa-times fa-lg"
iconPos="right"
styleClass="#{isViewMode ? 'primary' : 'secondary'}"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static void cleanDatabase() throws Exception {
public void shouldGenerateTaskWithoutSourceTarget() {
Task task = template.getTasks().stream().filter(x -> x.getOrdering().equals(2)).findAny().orElse(null);

String taskString = XmlGenerator.generateTask(task);
String taskString = XmlGenerator.generateTask(task, task.getOrdering());
String expected = " <bpmn2:scriptTask id=\"Task_2\" name=\"Blocking\" template:editType=\"1\" "
+ "template:processingStatus=\"3\" template:concurrent=\"false\" template:typeMetadata=\"false\" "
+ "template:separateStructure=\"false\" template:typeAutomatic=\"false\" template:typeExportDMS=\"false\" "
Expand All @@ -63,7 +63,7 @@ public void shouldGenerateTaskWithoutSourceTarget() {
public void shouldGenerateTaskWithSourceTarget() {
Task task = template.getTasks().stream().filter(x -> x.getOrdering().equals(1)).findAny().orElse(null);

String taskString = XmlGenerator.generateTask(task, "StartEvent_1", "Task_1");
String taskString = XmlGenerator.generateTask(task, "StartEvent_1", task.getOrdering());
String expected = " <bpmn2:task id=\"Task_1\" name=\"Finished\" template:editType=\"3\" "
+ "template:processingStatus=\"3\" template:concurrent=\"false\" template:typeMetadata=\"false\" "
+ "template:separateStructure=\"false\" template:typeAutomatic=\"false\" template:typeExportDMS=\"false\" "
Expand Down
3 changes: 2 additions & 1 deletion Kitodo/src/test/java/org/kitodo/selenium/MigrationST.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.net.URI;
Expand Down Expand Up @@ -63,7 +64,7 @@ public void testMigration() throws Exception {
assertEquals("Finished, Closed, Progress, Open, Locked", systemPage.getAggregatedTasks(2));
WorkflowEditPage workflowEditPage = systemPage.createNewWorkflow();
workflowEditPage.changeWorkflowStatusToActive();
assertEquals("ChangeME", workflowEditPage.getWorkflowTitle());
assertTrue(workflowEditPage.getWorkflowTitle().contains("ChangeME"));
workflowEditPage.changeWorkflowTitle("migrationWorkflow");
systemPage = workflowEditPage.saveForMigration();
String newTemplateTitle = "newTemplate";
Expand Down