From 5b9687fe37c7b8b1bdff62073607160d8944721a Mon Sep 17 00:00:00 2001 From: BartChris Date: Tue, 5 Nov 2024 18:51:51 +0100 Subject: [PATCH 1/4] Preserve workflow SVG if no changes are transmitted --- .../java/org/kitodo/production/forms/WorkflowForm.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/WorkflowForm.java b/Kitodo/src/main/java/org/kitodo/production/forms/WorkflowForm.java index 3fdb5ea6c6f..3db15a087bd 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/WorkflowForm.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/WorkflowForm.java @@ -270,8 +270,10 @@ private boolean saveFiles() throws IOException, WorkflowException { xmlDiagram = requestParameterMap.get("editForm:workflowTabView:xmlDiagram"); if (Objects.nonNull(xmlDiagram)) { - svgDiagram = StringUtils.substringAfter(xmlDiagram, "kitodo-diagram-separator"); - xmlDiagram = StringUtils.substringBefore(xmlDiagram, "kitodo-diagram-separator"); + if (xmlDiagram.contains("kitodo-diagram-separator")) { + svgDiagram = StringUtils.substringAfter(xmlDiagram, "kitodo-diagram-separator"); + xmlDiagram = StringUtils.substringBefore(xmlDiagram, "kitodo-diagram-separator"); + } Reader reader = new Reader(new ByteArrayInputStream(xmlDiagram.getBytes(StandardCharsets.UTF_8))); reader.validateWorkflowTasks(); @@ -279,7 +281,9 @@ private boolean saveFiles() throws IOException, WorkflowException { Converter converter = new Converter(new ByteArrayInputStream(xmlDiagram.getBytes(StandardCharsets.UTF_8))); converter.validateWorkflowTaskList(); - saveFile(svgDiagramURI, svgDiagram); + if (Objects.nonNull(svgDiagram)) { + saveFile(svgDiagramURI, svgDiagram); + } saveFile(xmlDiagramURI, xmlDiagram); } From 9d5a7f5ab979ddde9692d6eafb379cfeca438345 Mon Sep 17 00:00:00 2001 From: BartChris Date: Wed, 6 Nov 2024 11:02:10 +0100 Subject: [PATCH 2/4] change to Viewscpoed --- .../main/java/org/kitodo/production/forms/WorkflowForm.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/WorkflowForm.java b/Kitodo/src/main/java/org/kitodo/production/forms/WorkflowForm.java index 3db15a087bd..ba3cf3c1e09 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/WorkflowForm.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/WorkflowForm.java @@ -29,9 +29,9 @@ import java.util.Map; import java.util.Objects; -import javax.enterprise.context.SessionScoped; import javax.faces.context.FacesContext; import javax.faces.model.SelectItem; +import javax.faces.view.ViewScoped; import javax.inject.Named; import org.apache.commons.io.IOUtils; @@ -59,7 +59,7 @@ import org.kitodo.production.workflow.model.Reader; @Named("WorkflowForm") -@SessionScoped +@ViewScoped public class WorkflowForm extends BaseForm { private static final Logger logger = LogManager.getLogger(WorkflowForm.class); From 99ba6d5d7a192ce4828d9096e44ed4e0e2a63c4f Mon Sep 17 00:00:00 2001 From: BartChris Date: Wed, 6 Nov 2024 11:55:12 +0100 Subject: [PATCH 3/4] add client before saving --- .../src/main/java/org/kitodo/production/forms/WorkflowForm.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/WorkflowForm.java b/Kitodo/src/main/java/org/kitodo/production/forms/WorkflowForm.java index ba3cf3c1e09..81e35dd5e87 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/WorkflowForm.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/WorkflowForm.java @@ -332,6 +332,7 @@ private String encodeXMLDiagramName(String xmlDiagramName) { private void saveWorkflow() { try { + this.workflow.setClient(ServiceManager.getUserService().getSessionClientOfAuthenticatedUser()); ServiceManager.getWorkflowService().save(this.workflow, true); } catch (DataException e) { Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); @@ -345,7 +346,6 @@ private void saveWorkflow() { */ public String newWorkflow() { this.workflow = new Workflow(); - this.workflow.setClient(ServiceManager.getUserService().getSessionClientOfAuthenticatedUser()); return workflowEditPath + "&id=" + (Objects.isNull(this.workflow.getId()) ? 0 : this.workflow.getId()); } From b879e50be0c5b1675cbf211bf4363db5bbc7a894 Mon Sep 17 00:00:00 2001 From: BartChris Date: Wed, 6 Nov 2024 13:09:44 +0100 Subject: [PATCH 4/4] Remove unnecessary instantiation of new Workflow --- .../main/java/org/kitodo/production/forms/WorkflowForm.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/WorkflowForm.java b/Kitodo/src/main/java/org/kitodo/production/forms/WorkflowForm.java index 81e35dd5e87..302e16e36ff 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/WorkflowForm.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/WorkflowForm.java @@ -345,8 +345,7 @@ private void saveWorkflow() { * @return page */ public String newWorkflow() { - this.workflow = new Workflow(); - return workflowEditPath + "&id=" + (Objects.isNull(this.workflow.getId()) ? 0 : this.workflow.getId()); + return workflowEditPath + "&id=0"; } /**