2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.bpmn.common.scripts
25 import org.onap.so.logger.ErrorCode;
27 import static org.apache.commons.lang3.StringUtils.*;
29 import java.time.chrono.AbstractChronology
31 import java.text.SimpleDateFormat
34 import org.apache.commons.lang3.*
35 import org.camunda.bpm.engine.TaskService
36 import org.camunda.bpm.engine.task.Task
37 import org.camunda.bpm.engine.task.TaskQuery
38 import org.camunda.bpm.engine.delegate.BpmnError
39 import org.camunda.bpm.engine.delegate.DelegateTask
40 import org.camunda.bpm.engine.delegate.DelegateExecution
41 import org.camunda.bpm.engine.delegate.DelegateExecution
42 import org.json.JSONObject;
43 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
44 import org.onap.so.bpmn.common.scripts.ExceptionUtil
45 import org.onap.so.bpmn.core.domain.ServiceDecomposition
46 import org.onap.so.bpmn.core.json.JsonUtils
47 import org.onap.so.client.ruby.*
48 import org.onap.so.logger.MessageEnum
49 import org.slf4j.Logger
50 import org.slf4j.LoggerFactory
57 * This groovy class supports the <class>ManualHandling.bpmn</class> process.
62 * @param - msoRequestId
63 * @param - isDebugLogEnabled
64 * @param - serviceType
66 * @param - requestorId
67 * @param - currentActivity
69 * @param - failedActivity
72 * @param - validResponses
76 * @param - WorkflowException
80 public class ManualHandling extends AbstractServiceTaskProcessor {
81 private static final Logger logger = LoggerFactory.getLogger( ManualHandling.class);
85 ExceptionUtil exceptionUtil = new ExceptionUtil()
87 JsonUtils jsonUtils = new JsonUtils()
89 public void preProcessRequest (DelegateExecution execution) {
91 logger.trace("preProcessRequest of ManualHandling ")
94 execution.setVariable("prefix", Prefix)
95 setBasicDBAuthHeader(execution, execution.getVariable('isDebugLogEnabled'))
96 // check for required input
97 String requestId = execution.getVariable("msoRequestId")
98 logger.debug("msoRequestId is: " + requestId)
99 def serviceType = execution.getVariable("serviceType")
100 logger.debug("serviceType is: " + serviceType)
101 def vnfType = execution.getVariable("vnfType")
102 logger.debug("vnftype is: " + vnfType)
103 def currentActivity = execution.getVariable("currentActivity")
104 logger.debug("currentActivity is: " + currentActivity)
105 def workStep = execution.getVariable("workStep")
106 logger.debug("workStep is: " + workStep)
107 def failedActivity = execution.getVariable("failedActivity")
108 logger.debug("failedActivity is: " + failedActivity)
109 def errorCode = execution.getVariable("errorCode")
110 logger.debug("errorCode is: " + errorCode)
111 def errorText = execution.getVariable("errorText")
112 logger.debug("errorText is: " + errorText)
113 def requestorId = execution.getVariable("requestorId")
114 logger.debug("requestorId is: " + requestorId)
115 def validResponses = execution.getVariable("validResponses")
116 logger.debug("validResponses is: " + validResponses)
118 } catch (BpmnError e) {
120 } catch (Exception ex){
121 msg = "Exception in preProcessRequest " + ex.getMessage()
123 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
125 logger.trace("Exit preProcessRequest of RainyDayHandler ")
128 public void createManualTask (DelegateExecution execution) {
130 logger.trace("createManualTask of ManualHandling ")
133 String taskId = UUID.randomUUID()
134 execution.setVariable('taskId', taskId)
135 String type = "fallout"
136 String nfRole = execution.getVariable("vnfType")
137 String subscriptionServiceType = execution.getVariable("serviceType")
138 String originalRequestId = execution.getVariable("msoRequestId")
139 String originalRequestorId = execution.getVariable("requestorId")
140 String errorSource = execution.getVariable("failedActivity")
141 String errorCode = execution.getVariable("errorCode")
142 String errorMessage = execution.getVariable("errorText")
143 String buildingBlockName = execution.getVariable("currentActivity")
144 String buildingBlockStep = execution.getVariable("workStep")
145 String validResponses = execution.getVariable("validResponses")
147 logger.debug("Before creating task")
149 Map<String, String> taskVariables = new HashMap<String, String>()
150 taskVariables.put("type", type)
151 taskVariables.put("nfRole", nfRole)
152 taskVariables.put("subscriptionServiceType", subscriptionServiceType)
153 taskVariables.put("originalRequestId", originalRequestId)
154 taskVariables.put("originalRequestorId", originalRequestorId)
155 taskVariables.put("errorSource", errorSource)
156 taskVariables.put("errorCode", errorCode)
157 taskVariables.put("errorMessage", errorMessage)
158 taskVariables.put("buildingBlockName", buildingBlockName)
159 taskVariables.put("buildingBlockStep", buildingBlockStep)
160 taskVariables.put("validResponses", validResponses)
162 TaskService taskService = execution.getProcessEngineServices().getTaskService()
163 Task manualTask = taskService.newTask(taskId)
164 taskService.saveTask(manualTask)
165 taskService.setVariables(taskId, taskVariables)
166 logger.debug("successfully created task: "+ taskId)
167 } catch (BpmnError e) {
168 logger.debug("BPMN exception: " + e.errorMessage)
170 } catch (Exception ex){
171 msg = "Exception in createManualTask " + ex.getMessage()
173 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
175 logger.trace("Exit createManualTask of ManualHandling ")
178 public void setTaskVariables (DelegateTask task) {
180 DelegateExecution execution = task.getExecution()
183 logger.trace("setTaskVariables of ManualHandling ")
184 String taskId = task.getId()
185 logger.debug("taskId is: " + taskId)
188 execution.setVariable('taskId', taskId)
189 String type = "fallout"
190 String nfRole = execution.getVariable("vnfType")
191 String subscriptionServiceType = execution.getVariable("serviceType")
192 String originalRequestId = execution.getVariable("msoRequestId")
193 String originalRequestorId = execution.getVariable("requestorId")
194 String errorSource = execution.getVariable("failedActivity")
195 String errorCode = execution.getVariable("errorCode")
196 String errorMessage = execution.getVariable("errorText")
197 String buildingBlockName = execution.getVariable("currentActivity")
198 String buildingBlockStep = execution.getVariable("workStep")
199 String validResponses = execution.getVariable("validResponses")
201 logger.debug("Before creating task")
203 Map<String, String> taskVariables = new HashMap<String, String>()
204 taskVariables.put("type", type)
205 taskVariables.put("nfRole", nfRole)
206 taskVariables.put("subscriptionServiceType", subscriptionServiceType)
207 taskVariables.put("originalRequestId", originalRequestId)
208 taskVariables.put("originalRequestorId", originalRequestorId)
209 taskVariables.put("errorSource", errorSource)
210 taskVariables.put("errorCode", errorCode)
211 taskVariables.put("errorMessage", errorMessage)
212 taskVariables.put("buildingBlockName", buildingBlockName)
213 taskVariables.put("buildingBlockStep", buildingBlockStep)
214 taskVariables.put("validResponses", validResponses)
215 TaskService taskService = execution.getProcessEngineServices().getTaskService()
218 taskService.setVariables(taskId, taskVariables)
219 logger.debug("successfully created task: "+ taskId)
220 } catch (BpmnError e) {
221 logger.debug("BPMN exception: " + e.errorMessage)
223 } catch (Exception ex){
224 msg = "Exception in createManualTask " + ex.getMessage()
226 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
228 logger.trace("Exit createManualTask of ManualHandling ")
231 public void completeTask (DelegateTask task) {
233 DelegateExecution execution = task.getExecution()
236 logger.trace("completeTask of ManualHandling ")
237 String taskId = task.getId()
238 logger.debug("taskId is: " + taskId)
241 TaskService taskService = execution.getProcessEngineServices().getTaskService()
243 Map<String, String> taskVariables = taskService.getVariables(taskId)
244 String responseValue = taskVariables.get("responseValue")
246 logger.debug("Received responseValue on completion: "+ responseValue)
247 // Have to set the first letter of the response to upper case
248 String responseValueForRainyDay = responseValue.substring(0, 1).toUpperCase() + responseValue.substring(1)
249 logger.debug("ResponseValue to RainyDayHandler: "+ responseValueForRainyDay)
250 execution.setVariable("responseValue", responseValueForRainyDay)
252 } catch (BpmnError e) {
253 logger.debug("BPMN exception: " + e.errorMessage)
255 } catch (Exception ex){
256 msg = "Exception in createManualTask " + ex.getMessage()
258 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
260 logger.trace("Exit completeTask of ManualHandling ")
263 public void prepareRequestsDBStatusUpdate (DelegateExecution execution, String requestStatus){
265 def method = getClass().getSimpleName() + '.prepareRequestsDBStatusUpdate(' +'execution=' + execution.getId() +')'
266 logger.trace("prepareRequestsDBStatusUpdate of ManualHandling ")
268 def requestId = execution.getVariable("msoRequestId")
270 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://org.onap.so/requestsdb">
273 <req:updateInfraRequest>
274 <requestId>${MsoUtils.xmlEscape(requestId)}</requestId>
275 <lastModifiedBy>ManualHandling</lastModifiedBy>
276 <requestStatus>${MsoUtils.xmlEscape(requestStatus)}</requestStatus>
277 </req:updateInfraRequest>
282 execution.setVariable("setUpdateDBstatusPayload", payload)
283 logger.debug("Outgoing Update Mso Request Payload is: " + payload)
284 logger.debug("setUpdateDBstatusPayload: " + payload)
285 } catch (BpmnError e) {
287 } catch (Exception e) {
288 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
289 'Caught exception in ' + method, "BPMN",
290 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
291 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in" + method)
294 logger.trace("Exit prepareRequestsDBStatusUpdate of ManualHandling ")
297 public void createAOTSTicket (DelegateExecution execution) {
299 logger.trace("createAOTSTicket of ManualHandling ")
300 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
301 // This method will not be throwing an exception, but rather log the error
304 execution.setVariable("prefix", Prefix)
305 setBasicDBAuthHeader(execution,isDebugLogEnabled)
306 // check for required input
307 String requestId = execution.getVariable("msoRequestId")
308 logger.debug("requestId is: " + requestId)
309 def currentActivity = execution.getVariable("currentActivity")
310 logger.debug("currentActivity is: " + currentActivity)
311 def workStep = execution.getVariable("workStep")
312 logger.debug("workStep is: " + workStep)
313 def failedActivity = execution.getVariable("failedActivity")
314 logger.debug("failedActivity is: " + failedActivity)
315 def errorCode = execution.getVariable("errorCode")
316 logger.debug("errorCode is: " + errorCode)
317 def errorText = execution.getVariable("errorText")
318 logger.debug("errorText is: " + errorText)
319 def vnfName = execution.getVariable("vnfName")
320 logger.debug("vnfName is: " + vnfName)
322 String rubyRequestId = UUID.randomUUID()
323 logger.debug("rubyRequestId: " + rubyRequestId)
324 String sourceName = vnfName
325 logger.debug("sourceName: " + sourceName)
326 String reason = "VID Workflow failed at " + failedActivity + " " + workStep + " call with error " + errorCode
327 logger.debug("reason: " + reason)
328 String workflowId = requestId
329 logger.debug("workflowId: " + workflowId)
330 String notification = "Request originated from VID | Workflow fallout on " + vnfName + " | Workflow step failure: " + workStep + " failed | VID workflow ID: " + workflowId
331 logger.debug("notification: " + notification)
333 logger.debug("Creating AOTS Ticket request")
335 RubyClient rubyClient = new RubyClient()
336 rubyClient.rubyCreateTicketCheckRequest(rubyRequestId, sourceName, reason, workflowId, notification)
338 } catch (BpmnError e) {
339 msg = "BPMN error in createAOTSTicket " + ex.getMessage()
340 logger.error("{} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
341 ErrorCode.UnknownError.getValue());
342 } catch (Exception ex){
343 msg = "Exception in createAOTSTicket " + ex.getMessage()
344 logger.error("{} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
345 ErrorCode.UnknownError.getValue());
347 logger.trace("Exit createAOTSTicket of ManualHandling ")