summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLvbo163 <lv.bo163@zte.com.cn>2017-09-25 16:39:41 +0800
committerLvbo163 <lv.bo163@zte.com.cn>2017-09-25 16:39:41 +0800
commit2e910cdd98bebd2035aaa40732d71a1eb3703954 (patch)
tree166c2bbcc8138dcb939e8db40f0d009af889a9a2
parentd3f700697c117a152c6c06fc8364b199b3825005 (diff)
Support convert json object to Java BPMN object
Issue-ID: SDC-367 Change-Id: I69d3932536fb46c52cc5f4b53e59776fc9977d27 Signed-off-by: Lvbo163 <lv.bo163@zte.com.cn>
-rw-r--r--sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/parser/Bpmn4ToscaJsonParser.java71
1 files changed, 71 insertions, 0 deletions
diff --git a/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/parser/Bpmn4ToscaJsonParser.java b/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/parser/Bpmn4ToscaJsonParser.java
new file mode 100644
index 00000000..81b41d98
--- /dev/null
+++ b/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/parser/Bpmn4ToscaJsonParser.java
@@ -0,0 +1,71 @@
+/**
+ * Copyright (c) 2017 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,
+ * and are available at http://www.eclipse.org/legal/epl-v10.html
+ * and http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Contributors:
+ * ZTE - initial API and implementation and/or initial documentation
+ */
+package org.onap.sdc.workflowdesigner.parser;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.util.Iterator;
+
+import org.onap.sdc.workflowdesigner.model.Element;
+import org.onap.sdc.workflowdesigner.model.Process;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+
+public class Bpmn4ToscaJsonParser {
+
+ private static Logger log = LoggerFactory.getLogger(Bpmn4ToscaJsonParser.class);
+
+ private static ObjectMapper MAPPER = new ObjectMapper();
+
+ static {
+ MAPPER.enable(SerializationFeature.INDENT_OUTPUT);
+ MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ }
+
+ public Process parse(String processName, URI jsonFileUrl) throws JsonParseException, JsonMappingException, MalformedURLException, IOException {
+ Process process = new Process(processName);
+
+ JsonNode rootNode = MAPPER.readValue(jsonFileUrl.toURL(), JsonNode.class);
+
+ log.debug("Creating Process models...");
+ JsonNode nodes = rootNode.get("nodes");
+ if(nodes == null) {
+ return process;
+ }
+
+ Iterator<JsonNode> iter = nodes.iterator();
+ while (iter.hasNext()) {
+ JsonNode jsonNode = (JsonNode) iter.next();
+
+ // get element
+ Element element = createElementFromJson(jsonNode);
+ process.getElementList().add(element);
+ }
+
+ return process;
+
+ }
+
+ protected Element createElementFromJson(JsonNode jsonNode) throws JsonParseException, JsonMappingException, IOException {
+ String jsonObject = jsonNode.toString();
+ return MAPPER.readValue(jsonObject, Element.class);
+ }
+
+}