From 9e84387415b9d665f7f8386ab1d279362bd16d31 Mon Sep 17 00:00:00 2001 From: Bruno Date: Mon, 4 Sep 2023 16:29:30 +0200 Subject: [PATCH] feature complete import --- README.md | 1 + .../portal/express/importer/DialogWriter.java | 702 ++++++++++-------- .../portal/express/importer/ExpressEmail.java | 59 ++ .../importer/ExpressTaskDefinition.java | 12 +- .../importer/ExpressWorkflowConverter.java | 2 +- .../express/importer/ProcessWriter.java | 484 ++++++------ .../express/importer/component_template.xhtml | 38 +- .../importer/fileupload_template.xhtml | 11 +- .../express/importer/task_template.xhtml | 4 +- 9 files changed, 727 insertions(+), 586 deletions(-) create mode 100644 express-importer/src/com/axonivy/portal/express/importer/ExpressEmail.java diff --git a/README.md b/README.md index a7d714a..a637a19 100644 --- a/README.md +++ b/README.md @@ -3,5 +3,6 @@ [![CI Build](https://github.com/axonivy-market/express-importer/actions/workflows/ci.yml/badge.svg)](https://github.com/axonivy-market/express-importer/actions/workflows/ci.yml) Imports No-Code Processes from Axon Ivy Express into the Designer for further development. +The result is an up and running Axon Ivy BPMN process with task dialogs and the data objects behind. Read our [documentation](express-importer-product/README.md). diff --git a/express-importer/src/com/axonivy/portal/express/importer/DialogWriter.java b/express-importer/src/com/axonivy/portal/express/importer/DialogWriter.java index 39994e0..51f04ab 100644 --- a/express-importer/src/com/axonivy/portal/express/importer/DialogWriter.java +++ b/express-importer/src/com/axonivy/portal/express/importer/DialogWriter.java @@ -29,324 +29,386 @@ class DialogWriter { - private final IProject project; - - public DialogWriter(IProject project) { - this.project = project; - } - - void createDialogs(List tasks, - List dataFields, String dataclassName, String processName) - throws ResourceDataModelException, Exception - { - for (ExpressTaskDefinition taskdef : tasks) - { - createDialogComponent(taskdef, dataFields); - } - createDialogMaster(tasks,dataclassName, processName); - } - - private void createDialogMaster(List tasks, - String dataclassName, String processName) - throws Exception - { - StringBuffer stepsPanel = new StringBuffer(); - StringBuffer formPanel = new StringBuffer(); - - writeDialogMasterStepPanel(tasks, stepsPanel); - writeDialogMasterFormPanel(tasks, formPanel); - - InputStream is = ExpressWorkflowConverter.class.getResourceAsStream("task_template.xhtml"); - String template = new String(is.readAllBytes()); - template = template.replace("${pagetitle}", processName); - template = template.replace("${stepspanel}", stepsPanel.toString()); - template = template.replace("${formpanel}", formPanel.toString()); - is.close(); - - List inputParameters = Arrays.asList(new VariableDesc("data", dataclassName)); - List outputParameters = Arrays.asList(new VariableDesc("data", dataclassName)); - CallSignature dlgCallSigature = new CallSignature("start", inputParameters, outputParameters); - - List dlgDataFields = Arrays.asList(new VariableDesc("processData", dataclassName), - new VariableDesc("currentStep", "java.lang.Integer"), - new VariableDesc("parallelIndex", "java.lang.Integer")); - List paramMappings = Arrays.asList(new Mapping("out.processData", "param.data"), - new Mapping("out.currentStep", - "ivy.task.customFields().numberField(\"stepindex\").getOrDefault(0)"), - new Mapping("out.parallelIndex", - "ivy.task.customFields().numberField(\"parallelindex\").getOrDefault(0)")); - List resultMappings = Arrays.asList(new Mapping("result.data", "in.processData")); - - var ivyProject =IvyProjectNavigationUtil.getIvyProject(project); - IViewTechnologyDesignerUi viewTech = ViewTechnologyDesignerUiRegistry.getInstance().getViewTechnology(JsfViewTechnologyConfiguration.TECHNOLOGY_IDENTIFIER); - viewTech.getViewLayoutProvider().getViewLayouts(ivyProject).get(0).getViewContent(ExpressWorkflowConverter.NAMESPACE, "frame-10", null); - - DialogCreationParameters params = new DialogCreationParameters.Builder(project, - ExpressWorkflowConverter.NAMESPACE + StringUtil.toJavaIdentifier("TaskDialog")).viewContent(template) - .dataClassFields(dlgDataFields).calleeParamMappings(paramMappings) - .calleeResultMappings(resultMappings) - .signature(dlgCallSigature) - .addCreationParameter(template, resultMappings).toCreationParams(); - IUserDialogManager.instance().getProjectDataModelFor(project) - .createProjectUserDialog(params); - - } - - private void createFileUploadEventHandler(IUserDialog dialog) - { - IProcess process = dialog.getProcess(); - Diagram diagram = process.getModel().getDiagram(); - DiagramShape start = diagram.add().shape(HtmlDialogMethodStart.class).at(96, 260); - DiagramShape end = diagram.add().shape(HtmlDialogEnd.class).at(224, 260); - start.edges().connectTo(end); - HtmlDialogMethodStart startmethod = start.getElement(); - startmethod.setName("handleFileUpload"); - List methodInputParams = Arrays - .asList(new VariableDesc("event", "org.primefaces.event.FileUploadEvent")); - startmethod.setSignature(new CallSignature("handleFileUpload", methodInputParams, Arrays.asList())); - - MappingCode mc = startmethod.getParameterMappings(); - mc = mc.setCode("org.primefaces.model.file.UploadedFile f = param.event.getFile();\n" - + "File ivyFile = new File(f.getFileName(), true);\n" - + "ivyFile.writeBinary(f.getContent());\n" - + "ivy.case.documents().add(ivyFile.getPath()).write().withContentFrom(ivyFile);"); - startmethod.setParameterMappings(mc); - - process.save(); - } - - private void writeDialogMasterFormPanel(List tasks, StringBuffer formPanel) - { - for (int t = 0; t < tasks.size(); t++) - { - ExpressTaskDefinition taskdef = tasks.get(t); - String componentName = StringUtil.toJavaIdentifier(taskdef.getSubject()); - String componentData = "data.processData." + componentName.toLowerCase(); - - formPanel.append( - "\n"); - formPanel.append(""+taskdef.getDescription()+"
\n"); - formPanel.append("\n"); - formPanel.append("
\n"); - - for (int parallelInstance = 1; parallelInstance < taskdef.getResponsibles().size(); parallelInstance++) - { - componentData = "data.processData." + componentName.toLowerCase() + (parallelInstance + 1); - formPanel.append( - "\n"); - formPanel.append(""+taskdef.getDescription()+"
\n"); - formPanel.append("\n"); - formPanel.append("
\n"); - } - } - } - - private void writeDialogMasterStepPanel(List tasks, StringBuffer stepsPanel) - { - for (int stepIndex = 0; stepIndex < tasks.size(); stepIndex++) - { - ExpressTaskDefinition taskdef = tasks.get(stepIndex); - - String stepName = taskdef.getSubject(); - String componentName = StringUtil.toJavaIdentifier(taskdef.getSubject()); - String componentData = "data.processData." + componentName.toLowerCase(); - String responsableName = "Applikant: #{" + componentData + ".wfuser}"; - - stepsPanel.append( - "\n"); - stepsPanel.append(responsableName + "
\n"); - stepsPanel - .append("Form Details:\n"); - stepsPanel.append("
\n"); - - for (int parallelInstance = 1; parallelInstance < taskdef.getResponsibles().size(); parallelInstance++) - { - componentData = "data.processData." + componentName.toLowerCase() + (parallelInstance + 1); - responsableName = "Applikant
Full name: #{" + componentData + ".wfuser}"; - stepsPanel.append( - "\n"); - stepsPanel.append("" + responsableName + "
\n"); - stepsPanel.append( - "Form Details:\n"); - stepsPanel.append("
\n"); - } - } - } - - private void createDialogComponent(ExpressTaskDefinition taskdef, - List dataFields) throws ResourceDataModelException, IOException - { - List formElements = taskdef.getFormElements(); - var form = parseFormElements(formElements); - - var component = new FormComponent(StringUtil.toJavaIdentifier(taskdef.getSubject())); - dataFields.add(new VariableDesc(component.name.toLowerCase(), component.dataClass)); - for (int parallelInstance = 1; parallelInstance < taskdef.getResponsibles().size(); parallelInstance++) - { - var variable = new VariableDesc(component.name.toLowerCase() + (parallelInstance + 1), component.dataClass); - dataFields.add(variable); - } - - var panels = form.panels; - String viewForm = buildTaskForm(taskdef, panels); - - List inputParameters = Arrays.asList(new VariableDesc("data", component.dataClass)); - List outputParameters = Arrays.asList(new VariableDesc("data", component.dataClass)); - CallSignature dlgCallSigature = new CallSignature("start", inputParameters, outputParameters); - - List paramMappings = Arrays.asList(new Mapping("out", "param.data")); - List resultMappings = Arrays.asList(new Mapping("result.data", "in"), - new Mapping("result.data.wfuser", - "in.wfuser.isEmpty() ? ivy.session.getSessionUserName() : in.wfuser")); - - DialogCreationParameters params = new DialogCreationParameters.Builder(project, component.qualifiedName) - .viewContent(viewForm).dataClassFields(form.dialogDataFields).calleeParamMappings(paramMappings) - .calleeResultMappings(resultMappings).signature(dlgCallSigature).toCreationParams(); - IUserDialog dialog = IUserDialogManager.instance().getProjectDataModelFor(project) - .createProjectUserDialog(params); - - if (form.withFileUpload) - { - createFileUploadEventHandler(dialog); - } - } - - private String buildTaskForm(ExpressTaskDefinition taskdef, Panels panels) throws IOException - { - String template = ""; - try (InputStream is = ExpressWorkflowConverter.class - .getResourceAsStream("component_template.xhtml")) - { - template = new String(is.readAllBytes()) - .replace("${headerpanelfields}", panels.header.toString()) - .replace("${leftpanelfields}", panels.left.toString()) - .replace("${rightpanelfields}", panels.right.toString()) - .replace("${footerpanelfields}", panels.footer.toString()) - .replace("${tasktitle}", taskdef.getSubject()) - .replace("${taskdescription}", "" + taskdef.getDescription()); - } - return template; - } - - private FormParseResult parseFormElements(List formElements) throws IOException - { - var result = new FormParseResult(); - result.dialogDataFields.add(new VariableDesc("wfuser", "java.lang.String")); - if (formElements == null) { - return result; - } - for (ExpressFormElement formElement : formElements) - { - String datafield = StringUtil.toJavaIdentifier(formElement.getLabel().replace(":", "")); - - if (formElement.getElementType().equals("ManyCheckbox")) - { - result.dialogDataFields - .add(new VariableDesc(datafield, "ch.ivyteam.ivy.scripting.objects.List")); - } - else - { - result.dialogDataFields.add(new VariableDesc(datafield, "java.lang.String")); - } - result.withFileUpload = result.withFileUpload || formElement.getElementType().equals("FileUpload"); - - switch (formElement.getElementPosition()) - { - case "HEADER": - writeFormElement(result.panels.header, formElement, datafield); - break; - case "LEFTPANEL": - writeFormElement(result.panels.left, formElement, datafield); - break; - case "RIGHTPANEL": - writeFormElement(result.panels.right, formElement, datafield); - break; - case "FOOTER": - writeFormElement(result.panels.footer, formElement, datafield); - } - } - return result; - } - - private void writeFormElement(StringBuffer sb, ExpressFormElement formElement, String datafield) - throws IOException - { - if (sb.length() > 1) - { - sb.append("

"); - } - sb.append("\n"); - - switch (formElement.getElementType()) - { - case "InputFieldText": - sb.append("\n"); - break; - case "InputTextArea": - sb.append("\n"); - break; - case "ManyCheckbox": - sb.append("\n"); - List opts = formElement.getOptionStrs(); - for (String option : opts) - { - sb.append("\n"); - } - sb.append(""); - break; - case "OneRadio": - sb.append("\n"); - List options = formElement.getOptionStrs(); - for (String option : options) - { - sb.append("\n"); - } - sb.append(""); - break; - case "FileUpload": - try(InputStream is = ExpressWorkflowConverter.class.getResourceAsStream("fileupload_template.xhtml")){ - String fileuploadTemplate = new String(is.readAllBytes()) - .replace("${fieldname}", datafield); - sb.append(fileuploadTemplate); - } - } - - } - - private class Panels { - StringBuffer header = new StringBuffer(); - StringBuffer left = new StringBuffer(); - StringBuffer right = new StringBuffer(); - StringBuffer footer = new StringBuffer(); - } - - private class FormParseResult { - List dialogDataFields = new ArrayList(); - boolean withFileUpload = false; - Panels panels = new Panels(); - } - - private class FormComponent { - - private String name; - private String qualifiedName; - private String dataClass; - - FormComponent(String componentName) { - this.name = componentName; - this.qualifiedName = ExpressWorkflowConverter.NAMESPACE + componentName; - this.dataClass = qualifiedName + "." + componentName + "Data"; - } - - } + private final IProject project; + + public DialogWriter(IProject project) { + this.project = project; + } + + void createDialogs(List tasks, List dataFields, String dataclassName, + String processName) throws ResourceDataModelException, Exception { + for (ExpressTaskDefinition taskdef : tasks) { + switch (taskdef.getType()) { + case "USER_TASK": + createUserTaskDialogComponent(taskdef, dataFields); + break; + case "USER_TASK_WITH_EMAIL": + createUserTaskDialogComponent(taskdef, dataFields); + break; + case "APPROVAL": + createApprovalTaskDialogComponent(taskdef, dataFields); + break; + case "EMAIL": + break; + } + } + createDialogMaster(tasks, dataclassName, processName); + } + + private void createDialogMaster(List tasks, String dataclassName, String processName) + throws Exception { + StringBuffer stepsPanel = new StringBuffer(); + StringBuffer formPanel = new StringBuffer(); + + writeDialogMasterStepPanel(tasks, stepsPanel); + writeDialogMasterFormPanel(tasks, formPanel); + + InputStream is = ExpressWorkflowConverter.class.getResourceAsStream("task_template.xhtml"); + String template = new String(is.readAllBytes()); + template = template.replace("${pagetitle}", processName); + template = template.replace("${stepspanel}", stepsPanel.toString()); + template = template.replace("${formpanel}", formPanel.toString()); + is.close(); + + List inputParameters = Arrays.asList(new VariableDesc("data", dataclassName)); + List outputParameters = Arrays.asList(new VariableDesc("data", dataclassName)); + CallSignature dlgCallSigature = new CallSignature("start", inputParameters, outputParameters); + + List dlgDataFields = Arrays.asList(new VariableDesc("processData", dataclassName), + new VariableDesc("currentStep", "java.lang.Integer"), + new VariableDesc("parallelIndex", "java.lang.Integer")); + List paramMappings = Arrays.asList(new Mapping("out.processData", "param.data"), + new Mapping("out.currentStep", "ivy.task.customFields().numberField(\"stepindex\").getOrDefault(0)"), + new Mapping("out.parallelIndex", + "ivy.task.customFields().numberField(\"parallelindex\").getOrDefault(0)")); + List resultMappings = Arrays.asList(new Mapping("result.data", "in.processData")); + + var ivyProject = IvyProjectNavigationUtil.getIvyProject(project); + IViewTechnologyDesignerUi viewTech = ViewTechnologyDesignerUiRegistry.getInstance() + .getViewTechnology(JsfViewTechnologyConfiguration.TECHNOLOGY_IDENTIFIER); + viewTech.getViewLayoutProvider().getViewLayouts(ivyProject).get(0) + .getViewContent(ExpressWorkflowConverter.NAMESPACE, "frame-10-full-width", null); + + DialogCreationParameters params = new DialogCreationParameters.Builder(project, + ExpressWorkflowConverter.NAMESPACE + StringUtil.toJavaIdentifier(processName + "TaskDialog")) + .viewContent(template).dataClassFields(dlgDataFields).calleeParamMappings(paramMappings) + .calleeResultMappings(resultMappings).signature(dlgCallSigature) + .addCreationParameter(template, resultMappings).toCreationParams(); + IUserDialogManager.instance().getProjectDataModelFor(project).createProjectUserDialog(params); + + } + + private void createFileUploadEventHandler(IUserDialog dialog) { + IProcess process = dialog.getProcess(); + Diagram diagram = process.getModel().getDiagram(); + DiagramShape start = diagram.add().shape(HtmlDialogMethodStart.class).at(96, 260); + DiagramShape end = diagram.add().shape(HtmlDialogEnd.class).at(224, 260); + start.edges().connectTo(end); + HtmlDialogMethodStart startmethod = start.getElement(); + startmethod.setName("handleFileUpload"); + List methodInputParams = Arrays + .asList(new VariableDesc("event", "org.primefaces.event.FileUploadEvent")); + startmethod.setSignature(new CallSignature("handleFileUpload", methodInputParams, Arrays.asList())); + + MappingCode mc = startmethod.getParameterMappings(); + mc = mc.setCode("org.primefaces.model.file.UploadedFile f = param.event.getFile();\n" + + "File ivyFile = new File(f.getFileName(), true);\n" + "ivyFile.writeBinary(f.getContent());\n" + + "ivy.case.documents().add(ivyFile.getPath()).write().withContentFrom(ivyFile);"); + startmethod.setParameterMappings(mc); + + start = diagram.add().shape(HtmlDialogMethodStart.class).at(96, 320); + end = diagram.add().shape(HtmlDialogEnd.class).at(224, 320); + start.edges().connectTo(end); + startmethod = start.getElement(); + startmethod.setName("handleFileDelete"); + methodInputParams = Arrays.asList(new VariableDesc("docname", "java.lang.String")); + startmethod.setSignature(new CallSignature("handleFileDelete", methodInputParams, Arrays.asList())); + + mc = startmethod.getParameterMappings(); + mc = mc.setCode("import ch.ivyteam.ivy.workflow.document.Path;\n" + + "ivy.case.documents().delete(new Path(param.docname));"); + startmethod.setParameterMappings(mc); + + process.save(); + } + + private void writeDialogMasterFormPanel(List tasks, StringBuffer formPanel) { + for (int t = 0; t < tasks.size(); t++) { + ExpressTaskDefinition taskdef = tasks.get(t); + String componentName = StringUtil.toJavaIdentifier(taskdef.getSubject()); + String componentData = "data.processData." + componentName.toLowerCase(); + String stepName = taskdef.getSubject(); + + if (!taskdef.getType().equals("EMAIL")) { + formPanel.append( + "\n"); + formPanel.append("" + taskdef.getDescription() + "
\n"); + formPanel.append( + "\n"); + formPanel.append("
\n"); + + for (int parallelInstance = 1; parallelInstance < taskdef.getResponsibles() + .size(); parallelInstance++) { + componentData = "data.processData." + componentName.toLowerCase() + (parallelInstance + 1); + formPanel.append( + "\n"); + formPanel.append("" + taskdef.getDescription() + "
\n"); + formPanel.append( + "\n"); + formPanel.append("
\n"); + } + } + } + } + + private void writeDialogMasterStepPanel(List tasks, StringBuffer stepsPanel) { + for (int stepIndex = 0; stepIndex < tasks.size(); stepIndex++) { + ExpressTaskDefinition taskdef = tasks.get(stepIndex); + + if (!taskdef.getType().equals("EMAIL")) { + String stepName = taskdef.getSubject(); + String componentName = StringUtil.toJavaIdentifier(taskdef.getSubject()); + String componentData = "data.processData." + componentName.toLowerCase(); + String responsableName = "User: #{" + componentData + ".wfuser}"; + String collapseIt = (stepIndex == tasks.size() - 1 ? "false" : "true"); // show last fieldset expanded + + stepsPanel.append( + "\n"); + stepsPanel.append(responsableName + "
\n"); + stepsPanel.append("Form:\n"); + stepsPanel.append("
\n"); + + for (int parallelInstance = 1; parallelInstance < taskdef.getResponsibles() + .size(); parallelInstance++) { + componentData = "data.processData." + componentName.toLowerCase() + (parallelInstance + 1); + responsableName = "User
Full name: #{" + componentData + ".wfuser}"; + stepsPanel.append( + "\n"); + stepsPanel.append("" + responsableName + "
\n"); + stepsPanel.append("Form:\n"); + stepsPanel.append("
\n"); + } + } + } + } + + private void createUserTaskDialogComponent(ExpressTaskDefinition taskdef, List dataFields) + throws ResourceDataModelException, IOException { + List formElements = taskdef.getFormElements(); + var form = parseFormElements(formElements); + + var component = new FormComponent(StringUtil.toJavaIdentifier(taskdef.getSubject())); + dataFields.add(new VariableDesc(component.name.toLowerCase(), component.dataClass)); + for (int parallelInstance = 1; parallelInstance < taskdef.getResponsibles().size(); parallelInstance++) { + var variable = new VariableDesc(component.name.toLowerCase() + (parallelInstance + 1), component.dataClass); + dataFields.add(variable); + } + + var panels = form.panels; + String viewForm = buildTaskForm(taskdef, panels); + + List inputParameters = Arrays.asList(new VariableDesc("data", component.dataClass)); + List outputParameters = Arrays.asList(new VariableDesc("data", component.dataClass)); + CallSignature dlgCallSigature = new CallSignature("start", inputParameters, outputParameters); + + List paramMappings = Arrays.asList(new Mapping("out", "param.data")); + List resultMappings = Arrays.asList(new Mapping("result.data", "in"), new Mapping("result.data.wfuser", + "in.wfuser.isEmpty() ? ivy.session.getSessionUserName() : in.wfuser")); + + DialogCreationParameters params = new DialogCreationParameters.Builder(project, component.qualifiedName) + .viewContent(viewForm).dataClassFields(form.dialogDataFields).calleeParamMappings(paramMappings) + .calleeResultMappings(resultMappings).signature(dlgCallSigature).toCreationParams(); + IUserDialog dialog = IUserDialogManager.instance().getProjectDataModelFor(project) + .createProjectUserDialog(params); + + if (form.withFileUpload) { + createFileUploadEventHandler(dialog); + } + } + + private void createApprovalTaskDialogComponent(ExpressTaskDefinition taskdef, List dataFields) + throws ResourceDataModelException, IOException { + List formElements = new ArrayList(); + ExpressFormElement approvalFormElement = new ExpressFormElement(); + approvalFormElement.setElementID(StringUtil.toJavaIdentifier(taskdef.getResponsibleDisplayName())); + approvalFormElement.setElementPosition("HEADER"); + approvalFormElement.setElementType("InputTextArea"); + approvalFormElement.setIntSetting(0); + approvalFormElement.setName("Comment_of_approver"); + approvalFormElement.setLabel("Comment of approver"); + formElements.add(approvalFormElement); + ExpressFormElement approvalDecisionElement = new ExpressFormElement(); + approvalDecisionElement + .setElementID(StringUtil.toJavaIdentifier("Approval_" + taskdef.getResponsibleDisplayName())); + approvalDecisionElement.setElementPosition("FOOTER"); + approvalDecisionElement.setElementType("OneRadio"); + approvalDecisionElement.setOptionStrs(Arrays.asList("yes", "no")); + approvalDecisionElement.setIntSetting(0); + approvalDecisionElement.setName("Grant_of_approver"); + approvalDecisionElement.setLabel("Grant approval"); + approvalDecisionElement.setRequired(true); + formElements.add(approvalDecisionElement); + var form = parseFormElements(formElements); + + var component = new FormComponent(StringUtil.toJavaIdentifier(taskdef.getSubject())); + dataFields.add(new VariableDesc(component.name.toLowerCase(), component.dataClass)); + for (int parallelInstance = 1; parallelInstance < taskdef.getResponsibles().size(); parallelInstance++) { + var variable = new VariableDesc(component.name.toLowerCase() + (parallelInstance + 1), component.dataClass); + dataFields.add(variable); + } + + var panels = form.panels; + String viewForm = buildTaskForm(taskdef, panels); + + List inputParameters = Arrays.asList(new VariableDesc("data", component.dataClass)); + List outputParameters = Arrays.asList(new VariableDesc("data", component.dataClass)); + CallSignature dlgCallSigature = new CallSignature("start", inputParameters, outputParameters); + + List paramMappings = Arrays.asList(new Mapping("out", "param.data")); + List resultMappings = Arrays.asList(new Mapping("result.data", "in"), new Mapping("result.data.wfuser", + "in.wfuser.isEmpty() ? ivy.session.getSessionUserName() : in.wfuser")); + + DialogCreationParameters params = new DialogCreationParameters.Builder(project, component.qualifiedName) + .viewContent(viewForm).dataClassFields(form.dialogDataFields).calleeParamMappings(paramMappings) + .calleeResultMappings(resultMappings).signature(dlgCallSigature).toCreationParams(); + IUserDialogManager.instance().getProjectDataModelFor(project).createProjectUserDialog(params); + } + + private String buildTaskForm(ExpressTaskDefinition taskdef, Panels panels) throws IOException { + String template = ""; + try (InputStream is = ExpressWorkflowConverter.class.getResourceAsStream("component_template.xhtml")) { + template = new String(is.readAllBytes()).replace("${headerpanelfields}", panels.header.toString()) + .replace("${leftpanelfields}", panels.left.toString()) + .replace("${rightpanelfields}", panels.right.toString()) + .replace("${footerpanelfields}", panels.footer.toString()) + .replace("${tasktitle}", taskdef.getSubject()) + .replace("${taskdescription}", "" + taskdef.getDescription()); + } + return template; + } + + private FormParseResult parseFormElements(List formElements) throws IOException { + var result = new FormParseResult(); + result.dialogDataFields.add(new VariableDesc("wfuser", "java.lang.String")); + if (formElements == null) { + return result; + } + for (ExpressFormElement formElement : formElements) { + String datafield = StringUtil.toJavaIdentifier(formElement.getLabel().replace(":", "")); + + if (formElement.getElementType().equals("ManyCheckbox")) { + result.dialogDataFields + .add(new VariableDesc(datafield, "ch.ivyteam.ivy.scripting.objects.List")); + } else if (formElement.getElementType().equals("InputFieldDate")) { + result.dialogDataFields.add(new VariableDesc(datafield, "ch.ivyteam.ivy.scripting.objects.Date")); + } else { + result.dialogDataFields.add(new VariableDesc(datafield, "java.lang.String")); + } + result.withFileUpload = result.withFileUpload || formElement.getElementType().equals("FileUpload"); + + switch (formElement.getElementPosition()) { + case "HEADER": + writeFormElement(result.panels.header, formElement, datafield); + break; + case "LEFTPANEL": + writeFormElement(result.panels.left, formElement, datafield); + break; + case "RIGHTPANEL": + writeFormElement(result.panels.right, formElement, datafield); + break; + case "FOOTER": + writeFormElement(result.panels.footer, formElement, datafield); + } + } + return result; + } + + private void writeFormElement(StringBuffer sb, ExpressFormElement formElement, String datafield) + throws IOException { + if (sb.length() > 1) { + sb.append("

"); + } + sb.append("\n"); + + switch (formElement.getElementType()) { + case "InputFieldText": + sb.append("\n"); + break; + case "InputFieldNumber": + sb.append("\n"); + break; + case "InputFieldDate": + sb.append("\n \n"); + break; + case "InputTextArea": + sb.append("\n"); + break; + case "ManyCheckbox": + sb.append("\n"); + List opts = formElement.getOptionStrs(); + for (String option : opts) { + sb.append("\n"); + } + sb.append(""); + break; + case "OneRadio": + sb.append("\n"); + List options = formElement.getOptionStrs(); + for (String option : options) { + sb.append("\n"); + } + sb.append(""); + break; + case "FileUpload": + try (InputStream is = ExpressWorkflowConverter.class.getResourceAsStream("fileupload_template.xhtml")) { + String fileuploadTemplate = new String(is.readAllBytes()).replace("${fieldname}", datafield); + sb.append(fileuploadTemplate); + } + } + } + + private class Panels { + StringBuffer header = new StringBuffer(); + StringBuffer left = new StringBuffer(); + StringBuffer right = new StringBuffer(); + StringBuffer footer = new StringBuffer(); + } + + private class FormParseResult { + List dialogDataFields = new ArrayList(); + boolean withFileUpload = false; + Panels panels = new Panels(); + } + + private class FormComponent { + + private String name; + private String qualifiedName; + private String dataClass; + + FormComponent(String componentName) { + this.name = componentName; + this.qualifiedName = ExpressWorkflowConverter.NAMESPACE + componentName; + this.dataClass = qualifiedName + "." + componentName + "Data"; + } + + } } \ No newline at end of file diff --git a/express-importer/src/com/axonivy/portal/express/importer/ExpressEmail.java b/express-importer/src/com/axonivy/portal/express/importer/ExpressEmail.java new file mode 100644 index 0000000..c93a027 --- /dev/null +++ b/express-importer/src/com/axonivy/portal/express/importer/ExpressEmail.java @@ -0,0 +1,59 @@ +package com.axonivy.portal.express.importer; + +import java.io.Serializable; +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.JsonNode; + +@JsonInclude(JsonInclude.Include.NON_NULL) +public class ExpressEmail implements Serializable { + + private static final long serialVersionUID = -4263607320804462685L; + private String recipients; + private String responseTo; + private String subject; + private String content; + private List attachments; + + public String getRecipients() { + return recipients; + } + + public void setRecipients(String recipients) { + this.recipients = recipients; + } + + public String getResponseTo() { + return responseTo; + } + + public void setResponseTo(String responseTo) { + this.responseTo = responseTo; + } + + public String getSubject() { + return subject; + } + + public void setSubject(String subject) { + this.subject = subject; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public List getAttachments() { + return attachments; + } + + public void setAttachments(List attachments) { + this.attachments = attachments; + } + +} \ No newline at end of file diff --git a/express-importer/src/com/axonivy/portal/express/importer/ExpressTaskDefinition.java b/express-importer/src/com/axonivy/portal/express/importer/ExpressTaskDefinition.java index f11b106..5699a17 100644 --- a/express-importer/src/com/axonivy/portal/express/importer/ExpressTaskDefinition.java +++ b/express-importer/src/com/axonivy/portal/express/importer/ExpressTaskDefinition.java @@ -1,10 +1,10 @@ package com.axonivy.portal.express.importer; import java.io.Serializable; +import java.util.ArrayList; import java.util.List; import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.databind.JsonNode; @JsonInclude(JsonInclude.Include.NON_NULL) public class ExpressTaskDefinition implements Serializable { @@ -17,7 +17,7 @@ public class ExpressTaskDefinition implements Serializable { private int taskPosition; private int untilDays; private String responsibleDisplayName; - private JsonNode email; + private ExpressEmail email; private List formElements; public String getType() { @@ -29,7 +29,7 @@ public void setType(String type) { } public List getResponsibles() { - return responsibles; + return responsibles == null ? new ArrayList() : responsibles; } public void setResponsibles(List responsibles) { @@ -45,7 +45,7 @@ public void setSubject(String subject) { } public String getDescription() { - return description; + return description == null ? "" : description; } public void setDescription(String description) { @@ -76,11 +76,11 @@ public void setResponsibleDisplayName(String responsibleDisplayName) { this.responsibleDisplayName = responsibleDisplayName; } - public JsonNode getEmail() { + public ExpressEmail getEmail() { return email; } - public void setEmail(JsonNode email) { + public void setEmail(ExpressEmail email) { this.email = email; } diff --git a/express-importer/src/com/axonivy/portal/express/importer/ExpressWorkflowConverter.java b/express-importer/src/com/axonivy/portal/express/importer/ExpressWorkflowConverter.java index 0228afe..7d28b35 100644 --- a/express-importer/src/com/axonivy/portal/express/importer/ExpressWorkflowConverter.java +++ b/express-importer/src/com/axonivy/portal/express/importer/ExpressWorkflowConverter.java @@ -65,7 +65,7 @@ private void writeProcess(ExpressProcess expressProcess) throws Exception { writer.drawElements( expressProcess.getTaskDefinitions(), diagram, - expressProcess.getProcessName(), + processName, dataclassName, dataFields); process.save(); diff --git a/express-importer/src/com/axonivy/portal/express/importer/ProcessWriter.java b/express-importer/src/com/axonivy/portal/express/importer/ProcessWriter.java index 7863e91..2b48aa5 100644 --- a/express-importer/src/com/axonivy/portal/express/importer/ProcessWriter.java +++ b/express-importer/src/com/axonivy/portal/express/importer/ProcessWriter.java @@ -8,12 +8,19 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.NullProgressMonitor; +import com.fasterxml.jackson.databind.JsonNode; + import ch.ivyteam.ivy.process.model.diagram.Diagram; import ch.ivyteam.ivy.process.model.diagram.shape.DiagramShape; +import ch.ivyteam.ivy.process.model.element.activity.EMail; import ch.ivyteam.ivy.process.model.element.activity.UserTask; import ch.ivyteam.ivy.process.model.element.activity.value.CallSignatureRef; import ch.ivyteam.ivy.process.model.element.activity.value.dialog.UserDialogId; import ch.ivyteam.ivy.process.model.element.activity.value.dialog.UserDialogStart; +import ch.ivyteam.ivy.process.model.element.activity.value.email.Attachments; +import ch.ivyteam.ivy.process.model.element.activity.value.email.Headers; +import ch.ivyteam.ivy.process.model.element.activity.value.email.MailContentType; +import ch.ivyteam.ivy.process.model.element.activity.value.email.Message; import ch.ivyteam.ivy.process.model.element.event.end.TaskEnd; import ch.ivyteam.ivy.process.model.element.event.start.RequestStart; import ch.ivyteam.ivy.process.model.element.event.start.value.CallSignature; @@ -21,6 +28,7 @@ import ch.ivyteam.ivy.process.model.element.gateway.TaskSwitchGateway; import ch.ivyteam.ivy.process.model.element.value.CaseConfig; import ch.ivyteam.ivy.process.model.element.value.IvyScriptExpression; +import ch.ivyteam.ivy.process.model.element.value.MacroExpression; import ch.ivyteam.ivy.process.model.element.value.Mapping; import ch.ivyteam.ivy.process.model.element.value.Mappings; import ch.ivyteam.ivy.process.model.element.value.task.Activator; @@ -37,244 +45,242 @@ class ProcessWriter { - static final int GRID_X = 128; - static final int GRID_Y = 96; - - private final IProject project; - - ProcessWriter(IProject project) { - this.project = project; - } - - void drawElements(List tasks, Diagram execDiagram, String processname, - String dataclassName, List dataFields) - { - int x = GRID_X; - int y = GRID_Y; - - DiagramShape start = execDiagram.add().shape(RequestStart.class).at(x, y); - start.getLabel().setText("start" + processname + ".ivp"); - RequestStart starter = start.getElement(); - makeExecutable(starter, processname, getSteps(tasks)); - - DiagramShape previous = start; - boolean isfirstTask = true; - for (ExpressTaskDefinition taskdef : tasks) - { - x += GRID_X; - - if (taskdef.getResponsibles().size() > 1) - { - DiagramShape split = execDiagram.add().shape(TaskSwitchGateway.class).at(x, y); - split.getLabel().setText("split"); - previous.edges().connectTo(split); // connect - x += GRID_X; - - DiagramShape current = execDiagram.add().shape(UserTask.class).at(x, y - GRID_Y / 2); - createUserTask(taskdef, current, dataclassName, isfirstTask, 0); - isfirstTask = false; - split.edges().connectTo(current); // connect - - x += GRID_X; - DiagramShape join = execDiagram.add().shape(TaskSwitchGateway.class).at(x, y); - join.getLabel().setText("join"); - current.edges().connectTo(join); // connect - - for (int nb = 1; nb < taskdef.getResponsibles().size(); nb++) - { - DiagramShape more = execDiagram.add().shape(UserTask.class).at(x - GRID_X, - y + nb * GRID_Y - GRID_Y / 2); - createUserTask(taskdef, more, dataclassName, isfirstTask, nb); - isfirstTask = false; - - split.edges().connectTo(more); // connect - more.edges().connectTo(join); // connect - - } - createSystemTaskGateway(dataFields, split); - - previous = join; - - } - else - { - DiagramShape current = execDiagram.add().shape(UserTask.class).at(x, y); - createUserTask(taskdef, current, dataclassName, isfirstTask, 0); - isfirstTask = false; - previous.edges().connectTo(current); // connect - if (previous.representsInstanceOf(TaskSwitchGateway.class)) - { - createSystemTaskGateway(dataFields, previous); - } - - previous = current; - } - } - - x += GRID_X; - DiagramShape finalreviewtask = execDiagram.add().shape(UserTask.class).at(x, y); - createFinalReviewTask(finalreviewtask, processname, dataclassName, tasks.size()); - previous.edges().connectTo(finalreviewtask); - if (previous.representsInstanceOf(TaskSwitchGateway.class)) - { - createSystemTaskGateway(dataFields, previous); - } - - x += GRID_X; - DiagramShape end = execDiagram.add().shape(TaskEnd.class).at(x, y); - finalreviewtask.edges().connectTo(end); - } - - private void createSystemTaskGateway(List dataFields, DiagramShape taskGateway) - { - TaskSwitchGateway gateway = taskGateway.getElement(); - TaskConfigs taskConfigs = gateway.getTaskConfigs(); - Set taskIdentifiers = taskConfigs.getTaskIdentifiers(); - for (TaskIdentifier ident : taskIdentifiers) - { - TaskConfig taskConfig = taskConfigs.getTaskConfig(ident); - taskConfig = taskConfig.setName("SYSTEM " + taskGateway.getLabel()); - taskConfig = taskConfig.setActivator(new Activator("SYSTEM", ActivatorType.ROLE)); - taskConfigs = taskConfigs.setTaskConfig(ident, taskConfig); - } - gateway.setTaskConfigs(taskConfigs); - - if (gateway.getIncoming().size() > 1) // join - { - MappingCode mc = gateway.getOutput(); - Mappings ms = mc.getMappings(); - for (VariableDesc dataField : dataFields) - { - String name = dataField.getName(); - String expr = (name.matches(".+[0-9]") ? "in2." + name : "in1." + name); - ms = ms.add(new Mapping("out." + name, expr)); - mc = mc.setMappings(ms); - } - gateway.setOutput(mc); - } - } - - private String getSteps(List tasks) - { - StringBuffer sb = new StringBuffer(); - sb.append("\""); - for (ExpressTaskDefinition task : tasks) - { - sb.append(task.getSubject()); - sb.append(","); - } - sb.append("Final Review"); - sb.append("\""); - return sb.toString(); - } - - private void createUserTask(ExpressTaskDefinition taskdef, DiagramShape current, - String dataclassName, - boolean isfirstTask, int index) - { - - current.getLabel().setText(taskdef.getSubject()); - - UserTask usertask = current.getElement(); - usertask.setName(taskdef.getSubject()); - - TaskConfig taskConfig = usertask.getTaskConfig(); - taskConfig = taskConfig.setName(taskdef.getSubject()); - taskConfig = taskConfig.setDescription(taskdef.getDescription() == null ? "" : taskdef.getDescription()); - - taskConfig = taskConfig.setTaskListSkipped(isfirstTask); - - List responsibles = taskdef.getResponsibles(); - if (index < responsibles.size()) { - Activator activator = new Activator("\"" + responsibles.get(index) + "\"", - ActivatorType.ROLE_FROM_ATTRIBUTE); - taskConfig = taskConfig.setActivator(activator); - } - - List customFields = taskConfig.getCustomFields(); - customFields - .add(new CustomField("stepindex", new IvyScriptExpression("" + (taskdef.getTaskPosition() - 1)), - CustomField.Type.NUMBER)); - customFields - .add(new CustomField("parallelindex", new IvyScriptExpression("" + index), - CustomField.Type.NUMBER)); - - taskConfig = taskConfig.setCustomFields(customFields); - - taskConfig = taskConfig.setExpiryDelay("new Duration(0,0," + taskdef.getUntilDays() + ",0,0,0)"); - - usertask.setTaskConfig(taskConfig); - - createUserTask(usertask, dataclassName); - } - - private void createFinalReviewTask(DiagramShape finalreviewtask, String processname, - String dataclassName, - int index) - { - finalreviewtask.getLabel().setText("Final Review"); - - UserTask usertask = finalreviewtask.getElement(); - usertask.setName("Final Review"); - usertask.setDescription("Exported AxonIvyExpress Workflow " + processname); - - TaskConfig taskConfig = usertask.getTaskConfig(); - taskConfig = taskConfig.setName(processname + ": Final Review"); - taskConfig.setDescription("The workflow " + processname + " has been finsihed"); - taskConfig = taskConfig.setActivator(new Activator("CREATOR", ActivatorType.ROLE)); - - List customFields = taskConfig.getCustomFields(); - customFields - .add(new CustomField("stepindex", new IvyScriptExpression("" + index), CustomField.Type.NUMBER)); - taskConfig = taskConfig.setCustomFields(customFields); - usertask.setTaskConfig(taskConfig); - - createUserTask(usertask, dataclassName); - - } - - private void createUserTask(UserTask usertask, String dataclassName) { - CallSignatureRef signature = new CallSignatureRef("start", List.of(new QualifiedType(dataclassName))); - UserDialogStart userDialogStart = usertask.getTargetDialog() - .setId(UserDialogId.create(ExpressWorkflowConverter.NAMESPACE + StringUtil.toJavaIdentifier("TaskDialog"))) - .setStartMethod(signature); - usertask.setTargetDialog(userDialogStart); - usertask.setParameters(MappingCode.mapOnly("param.data", "in")); - usertask.setOutput(MappingCode.mapOnly("out", "result.data")); - } - - private void makeExecutable(RequestStart starter, String processname, String steps) - { - starter.setSignature(new CallSignature("start_" + processname)); - starter.setDescription(processname); - starter.setRequest(starter.getRequest().isHttpRequestable(true).name(processname)); - StartAccessPermissions permissions = new StartAccessPermissions("Everybody"); - starter.setRequiredPermissions(permissions); - - CaseConfig caseConfig = starter.getCaseConfig(); - caseConfig = caseConfig.setName(processname); - List customFields = caseConfig.getCustomFields(); - customFields.add(new CustomField("steps", new IvyScriptExpression(steps), CustomField.Type.STRING)); - customFields.add( - new CustomField("embedInFrame", new IvyScriptExpression("\"True\""), CustomField.Type.STRING)); - caseConfig = caseConfig.setCustomFields(customFields); - starter.setCaseConfig(caseConfig); - } - - void refreshTree() - { - try - { - if (EngineMode.isEmbeddedInDesigner()) - { - project.getProject().build(IResource.PROJECT, new NullProgressMonitor()); - project.getFolder("processes").refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); - } - } - catch (CoreException e) - { - e.printStackTrace(); - } - } + static final int GRID_X = 128; + static final int GRID_Y = 96; + + private final IProject project; + + ProcessWriter(IProject project) { + this.project = project; + } + + void drawElements(List tasks, Diagram execDiagram, String processName, String dataclassName, + List dataFields) { + int x = GRID_X; + int y = GRID_Y; + + DiagramShape start = execDiagram.add().shape(RequestStart.class).at(x, y); + start.getLabel().setText(processName); + RequestStart starter = start.getElement(); + makeExecutable(starter, processName, getSteps(tasks)); + + DiagramShape previous = start; + boolean isfirstTask = true; + for (ExpressTaskDefinition taskdef : tasks) { + x += GRID_X; + + if (taskdef.getResponsibles().size() > 1) { + DiagramShape split = execDiagram.add().shape(TaskSwitchGateway.class).at(x, y); + split.getLabel().setText("split"); + previous.edges().connectTo(split); // connect + x += GRID_X; + + DiagramShape current = execDiagram.add().shape(UserTask.class).at(x, y - GRID_Y / 2); + createUserTask(taskdef, current, dataclassName, processName, isfirstTask, 0); + isfirstTask = false; + split.edges().connectTo(current); // connect + + x += GRID_X; + DiagramShape join = execDiagram.add().shape(TaskSwitchGateway.class).at(x, y); + join.getLabel().setText("join"); + current.edges().connectTo(join); // connect + + for (int nb = 1; nb < taskdef.getResponsibles().size(); nb++) { + DiagramShape more = execDiagram.add().shape(UserTask.class).at(x - GRID_X, + y + nb * GRID_Y - GRID_Y / 2); + createUserTask(taskdef, more, dataclassName, processName, isfirstTask, nb); + isfirstTask = false; + + split.edges().connectTo(more); // connect + more.edges().connectTo(join); // connect + + } + createSystemTaskGateway(dataFields, split); + + previous = join; + + } else { + DiagramShape current; + if (taskdef.getType().equals("EMAIL")) { + current = execDiagram.add().shape(EMail.class).at(x, y); + createEmailTask(taskdef, current); + } else { + current = execDiagram.add().shape(UserTask.class).at(x, y); + createUserTask(taskdef, current, dataclassName, processName, isfirstTask, 0); + } + isfirstTask = false; + previous.edges().connectTo(current); // connect + if (previous.representsInstanceOf(TaskSwitchGateway.class)) { + createSystemTaskGateway(dataFields, previous); + } + + previous = current; + } + } + + x += GRID_X; + DiagramShape finalreviewtask = execDiagram.add().shape(UserTask.class).at(x, y); + createFinalReviewTask(finalreviewtask, dataclassName, processName, tasks.size()); + previous.edges().connectTo(finalreviewtask); + if (previous.representsInstanceOf(TaskSwitchGateway.class)) { + createSystemTaskGateway(dataFields, previous); + } + + x += GRID_X; + DiagramShape end = execDiagram.add().shape(TaskEnd.class).at(x, y); + finalreviewtask.edges().connectTo(end); + } + + private void createSystemTaskGateway(List dataFields, DiagramShape taskGateway) { + TaskSwitchGateway gateway = taskGateway.getElement(); + TaskConfigs taskConfigs = gateway.getTaskConfigs(); + Set taskIdentifiers = taskConfigs.getTaskIdentifiers(); + for (TaskIdentifier ident : taskIdentifiers) { + TaskConfig taskConfig = taskConfigs.getTaskConfig(ident); + taskConfig = taskConfig.setName("SYSTEM " + taskGateway.getLabel()); + taskConfig = taskConfig.setActivator(new Activator("SYSTEM", ActivatorType.ROLE)); + taskConfigs = taskConfigs.setTaskConfig(ident, taskConfig); + } + gateway.setTaskConfigs(taskConfigs); + + if (gateway.getIncoming().size() > 1) // join + { + MappingCode mc = gateway.getOutput(); + Mappings ms = mc.getMappings(); + for (VariableDesc dataField : dataFields) { + String name = dataField.getName(); + String expr = (name.matches(".+[0-9]") ? "in2." + name : "in1." + name); + ms = ms.add(new Mapping("out." + name, expr)); + mc = mc.setMappings(ms); + } + gateway.setOutput(mc); + } + } + + private String getSteps(List tasks) { + StringBuffer sb = new StringBuffer(); + sb.append("\""); + for (ExpressTaskDefinition task : tasks) { + sb.append(task.getSubject()); + sb.append(","); + } + sb.append("Final Review"); + sb.append("\""); + return sb.toString(); + } + + private void createUserTask(ExpressTaskDefinition taskdef, DiagramShape current, String dataclassName, + String processName, boolean isfirstTask, int index) { + + current.getLabel().setText(taskdef.getSubject()); + + UserTask usertask = current.getElement(); + usertask.setName(taskdef.getSubject()); + + TaskConfig taskConfig = usertask.getTaskConfig(); + taskConfig = taskConfig.setName(taskdef.getSubject()); + taskConfig = taskConfig.setDescription(taskdef.getDescription() == null ? "" : taskdef.getDescription()); + + taskConfig = taskConfig.setTaskListSkipped(isfirstTask); + + List responsibles = taskdef.getResponsibles(); + if (index < responsibles.size()) { + Activator activator = new Activator("\"" + responsibles.get(index) + "\"", + ActivatorType.ROLE_FROM_ATTRIBUTE); + taskConfig = taskConfig.setActivator(activator); + } + + List customFields = taskConfig.getCustomFields(); + customFields.add(new CustomField("stepindex", new IvyScriptExpression("" + (taskdef.getTaskPosition() - 1)), + CustomField.Type.NUMBER)); + customFields + .add(new CustomField("parallelindex", new IvyScriptExpression("" + index), CustomField.Type.NUMBER)); + + taskConfig = taskConfig.setCustomFields(customFields); + + taskConfig = taskConfig.setExpiryDelay("new Duration(0,0," + taskdef.getUntilDays() + ",0,0,0)"); + + usertask.setTaskConfig(taskConfig); + + createUserTask(usertask, dataclassName, processName); + } + + private void createFinalReviewTask(DiagramShape finalreviewtask, String dataclassName, String processName, + int index) { + finalreviewtask.getLabel().setText("Final Review"); + + UserTask usertask = finalreviewtask.getElement(); + usertask.setName("Final Review"); + usertask.setDescription("Final " + processName); + + TaskConfig taskConfig = usertask.getTaskConfig(); + taskConfig = taskConfig.setName(processName + ": Final Review"); + taskConfig = taskConfig.setDescription("The workflow " + processName + " has been finsihed"); + taskConfig = taskConfig.setActivator(new Activator("CREATOR", ActivatorType.ROLE)); + + List customFields = taskConfig.getCustomFields(); + customFields.add(new CustomField("stepindex", new IvyScriptExpression("" + index), CustomField.Type.NUMBER)); + taskConfig = taskConfig.setCustomFields(customFields); + usertask.setTaskConfig(taskConfig); + + createUserTask(usertask, dataclassName, processName); + + } + + private void createUserTask(UserTask usertask, String dataclassName, String processName) { + CallSignatureRef signature = new CallSignatureRef("start", List.of(new QualifiedType(dataclassName))); + UserDialogStart userDialogStart = usertask.getTargetDialog() + .setId(UserDialogId.create( + ExpressWorkflowConverter.NAMESPACE + StringUtil.toJavaIdentifier(processName + "TaskDialog"))) + .setStartMethod(signature); + usertask.setTargetDialog(userDialogStart); + usertask.setParameters(MappingCode.mapOnly("param.data", "in")); + usertask.setOutput(MappingCode.mapOnly("out", "result.data")); + } + + private void createEmailTask(ExpressTaskDefinition taskdef, DiagramShape current) { + current.getLabel().setText("Information E-mail"); + + EMail mailstep = current.getElement(); + mailstep.setName("Information E-mail"); + Headers headers = new Headers().setSubject(new MacroExpression(taskdef.getEmail().getSubject())) + .setTo(new MacroExpression(taskdef.getEmail().getRecipients())) + .setReplyTo(new MacroExpression(taskdef.getEmail().getResponseTo())); + mailstep.setHeaders(headers); + Message message = new Message(new MacroExpression(taskdef.getEmail().getContent()), MailContentType.HTML); + mailstep.setMessage(message); + Attachments attachments = new Attachments(); + for (JsonNode attachment : taskdef.getEmail().getAttachments()) { + attachments = attachments.add((new IvyScriptExpression(attachment.get("name").toString()))); + } + mailstep.setAttachments(attachments); + } + + private void makeExecutable(RequestStart starter, String processname, String steps) { + starter.setSignature(new CallSignature("start_" + processname)); + starter.setDescription(processname); + starter.setRequest(starter.getRequest().isHttpRequestable(true).name(processname)); + StartAccessPermissions permissions = new StartAccessPermissions("Everybody"); + starter.setRequiredPermissions(permissions); + + CaseConfig caseConfig = starter.getCaseConfig(); + caseConfig = caseConfig.setName(processname); + List customFields = caseConfig.getCustomFields(); + customFields.add(new CustomField("steps", new IvyScriptExpression(steps), CustomField.Type.STRING)); + customFields.add(new CustomField("embedInFrame", new IvyScriptExpression("\"True\""), CustomField.Type.STRING)); + caseConfig = caseConfig.setCustomFields(customFields); + starter.setCaseConfig(caseConfig); + } + + void refreshTree() { + try { + if (EngineMode.isEmbeddedInDesigner()) { + project.getProject().build(IResource.PROJECT, new NullProgressMonitor()); + project.getFolder("processes").refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); + } + } catch (CoreException e) { + e.printStackTrace(); + } + } } \ No newline at end of file diff --git a/express-importer/src/com/axonivy/portal/express/importer/component_template.xhtml b/express-importer/src/com/axonivy/portal/express/importer/component_template.xhtml index d8870d7..10ed880 100644 --- a/express-importer/src/com/axonivy/portal/express/importer/component_template.xhtml +++ b/express-importer/src/com/axonivy/portal/express/importer/component_template.xhtml @@ -7,7 +7,7 @@ xmlns:p="http://primefaces.org/ui" xmlns:pe="http://primefaces.org/ui/extensions"> - + - + + ${headerpanelfields} - - - ${leftpanelfields} - - - ${rightpanelfields} - - - - + + + ${leftpanelfields} + + + ${rightpanelfields} + + + + ${footerpanelfields} diff --git a/express-importer/src/com/axonivy/portal/express/importer/fileupload_template.xhtml b/express-importer/src/com/axonivy/portal/express/importer/fileupload_template.xhtml index 4d53a49..6f20c4e 100644 --- a/express-importer/src/com/axonivy/portal/express/importer/fileupload_template.xhtml +++ b/express-importer/src/com/axonivy/portal/express/importer/fileupload_template.xhtml @@ -7,13 +7,16 @@ - - + + +
\ No newline at end of file + label="Upload new file" listener="#{logic.handleFileUpload}" + rendered="#{cc.attrs.readonly eq 'false'}" /> \ No newline at end of file diff --git a/express-importer/src/com/axonivy/portal/express/importer/task_template.xhtml b/express-importer/src/com/axonivy/portal/express/importer/task_template.xhtml index 3d9e6a6..dbaed17 100644 --- a/express-importer/src/com/axonivy/portal/express/importer/task_template.xhtml +++ b/express-importer/src/com/axonivy/portal/express/importer/task_template.xhtml @@ -6,7 +6,7 @@ xmlns:p="http://primefaces.org/ui" xmlns:pe="http://primefaces.org/ui/extensions"> - + ${pagetitle}