1 package org.onap.so.bpmn.infrastructure.manualhandling.tasks;
4 import java.util.HashMap;
5 import org.camunda.bpm.engine.TaskService;
6 import org.camunda.bpm.engine.delegate.BpmnError;
7 import org.camunda.bpm.engine.delegate.DelegateTask;
8 import org.camunda.bpm.engine.delegate.DelegateExecution;
9 import org.onap.so.client.exception.ExceptionBuilder;
10 import org.onap.so.client.ticket.ExternalTicket;
11 import org.onap.so.db.request.beans.InfraActiveRequests;
12 import org.onap.so.db.request.client.RequestsDbClient;
13 import org.onap.so.logger.ErrorCode;
14 import org.onap.so.logger.MessageEnum;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17 import org.springframework.beans.factory.annotation.Autowired;
18 import org.springframework.stereotype.Component;
21 public class ManualHandlingTasks {
22 private static final Logger logger = LoggerFactory.getLogger(ManualHandlingTasks.class);
24 private static final String TASK_TYPE_PAUSE = "pause";
25 private static final String TASK_TYPE_FALLOUT = "fallout";
26 public static final String VNF_TYPE = "vnfType";
27 public static final String SERVICE_TYPE = "serviceType";
28 public static final String MSO_REQUEST_ID = "msoRequestId";
29 public static final String REQUESTOR_ID = "requestorId";
30 public static final String ERROR_CODE = "errorCode";
31 public static final String VALID_RESPONSES = "validResponses";
32 public static final String DESCRIPTION = "description";
33 public static final String BPMN_EXCEPTION = "BPMN exception: ";
36 private ExceptionBuilder exceptionUtil;
39 private RequestsDbClient requestDbclient;
41 public void setFalloutTaskVariables(DelegateTask task) {
43 DelegateExecution execution = task.getExecution();
45 String taskId = task.getId();
46 logger.debug("taskId is: " + taskId);
47 String type = TASK_TYPE_FALLOUT;
48 String nfRole = (String) execution.getVariable(VNF_TYPE);
49 String subscriptionServiceType = (String) execution.getVariable(SERVICE_TYPE);
50 String originalRequestId = (String) execution.getVariable(MSO_REQUEST_ID);
51 String originalRequestorId = (String) execution.getVariable(REQUESTOR_ID);
52 String description = "";
54 String errorSource = (String) execution.getVariable("failedActivity");
55 String errorCode = (String) execution.getVariable(ERROR_CODE);
56 String errorMessage = (String) execution.getVariable("errorText");
57 String buildingBlockName = (String) execution.getVariable("currentActivity");
58 String buildingBlockStep = (String) execution.getVariable("workStep");
59 String validResponses = (String) execution.getVariable(VALID_RESPONSES);
61 Map<String, String> taskVariables = new HashMap<>();
62 taskVariables.put("type", type);
63 taskVariables.put("nfRole", nfRole);
64 taskVariables.put("subscriptionServiceType", subscriptionServiceType);
65 taskVariables.put("originalRequestId", originalRequestId);
66 taskVariables.put("originalRequestorId", originalRequestorId);
67 taskVariables.put("errorSource", errorSource);
68 taskVariables.put(ERROR_CODE, errorCode);
69 taskVariables.put("errorMessage", errorMessage);
70 taskVariables.put("buildingBlockName", buildingBlockName);
71 taskVariables.put("buildingBlockStep", buildingBlockStep);
72 taskVariables.put(VALID_RESPONSES, validResponses);
73 taskVariables.put("tmeout", timeout);
74 taskVariables.put(DESCRIPTION, description);
75 TaskService taskService = execution.getProcessEngineServices().getTaskService();
77 taskService.setVariables(taskId, taskVariables);
78 logger.debug("successfully created fallout task: " + taskId);
79 } catch (BpmnError e) {
80 logger.debug(BPMN_EXCEPTION + e.getMessage());
82 } catch (Exception ex) {
83 String msg = "Exception in setFalloutTaskVariables " + ex.getMessage();
85 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
89 public void setPauseTaskVariables(DelegateTask task) {
91 DelegateExecution execution = task.getExecution();
94 String taskId = task.getId();
95 logger.debug("taskId is: " + taskId);
96 String type = TASK_TYPE_PAUSE;
97 String nfRole = (String) execution.getVariable(VNF_TYPE);
98 String subscriptionServiceType = (String) execution.getVariable(SERVICE_TYPE);
99 String originalRequestId = (String) execution.getVariable(MSO_REQUEST_ID);
100 String originalRequestorId = (String) execution.getVariable(REQUESTOR_ID);
101 String description = (String) execution.getVariable(DESCRIPTION);
102 String timeout = (String) execution.getVariable("taskTimeout");
103 String errorSource = "";
104 String errorCode = "";
105 String errorMessage = "";
106 String buildingBlockName = "";
107 String buildingBlockStep = "";
108 String validResponses = (String) execution.getVariable(VALID_RESPONSES);
110 Map<String, String> taskVariables = new HashMap<>();
111 taskVariables.put("type", type);
112 taskVariables.put("nfRole", nfRole);
113 taskVariables.put(DESCRIPTION, description);
114 taskVariables.put("timeout", timeout);
115 taskVariables.put("subscriptionServiceType", subscriptionServiceType);
116 taskVariables.put("originalRequestId", originalRequestId);
117 taskVariables.put("originalRequestorId", originalRequestorId);
118 taskVariables.put("errorSource", errorSource);
119 taskVariables.put(ERROR_CODE, errorCode);
120 taskVariables.put("errorMessage", errorMessage);
121 taskVariables.put("buildingBlockName", buildingBlockName);
122 taskVariables.put("buildingBlockStep", buildingBlockStep);
123 taskVariables.put(VALID_RESPONSES, validResponses);
124 TaskService taskService = execution.getProcessEngineServices().getTaskService();
126 taskService.setVariables(taskId, taskVariables);
127 logger.debug("successfully created pause task: " + taskId);
128 } catch (BpmnError e) {
129 logger.debug(BPMN_EXCEPTION + e.getMessage());
131 } catch (Exception ex) {
132 String msg = "Exception in setPauseTaskVariables " + ex.getMessage();
134 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
139 public void completeTask(DelegateTask task) {
141 DelegateExecution execution = task.getExecution();
145 String taskId = task.getId();
146 logger.debug("taskId is: " + taskId);
147 TaskService taskService = execution.getProcessEngineServices().getTaskService();
149 Map<String, Object> taskVariables = taskService.getVariables(taskId);
150 String responseValue = (String) taskVariables.get("responseValue");
152 logger.debug("Received responseValue on completion: " + responseValue);
153 // Have to set the first letter of the response to upper case
154 String responseValueUppercaseStart =
155 responseValue.substring(0, 1).toUpperCase() + responseValue.substring(1);
156 logger.debug("ResponseValue to taskListener: " + responseValueUppercaseStart);
157 execution.setVariable("responseValueTask", responseValueUppercaseStart);
159 } catch (BpmnError e) {
160 logger.debug(BPMN_EXCEPTION + e.getMessage());
162 } catch (Exception ex) {
163 String msg = "Exception in completeManualTask " + ex.getMessage();
165 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
170 public void createExternalTicket(DelegateExecution execution) {
173 ExternalTicket ticket = new ExternalTicket();
175 ticket.setRequestId((String) execution.getVariable(MSO_REQUEST_ID));
176 ticket.setCurrentActivity((String) execution.getVariable("currentActivity"));
177 ticket.setNfRole((String) execution.getVariable(VNF_TYPE));
178 ticket.setDescription((String) execution.getVariable(DESCRIPTION));
179 ticket.setSubscriptionServiceType((String) execution.getVariable(SERVICE_TYPE));
180 ticket.setRequestorId((String) execution.getVariable(REQUESTOR_ID));
181 ticket.setTimeout((String) execution.getVariable("taskTimeout"));
182 ticket.setErrorSource((String) execution.getVariable("failedActivity"));
183 ticket.setErrorCode((String) execution.getVariable(ERROR_CODE));
184 ticket.setErrorMessage((String) execution.getVariable("errorText"));
185 ticket.setWorkStep((String) execution.getVariable("workStep"));
187 ticket.createTicket();
188 } catch (BpmnError e) {
189 String msg = "BPMN error in createAOTSTicket " + e.getMessage();
190 logger.error("{} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN",
191 ErrorCode.UnknownError.getValue());
192 } catch (Exception ex) {
193 String msg = "Exception in createExternalTicket " + ex.getMessage();
194 logger.error("{} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN",
195 ErrorCode.UnknownError.getValue());
200 public void updateRequestDbStatus(DelegateExecution execution, String status) {
202 String requestId = (String) execution.getVariable(MSO_REQUEST_ID);
203 InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId);
205 request.setRequestStatus(status);
206 request.setLastModifiedBy("ManualHandling");
208 requestDbclient.updateInfraActiveRequests(request);
209 } catch (Exception e) {
210 logger.error("Unable to save the updated request status to the DB", e);