1 package org.onap.so.bpmn.infrastructure.manualhandling.tasks;
4 import java.util.HashMap;
6 import org.camunda.bpm.engine.TaskService;
7 import org.camunda.bpm.engine.delegate.BpmnError;
8 import org.camunda.bpm.engine.delegate.DelegateTask;
9 import org.camunda.bpm.engine.delegate.DelegateExecution;
10 import org.onap.so.client.exception.ExceptionBuilder;
11 import org.onap.so.client.ticket.ExternalTicket;
12 import org.onap.so.db.request.beans.InfraActiveRequests;
13 import org.onap.so.db.request.client.RequestsDbClient;
14 import org.onap.so.logger.ErrorCode;
15 import org.onap.so.logger.MessageEnum;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18 import org.springframework.beans.factory.annotation.Autowired;
19 import org.springframework.stereotype.Component;
22 public class ManualHandlingTasks {
23 private static final Logger logger = LoggerFactory.getLogger(ManualHandlingTasks.class);
25 private static final String TASK_TYPE_PAUSE = "pause";
26 private static final String TASK_TYPE_FALLOUT = "fallout";
29 private ExceptionBuilder exceptionUtil;
32 private RequestsDbClient requestDbclient;
34 public void setFalloutTaskVariables (DelegateTask task) {
36 DelegateExecution execution = task.getExecution();
38 String taskId = task.getId();
39 logger.debug("taskId is: " + taskId);
40 String type = TASK_TYPE_FALLOUT;
41 String nfRole = (String) execution.getVariable("vnfType");
42 String subscriptionServiceType = (String) execution.getVariable("serviceType");
43 String originalRequestId = (String) execution.getVariable("msoRequestId");
44 String originalRequestorId = (String) execution.getVariable("requestorId");
45 String description = "";
47 String errorSource = (String) execution.getVariable("failedActivity");
48 String errorCode = (String) execution.getVariable("errorCode");
49 String errorMessage = (String) execution.getVariable("errorText");
50 String buildingBlockName = (String) execution.getVariable("currentActivity");
51 String buildingBlockStep = (String) execution.getVariable("workStep");
52 String validResponses = (String) execution.getVariable("validResponses");
54 Map<String, String> taskVariables = new HashMap<String, String>();
55 taskVariables.put("type", type);
56 taskVariables.put("nfRole", nfRole);
57 taskVariables.put("subscriptionServiceType", subscriptionServiceType);
58 taskVariables.put("originalRequestId", originalRequestId);
59 taskVariables.put("originalRequestorId", originalRequestorId);
60 taskVariables.put("errorSource", errorSource);
61 taskVariables.put("errorCode", errorCode);
62 taskVariables.put("errorMessage", errorMessage);
63 taskVariables.put("buildingBlockName", buildingBlockName);
64 taskVariables.put("buildingBlockStep", buildingBlockStep);
65 taskVariables.put("validResponses", validResponses);
66 taskVariables.put("tmeout", timeout);
67 taskVariables.put("description", description);
68 TaskService taskService = execution.getProcessEngineServices().getTaskService();
70 taskService.setVariables(taskId, taskVariables);
71 logger.debug("successfully created fallout task: "+ taskId);
72 } catch (BpmnError e) {
73 logger.debug("BPMN exception: " + e.getMessage());
75 } catch (Exception ex){
76 String msg = "Exception in setFalloutTaskVariables " + ex.getMessage();
78 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
82 public void setPauseTaskVariables (DelegateTask task) {
84 DelegateExecution execution = task.getExecution();
87 String taskId = task.getId();
88 logger.debug("taskId is: " + taskId);
89 String type = TASK_TYPE_PAUSE;
90 String nfRole = (String) execution.getVariable("vnfType");
91 String subscriptionServiceType = (String) execution.getVariable("serviceType");
92 String originalRequestId = (String) execution.getVariable("msoRequestId");
93 String originalRequestorId = (String) execution.getVariable("requestorId");
94 String description = (String) execution.getVariable("description");
95 String timeout = (String) execution.getVariable("taskTimeout");
96 String errorSource = "";
97 String errorCode = "";
98 String errorMessage = "";
99 String buildingBlockName = "";
100 String buildingBlockStep = "";
101 String validResponses = (String) execution.getVariable("validResponses");
103 Map<String, String> taskVariables = new HashMap<String, String>();
104 taskVariables.put("type", type);
105 taskVariables.put("nfRole", nfRole);
106 taskVariables.put("description", description);
107 taskVariables.put("timeout", timeout);
108 taskVariables.put("subscriptionServiceType", subscriptionServiceType);
109 taskVariables.put("originalRequestId", originalRequestId);
110 taskVariables.put("originalRequestorId", originalRequestorId);
111 taskVariables.put("errorSource", errorSource);
112 taskVariables.put("errorCode", errorCode);
113 taskVariables.put("errorMessage", errorMessage);
114 taskVariables.put("buildingBlockName", buildingBlockName);
115 taskVariables.put("buildingBlockStep", buildingBlockStep);
116 taskVariables.put("validResponses", validResponses);
117 TaskService taskService = execution.getProcessEngineServices().getTaskService();
119 taskService.setVariables(taskId, taskVariables);
120 logger.debug("successfully created pause task: "+ taskId);
121 } catch (BpmnError e) {
122 logger.debug("BPMN exception: " + e.getMessage());
124 } catch (Exception ex){
125 String msg = "Exception in setPauseTaskVariables " + ex.getMessage();
127 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
132 public void completeTask (DelegateTask task) {
134 DelegateExecution execution = task.getExecution();
138 String taskId = task.getId();
139 logger.debug("taskId is: " + taskId);
140 TaskService taskService = execution.getProcessEngineServices().getTaskService();
142 Map<String, Object> taskVariables = taskService.getVariables(taskId);
143 String responseValue = (String) taskVariables.get("responseValue");
145 logger.debug("Received responseValue on completion: "+ responseValue);
146 // Have to set the first letter of the response to upper case
147 String responseValueUppercaseStart = 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", ErrorCode.UnknownError.getValue());
183 } catch (Exception ex){
184 String msg = "Exception in createExternalTicket " + ex.getMessage();
185 logger.error("{} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", ErrorCode.UnknownError.getValue());
190 public void updateRequestDbStatus(DelegateExecution execution, String status) {
192 String requestId = (String) execution.getVariable("msoRequestId");
193 InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId);
195 request.setRequestStatus(status);
196 request.setLastModifiedBy("ManualHandling");
198 requestDbclient.updateInfraActiveRequests(request);
199 } catch (Exception e) {
200 logger.error("Unable to save the updated request status to the DB",e);