--- /dev/null
+<?xml version="1.0"?>\r
+<!-- Copyright 2016 ZTE Corporation. Licensed under the Apache License, Version \r
+ 2.0 (the "License"); you may not use this file except in compliance with \r
+ the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 \r
+ Unless required by applicable law or agreed to in writing, software distributed \r
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES \r
+ OR CONDITIONS OF ANY KIND, either express or implied. See the License for \r
+ the specific language governing permissions and limitations under the License. -->\r
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">\r
+ <parent>\r
+ <groupId>org.onap.oparent</groupId>\r
+ <artifactId>oparent</artifactId>\r
+ <version>1.0.0-SNAPSHOT</version>\r
+ </parent>\r
+\r
+ <modelVersion>4.0.0</modelVersion>\r
+ <artifactId>workflow-engine-mgr-service</artifactId>\r
+ <name>vfc/nfvo/wfengine/wfenginemgrservice</name>\r
+ <packaging>jar</packaging>\r
+\r
+ <properties>\r
+ <ant.version>1.9.6</ant.version>\r
+ <apache-velocity.version>1.6.2</apache-velocity.version>\r
+ <jgrapht.version>0.9.1</jgrapht.version>\r
+ </properties>\r
+\r
+ <build>\r
+ <plugins>\r
+ <plugin>\r
+ <groupId>org.eclipse.m2e</groupId>\r
+ <artifactId>lifecycle-mapping</artifactId>\r
+ <version>1.0.0</version>\r
+ <configuration>\r
+ <lifecycleMappingMetadata>\r
+ <pluginExecutions>\r
+ <pluginExecution>\r
+ <pluginExecutionFilter>\r
+ <groupId>org.apache.maven.plugins</groupId>\r
+ <artifactId>maven-dependency-plugin</artifactId>\r
+ <versionRange>[2.0,)</versionRange>\r
+ <goals>\r
+ <goal>copy-dependencies</goal>\r
+ </goals>\r
+ </pluginExecutionFilter>\r
+ <action>\r
+ <ignore />\r
+ </action>\r
+ </pluginExecution>\r
+ </pluginExecutions>\r
+ </lifecycleMappingMetadata>\r
+ </configuration>\r
+ </plugin>\r
+ <plugin>\r
+ <groupId>org.apache.maven.plugins</groupId>\r
+ <artifactId>maven-jar-plugin</artifactId>\r
+ <version>2.6</version>\r
+ <configuration>\r
+ <archive>\r
+ <manifest>\r
+ <addDefaultImplementationEntries>true</addDefaultImplementationEntries>\r
+ </manifest>\r
+ </archive>\r
+ </configuration>\r
+ </plugin>\r
+ <plugin>\r
+ <groupId>org.apache.maven.plugins</groupId>\r
+ <artifactId>maven-compiler-plugin</artifactId>\r
+ <version>3.5.1</version>\r
+ <configuration>\r
+ <source>1.8</source>\r
+ <target>1.8</target>\r
+ </configuration>\r
+ </plugin>\r
+ <plugin>\r
+ <groupId>org.apache.maven.plugins</groupId>\r
+ <artifactId>maven-shade-plugin</artifactId>\r
+ <version>2.4</version>\r
+ <configuration>\r
+ <createDependencyReducedPom>false</createDependencyReducedPom>\r
+ <filters>\r
+ <filter>\r
+ <artifact>*:*</artifact>\r
+ <excludes>\r
+ <exclude>META-INF/*.SF</exclude>\r
+ <exclude>META-INF/*.DSA</exclude>\r
+ <exclude>META-INF/*.RSA</exclude>\r
+ </excludes>\r
+ </filter>\r
+ </filters>\r
+ </configuration>\r
+ <executions>\r
+ <execution>\r
+ <phase>package</phase>\r
+ <goals>\r
+ <goal>shade</goal>\r
+ </goals>\r
+ <configuration>\r
+ <transformers>\r
+ <transformer\r
+ implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />\r
+ <transformer\r
+ implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">\r
+ <mainClass>com.onap.workflow.WorkflowApp</mainClass>\r
+ </transformer>\r
+ </transformers>\r
+ </configuration>\r
+ </execution>\r
+ </executions>\r
+ </plugin>\r
+ <plugin>\r
+ <groupId>org.apache.maven.plugins</groupId>\r
+ <artifactId>maven-dependency-plugin</artifactId>\r
+ <executions>\r
+ <execution>\r
+ <id>copy-dependencies</id>\r
+ <phase>package</phase>\r
+ <goals>\r
+ <goal>copy-dependencies</goal>\r
+ </goals>\r
+ <configuration>\r
+ <artifactItems>\r
+ <artifactItem>\r
+ <groupId>io.dropwizard</groupId>\r
+ <artifactId>dropwizard-core</artifactId>\r
+ <version>${dropwizard.version}</version>\r
+ <overWrite>true</overWrite>\r
+ </artifactItem>\r
+ </artifactItems>\r
+ </configuration>\r
+ </execution>\r
+ </executions>\r
+ </plugin>\r
+\r
+ <plugin>\r
+ <groupId>org.apache.maven.plugins</groupId>\r
+ <artifactId>maven-failsafe-plugin</artifactId>\r
+ <version>2.8</version>\r
+ </plugin>\r
+ </plugins>\r
+ <pluginManagement>\r
+ <plugins>\r
+ <!--This plugin's configuration is used to store Eclipse m2e settings \r
+ only. It has no influence on the Maven build itself. -->\r
+ <plugin>\r
+ <groupId>org.eclipse.m2e</groupId>\r
+ <artifactId>lifecycle-mapping</artifactId>\r
+ <version>1.0.0</version>\r
+ <configuration>\r
+ <lifecycleMappingMetadata>\r
+ <pluginExecutions>\r
+ <pluginExecution>\r
+ <pluginExecutionFilter>\r
+ <groupId>\r
+ org.apache.maven.plugins\r
+ </groupId>\r
+ <artifactId>\r
+ maven-checkstyle-plugin\r
+ </artifactId>\r
+ <versionRange>\r
+ [2.17,)\r
+ </versionRange>\r
+ <goals>\r
+ <goal>check</goal>\r
+ </goals>\r
+ </pluginExecutionFilter>\r
+ <action>\r
+ <ignore></ignore>\r
+ </action>\r
+ </pluginExecution>\r
+ </pluginExecutions>\r
+ </lifecycleMappingMetadata>\r
+ </configuration>\r
+ </plugin>\r
+ </plugins>\r
+ </pluginManagement>\r
+ </build>\r
+ <dependencies>\r
+ <dependency>\r
+ <groupId>io.dropwizard</groupId>\r
+ <artifactId>dropwizard-core</artifactId>\r
+ <version>0.8.0</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>io.dropwizard</groupId>\r
+ <artifactId>dropwizard-assets</artifactId>\r
+ <version>0.8.0</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>io.dropwizard</groupId>\r
+ <artifactId>dropwizard-hibernate</artifactId>\r
+ <version>0.8.0</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>io.dropwizard</groupId>\r
+ <artifactId>dropwizard-migrations</artifactId>\r
+ <version>0.8.0</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>io.swagger</groupId>\r
+ <artifactId>swagger-jersey2-jaxrs</artifactId>\r
+ <version>1.5.3</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.projectlombok</groupId>\r
+ <artifactId>lombok</artifactId>\r
+ <version>1.16.4</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.glassfish.jersey.core</groupId>\r
+ <artifactId>jersey-server</artifactId>\r
+ <version>2.16</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.glassfish.jersey.media</groupId>\r
+ <artifactId>jersey-media-multipart</artifactId>\r
+ <version>2.16</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.glassfish.jersey.containers</groupId>\r
+ <artifactId>jersey-container-servlet-core</artifactId>\r
+ <version>2.16</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>com.eclipsesource.jaxrs</groupId>\r
+ <artifactId>consumer</artifactId>\r
+ <version>5.0</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>com.jcraft</groupId>\r
+ <artifactId>jsch</artifactId>\r
+ <version>0.1.53</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>com.fasterxml.jackson.dataformat</groupId>\r
+ <artifactId>jackson-dataformat-xml</artifactId>\r
+ <version>2.5.1</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>com.fasterxml.jackson.core</groupId>\r
+ <artifactId>jackson-annotations</artifactId>\r
+ <version>2.8.0</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>com.google.code.gson</groupId>\r
+ <artifactId>gson</artifactId>\r
+ <version>2.2.4</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>dom4j</groupId>\r
+ <artifactId>dom4j</artifactId>\r
+ <version>1.6.1</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>io.dropwizard</groupId>\r
+ <artifactId>dropwizard-jdbi</artifactId>\r
+ <version>0.8.0</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>mysql</groupId>\r
+ <artifactId>mysql-connector-java</artifactId>\r
+ <version>5.1.40</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>commons-io</groupId>\r
+ <artifactId>commons-io</artifactId>\r
+ <version>2.4</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.apache.httpcomponents</groupId>\r
+ <artifactId>httpcore</artifactId>\r
+ <version>4.4.1</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.apache.httpcomponents</groupId>\r
+ <artifactId>httpmime</artifactId>\r
+ <version>4.4.1</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>junit</groupId>\r
+ <artifactId>junit</artifactId>\r
+ <version>4.12</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.powermock</groupId>\r
+ <artifactId>powermock-module-junit4</artifactId>\r
+ <version>1.6.1</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.powermock</groupId>\r
+ <artifactId>powermock-api-mockito</artifactId>\r
+ <version>1.6.1</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.mockito</groupId>\r
+ <artifactId>mockito-all</artifactId>\r
+ <version>1.9.5</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.apache.ant</groupId>\r
+ <artifactId>ant</artifactId>\r
+ <version>1.9.6</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.slf4j</groupId>\r
+ <artifactId>slf4j-api</artifactId>\r
+ <version>1.7.12</version>\r
+ </dependency>\r
+ </dependencies>\r
+</project>\r
--- /dev/null
+/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.workflow;
+
+import org.glassfish.jersey.media.multipart.MultiPartFeature;
+import org.onap.workflow.common.Config;
+
+import io.dropwizard.Application;
+import io.dropwizard.setup.Environment;
+
+public class WorkflowApp extends Application<WorkflowAppConfig> {
+
+ public static void main(String[] args) throws Exception {
+ new WorkflowApp().run(args);
+ }
+
+ public String getName() {
+ return " Workflow APP ";
+ }
+
+ @Override
+ public void run(WorkflowAppConfig configuration, Environment environment) throws Exception {
+ // TODO Auto-generated method stub
+ environment.jersey().register(MultiPartFeature.class);
+
+ Config.setWorkflowAppConfig(configuration);
+ }
+}
--- /dev/null
+/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.workflow;
+
+import javax.validation.Valid;
+
+import org.hibernate.validator.constraints.NotEmpty;
+import org.onap.workflow.entity.MsbClientConfig;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import io.dropwizard.Configuration;
+
+public class WorkflowAppConfig extends Configuration {
+
+ @NotEmpty
+ private String defaultName = "WORKFLOW-ACTIVITI-EXT";
+ @NotEmpty
+ @JsonProperty
+ private String apidescription = "ZTE workflow-activiti-ext rest API";
+
+ @JsonProperty
+ @Valid
+ private MsbClientConfig msbClientConfig;
+
+ public MsbClientConfig getMsbClientConfig() {
+ return msbClientConfig;
+ }
+}
--- /dev/null
+/**\r
+ * Copyright 2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.onap.workflow.activitiext.common;\r
+\r
+import java.io.IOException;\r
+import java.io.InputStream;\r
+\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+\r
+\r
+\r
+public class ToolUtil {\r
+ private static final Logger logger = LoggerFactory.getLogger(ToolUtil.class);\r
+ public static boolean isEmptyString(String val) {\r
+ return ((val == null || "".equals(val)) ? true : false);\r
+ }\r
+\r
+ public static boolean isTrimedEmptyString(String val) {\r
+ return ((val == null || "".equals(val.trim())) ? true : false);\r
+ }\r
+\r
+ public static boolean isTrimedEmptyArray(String[] val) {\r
+ return ((val == null || val.length == 0) ? true : false);\r
+ }\r
+ \r
+ /**\r
+ * @param ins\r
+ */\r
+ public static void closeInputStream(InputStream ins) {\r
+ if (ins != null) {\r
+ try {\r
+ ins.close();\r
+ } catch (IOException e) {\r
+ logger.info("Close InputStream failed.", e);\r
+ }\r
+ }\r
+ }\r
+}\r
--- /dev/null
+/**\r
+ * Copyright 2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.onap.workflow.activitiext.common;
\ No newline at end of file
--- /dev/null
+/**\r
+ * Copyright 2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.onap.workflow.common;\r
+\r
+import org.onap.workflow.WorkflowAppConfig;\r
+\r
+public class Config {\r
+ private static WorkflowAppConfig workflowAppConfig;\r
+\r
+ public static WorkflowAppConfig getWorkflowAppConfig() {\r
+ return workflowAppConfig;\r
+ }\r
+\r
+ public static void setWorkflowAppConfig(WorkflowAppConfig config) {\r
+ workflowAppConfig = config;\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+/**\r
+ * Copyright 2017 [ZTE] and others.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.onap.workflow.common;\r
+\r
+public enum EnumModuleUrl {\r
+ ACTIVITI {\r
+ @Override\r
+ public String getApiRootDomain() {\r
+ return "/activiti-rest/service";\r
+ }\r
+ };\r
+\r
+ public abstract String getApiRootDomain();\r
+\r
+ public static String getBaseUrl(EnumModuleUrl enumUrl) {\r
+ String msbHost = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrIp();\r
+ return "http://" + msbHost + ":" + "80" + enumUrl.getApiRootDomain();\r
+ }\r
+\r
+}\r
--- /dev/null
+/**\r
+ * Copyright 2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.onap.workflow.common;\r
+\r
+public enum EnumStatus {\r
+ SUCCESS, FAIL\r
+}\r
--- /dev/null
+/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.workflow.common;
+
+import java.io.IOException;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpHost;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.ResponseHandler;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpDelete;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpPut;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.BasicResponseHandler;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+import org.onap.workflow.externalservice.entity.activitientitiy.ActivitiStartProcessRequest;
+import org.onap.workflow.tools.Constants;
+import org.onap.workflow.tools.HttpDeleteWithBody;
+import org.onap.workflow.tools.RequestParameters;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.gson.Gson;
+
+public class RestClient {
+ private static final String HTTP = "http";
+ private static final Logger logger = LoggerFactory.getLogger(RestClient.class);
+
+ enum HttpMethod {
+ GET, POST, PUT, DELETE
+ }
+
+ /**
+ *
+ * @param method
+ * @param ip
+ * @param port
+ * @param url
+ * @param body
+ * @return
+ * @throws ClientProtocolException
+ * @throws IOException
+ */
+ public static RestResponse executeHttp(HttpMethod method, String ip, Integer port, String url,
+ HttpEntity body) throws ClientProtocolException, IOException {
+ logger.info("deployfile method send");
+ CloseableHttpClient httpclient = HttpClients.createDefault();
+ HttpResponse httpResponse = null;
+ RestResponse result = new RestResponse();
+ try {
+ if (ip == null) {
+ ip = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrIp();
+ }
+ if (port == null) {
+ port = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrPort();
+ }
+ HttpHost target = new HttpHost(ip, port, HTTP);
+ HttpRequest request = getRequest(method, url, body);
+ logger.info("deployfile method send ip"+ip);
+ request.addHeader(Constants.AUTHORIZATION, ToolUtil.getHeader());
+
+ httpResponse = httpclient.execute(target, request);
+ HttpEntity entity = httpResponse.getEntity();
+ logger.info("deployfile method send");
+ if (entity != null) {
+ result.setStatusCode(httpResponse.getStatusLine().getStatusCode());
+ logger.info("reply status code deploy"+httpResponse.getStatusLine().getStatusCode());
+ result.setResult(EntityUtils.toString(entity));
+ }
+ } catch (IOException e) {
+ logger.warn("Close httpclient failed.", e);
+ } finally {
+ if (httpclient != null) {
+ try {
+ httpclient.close();
+ } catch (IOException e) {
+ logger.warn("Close httpclient failed.", e);
+ }
+ }
+ }
+ return result;
+ }
+
+ private static HttpRequest getRequest(HttpMethod method, String url, HttpEntity body) {
+ HttpRequest request = null;
+ switch (method) {
+ case GET:
+ request = new HttpGet(url);
+ break;
+ case POST:
+ request = new HttpPost(url);
+ ((HttpPost) request).setEntity(body);
+ break;
+ case PUT:
+ request = new HttpPut(url);
+ ((HttpPut) request).setEntity(body);
+ break;
+ case DELETE:
+ request = new HttpDelete(url);
+ break;
+ default:
+ break;
+ }
+ return request;
+ }
+
+ /**
+ *
+ * @param ip
+ * @param port
+ * @param url
+ * @return
+ * @throws ClientProtocolException
+ * @throws IOException
+ */
+ public static String get(String ip, int port, String url)
+ throws ClientProtocolException, IOException {
+ return executeHttp(HttpMethod.GET, ip, port, url, null).getResult();
+ }
+
+ /**
+ *
+ * @param ip
+ * @param port
+ * @param url
+ * @return
+ * @throws ClientProtocolException
+ * @throws IOException
+ */
+ public static RestResponse delete(String ip, int port, String url)
+ throws ClientProtocolException, IOException {
+ return executeHttp(HttpMethod.GET, ip, port, url, null);
+ }
+
+ /**
+ *
+ * @param ip
+ * @param port
+ * @param url
+ * @param requestBody
+ * @return
+ * @throws ClientProtocolException
+ * @throws IOException
+ */
+ public static RestResponse post(String ip, int port, String url, HttpEntity requestBody)
+ throws ClientProtocolException, IOException {
+ return executeHttp(HttpMethod.POST, ip, port, url, requestBody);
+ }
+
+
+
+ /**
+ *
+ * @param method
+ * @param ip
+ * @param port
+ * @param url
+ * @param body
+ * @return
+ * @throws ClientProtocolException
+ * @throws IOException
+ */
+ public static RestResponse executeHttpDeleteDeploy(HttpMethod method, String ip, Integer port,
+ String url) throws ClientProtocolException, IOException {
+ if (ip == null) {
+ ip = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrIp();
+ }
+ port = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrPort();
+ RestResponse result = new RestResponse();
+ CloseableHttpClient httpClient = HttpClients.createDefault();
+ try {
+ httpClient = HttpClients.createDefault();
+ // "http://localhost:8080/activiti-rest/service/repository/deployments/167501"
+ String deleteUrl = Constants.HTTP_HEADER + ip + Constants.COLON + port + url;
+ HttpDeleteWithBody httpDeteTest = new HttpDeleteWithBody(deleteUrl);
+ Gson gson = new Gson();
+ RequestParameters reqPa = new RequestParameters();
+ reqPa.setCasCade(true);
+ String jsonStr = gson.toJson(reqPa, RequestParameters.class);
+ StringEntity requestEntity = new StringEntity(jsonStr, "UTF-8");
+ requestEntity.setContentEncoding("UTF-8");
+ httpDeteTest.setHeader("Content-type", "application/json");
+ httpDeteTest.setHeader(Constants.AUTHORIZATION, ToolUtil.getHeader());
+ httpDeteTest.setEntity(new StringEntity(jsonStr));
+ // returnValue = httpClient.execute(httpDeteTest, responseHandler); // 调接口获取返回值时,必须用此方法
+ CloseableHttpResponse httpResonse = httpClient.execute(httpDeteTest);
+ int statusCode = httpResonse.getStatusLine().getStatusCode();
+ result.setStatusCode(statusCode);
+ // result.setResult(EntityUtils.toString(httpResonse.getEntity()));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ finally {
+ try {
+ httpClient.close();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ *
+ * @param method
+ * @param ip
+ * @param port
+ * @param url
+ * @param body
+ * @return
+ * @throws ClientProtocolException
+ * @throws IOException
+ */
+ public static RestResponse executeHttpStartIntance(HttpMethod method, String ip, Integer port,
+ String url, ActivitiStartProcessRequest object) throws ClientProtocolException, IOException {
+ String returnValue = "";
+ RestResponse result = new RestResponse();
+ CloseableHttpClient httpClient = HttpClients.createDefault();
+ ResponseHandler<String> responseHandler = new BasicResponseHandler();
+ try {
+ httpClient = HttpClients.createDefault();
+ if (ip == null) {
+ ip = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrIp();
+ }
+ port = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrPort();
+
+ HttpPost httpPost = new HttpPost(Constants.HTTP_HEADER + ip + ":" + port + url);
+ Gson gson = new Gson();
+ String jsonStr = gson.toJson(object, ActivitiStartProcessRequest.class);
+ StringEntity requestEntity = new StringEntity(jsonStr, "utf-8");
+ requestEntity.setContentEncoding("UTF-8");
+ httpPost.setHeader("Content-type", "application/json");
+ httpPost.setHeader(Constants.AUTHORIZATION, ToolUtil.getHeader());
+ httpPost.setEntity(requestEntity);
+ returnValue = httpClient.execute(httpPost, responseHandler); // 调接口获取返回值时,必须用此方法
+ CloseableHttpResponse httpResonse = httpClient.execute(httpPost);
+ int statusCode = httpResonse.getStatusLine().getStatusCode();
+ returnValue = EntityUtils.toString(httpResonse.getEntity(),"UTF-8");
+ result.setStatusCode(statusCode);
+ result.setResult(returnValue);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ finally {
+ try {
+ httpClient.close();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ *
+ * @param ip
+ * @param port
+ * @param url
+ * @param requestBody
+ * @return
+ * @throws ClientProtocolException
+ * @throws IOException
+ */
+ public static RestResponse post(String ip, Integer port, String url,
+ ActivitiStartProcessRequest requestBody) throws ClientProtocolException, IOException {
+ return executeHttpStartIntance(HttpMethod.POST, ip, port, url, requestBody);
+ }
+
+ /**
+ *
+ * @param ip
+ * @param port
+ * @param url
+ * @param requestBody
+ * @return
+ * @throws ClientProtocolException
+ * @throws IOException
+ */
+ public static RestResponse post(String ip, Integer port, String url)
+ throws ClientProtocolException, IOException {
+ return executeHttpDeleteDeploy(HttpMethod.DELETE, ip, port, url);
+ }
+
+}
--- /dev/null
+/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.workflow.common;
+
+import java.io.InputStream;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.mime.MultipartEntityBuilder;
+
+/**
+ *
+ * @author 10090474
+ *
+ */
+public class RestClientUtils {
+ /**
+ *
+ * @param ins
+ * @param fileName
+ * @return
+ */
+ public static HttpEntity buildMultipartRequest(InputStream ins, String fileName) {
+ MultipartEntityBuilder builder = MultipartEntityBuilder.create();
+ builder.seContentType(ContentType.MULTIPART_FORM_DATA);
+ builder.addBinaryBody("file", ins, ContentType.APPLICATION_OCTET_STREAM, fileName);
+ return builder.build();
+ }
+}
--- /dev/null
+/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.workflow.common;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class RestResponse {
+ private int statusCode;
+ private String result;
+
+ @Override
+ public String toString() {
+ return "RestResponse [statusCode=" + statusCode + ", result=" + result + "]";
+ }
+
+}
--- /dev/null
+/**\r
+ * Copyright (C) 2017 ZTE, Inc. and others. All rights reserved. (ZTE)\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.onap.workflow.common;\r
+\r
+import java.io.IOException;\r
+import java.io.InputStream;\r
+import java.nio.charset.Charset;\r
+\r
+import org.apache.commons.codec.binary.Base64;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+\r
+\r
+\r
+public class ToolUtil {\r
+ private static final Logger logger = LoggerFactory.getLogger(ToolUtil.class);\r
+ \r
+ /**\r
+ * 构造Basic Auth认证头信息\r
+ * \r
+ * @return\r
+ */\r
+ public static String getHeader() {\r
+ String auth = "kermit" + ":" +"kermit";\r
+ byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(Charset.forName("US-ASCII")));\r
+ String authHeader = "Basic " + new String(encodedAuth);\r
+ return authHeader;\r
+ }\r
+ \r
+ public static boolean isEmptyString(String val) {\r
+ return ((val == null || "".equals(val)) ? true : false);\r
+ }\r
+\r
+ public static boolean isTrimedEmptyString(String val) {\r
+ return ((val == null || "".equals(val.trim())) ? true : false);\r
+ }\r
+\r
+ public static boolean isTrimedEmptyArray(String[] val) {\r
+ return ((val == null || val.length == 0) ? true : false);\r
+ }\r
+ \r
+ /**\r
+ * @param ins\r
+ */\r
+ public static void closeInputStream(InputStream ins) {\r
+ if (ins != null) {\r
+ try {\r
+ ins.close();\r
+ } catch (IOException e) {\r
+ logger.info("Close InputStream failed.", e);\r
+ }\r
+ }\r
+ }\r
+}\r
--- /dev/null
+/**\r
+ * Copyright 2017 [ZTE] and others.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.onap.workflow.common;
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.workflow.entity;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class DeployBpmnFileResponse {
+ private int status;
+ private String message;
+ private String deployedId;
+ private String processId;
+}
--- /dev/null
+/**\r
+ * Copyright 2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.onap.workflow.entity;\r
+\r
+import lombok.Data;\r
+\r
+@Data\r
+public class MsbClientConfig {\r
+\r
+ private String msbSvrIp;\r
+ private Integer msbSvrPort;\r
+}\r
--- /dev/null
+/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.workflow.entity;
+
+import java.util.Map;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class StartProcessRequest {
+ private String processDefinitionKey;
+ private Map<String, String> params;
+}
--- /dev/null
+/**\r
+ * Copyright 2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.onap.workflow.externalservice.entity.activitientitiy;\r
+\r
+import lombok.Data;\r
+\r
+@Data\r
+public class ActivitiDeployResponse {\r
+ private String id;\r
+ private String deploymentTime;\r
+ private String url;\r
+}\r
--- /dev/null
+/**\r
+ * Copyright 2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.onap.workflow.externalservice.entity.activitientitiy;\r
+\r
+import lombok.Data;\r
+\r
+@Data\r
+public class ActivitiStartProcessRequest {\r
+ private String processDefinitionKey;\r
+ private ActivitiStartProcessRequestParam[] variables;\r
+}\r
--- /dev/null
+/**\r
+ * Copyright 2017 [ZTE] and others.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.onap.workflow.externalservice.entity.activitientitiy;\r
+\r
+import lombok.Data;\r
+\r
+/**\r
+ *\r
+ */\r
+@Data\r
+public class ActivitiStartProcessRequestParam {\r
+ private String name;\r
+ private String value;\r
+}\r
--- /dev/null
+/**\r
+ * Copyright 2017 [ZTE] and others.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+/**\r
+ *\r
+ */\r
+package org.onap.workflow.externalservice.entity.activitientitiy;
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.workflow.externalservice.service.activitiservice;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.ws.rs.core.Response;
+
+import org.apache.http.client.ClientProtocolException;
+import org.glassfish.jersey.client.ClientConfig;
+import org.onap.workflow.common.Config;
+import org.onap.workflow.common.EnumModuleUrl;
+import org.onap.workflow.common.RestClient;
+import org.onap.workflow.common.RestClientUtils;
+import org.onap.workflow.common.RestResponse;
+import org.onap.workflow.common.ToolUtil;
+import org.onap.workflow.externalservice.entity.activitientitiy.ActivitiDeployResponse;
+import org.onap.workflow.externalservice.entity.activitientitiy.ActivitiStartProcessRequest;
+import org.onap.workflow.tools.Constants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.eclipsesource.jaxrs.consumer.ConsumerFactory;
+import com.google.gson.Gson;
+
+/**
+ *
+ * @author 10090474
+ *
+ */
+public class ActivitiServiceConsumer {
+ private static final Logger logger = LoggerFactory.getLogger(ActivitiServiceConsumer.class);
+ private static final String DEPLOY_BPMNFILE_URL =
+ EnumModuleUrl.ACTIVITI.getApiRootDomain() + "/repository/deployments";
+
+ private static IActivitiRestService activitiServiceProxy = null;
+
+ private static IActivitiRestService getActivitiService() {
+ if (activitiServiceProxy == null) {
+ ClientConfig config = new ClientConfig();
+ activitiServiceProxy = ConsumerFactory.createConsumer(
+ EnumModuleUrl.getBaseUrl(EnumModuleUrl.ACTIVITI), config, IActivitiRestService.class);
+
+ }
+ return activitiServiceProxy;
+ }
+
+ public static RestResponse undeploybpmnfile(String deploymentId) {
+ /*
+ * IActivitiRestService activitiProxy = getActivitiService();
+ * activitiProxy.undeployBpmnFile(deploymentId);
+ */
+ RestResponse res = deleteDeployProcess(deploymentId);
+ // activitiProxy.startProcess(request);
+
+ return res;
+ }
+
+ public static RestResponse startBpmnProcess(ActivitiStartProcessRequest request) {
+ // IActivitiRestService activitiProxy = getActivitiService();
+ // startProcess( request);
+ // activitiProxy.startProcess(request);
+ return startProcess(request);
+ }
+
+ public static RestResponse deleteDeployProcess(String deploymentId) {
+ // TODO Auto-generated method stub
+ RestResponse res = null;
+ try {
+ res = RestClient.post(null, null, Constants.DEPLOY_BPMNFILE_URL + "/" + deploymentId);
+ } catch (ClientProtocolException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return res;
+ }
+
+ public static RestResponse startProcess(ActivitiStartProcessRequest request) {
+ // TODO Auto-generated method stub
+ RestResponse res = null;
+ try {
+ res = RestClient.post(null, null, Constants.ACITIVI_START_INSTANCE_URL, request);
+ } catch (ClientProtocolException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ // if (Response.Status.OK.getStatusCode() == res.getStatusCode()
+ // || Response.Status.CREATED.getStatusCode() == res.getStatusCode()) {
+ // Response response = new Gson().fromJson(res.getResult(), Response.class);
+ // return response;
+ // }
+ return res;
+ }
+
+ public static ActivitiDeployResponse deploybpmnfile(InputStream ins, String filename)
+ throws ClientProtocolException, IOException {
+ try {
+ return deployPackage2Activiti(ins, filename);
+ } finally {
+ ToolUtil.closeInputStream(ins);
+ }
+ }
+
+ private static ActivitiDeployResponse deployPackage2Activiti(InputStream ins, String filename)
+ throws ClientProtocolException, IOException {
+ String ip = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrIp();
+ int port = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrPort();
+ RestResponse res = RestClient.post(ip, port, DEPLOY_BPMNFILE_URL,
+ RestClientUtils.buildMultipartRequest(ins, filename));
+ logger.info("deployfile to activiti return. {}", res);
+
+ if (Response.Status.OK.getStatusCode() == res.getStatusCode()
+ || Response.Status.CREATED.getStatusCode() == res.getStatusCode()) {
+ ActivitiDeployResponse response =
+ new Gson().fromJson(res.getResult(), ActivitiDeployResponse.class);
+ return response;
+ }
+ return null;
+ }
+}
--- /dev/null
+/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.workflow.externalservice.service.activitiservice;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.onap.workflow.externalservice.entity.activitientitiy.ActivitiStartProcessRequest;
+
+@Path("/")
+public interface IActivitiRestService {
+ @Path("/repository/deployments/{deploymentId}")
+ @DELETE
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ Response undeployBpmnFile(@PathParam("deploymentId") String deploymentId);
+
+
+ @Path("/runtime/process-instances")
+ @POST
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ Response startProcess(ActivitiStartProcessRequest request);
+}
--- /dev/null
+/**\r
+ * Copyright 2017 [ZTE] and others.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.onap.workflow.externalservice.service.activitiservice;
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.workflow.resources;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+
+import java.io.InputStream;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.eclipse.jetty.http.HttpStatus;
+import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
+import org.glassfish.jersey.media.multipart.FormDataParam;
+import org.jvnet.hk2.annotations.Service;
+import org.onap.workflow.common.RestResponse;
+import org.onap.workflow.entity.DeployBpmnFileResponse;
+import org.onap.workflow.entity.StartProcessRequest;
+import org.onap.workflow.wrapper.WorkflowInstanceWrapper;
+
+@Path("/")
+@Api(tags = {"Workflow Resource"})
+@Produces(MediaType.APPLICATION_JSON)
+@Service
+public class WorkflowResource {
+ @POST
+ @Path("/package")
+ @Consumes({"multipart/form-data"})
+ @Produces({"application/json"})
+ @ApiOperation(value = "deploy bpmn file")
+ @ApiResponses(value = {
+ @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
+ response = DeployBpmnFileResponse.class),
+ @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
+ message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
+ @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "error")})
+ public Response deployBpmnFile(
+ @ApiParam(value = "file inputstream",
+ required = true) @FormDataParam("file") InputStream fileInputStream,
+ @ApiParam(value = "file detail",
+ required = false) @FormDataParam("file") FormDataContentDisposition fileDetail) {
+ return WorkflowInstanceWrapper.getInstance().deployBpmnFile(fileDetail.getFileName(),
+ fileInputStream, null);
+ }
+
+ @Path("/package/{deployId}")
+ @DELETE
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "undeploy bpmn file")
+ @ApiResponses(value = {
+ @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
+ response = DeployBpmnFileResponse.class),
+ @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
+ message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
+ @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "error")})
+ public RestResponse undeployBpmnFile(
+ @ApiParam("deployId") @PathParam("deployId") String deployId) {
+ return WorkflowInstanceWrapper.getInstance().undeployBpmnFile(deployId);
+ }
+
+ @Path("process/instance")
+ @POST
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "package process")
+ @ApiResponses(value = {
+ @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
+ response = DeployBpmnFileResponse.class),
+ @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
+ message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
+ @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "error")})
+ public Response startProcess(
+ @ApiParam(value = "request", required = false) StartProcessRequest request) {
+ return WorkflowInstanceWrapper.getInstance().startProcess(request);
+ }
+}
--- /dev/null
+/**\r
+ * Copyright 2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.onap.workflow.tools;\r
+\r
+import org.onap.workflow.common.EnumModuleUrl;\r
+\r
+public class Constants {\r
+ public final static String AUTHORIZATION ="Authorization";\r
+ public final static String HTTP_HEADER ="http://";\r
+ public final static String HTTP ="HTTP";\r
+ public final static String COLON =":";\r
+ public static final String ACITIVI_START_INSTANCE_URL =\r
+ EnumModuleUrl.ACTIVITI.getApiRootDomain() + "/runtime/process-instances";\r
+ public static final String DEPLOY_BPMNFILE_URL = EnumModuleUrl.ACTIVITI.getApiRootDomain() + "/repository/deployments";\r
+}\r
--- /dev/null
+/**\r
+ * Copyright 2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.onap.workflow.tools;\r
+\r
+import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;\r
+import java.net.URI;\r
+import org.apache.http.annotation.NotThreadSafe;\r
+\r
+@NotThreadSafe\r
+public class HttpDeleteWithBody extends HttpEntityEnclosingRequestBase {\r
+ public static final String METHOD_NAME = "DELETE";\r
+ public String getMethod() { return METHOD_NAME; }\r
+\r
+ public HttpDeleteWithBody(final String uri) {\r
+ super();\r
+ setURI(URI.create(uri));\r
+ }\r
+ public HttpDeleteWithBody(final URI uri) {\r
+ super();\r
+ setURI(uri);\r
+ }\r
+ public HttpDeleteWithBody() { super(); }\r
+}
\ No newline at end of file
--- /dev/null
+/**\r
+ * Copyright 2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.onap.workflow.tools;\r
+\r
+import lombok.Data;\r
+\r
+/**\r
+ * @author 10175158\r
+ *\r
+ */\r
+@Data\r
+public class RequestParameters {\r
+\r
+ protected boolean casCade;\r
+ @Override\r
+ public String toString() {\r
+ return "casCade [casCade=" + casCade + "]";\r
+ }\r
+}\r
+\r
+\r
--- /dev/null
+/**\r
+ * Copyright 2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.onap.workflow.tools;\r
--- /dev/null
+/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.workflow.wrapper;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
+import org.onap.workflow.common.EnumStatus;
+import org.onap.workflow.common.RestResponse;
+import org.onap.workflow.entity.DeployBpmnFileResponse;
+import org.onap.workflow.entity.StartProcessRequest;
+import org.onap.workflow.externalservice.entity.activitientitiy.ActivitiDeployResponse;
+import org.onap.workflow.externalservice.entity.activitientitiy.ActivitiStartProcessRequest;
+import org.onap.workflow.externalservice.entity.activitientitiy.ActivitiStartProcessRequestParam;
+import org.onap.workflow.externalservice.service.activitiservice.ActivitiServiceConsumer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class WorkflowInstanceWrapper {
+ private static final Logger logger = LoggerFactory.getLogger(WorkflowInstanceWrapper.class);
+
+ private static WorkflowInstanceWrapper wrapper = new WorkflowInstanceWrapper();
+
+ public static WorkflowInstanceWrapper getInstance() {
+ return wrapper;
+ }
+
+ public Response deployBpmnFile(String filename, InputStream fileInputStream,
+ FormDataContentDisposition fileDetail) {
+ try {
+ ActivitiDeployResponse deployresult =
+ ActivitiServiceConsumer.deploybpmnfile(fileInputStream, filename);
+ if (deployresult != null) {
+ DeployBpmnFileResponse result = new DeployBpmnFileResponse();
+ result.setStatus(EnumStatus.SUCCESS.ordinal());
+ result.setMessage(EnumStatus.SUCCESS.toString());
+ result.setDeployedId(deployresult.getId());
+ result.setProcessId(filename);
+ return Response.ok(result).build();
+ }
+ } catch (Exception e) {
+ logger.error("deployBpmnFile fail.", e);
+ }
+ return Response.serverError().build();
+ }
+
+ public RestResponse undeployBpmnFile(String deployId) {
+ return ActivitiServiceConsumer.undeploybpmnfile(deployId);
+ }
+
+ public Response startProcess(StartProcessRequest request) {
+ try {
+ ActivitiStartProcessRequest bpmnrequest = new ActivitiStartProcessRequest();
+ bpmnrequest.setProcessDefinitionKey(request.getProcessDefinitionKey());
+ if (request.getParams() != null) {
+ List<ActivitiStartProcessRequestParam> paramlist = convertProcessRequest(request);
+ bpmnrequest.setVariables(paramlist.toArray(new ActivitiStartProcessRequestParam[0]));
+ }
+ RestResponse result = ActivitiServiceConsumer.startBpmnProcess(bpmnrequest);
+ return Response.ok(result.getResult()).build();
+ } catch (Exception e) {
+ logger.error("startProcess fail.", e);
+ }
+ return Response.serverError().build();
+ }
+
+ private List<ActivitiStartProcessRequestParam> convertProcessRequest(
+ StartProcessRequest request) {
+ List<ActivitiStartProcessRequestParam> paramlist =
+ new ArrayList<ActivitiStartProcessRequestParam>();
+ while (request.getParams().keySet().iterator().hasNext()) {
+ String key = request.getParams().keySet().iterator().next();
+ ActivitiStartProcessRequestParam param = new ActivitiStartProcessRequestParam();
+ param.setName(key);
+ param.setValue(request.getParams().get(key));
+ paramlist.add(param);
+ }
+ return paramlist;
+ }
+}
--- /dev/null
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Swagger UI</title>
+ <link href='css/typography.css' media='screen' rel='stylesheet' type='text/css'/>
+ <link href='css/reset.css' media='screen' rel='stylesheet' type='text/css'/>
+ <link href='css/screen.css' media='screen' rel='stylesheet' type='text/css'/>
+ <link href='css/reset.css' media='print' rel='stylesheet' type='text/css'/>
+ <link href='css/screen.css' media='print' rel='stylesheet' type='text/css'/>
+ <script type="text/javascript" src="lib/shred.bundle.js"></script>
+ <script src='lib/jquery-1.8.0.min.js' type='text/javascript'></script>
+ <script src='lib/jquery.slideto.min.js' type='text/javascript'></script>
+ <script src='lib/jquery.wiggle.min.js' type='text/javascript'></script>
+ <script src='lib/jquery.ba-bbq.min.js' type='text/javascript'></script>
+ <script src='lib/handlebars-2.0.0.js' type='text/javascript'></script>
+ <script src='lib/underscore-min.js' type='text/javascript'></script>
+ <script src='lib/backbone-min.js' type='text/javascript'></script>
+ <script src='lib/swagger-client.js' type='text/javascript'></script>
+ <script src='swagger-ui.js' type='text/javascript'></script>
+ <script src='lib/highlight.7.3.pack.js' type='text/javascript'></script>
+ <script src='lib/marked.js' type='text/javascript'></script>
+
+ <!-- enabling this will enable oauth2 implicit scope support -->
+ <script src='lib/swagger-oauth.js' type='text/javascript'></script>
+ <script type="text/javascript">
+ $(function () {
+ var url = window.location.search.match(/url=([^&]+)/);
+ if (url && url.length > 1) {
+ url = decodeURIComponent(url[1]);
+ } else {
+ url = "/api/workflow/v1/swagger.json";
+ }
+ window.swaggerUi = new SwaggerUi({
+ url: url,
+ dom_id: "swagger-ui-container",
+ supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'],
+ onComplete: function(swaggerApi, swaggerUi){
+
+ if(typeof initOAuth == "function") {
+ /*
+ initOAuth({
+ clientId: "your-client-id",
+ realm: "your-realms",
+ appName: "your-app-name"
+ });
+ */
+ }
+ $('pre code').each(function(i, e) {
+ hljs.highlightBlock(e)
+ });
+ },
+ onFailure: function(data) {
+ log("Unable to Load SwaggerUI");
+ },
+ docExpansion: "none",
+ sorter : "alpha"
+ });
+
+ function addApiKeyAuthorization() {
+ var key = $('#input_apiKey')[0].value;
+ log("key: " + key);
+ if(key && key.trim() != "") {
+ log("added key " + key);
+ window.authorizations.add("api_key", new ApiKeyAuthorization("api_key", key, "query"));
+ }
+ }
+
+ $('#input_apiKey').change(function() {
+ addApiKeyAuthorization();
+ });
+
+ // if you have an apiKey you would like to pre-populate on the page for demonstration purposes...
+ /*
+ var apiKey = "myApiKeyXXXX123456789";
+ $('#input_apiKey').val(apiKey);
+ addApiKeyAuthorization();
+ */
+
+ window.swaggerUi.load();
+ });
+ </script>
+</head>
+
+<body class="swagger-section">
+<div id='header' style="display:none">
+ <div class="swagger-ui-wrap" >
+ <a id="logo" >zte conductor</a>
+ <form id='api_selector'>
+ <div class='input'><input placeholder="http://example.com/api" id="input_baseUrl" name="baseUrl" type="text"/></div>
+ <div class='input'><input placeholder="api_key" id="input_apiKey" name="apiKey" type="text"/></div>
+ <div class='input'><a id="explore" href="#">Explore</a></div>
+ </form>
+ </div>
+</div>
+
+<div id="message-bar" class="swagger-ui-wrap"> </div>
+<div id="swagger-ui-container" class="swagger-ui-wrap"></div>
+</body>
+</html>
--- /dev/null
+ _ ____ _____ ___ __ __ ___ _____ ___ _____ __ __ _____ \r
+ / \ / ___| |_ _| |_ _| \ \ / / |_ _| |_ _| |_ _| | ____| \ \/ / |_ _|\r
+ / _ \ | | | | | | \ \ / / | | | | | | _____ | _| \ / | | \r
+ / ___ \ | |___ | | | | \ V / | | | | | | |_____| | |___ / \ | | \r
+ /_/ \_\ \____| |_| |___| \_/ |___| |_| |___| |_____| /_/\_\ |_| \r
+
\ No newline at end of file