--- /dev/null
+/**\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.parser;\r
+\r
+import java.io.IOException;\r
+import java.net.MalformedURLException;\r
+import java.net.URI;\r
+import java.util.Iterator;\r
+\r
+import org.onap.sdc.workflowdesigner.model.Element;\r
+import org.onap.sdc.workflowdesigner.model.Process;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+\r
+import com.fasterxml.jackson.core.JsonParseException;\r
+import com.fasterxml.jackson.databind.DeserializationFeature;\r
+import com.fasterxml.jackson.databind.JsonMappingException;\r
+import com.fasterxml.jackson.databind.JsonNode;\r
+import com.fasterxml.jackson.databind.ObjectMapper;\r
+import com.fasterxml.jackson.databind.SerializationFeature;\r
+\r
+public class Bpmn4ToscaJsonParser {\r
+\r
+ private static Logger log = LoggerFactory.getLogger(Bpmn4ToscaJsonParser.class);\r
+ \r
+ private static ObjectMapper MAPPER = new ObjectMapper();\r
+ \r
+ static {\r
+ MAPPER.enable(SerializationFeature.INDENT_OUTPUT);\r
+ MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);\r
+ }\r
+ \r
+ public Process parse(String processName, URI jsonFileUrl) throws JsonParseException, JsonMappingException, MalformedURLException, IOException {\r
+ Process process = new Process(processName);\r
+\r
+ JsonNode rootNode = MAPPER.readValue(jsonFileUrl.toURL(), JsonNode.class);\r
+\r
+ log.debug("Creating Process models...");\r
+ JsonNode nodes = rootNode.get("nodes");\r
+ if(nodes == null) {\r
+ return process;\r
+ }\r
+ \r
+ Iterator<JsonNode> iter = nodes.iterator();\r
+ while (iter.hasNext()) {\r
+ JsonNode jsonNode = (JsonNode) iter.next();\r
+\r
+ // get element\r
+ Element element = createElementFromJson(jsonNode);\r
+ process.getElementList().add(element);\r
+ }\r
+\r
+ return process;\r
+\r
+ }\r
+ \r
+ protected Element createElementFromJson(JsonNode jsonNode) throws JsonParseException, JsonMappingException, IOException {\r
+ String jsonObject = jsonNode.toString();\r
+ return MAPPER.readValue(jsonObject, Element.class);\r
+ }\r
+ \r
+}\r