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

Preserve workflow SVG if no changes are transmitted #6294

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
19 changes: 11 additions & 8 deletions Kitodo/src/main/java/org/kitodo/production/forms/WorkflowForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -270,16 +270,20 @@ 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();

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);
}

Expand Down Expand Up @@ -328,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);
Expand All @@ -340,9 +345,7 @@ private void saveWorkflow() {
* @return page
*/
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());
return workflowEditPath + "&id=0";
}

/**
Expand Down
Loading