From: Lvbo163 Date: Thu, 28 Sep 2017 03:12:24 +0000 (+0800) Subject: extract json object keys to static variable X-Git-Tag: v1.0.0~14 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=1061c1fd447e4fe341cc3ade66556d82f9f77d22;p=sdc%2Fsdc-workflow-designer.git extract json object keys to static variable Issue-ID: SDC-413 Change-Id: Iaa4d823523448c6544b17865e235637250cd7668 Signed-off-by: Lvbo163 --- 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 index df11e402..8cad4d8c 100644 --- 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 @@ -51,7 +51,7 @@ public class Bpmn4ToscaJsonParser { JsonNode rootNode = MAPPER.readValue(jsonFileUrl.toURL(), JsonNode.class); log.debug("Creating Process models..."); - JsonNode nodes = rootNode.get("nodes"); + JsonNode nodes = rootNode.get(JsonKeys.NODES); if (nodes == null) { return process; } @@ -75,14 +75,14 @@ public class Bpmn4ToscaJsonParser { private List getSequenceFlows(JsonNode jsonNode) { List flowList = new ArrayList(); - JsonNode sequenceFlowNodes = jsonNode.get("sequenceFlows"); + JsonNode sequenceFlowNodes = jsonNode.get(JsonKeys.SEQUENCE_FLOWS); Iterator iter = sequenceFlowNodes.iterator(); while (iter.hasNext()) { JsonNode connectionEntry = (JsonNode) iter.next(); - String sourceRef = getValueFromJsonNode(connectionEntry, "sourceRef"); - String targetRef = getValueFromJsonNode(connectionEntry, "targetRef"); - String condition = getValueFromJsonNode(connectionEntry, "condition"); + String sourceRef = getValueFromJsonNode(connectionEntry, JsonKeys.SOURCE_REF); + String targetRef = getValueFromJsonNode(connectionEntry, JsonKeys.TARGET_REF); + String condition = getValueFromJsonNode(connectionEntry, JsonKeys.CONDITION); SequenceFlow flow = new SequenceFlow(); flow.setId(sourceRef + targetRef); flow.setSourceRef(sourceRef); @@ -103,7 +103,7 @@ public class Bpmn4ToscaJsonParser { String jsonObject = jsonNode.toString(); Element element; - String nodeType = getValueFromJsonNode(jsonNode, "type"); + String nodeType = getValueFromJsonNode(jsonNode, JsonKeys.TYPE); switch (nodeType) { case "startEvent": element = MAPPER.readValue(jsonObject, StartEvent.class); diff --git a/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/parser/JsonKeys.java b/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/parser/JsonKeys.java new file mode 100644 index 00000000..da97a348 --- /dev/null +++ b/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/parser/JsonKeys.java @@ -0,0 +1,32 @@ +/** + * Copyright (c) 2017 ZTE Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the Apache License, Version 2.0 + * and the Eclipse Public License v1.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; + +public class JsonKeys { + // workflow keys + public static final String NODES = "nodes"; + public static final String CONFIGS = "configs"; + + // configs keys + public static final String REST_CONFIGS = "restConfigs"; + public static final String TYPE = "type"; + + // workflow node keys + public static final String SEQUENCE_FLOWS = "sequenceFlows"; + + // sequence flow keys + public static final String SOURCE_REF = "sourceRef"; + public static final String TARGET_REF = "targetRef"; + public static final String CONDITION = "condition"; + + +}