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.MessageEnum;
15 import org.onap.so.logger.MsoLogger;
16 import org.springframework.beans.factory.annotation.Autowired;
17 import org.springframework.stereotype.Component;
20 public class ManualHandlingTasks {
21 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, ManualHandlingTasks.class);
23 private static final String TASK_TYPE_PAUSE = "pause";
24 private static final String TASK_TYPE_FALLOUT = "fallout";
27 private ExceptionBuilder exceptionUtil;
30 private RequestsDbClient requestDbclient;
32 public void setFalloutTaskVariables (DelegateTask task) {
34 DelegateExecution execution = task.getExecution();
36 String taskId = task.getId();
37 msoLogger.debug("taskId is: " + taskId);
38 String type = TASK_TYPE_FALLOUT;
39 String nfRole = (String) execution.getVariable("vnfType");
40 String subscriptionServiceType = (String) execution.getVariable("serviceType");
41 String originalRequestId = (String) execution.getVariable("msoRequestId");
42 String originalRequestorId = (String) execution.getVariable("requestorId");
43 String description = "";
45 String errorSource = (String) execution.getVariable("failedActivity");
46 String errorCode = (String) execution.getVariable("errorCode");
47 String errorMessage = (String) execution.getVariable("errorText");
48 String buildingBlockName = (String) execution.getVariable("currentActivity");
49 String buildingBlockStep = (String) execution.getVariable("workStep");
50 String validResponses = (String) execution.getVariable("validResponses");
52 Map<String, String> taskVariables = new HashMap<String, String>();
53 taskVariables.put("type", type);
54 taskVariables.put("nfRole", nfRole);
55 taskVariables.put("subscriptionServiceType", subscriptionServiceType);
56 taskVariables.put("originalRequestId", originalRequestId);
57 taskVariables.put("originalRequestorId", originalRequestorId);
58 taskVariables.put("errorSource", errorSource);
59 taskVariables.put("errorCode", errorCode);
60 taskVariables.put("errorMessage", errorMessage);
61 taskVariables.put("buildingBlockName", buildingBlockName);
62 taskVariables.put("buildingBlockStep", buildingBlockStep);
63 taskVariables.put("validResponses", validResponses);
64 taskVariables.put("tmeout", timeout);
65 taskVariables.put("description", description);
66 TaskService taskService = execution.getProcessEngineServices().getTaskService();
68 taskService.setVariables(taskId, taskVariables);
69 msoLogger.debug("successfully created fallout task: "+ taskId);
70 } catch (BpmnError e) {
71 msoLogger.debug("BPMN exception: " + e.getMessage());
73 } catch (Exception ex){
74 String msg = "Exception in setFalloutTaskVariables " + ex.getMessage();
76 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
80 public void setPauseTaskVariables (DelegateTask task) {
82 DelegateExecution execution = task.getExecution();
85 String taskId = task.getId();
86 msoLogger.debug("taskId is: " + taskId);
87 String type = TASK_TYPE_PAUSE;
88 String nfRole = (String) execution.getVariable("vnfType");
89 String subscriptionServiceType = (String) execution.getVariable("serviceType");
90 String originalRequestId = (String) execution.getVariable("msoRequestId");
91 String originalRequestorId = (String) execution.getVariable("requestorId");
92 String description = (String) execution.getVariable("description");
93 String timeout = (String) execution.getVariable("taskTimeout");
94 String errorSource = "";
95 String errorCode = "";
96 String errorMessage = "";
97 String buildingBlockName = "";
98 String buildingBlockStep = "";
99 String validResponses = (String) execution.getVariable("validResponses");
101 Map<String, String> taskVariables = new HashMap<String, String>();
102 taskVariables.put("type", type);
103 taskVariables.put("nfRole", nfRole);
104 taskVariables.put("description", description);
105 taskVariables.put("timeout", timeout);
106 taskVariables.put("subscriptionServiceType", subscriptionServiceType);
107 taskVariables.put("originalRequestId", originalRequestId);
108 taskVariables.put("originalRequestorId", originalRequestorId);
109 taskVariables.put("errorSource", errorSource);
110 taskVariables.put("errorCode", errorCode);
111 taskVariables.put("errorMessage", errorMessage);
112 taskVariables.put("buildingBlockName", buildingBlockName);
113 taskVariables.put("buildingBlockStep", buildingBlockStep);
114 taskVariables.put("validResponses", validResponses);
115 TaskService taskService = execution.getProcessEngineServices().getTaskService();
117 taskService.setVariables(taskId, taskVariables);
118 msoLogger.debug("successfully created pause task: "+ taskId);
119 } catch (BpmnError e) {
120 msoLogger.debug("BPMN exception: " + e.getMessage());
122 } catch (Exception ex){
123 String msg = "Exception in setPauseTaskVariables " + ex.getMessage();
124 msoLogger.debug(msg);
125 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
130 public void completeTask (DelegateTask task) {
132 DelegateExecution execution = task.getExecution();
136 String taskId = task.getId();
137 msoLogger.debug("taskId is: " + taskId);
138 TaskService taskService = execution.getProcessEngineServices().getTaskService();
140 Map<String, Object> taskVariables = taskService.getVariables(taskId);
141 String responseValue = (String) taskVariables.get("responseValue");
143 msoLogger.debug("Received responseValue on completion: "+ responseValue);
144 // Have to set the first letter of the response to upper case
145 String responseValueUppercaseStart = responseValue.substring(0, 1).toUpperCase() + responseValue.substring(1);
146 msoLogger.debug("ResponseValue to taskListener: "+ responseValueUppercaseStart);
147 execution.setVariable("responseValueTask", responseValueUppercaseStart);
149 } catch (BpmnError e) {
150 msoLogger.debug("BPMN exception: " + e.getMessage());
152 } catch (Exception ex){
153 String msg = "Exception in completeManualTask " + ex.getMessage();
154 msoLogger.debug(msg);
155 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
160 public void createExternalTicket (DelegateExecution execution) {
163 ExternalTicket ticket = new ExternalTicket();
165 ticket.setRequestId((String) execution.getVariable("msoRequestId"));
166 ticket.setCurrentActivity((String) execution.getVariable("currentActivity"));
167 ticket.setNfRole((String) execution.getVariable("vnfType"));
168 ticket.setDescription((String) execution.getVariable("description"));
169 ticket.setSubscriptionServiceType((String) execution.getVariable("serviceType"));
170 ticket.setRequestorId((String) execution.getVariable("requestorId"));
171 ticket.setTimeout((String) execution.getVariable("taskTimeout"));
172 ticket.setErrorSource((String) execution.getVariable("failedActivity"));
173 ticket.setErrorCode((String) execution.getVariable("errorCode"));
174 ticket.setErrorMessage((String) execution.getVariable("errorText"));
175 ticket.setWorkStep((String) execution.getVariable("workStep"));
177 ticket.createTicket();
178 } catch (BpmnError e) {
179 String msg = "BPMN error in createAOTSTicket " + e.getMessage();
180 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", MsoLogger.ErrorCode.UnknownError, "");
181 } catch (Exception ex){
182 String msg = "Exception in createExternalTicket " + ex.getMessage();
183 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", MsoLogger.ErrorCode.UnknownError, "");
188 public void updateRequestDbStatus(DelegateExecution execution, String status) {
190 String requestId = (String) execution.getVariable("msoRequestId");
191 InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId);
193 request.setRequestStatus(status);
194 request.setLastModifiedBy("ManualHandling");
196 requestDbclient.updateInfraActiveRequests(request);
197 } catch (Exception e) {
198 msoLogger.error("Unable to save the updated request status to the DB",e);