2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.bpmn.infrastructure.manualhandling.tasks;
24 import java.util.HashMap;
25 import org.onap.so.logger.LoggingAnchor;
26 import org.camunda.bpm.engine.TaskService;
27 import org.camunda.bpm.engine.delegate.BpmnError;
28 import org.camunda.bpm.engine.delegate.DelegateTask;
29 import org.camunda.bpm.engine.delegate.DelegateExecution;
30 import org.onap.so.client.exception.ExceptionBuilder;
31 import org.onap.so.client.ticket.ExternalTicket;
32 import org.onap.so.db.request.beans.InfraActiveRequests;
33 import org.onap.so.db.request.client.RequestsDbClient;
34 import org.onap.so.logger.ErrorCode;
35 import org.onap.so.logger.MessageEnum;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
38 import org.springframework.beans.factory.annotation.Autowired;
39 import org.springframework.stereotype.Component;
42 public class ManualHandlingTasks {
43 private static final Logger logger = LoggerFactory.getLogger(ManualHandlingTasks.class);
45 private static final String TASK_TYPE_PAUSE = "pause";
46 private static final String TASK_TYPE_FALLOUT = "fallout";
47 public static final String VNF_TYPE = "vnfType";
48 public static final String SERVICE_TYPE = "serviceType";
49 public static final String MSO_REQUEST_ID = "msoRequestId";
50 public static final String REQUESTOR_ID = "requestorId";
51 public static final String ERROR_CODE = "errorCode";
52 public static final String VALID_RESPONSES = "validResponses";
53 public static final String DESCRIPTION = "description";
54 public static final String BPMN_EXCEPTION = "BPMN exception: ";
57 private ExceptionBuilder exceptionUtil;
60 private RequestsDbClient requestDbclient;
62 public void setFalloutTaskVariables(DelegateTask task) {
64 DelegateExecution execution = task.getExecution();
66 String taskId = task.getId();
67 logger.debug("taskId is: " + taskId);
68 String type = TASK_TYPE_FALLOUT;
69 String nfRole = (String) execution.getVariable(VNF_TYPE);
70 String subscriptionServiceType = (String) execution.getVariable(SERVICE_TYPE);
71 String originalRequestId = (String) execution.getVariable(MSO_REQUEST_ID);
72 String originalRequestorId = (String) execution.getVariable(REQUESTOR_ID);
73 String description = "";
75 String errorSource = (String) execution.getVariable("failedActivity");
76 String errorCode = (String) execution.getVariable(ERROR_CODE);
77 String errorMessage = (String) execution.getVariable("errorText");
78 String buildingBlockName = (String) execution.getVariable("currentActivity");
79 String buildingBlockStep = (String) execution.getVariable("workStep");
80 String validResponses = (String) execution.getVariable(VALID_RESPONSES);
82 Map<String, String> taskVariables = new HashMap<>();
83 taskVariables.put("type", type);
84 taskVariables.put("nfRole", nfRole);
85 taskVariables.put("subscriptionServiceType", subscriptionServiceType);
86 taskVariables.put("originalRequestId", originalRequestId);
87 taskVariables.put("originalRequestorId", originalRequestorId);
88 taskVariables.put("errorSource", errorSource);
89 taskVariables.put(ERROR_CODE, errorCode);
90 taskVariables.put("errorMessage", errorMessage);
91 taskVariables.put("buildingBlockName", buildingBlockName);
92 taskVariables.put("buildingBlockStep", buildingBlockStep);
93 taskVariables.put(VALID_RESPONSES, validResponses);
94 taskVariables.put("tmeout", timeout);
95 taskVariables.put(DESCRIPTION, description);
96 TaskService taskService = execution.getProcessEngineServices().getTaskService();
98 taskService.setVariables(taskId, taskVariables);
99 logger.debug("successfully created fallout task: " + taskId);
100 } catch (BpmnError e) {
101 logger.debug(BPMN_EXCEPTION + e.getMessage());
103 } catch (Exception ex) {
104 String msg = "Exception in setFalloutTaskVariables " + ex.getMessage();
106 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
110 public void setPauseTaskVariables(DelegateTask task) {
112 DelegateExecution execution = task.getExecution();
115 String taskId = task.getId();
116 logger.debug("taskId is: " + taskId);
117 String type = TASK_TYPE_PAUSE;
118 String nfRole = (String) execution.getVariable(VNF_TYPE);
119 String subscriptionServiceType = (String) execution.getVariable(SERVICE_TYPE);
120 String originalRequestId = (String) execution.getVariable(MSO_REQUEST_ID);
121 String originalRequestorId = (String) execution.getVariable(REQUESTOR_ID);
122 String description = (String) execution.getVariable(DESCRIPTION);
123 String timeout = (String) execution.getVariable("taskTimeout");
124 String errorSource = "";
125 String errorCode = "";
126 String errorMessage = "";
127 String buildingBlockName = "";
128 String buildingBlockStep = "";
129 String validResponses = (String) execution.getVariable(VALID_RESPONSES);
131 Map<String, String> taskVariables = new HashMap<>();
132 taskVariables.put("type", type);
133 taskVariables.put("nfRole", nfRole);
134 taskVariables.put(DESCRIPTION, description);
135 taskVariables.put("timeout", timeout);
136 taskVariables.put("subscriptionServiceType", subscriptionServiceType);
137 taskVariables.put("originalRequestId", originalRequestId);
138 taskVariables.put("originalRequestorId", originalRequestorId);
139 taskVariables.put("errorSource", errorSource);
140 taskVariables.put(ERROR_CODE, errorCode);
141 taskVariables.put("errorMessage", errorMessage);
142 taskVariables.put("buildingBlockName", buildingBlockName);
143 taskVariables.put("buildingBlockStep", buildingBlockStep);
144 taskVariables.put(VALID_RESPONSES, validResponses);
145 TaskService taskService = execution.getProcessEngineServices().getTaskService();
147 taskService.setVariables(taskId, taskVariables);
148 logger.debug("successfully created pause task: " + taskId);
149 } catch (BpmnError e) {
150 logger.debug(BPMN_EXCEPTION + e.getMessage());
152 } catch (Exception ex) {
153 String msg = "Exception in setPauseTaskVariables " + ex.getMessage();
155 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
160 public void completeTask(DelegateTask task) {
162 DelegateExecution execution = task.getExecution();
166 String taskId = task.getId();
167 logger.debug("taskId is: " + taskId);
168 TaskService taskService = execution.getProcessEngineServices().getTaskService();
170 Map<String, Object> taskVariables = taskService.getVariables(taskId);
171 String responseValue = (String) taskVariables.get("responseValue");
173 logger.debug("Received responseValue on completion: " + responseValue);
174 // Have to set the first letter of the response to upper case
175 String responseValueUppercaseStart =
176 responseValue.substring(0, 1).toUpperCase() + responseValue.substring(1);
177 logger.debug("ResponseValue to taskListener: " + responseValueUppercaseStart);
178 execution.setVariable("responseValueTask", responseValueUppercaseStart);
180 } catch (BpmnError e) {
181 logger.debug(BPMN_EXCEPTION + e.getMessage());
183 } catch (Exception ex) {
184 String msg = "Exception in completeManualTask " + ex.getMessage();
186 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
191 public void createExternalTicket(DelegateExecution execution) {
194 ExternalTicket ticket = new ExternalTicket();
196 ticket.setRequestId((String) execution.getVariable(MSO_REQUEST_ID));
197 ticket.setCurrentActivity((String) execution.getVariable("currentActivity"));
198 ticket.setNfRole((String) execution.getVariable(VNF_TYPE));
199 ticket.setDescription((String) execution.getVariable(DESCRIPTION));
200 ticket.setSubscriptionServiceType((String) execution.getVariable(SERVICE_TYPE));
201 ticket.setRequestorId((String) execution.getVariable(REQUESTOR_ID));
202 ticket.setTimeout((String) execution.getVariable("taskTimeout"));
203 ticket.setErrorSource((String) execution.getVariable("failedActivity"));
204 ticket.setErrorCode((String) execution.getVariable(ERROR_CODE));
205 ticket.setErrorMessage((String) execution.getVariable("errorText"));
206 ticket.setWorkStep((String) execution.getVariable("workStep"));
208 ticket.createTicket();
209 } catch (BpmnError e) {
210 String msg = "BPMN error in createAOTSTicket " + e.getMessage();
211 logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN",
212 ErrorCode.UnknownError.getValue());
213 } catch (Exception ex) {
214 String msg = "Exception in createExternalTicket " + ex.getMessage();
215 logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN",
216 ErrorCode.UnknownError.getValue());
221 public void updateRequestDbStatus(DelegateExecution execution, String status) {
223 String requestId = (String) execution.getVariable(MSO_REQUEST_ID);
224 InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId);
226 request.setRequestStatus(status);
227 request.setLastModifiedBy("ManualHandling");
229 requestDbclient.updateInfraActiveRequests(request);
230 } catch (Exception e) {
231 logger.error("Unable to save the updated request status to the DB", e);