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";
28 private ExceptionBuilder exceptionUtil;
31 private RequestsDbClient requestDbclient;
33 public void setFalloutTaskVariables(DelegateTask task) {
35 DelegateExecution execution = task.getExecution();
37 String taskId = task.getId();
38 logger.debug("taskId is: " + taskId);
39 String type = TASK_TYPE_FALLOUT;
40 String nfRole = (String) execution.getVariable("vnfType");
41 String subscriptionServiceType = (String) execution.getVariable("serviceType");
42 String originalRequestId = (String) execution.getVariable("msoRequestId");
43 String originalRequestorId = (String) execution.getVariable("requestorId");
44 String description = "";
46 String errorSource = (String) execution.getVariable("failedActivity");
47 String errorCode = (String) execution.getVariable("errorCode");
48 String errorMessage = (String) execution.getVariable("errorText");
49 String buildingBlockName = (String) execution.getVariable("currentActivity");
50 String buildingBlockStep = (String) execution.getVariable("workStep");
51 String validResponses = (String) execution.getVariable("validResponses");
53 Map<String, String> taskVariables = new HashMap<String, String>();
54 taskVariables.put("type", type);
55 taskVariables.put("nfRole", nfRole);
56 taskVariables.put("subscriptionServiceType", subscriptionServiceType);
57 taskVariables.put("originalRequestId", originalRequestId);
58 taskVariables.put("originalRequestorId", originalRequestorId);
59 taskVariables.put("errorSource", errorSource);
60 taskVariables.put("errorCode", errorCode);
61 taskVariables.put("errorMessage", errorMessage);
62 taskVariables.put("buildingBlockName", buildingBlockName);
63 taskVariables.put("buildingBlockStep", buildingBlockStep);
64 taskVariables.put("validResponses", validResponses);
65 taskVariables.put("tmeout", timeout);
66 taskVariables.put("description", description);
67 TaskService taskService = execution.getProcessEngineServices().getTaskService();
69 taskService.setVariables(taskId, taskVariables);
70 logger.debug("successfully created fallout task: " + taskId);
71 } catch (BpmnError e) {
72 logger.debug("BPMN exception: " + e.getMessage());
74 } catch (Exception ex) {
75 String msg = "Exception in setFalloutTaskVariables " + ex.getMessage();
77 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
81 public void setPauseTaskVariables(DelegateTask task) {
83 DelegateExecution execution = task.getExecution();
86 String taskId = task.getId();
87 logger.debug("taskId is: " + taskId);
88 String type = TASK_TYPE_PAUSE;
89 String nfRole = (String) execution.getVariable("vnfType");
90 String subscriptionServiceType = (String) execution.getVariable("serviceType");
91 String originalRequestId = (String) execution.getVariable("msoRequestId");
92 String originalRequestorId = (String) execution.getVariable("requestorId");
93 String description = (String) execution.getVariable("description");
94 String timeout = (String) execution.getVariable("taskTimeout");
95 String errorSource = "";
96 String errorCode = "";
97 String errorMessage = "";
98 String buildingBlockName = "";
99 String buildingBlockStep = "";
100 String validResponses = (String) execution.getVariable("validResponses");
102 Map<String, String> taskVariables = new HashMap<String, String>();
103 taskVariables.put("type", type);
104 taskVariables.put("nfRole", nfRole);
105 taskVariables.put("description", description);
106 taskVariables.put("timeout", timeout);
107 taskVariables.put("subscriptionServiceType", subscriptionServiceType);
108 taskVariables.put("originalRequestId", originalRequestId);
109 taskVariables.put("originalRequestorId", originalRequestorId);
110 taskVariables.put("errorSource", errorSource);
111 taskVariables.put("errorCode", errorCode);
112 taskVariables.put("errorMessage", errorMessage);
113 taskVariables.put("buildingBlockName", buildingBlockName);
114 taskVariables.put("buildingBlockStep", buildingBlockStep);
115 taskVariables.put("validResponses", validResponses);
116 TaskService taskService = execution.getProcessEngineServices().getTaskService();
118 taskService.setVariables(taskId, taskVariables);
119 logger.debug("successfully created pause task: " + taskId);
120 } catch (BpmnError e) {
121 logger.debug("BPMN exception: " + e.getMessage());
123 } catch (Exception ex) {
124 String msg = "Exception in setPauseTaskVariables " + ex.getMessage();
126 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
131 public void completeTask(DelegateTask task) {
133 DelegateExecution execution = task.getExecution();
137 String taskId = task.getId();
138 logger.debug("taskId is: " + taskId);
139 TaskService taskService = execution.getProcessEngineServices().getTaskService();
141 Map<String, Object> taskVariables = taskService.getVariables(taskId);
142 String responseValue = (String) taskVariables.get("responseValue");
144 logger.debug("Received responseValue on completion: " + responseValue);
145 // Have to set the first letter of the response to upper case
146 String responseValueUppercaseStart =
147 responseValue.substring(0, 1).toUpperCase() + responseValue.substring(1);
148 logger.debug("ResponseValue to taskListener: " + responseValueUppercaseStart);
149 execution.setVariable("responseValueTask", responseValueUppercaseStart);
151 } catch (BpmnError e) {
152 logger.debug("BPMN exception: " + e.getMessage());
154 } catch (Exception ex) {
155 String msg = "Exception in completeManualTask " + ex.getMessage();
157 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
162 public void createExternalTicket(DelegateExecution execution) {
165 ExternalTicket ticket = new ExternalTicket();
167 ticket.setRequestId((String) execution.getVariable("msoRequestId"));
168 ticket.setCurrentActivity((String) execution.getVariable("currentActivity"));
169 ticket.setNfRole((String) execution.getVariable("vnfType"));
170 ticket.setDescription((String) execution.getVariable("description"));
171 ticket.setSubscriptionServiceType((String) execution.getVariable("serviceType"));
172 ticket.setRequestorId((String) execution.getVariable("requestorId"));
173 ticket.setTimeout((String) execution.getVariable("taskTimeout"));
174 ticket.setErrorSource((String) execution.getVariable("failedActivity"));
175 ticket.setErrorCode((String) execution.getVariable("errorCode"));
176 ticket.setErrorMessage((String) execution.getVariable("errorText"));
177 ticket.setWorkStep((String) execution.getVariable("workStep"));
179 ticket.createTicket();
180 } catch (BpmnError e) {
181 String msg = "BPMN error in createAOTSTicket " + e.getMessage();
182 logger.error("{} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN",
183 ErrorCode.UnknownError.getValue());
184 } catch (Exception ex) {
185 String msg = "Exception in createExternalTicket " + ex.getMessage();
186 logger.error("{} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN",
187 ErrorCode.UnknownError.getValue());
192 public void updateRequestDbStatus(DelegateExecution execution, String status) {
194 String requestId = (String) execution.getVariable("msoRequestId");
195 InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId);
197 request.setRequestStatus(status);
198 request.setLastModifiedBy("ManualHandling");
200 requestDbclient.updateInfraActiveRequests(request);
201 } catch (Exception e) {
202 logger.error("Unable to save the updated request status to the DB", e);