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