2 * Copyright 2017 ZTE Corporation.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
16 package org.onap.workflow.externalservice.service.activitiservice;
\r
18 import java.io.IOException;
\r
19 import java.io.InputStream;
\r
21 import javax.ws.rs.core.Response;
\r
23 import org.apache.http.client.ClientProtocolException;
\r
24 import org.onap.workflow.common.Config;
\r
25 import org.onap.workflow.common.EnumModuleUrl;
\r
26 import org.onap.workflow.common.RestClient;
\r
27 import org.onap.workflow.common.RestClientUtils;
\r
28 import org.onap.workflow.common.RestResponse;
\r
29 import org.onap.workflow.common.ToolUtil;
\r
30 import org.onap.workflow.externalservice.entity.activitientitiy.ActivitiDeployResponse;
\r
31 import org.onap.workflow.externalservice.entity.activitientitiy.ActivitiStartProcessRequest;
\r
32 import org.onap.workflow.tools.Constants;
\r
33 import org.slf4j.Logger;
\r
34 import org.slf4j.LoggerFactory;
\r
36 import com.google.gson.Gson;
\r
43 public class ActivitiServiceConsumer {
\r
44 private static final Logger logger = LoggerFactory.getLogger(ActivitiServiceConsumer.class);
\r
45 private static final String DEPLOY_BPMNFILE_URL =
\r
46 EnumModuleUrl.ACTIVITI.getApiRootDomain() + "/repository/deployments";
\r
48 public static RestResponse undeploybpmnfile(String deploymentId) {
\r
49 return deleteDeployProcess(deploymentId);
\r
52 public static RestResponse startBpmnProcess(ActivitiStartProcessRequest request) {
\r
53 return startProcess(request);
\r
56 public static RestResponse deleteDeployProcess(String deploymentId) {
\r
57 RestResponse res = null;
\r
59 res = RestClient.post(null, null, Constants.DEPLOY_BPMNFILE_URL + "/" + deploymentId);
\r
60 } catch (Exception e) {
\r
67 public static RestResponse startProcess(ActivitiStartProcessRequest request) {
\r
68 RestResponse res = null;
\r
70 res = RestClient.post(null, null, Constants.ACITIVI_START_INSTANCE_URL, request);
\r
71 } catch (Exception e) {
\r
77 public static ActivitiDeployResponse deploybpmnfile(InputStream ins, String filename)
\r
78 throws ClientProtocolException, IOException {
\r
80 return deployPackage2Activiti(ins, filename);
\r
82 ToolUtil.closeInputStream(ins);
\r
86 private static ActivitiDeployResponse deployPackage2Activiti(InputStream ins, String filename)
\r
87 throws ClientProtocolException, IOException {
\r
88 String ip = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrIp();
\r
89 int port = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrPort();
\r
90 RestResponse res = RestClient.post(ip, port, DEPLOY_BPMNFILE_URL,
\r
91 RestClientUtils.buildMultipartRequest(ins, filename));
\r
92 logger.info("deployfile to activiti return. {}", res);
\r
94 if (Response.Status.OK.getStatusCode() == res.getStatusCode()
\r
95 || Response.Status.CREATED.getStatusCode() == res.getStatusCode()) {
\r
96 ActivitiDeployResponse response =
\r
97 new Gson().fromJson(res.getResult(), ActivitiDeployResponse.class);
\r