aboutsummaryrefslogtreecommitdiffstats
path: root/sdc-workflow-designer-server
diff options
context:
space:
mode:
authorYuanHu <yuan.hu1@zte.com.cn>2018-03-21 11:02:54 +0800
committerYuanHu <yuan.hu1@zte.com.cn>2018-03-21 11:19:21 +0800
commitde5748dc931aea9ee258ad0704731723a17e1421 (patch)
treeb2729f18ae87ff761e8b083ba7619affc4fb3567 /sdc-workflow-designer-server
parentdf9dc4750a33987dbb0b1609fda6ec310c55b07b (diff)
Insert Json to BPMN.
Insert Json to BPMN. Issue-ID: SDC-1004 Change-Id: Iaa72cb5c44b1846bcfc2124c371f0a8433cd7ce1 Signed-off-by: YuanHu <yuan.hu1@zte.com.cn>
Diffstat (limited to 'sdc-workflow-designer-server')
-rw-r--r--sdc-workflow-designer-server/pom.xml9
-rw-r--r--sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/resources/WorkflowModelerResource.java41
2 files changed, 46 insertions, 4 deletions
diff --git a/sdc-workflow-designer-server/pom.xml b/sdc-workflow-designer-server/pom.xml
index b47f8453..0871c5a9 100644
--- a/sdc-workflow-designer-server/pom.xml
+++ b/sdc-workflow-designer-server/pom.xml
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<!--
- Copyright (c) 2017 ZTE Corporation.
+ Copyright (c) 2017-2018 ZTE Corporation.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
and the Apache License 2.0 which both accompany this distribution,
@@ -35,6 +35,7 @@
<swagger.version>1.5.18</swagger.version>
<jersey.version>2.16</jersey.version>
<commons-io.version>2.4</commons-io.version>
+ <dom4j.version>1.6.1</dom4j.version>
</properties>
<build>
@@ -190,6 +191,12 @@
<artifactId>junit</artifactId>
<version>${junit.version}</version>
</dependency>
+
+ <dependency>
+ <groupId>dom4j</groupId>
+ <artifactId>dom4j</artifactId>
+ <version>${dom4j.version}</version>
+ </dependency>
</dependencies>
</project>
diff --git a/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/resources/WorkflowModelerResource.java b/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/resources/WorkflowModelerResource.java
index f6f1699a..4899f7c8 100644
--- a/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/resources/WorkflowModelerResource.java
+++ b/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/resources/WorkflowModelerResource.java
@@ -15,6 +15,7 @@ package org.onap.sdc.workflowdesigner.resources;
import java.io.IOException;
import java.net.URI;
import java.nio.file.Paths;
+import java.util.List;
import java.util.UUID;
import javax.ws.rs.Consumes;
@@ -26,6 +27,10 @@ import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
+import org.dom4j.Comment;
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.DocumentHelper;
import org.eclipse.jetty.http.HttpStatus;
import org.onap.sdc.workflowdesigner.common.WorkflowDesignerException;
import org.onap.sdc.workflowdesigner.externalservice.sdc.SDCServiceProxy;
@@ -111,9 +116,10 @@ public class WorkflowModelerResource {
URI srcUri = Paths.get(".", WORKFLOW_JSON_TEMP_FILE_NAME).toUri();
String processName = "plan_" + UUID.randomUUID().toString();
String bpmn = buildBPMN(srcUri, processName);
+ String jsonBpmn = insertJson2Bpmn(json, bpmn);
- save2SDC(json, bpmn);
- FileCommonUtils.write(WORKFLOW_XML_TEMP_FILE_NAME, bpmn);
+ save2SDC(json, jsonBpmn);
+ FileCommonUtils.write(WORKFLOW_XML_TEMP_FILE_NAME, jsonBpmn);
return Response.status(Response.Status.OK).entity(json).build();
} catch (IOException e) {
@@ -124,7 +130,36 @@ public class WorkflowModelerResource {
throw RestUtils.newInternalServerErrorException(e);
}
}
+
+ /**
+ * @param json
+ * @param bpmn
+ * @return
+ */
+ protected String insertJson2Bpmn(String json, String bpmn) {
+ StringBuffer sb = new StringBuffer(bpmn);
+ sb.append("<!-- \n").append(json).append("-->\n");
+ return sb.toString();
+ }
+
+ /**
+ *
+ * @return
+ * @throws DocumentException
+ */
+ protected String readJsonfromBPMNFile(String bpmn) throws DocumentException {
+ Document doc = DocumentHelper.parseText(bpmn);
+ List<?> elementList = doc.content();
+ for (Object object : elementList) {
+ if (object instanceof Comment) {
+ Comment comment = (Comment) object;
+ return comment.getText().trim();
+ }
+ }
+
+ return null;
+ }
/**
@@ -150,7 +185,7 @@ public class WorkflowModelerResource {
* @throws IOException
* @throws Exception
*/
- private String buildBPMN(URI srcUri, String processName) throws IOException, Exception {
+ protected String buildBPMN(URI srcUri, String processName) throws IOException, Exception {
Bpmn4ToscaJsonParser parser = new Bpmn4ToscaJsonParser();
Process process = parser.parse(processName, srcUri);