Write data to workflow template 77/15377/2
authorLvbo163 <lv.bo163@zte.com.cn>
Tue, 26 Sep 2017 07:03:13 +0000 (15:03 +0800)
committerLvbo163 <lv.bo163@zte.com.cn>
Tue, 26 Sep 2017 07:16:28 +0000 (15:16 +0800)
Issue-ID: SDC-398

Change-Id: Ia5cec2af1f9f2018b42933d48628a42fbefb29b5
Signed-off-by: Lvbo163 <lv.bo163@zte.com.cn>
sdc-workflow-designer-server/pom.xml
sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/writer/BpmnPlanArtefactWriter.java [new file with mode: 0644]
sdc-workflow-designer-server/src/main/resources/bpmn-templates/bpmn_template.xml [new file with mode: 0644]

index d28ff81..3ba7f3b 100644 (file)
@@ -28,6 +28,7 @@
     <properties>
         <slf4j.version>1.7.25</slf4j.version>
         <jackson.version>2.9.1</jackson.version>
+        <velocity.version>1.6.2</velocity.version>
     </properties>
     <dependencies>
         <dependency>
             <artifactId>jackson-databind</artifactId>
             <version>${jackson.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.velocity</groupId>
+            <artifactId>velocity</artifactId>
+            <version>${velocity.version}</version>
+        </dependency>
     </dependencies>
 </project>
diff --git a/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/writer/BpmnPlanArtefactWriter.java b/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/writer/BpmnPlanArtefactWriter.java
new file mode 100644 (file)
index 0000000..c39b0bb
--- /dev/null
@@ -0,0 +1,64 @@
+/**\r
+ * Copyright (c) 2017 ZTE Corporation.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * and the Apache License 2.0 which both accompany this distribution,\r
+ * and are available at http://www.eclipse.org/legal/epl-v10.html\r
+ * and http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Contributors:\r
+ *     ZTE - initial API and implementation and/or initial documentation\r
+ */\r
+package org.onap.sdc.workflowdesigner.writer;\r
+\r
+import java.io.StringWriter;\r
+\r
+import org.apache.velocity.Template;\r
+import org.apache.velocity.VelocityContext;\r
+import org.apache.velocity.app.Velocity;\r
+import org.apache.velocity.app.VelocityEngine;\r
+import org.apache.velocity.exception.ParseErrorException;\r
+import org.apache.velocity.exception.ResourceNotFoundException;\r
+import org.onap.sdc.workflowdesigner.config.Config;\r
+import org.onap.sdc.workflowdesigner.model.Process;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+\r
+public class BpmnPlanArtefactWriter {\r
+\r
+    private Process process;\r
+\r
+    public static String TEMPLATE_PATH = Config.PROPERTIES.getProperty(Config.TEMPLATE_PATH);\r
+\r
+    private static Logger log = LoggerFactory.getLogger(BpmnPlanArtefactWriter.class);\r
+\r
+    public BpmnPlanArtefactWriter(Process process) throws Exception {\r
+        this.process = process;\r
+        Velocity.init();\r
+    }\r
+\r
+    public String completePlanTemplate() throws ResourceNotFoundException, ParseErrorException, Exception {\r
+        log.debug("Completing BPMN process template...");\r
+\r
+        VelocityContext context = new VelocityContext();\r
+\r
+        VelocityEngine ve = new VelocityEngine();\r
+        ve.setProperty("resource.loader", "class");\r
+        ve.setProperty("class.resource.loader.class",\r
+                "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");\r
+        Template planTemplate = ve.getTemplate(TEMPLATE_PATH + "bpmn_template.xml");\r
+\r
+        context.put("process", process);\r
+        context.put("templatePath", TEMPLATE_PATH);\r
+        StringWriter planWriter = new StringWriter();\r
+        planTemplate.merge(context, planWriter);\r
+\r
+        String bpmnProcessContent = planWriter.toString();\r
+\r
+        log.debug("Completed BPMN process template" + bpmnProcessContent);\r
+\r
+        return bpmnProcessContent;\r
+\r
+    }\r
+\r
+}\r
diff --git a/sdc-workflow-designer-server/src/main/resources/bpmn-templates/bpmn_template.xml b/sdc-workflow-designer-server/src/main/resources/bpmn-templates/bpmn_template.xml
new file mode 100644 (file)
index 0000000..7783ece
--- /dev/null
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"\r
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
+    xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"\r
+    xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI"\r
+    typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath"\r
+    targetNamespace="http://www.activiti.org/test">\r
+    <process id="${process.id}" isExecutable="true">\r
+\r
+    </process>\r
+</definitions>\r
+\r