diff options
author | Lvbo163 <lv.bo163@zte.com.cn> | 2017-12-11 18:53:08 +0800 |
---|---|---|
committer | Lvbo163 <lv.bo163@zte.com.cn> | 2017-12-11 18:53:08 +0800 |
commit | 8e65c48141a6fdc259728d68508dc7819611e261 (patch) | |
tree | 7f79eb3e255fe520ac65addbf1622d6b7766f3f7 /sdc-workflow-designer-server/src | |
parent | 8fbae2c1cb3b4c5cb8a73b0226b9ad3bd64e3eae (diff) |
converter supports rest service task
converter supports extended bpmn element rest service task.
Issue-ID: SDC-747
Change-Id: Id468269bfc7eab3ed57a7da6d1d2e58043fa088c
Signed-off-by: Lvbo163 <lv.bo163@zte.com.cn>
Diffstat (limited to 'sdc-workflow-designer-server/src')
4 files changed, 187 insertions, 0 deletions
diff --git a/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/model/RestServiceTask.java b/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/model/RestServiceTask.java new file mode 100644 index 00000000..6110132e --- /dev/null +++ b/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/model/RestServiceTask.java @@ -0,0 +1,95 @@ +/**
+ * 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.model;
+
+import java.util.List;
+
+import org.onap.sdc.workflowdesigner.config.Config;
+
+public class RestServiceTask extends ServiceTask {
+ public static String handler = Config.PROPERTIES.getProperty(Config.HANDLER_ClASS);
+
+ private String restConfigId;
+ public String getRestConfigId() {
+ return restConfigId;
+ }
+ public void setRestConfigId(String restConfigId) {
+ this.restConfigId = restConfigId;
+ }
+ private List<String> produces;
+ private List<String> consumes;
+
+
+ private List<Parameter> parameters;
+ private String url;
+ private String serviceName;
+ private String serviceVersion;
+ private String path;
+ private String method;
+
+ public String getUrl() {
+ return url;
+ }
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ public String getMethod() {
+ return method;
+ }
+
+ public static String getHandler() {
+ return handler;
+ }
+ public static void setHandler(String handler) {
+ RestServiceTask.handler = handler;
+ }
+ public void setMethod(String method) {
+ this.method = method;
+ }
+ public List<String> getProduces() {
+ return produces;
+ }
+ public void setProduces(List<String> produces) {
+ this.produces = produces;
+ }
+ public List<String> getConsumes() {
+ return consumes;
+ }
+ public void setConsumes(List<String> consumes) {
+ this.consumes = consumes;
+ }
+ public List<Parameter> getParameters() {
+ return parameters;
+ }
+ public void setParameters(List<Parameter> parameters) {
+ this.parameters = parameters;
+ }
+ public String getServiceName() {
+ return serviceName;
+ }
+ public void setServiceName(String serviceName) {
+ this.serviceName = serviceName;
+ }
+ public String getServiceVersion() {
+ return serviceVersion;
+ }
+ public void setServiceVersion(String serviceVersion) {
+ this.serviceVersion = serviceVersion;
+ }
+ public String getPath() {
+ return path;
+ }
+ public void setPath(String path) {
+ this.path = path;
+ }
+}
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 b103f91d..4041a9ae 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 @@ -15,8 +15,10 @@ import java.io.IOException; import java.net.MalformedURLException;
import java.net.URI;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import org.onap.sdc.workflowdesigner.model.DataObject;
import org.onap.sdc.workflowdesigner.model.Element;
@@ -26,6 +28,7 @@ import org.onap.sdc.workflowdesigner.model.IntermediateCatchEvent; import org.onap.sdc.workflowdesigner.model.ParallelGateway;
import org.onap.sdc.workflowdesigner.model.Parameter;
import org.onap.sdc.workflowdesigner.model.Process;
+import org.onap.sdc.workflowdesigner.model.RestServiceTask;
import org.onap.sdc.workflowdesigner.model.ScriptTask;
import org.onap.sdc.workflowdesigner.model.SequenceFlow;
import org.onap.sdc.workflowdesigner.model.ServiceTask;
@@ -45,6 +48,8 @@ public class Bpmn4ToscaJsonParser { private static Logger log = LoggerFactory.getLogger(Bpmn4ToscaJsonParser.class);
private static ObjectMapper MAPPER = new ObjectMapper();
+
+ private Map<String, JsonNode> restConfigMap = new HashMap<String, JsonNode>();
static {
MAPPER.enable(SerializationFeature.INDENT_OUTPUT);
@@ -62,6 +67,8 @@ public class Bpmn4ToscaJsonParser { if (nodes == null) {
return process;
}
+
+ this.loadConfigs(rootNode.get(JsonKeys.CONFIGS));
Iterator<JsonNode> iter = nodes.iterator();
while (iter.hasNext()) {
@@ -100,6 +107,27 @@ public class Bpmn4ToscaJsonParser { return dataObjects;
}
+
+ private void loadConfigs(JsonNode config) {
+ if(config == null) {
+ return;
+ }
+ loadRestConfigs(config.get(JsonKeys.REST_CONFIGS));
+ }
+
+ private void loadRestConfigs(JsonNode restConfigs) {
+ if(restConfigs == null) {
+ return;
+ }
+
+ Iterator<JsonNode> iter = restConfigs.iterator();
+ while (iter.hasNext()) {
+ JsonNode restConfig = (JsonNode) iter.next();
+
+ String configId = getValueFromJsonNode(restConfig, JsonKeys.ID);
+ restConfigMap.put(configId, restConfig);
+ }
+ }
private List<SequenceFlow> getSequenceFlows(JsonNode jsonNode) {
List<SequenceFlow> flowList = new ArrayList<SequenceFlow>();
@@ -141,6 +169,9 @@ public class Bpmn4ToscaJsonParser { case "serviceTask":
element = MAPPER.readValue(jsonObject, ServiceTask.class);
break;
+ case "restTask":
+ element = this.createRestServiceTask(jsonObject);
+ break;
case "scriptTask":
element = MAPPER.readValue(jsonObject, ScriptTask.class);
break;
@@ -157,6 +188,28 @@ public class Bpmn4ToscaJsonParser { return element;
}
+
+ private RestServiceTask createRestServiceTask(String jsonObject) throws JsonParseException, JsonMappingException, IOException {
+ RestServiceTask restServiceTask = MAPPER.readValue(jsonObject, RestServiceTask.class);
+
+ // add baseUrl to relative url
+ String restConfigId = restServiceTask.getRestConfigId();
+ JsonNode restConfig = this.restConfigMap.get(restConfigId);
+
+ if(restConfig != null) { // while create a new rest task and didnot set method, the restconfig info may be null
+ restServiceTask.setUrl(getValueFromJsonNode(restConfig, JsonKeys.MICROSERVICE_URL));
+ restServiceTask.setServiceName(getValueFromJsonNode(restConfig, JsonKeys.MICROSERVICE_NAME));
+ restServiceTask.setServiceVersion(getValueFromJsonNode(restConfig, JsonKeys.MICROSERVICE_VERSION));
+ }
+
+ for(Parameter parameter : restServiceTask.getParameters()) {
+ if("body".equals(parameter.getPosition())) {
+ parameter.setValueSource(null);
+ }
+ }
+
+ return restServiceTask;
+ }
private String getValueFromJsonNode(JsonNode jsonNode, String key) {
return jsonNode.get(key) == null ? null : jsonNode.get(key).asText();
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 index da97a348..8c7c62f3 100644 --- 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 @@ -29,4 +29,10 @@ public class JsonKeys { public static final String CONDITION = "condition";
+ // microservice info
+ public static final String MICROSERVICE_URL = "url";
+ public static final String MICROSERVICE_NAME = "name";
+ public static final String MICROSERVICE_VERSION = "version";
+
+ public static final String ID = "id";
}
diff --git a/sdc-workflow-designer-server/src/main/resources/bpmn-templates/bpmn_element_restTask_template.xml b/sdc-workflow-designer-server/src/main/resources/bpmn-templates/bpmn_element_restTask_template.xml new file mode 100644 index 00000000..7f26177a --- /dev/null +++ b/sdc-workflow-designer-server/src/main/resources/bpmn-templates/bpmn_element_restTask_template.xml @@ -0,0 +1,33 @@ +
+<serviceTask id="${element.id}" name="${element.name}" activiti:class="${element.handler}">
+ <extensionElements>
+ <activiti:field name="url">
+ <activiti:string><![CDATA[$!{element.url}]]></activiti:string>
+ </activiti:field>
+ <activiti:field name="name">
+ <activiti:string><![CDATA[$!{element.serviceName}]]></activiti:string>
+ </activiti:field>
+ <activiti:field name="version">
+ <activiti:string><![CDATA[$!{element.serviceVersion}]]></activiti:string>
+ </activiti:field>
+ <activiti:field name="path">
+ <activiti:string><![CDATA[$!{element.path}]]></activiti:string>
+ </activiti:field>
+ <activiti:field name="method">
+ <activiti:string><![CDATA[$!{element.method}]]></activiti:string>
+ </activiti:field>
+ #if (${element.produces})
+ <activiti:field name="accept">
+ <activiti:string><![CDATA[${element.produces}]]></activiti:string>
+ </activiti:field>
+ #end
+ #if (${element.consumes})
+ <activiti:field name="contentType">
+ <activiti:string><![CDATA[${element.consumes}]]></activiti:string>
+ </activiti:field>
+ #end
+ <activiti:field name="parameters">
+ <activiti:string><![CDATA[${element.parameters}]]></activiti:string>
+ </activiti:field>
+ </extensionElements>
+</serviceTask>
|