2 * Copyright (c) 2017 ZTE Corporation.
\r
3 * All rights reserved. This program and the accompanying materials
\r
4 * are made available under the terms of the Eclipse Public License v1.0
\r
5 * and the Apache License 2.0 which both accompany this distribution,
\r
6 * and are available at http://www.eclipse.org/legal/epl-v10.html
\r
7 * and http://www.apache.org/licenses/LICENSE-2.0
\r
10 * ZTE - initial API and implementation and/or initial documentation
\r
12 package org.onap.sdc.workflowdesigner.parser;
\r
14 import java.io.IOException;
\r
15 import java.net.MalformedURLException;
\r
16 import java.net.URI;
\r
17 import java.util.Iterator;
\r
19 import org.onap.sdc.workflowdesigner.model.Element;
\r
20 import org.onap.sdc.workflowdesigner.model.Process;
\r
21 import org.slf4j.Logger;
\r
22 import org.slf4j.LoggerFactory;
\r
24 import com.fasterxml.jackson.core.JsonParseException;
\r
25 import com.fasterxml.jackson.databind.DeserializationFeature;
\r
26 import com.fasterxml.jackson.databind.JsonMappingException;
\r
27 import com.fasterxml.jackson.databind.JsonNode;
\r
28 import com.fasterxml.jackson.databind.ObjectMapper;
\r
29 import com.fasterxml.jackson.databind.SerializationFeature;
\r
31 public class Bpmn4ToscaJsonParser {
\r
33 private static Logger log = LoggerFactory.getLogger(Bpmn4ToscaJsonParser.class);
\r
35 private static ObjectMapper MAPPER = new ObjectMapper();
\r
38 MAPPER.enable(SerializationFeature.INDENT_OUTPUT);
\r
39 MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
\r
42 public Process parse(String processName, URI jsonFileUrl) throws JsonParseException, JsonMappingException, MalformedURLException, IOException {
\r
43 Process process = new Process(processName);
\r
45 JsonNode rootNode = MAPPER.readValue(jsonFileUrl.toURL(), JsonNode.class);
\r
47 log.debug("Creating Process models...");
\r
48 JsonNode nodes = rootNode.get("nodes");
\r
53 Iterator<JsonNode> iter = nodes.iterator();
\r
54 while (iter.hasNext()) {
\r
55 JsonNode jsonNode = (JsonNode) iter.next();
\r
58 Element element = createElementFromJson(jsonNode);
\r
59 process.getElementList().add(element);
\r
66 protected Element createElementFromJson(JsonNode jsonNode) throws JsonParseException, JsonMappingException, IOException {
\r
67 String jsonObject = jsonNode.toString();
\r
68 return MAPPER.readValue(jsonObject, Element.class);
\r