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.bpmn.common.BuildingBlockExecution;
31 import org.onap.so.client.exception.ExceptionBuilder;
32 import org.onap.so.client.ticket.ExternalTicket;
33 import org.onap.so.db.request.beans.InfraActiveRequests;
34 import org.onap.so.db.request.client.RequestsDbClient;
35 import org.onap.so.logger.ErrorCode;
36 import org.onap.so.logger.MessageEnum;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
39 import org.springframework.beans.factory.annotation.Autowired;
40 import org.springframework.stereotype.Component;
43 public class ManualHandlingTasks {
44 private static final Logger logger = LoggerFactory.getLogger(ManualHandlingTasks.class);
46 private static final String TASK_TYPE_PAUSE = "pause";
47 private static final String TASK_TYPE_FALLOUT = "fallout";
48 public static final String VNF_TYPE = "vnfType";
49 public static final String SERVICE_TYPE = "serviceType";
50 public static final String MSO_REQUEST_ID = "mso-request-id";
51 public static final String REQUESTOR_ID = "requestorId";
52 public static final String ERROR_CODE = "errorCode";
53 public static final String VALID_RESPONSES = "validResponses";
54 public static final String DESCRIPTION = "description";
55 public static final String BPMN_EXCEPTION = "BPMN exception: ";
58 private ExceptionBuilder exceptionUtil;
61 private RequestsDbClient requestDbclient;
63 public void setFalloutTaskVariables(DelegateTask task) {
65 DelegateExecution execution = task.getExecution();
67 String taskId = task.getId();
68 logger.debug("taskId is: " + taskId);
69 String type = TASK_TYPE_FALLOUT;
70 String nfRole = (String) execution.getVariable(VNF_TYPE);
71 String subscriptionServiceType = (String) execution.getVariable(SERVICE_TYPE);
72 String originalRequestId = (String) execution.getVariable(MSO_REQUEST_ID);
73 String originalRequestorId = (String) execution.getVariable(REQUESTOR_ID);
74 String description = "";
76 String errorSource = (String) execution.getVariable("failedActivity");
77 String errorCode = (String) execution.getVariable(ERROR_CODE);
78 String errorMessage = (String) execution.getVariable("errorText");
79 String buildingBlockName = (String) execution.getVariable("currentActivity");
80 String buildingBlockStep = (String) execution.getVariable("workStep");
81 String validResponses = (String) execution.getVariable(VALID_RESPONSES);
83 Map<String, String> taskVariables = new HashMap<>();
84 taskVariables.put("type", type);
85 taskVariables.put("nfRole", nfRole);
86 taskVariables.put("subscriptionServiceType", subscriptionServiceType);
87 taskVariables.put("originalRequestId", originalRequestId);
88 taskVariables.put("originalRequestorId", originalRequestorId);
89 taskVariables.put("errorSource", errorSource);
90 taskVariables.put(ERROR_CODE, errorCode);
91 taskVariables.put("errorMessage", errorMessage);
92 taskVariables.put("buildingBlockName", buildingBlockName);
93 taskVariables.put("buildingBlockStep", buildingBlockStep);
94 taskVariables.put(VALID_RESPONSES, validResponses);
95 taskVariables.put("tmeout", timeout);
96 taskVariables.put(DESCRIPTION, description);
97 TaskService taskService = execution.getProcessEngineServices().getTaskService();
99 taskService.setVariables(taskId, taskVariables);
100 logger.debug("successfully created fallout task: " + taskId);
101 } catch (BpmnError e) {
102 logger.debug(BPMN_EXCEPTION + e.getMessage());
104 } catch (Exception ex) {
105 String msg = "Exception in setFalloutTaskVariables " + ex.getMessage();
107 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
111 public void setPauseTaskVariables(DelegateTask task) {
113 DelegateExecution execution = task.getExecution();
116 String taskId = task.getId();
117 logger.debug("taskId is: " + taskId);
118 String type = TASK_TYPE_PAUSE;
119 String nfRole = (String) execution.getVariable(VNF_TYPE);
120 String subscriptionServiceType = (String) execution.getVariable(SERVICE_TYPE);
121 String originalRequestId = (String) execution.getVariable(MSO_REQUEST_ID);
122 String originalRequestorId = (String) execution.getVariable(REQUESTOR_ID);
123 String description = (String) execution.getVariable(DESCRIPTION);
125 String errorSource = "";
126 String errorCode = "";
127 String errorMessage = "";
128 String buildingBlockName = "";
129 String buildingBlockStep = "";
130 String validResponses = (String) execution.getVariable(VALID_RESPONSES);
132 Map<String, String> taskVariables = new HashMap<>();
133 taskVariables.put("type", type);
134 taskVariables.put("nfRole", nfRole);
135 taskVariables.put(DESCRIPTION, description);
136 taskVariables.put("timeout", timeout);
137 taskVariables.put("subscriptionServiceType", subscriptionServiceType);
138 taskVariables.put("originalRequestId", originalRequestId);
139 taskVariables.put("originalRequestorId", originalRequestorId);
140 taskVariables.put("errorSource", errorSource);
141 taskVariables.put(ERROR_CODE, errorCode);
142 taskVariables.put("errorMessage", errorMessage);
143 taskVariables.put("buildingBlockName", buildingBlockName);
144 taskVariables.put("buildingBlockStep", buildingBlockStep);
145 taskVariables.put(VALID_RESPONSES, validResponses);
146 TaskService taskService = execution.getProcessEngineServices().getTaskService();
148 taskService.setVariables(taskId, taskVariables);
149 logger.debug("successfully created pause task: " + taskId);
150 } catch (BpmnError e) {
151 logger.debug(BPMN_EXCEPTION + e.getMessage());
153 } catch (Exception ex) {
154 String msg = "Exception in setPauseTaskVariables " + ex.getMessage();
156 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
161 public void completeTask(DelegateTask task) {
163 DelegateExecution execution = task.getExecution();
167 String taskId = task.getId();
168 logger.debug("taskId is: " + taskId);
169 TaskService taskService = execution.getProcessEngineServices().getTaskService();
171 Map<String, Object> taskVariables = taskService.getVariables(taskId);
172 String responseValue = (String) taskVariables.get("responseValue");
174 logger.debug("Received responseValue on completion: " + responseValue);
175 // Have to set the first letter of the response to upper case
176 String responseValueUppercaseStart =
177 responseValue.substring(0, 1).toUpperCase() + responseValue.substring(1);
178 logger.debug("ResponseValue to taskListener: " + responseValueUppercaseStart);
179 execution.setVariable("responseValueTask", responseValueUppercaseStart);
181 } catch (BpmnError e) {
182 logger.debug(BPMN_EXCEPTION + e.getMessage());
184 } catch (Exception ex) {
185 String msg = "Exception in completeManualTask " + ex.getMessage();
187 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
192 public void createExternalTicket(BuildingBlockExecution execution) {
195 ExternalTicket ticket = new ExternalTicket();
197 ticket.setRequestId((String) execution.getVariable(MSO_REQUEST_ID));
198 ticket.setCurrentActivity((String) execution.getVariable("currentActivity"));
199 ticket.setNfRole((String) execution.getVariable(VNF_TYPE));
200 ticket.setDescription((String) execution.getVariable(DESCRIPTION));
201 ticket.setSubscriptionServiceType((String) execution.getVariable(SERVICE_TYPE));
202 ticket.setRequestorId((String) execution.getVariable(REQUESTOR_ID));
203 ticket.setTimeout((String) execution.getVariable("taskTimeout"));
204 ticket.setErrorSource((String) execution.getVariable("failedActivity"));
205 ticket.setErrorCode((String) execution.getVariable(ERROR_CODE));
206 ticket.setErrorMessage((String) execution.getVariable("errorText"));
207 ticket.setWorkStep((String) execution.getVariable("workStep"));
209 ticket.createTicket();
210 } catch (BpmnError e) {
211 String msg = "BPMN error in createAOTSTicket " + e.getMessage();
212 logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN",
213 ErrorCode.UnknownError.getValue());
214 } catch (Exception ex) {
215 String msg = "Exception in createExternalTicket " + ex.getMessage();
216 logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN",
217 ErrorCode.UnknownError.getValue());
222 public void updateRequestDbStatus(BuildingBlockExecution execution, String status) {
224 String requestId = (String) execution.getVariable(MSO_REQUEST_ID);
225 InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId);
227 request.setRequestStatus(status);
228 request.setLastModifiedBy("ManualHandling");
230 requestDbclient.updateInfraActiveRequests(request);
231 } catch (Exception e) {
232 logger.error("Unable to save the updated request status to the DB", e);