2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.common.scripts;
23 import static org.apache.commons.lang3.StringUtils.*;
25 import java.time.chrono.AbstractChronology
27 import java.text.SimpleDateFormat
30 import org.apache.commons.lang3.*
31 import org.camunda.bpm.engine.TaskService
32 import org.camunda.bpm.engine.task.Task
33 import org.camunda.bpm.engine.task.TaskQuery
34 import org.camunda.bpm.engine.delegate.BpmnError
35 import org.camunda.bpm.engine.delegate.DelegateTask
36 import org.camunda.bpm.engine.delegate.DelegateExecution
37 import org.camunda.bpm.engine.delegate.DelegateExecution
38 import org.json.JSONObject;
39 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
40 import org.onap.so.bpmn.common.scripts.ExceptionUtil
41 import org.onap.so.bpmn.core.domain.ServiceDecomposition
42 import org.onap.so.bpmn.core.json.JsonUtils
43 import org.onap.so.client.ruby.*
44 import org.onap.so.logger.MessageEnum
45 import org.onap.so.logger.MsoLogger
52 * This groovy class supports the <class>ManualHandling.bpmn</class> process.
57 * @param - msoRequestId
58 * @param - isDebugLogEnabled
59 * @param - serviceType
61 * @param - requestorId
62 * @param - currentActivity
64 * @param - failedActivity
67 * @param - validResponses
71 * @param - WorkflowException
75 public class ManualHandling extends AbstractServiceTaskProcessor {
76 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, ManualHandling.class);
80 ExceptionUtil exceptionUtil = new ExceptionUtil()
82 JsonUtils jsonUtils = new JsonUtils()
84 public void preProcessRequest (DelegateExecution execution) {
86 msoLogger.trace("preProcessRequest of ManualHandling ")
89 execution.setVariable("prefix", Prefix)
90 setBasicDBAuthHeader(execution, execution.getVariable('isDebugLogEnabled'))
91 // check for required input
92 String requestId = execution.getVariable("msoRequestId")
93 msoLogger.debug("msoRequestId is: " + requestId)
94 def serviceType = execution.getVariable("serviceType")
95 msoLogger.debug("serviceType is: " + serviceType)
96 def vnfType = execution.getVariable("vnfType")
97 msoLogger.debug("vnftype is: " + vnfType)
98 def currentActivity = execution.getVariable("currentActivity")
99 msoLogger.debug("currentActivity is: " + currentActivity)
100 def workStep = execution.getVariable("workStep")
101 msoLogger.debug("workStep is: " + workStep)
102 def failedActivity = execution.getVariable("failedActivity")
103 msoLogger.debug("failedActivity is: " + failedActivity)
104 def errorCode = execution.getVariable("errorCode")
105 msoLogger.debug("errorCode is: " + errorCode)
106 def errorText = execution.getVariable("errorText")
107 msoLogger.debug("errorText is: " + errorText)
108 def requestorId = execution.getVariable("requestorId")
109 msoLogger.debug("requestorId is: " + requestorId)
110 def validResponses = execution.getVariable("validResponses")
111 msoLogger.debug("validResponses is: " + validResponses)
113 } catch (BpmnError e) {
115 } catch (Exception ex){
116 msg = "Exception in preProcessRequest " + ex.getMessage()
118 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
120 msoLogger.trace("Exit preProcessRequest of RainyDayHandler ")
123 public void createManualTask (DelegateExecution execution) {
125 msoLogger.trace("createManualTask of ManualHandling ")
128 String taskId = UUID.randomUUID()
129 execution.setVariable('taskId', taskId)
130 String type = "fallout"
131 String nfRole = execution.getVariable("vnfType")
132 String subscriptionServiceType = execution.getVariable("serviceType")
133 String originalRequestId = execution.getVariable("msoRequestId")
134 String originalRequestorId = execution.getVariable("requestorId")
135 String errorSource = execution.getVariable("failedActivity")
136 String errorCode = execution.getVariable("errorCode")
137 String errorMessage = execution.getVariable("errorText")
138 String buildingBlockName = execution.getVariable("currentActivity")
139 String buildingBlockStep = execution.getVariable("workStep")
140 String validResponses = execution.getVariable("validResponses")
142 msoLogger.debug("Before creating task")
144 Map<String, String> taskVariables = new HashMap<String, String>()
145 taskVariables.put("type", type)
146 taskVariables.put("nfRole", nfRole)
147 taskVariables.put("subscriptionServiceType", subscriptionServiceType)
148 taskVariables.put("originalRequestId", originalRequestId)
149 taskVariables.put("originalRequestorId", originalRequestorId)
150 taskVariables.put("errorSource", errorSource)
151 taskVariables.put("errorCode", errorCode)
152 taskVariables.put("errorMessage", errorMessage)
153 taskVariables.put("buildingBlockName", buildingBlockName)
154 taskVariables.put("buildingBlockStep", buildingBlockStep)
155 taskVariables.put("validResponses", validResponses)
157 TaskService taskService = execution.getProcessEngineServices().getTaskService()
158 Task manualTask = taskService.newTask(taskId)
159 taskService.saveTask(manualTask)
160 taskService.setVariables(taskId, taskVariables)
161 msoLogger.debug("successfully created task: "+ taskId)
162 } catch (BpmnError e) {
163 msoLogger.debug("BPMN exception: " + e.errorMessage)
165 } catch (Exception ex){
166 msg = "Exception in createManualTask " + ex.getMessage()
168 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
170 msoLogger.trace("Exit createManualTask of ManualHandling ")
173 public void setTaskVariables (DelegateTask task) {
175 DelegateExecution execution = task.getExecution()
178 msoLogger.trace("setTaskVariables of ManualHandling ")
179 String taskId = task.getId()
180 msoLogger.debug("taskId is: " + taskId)
183 execution.setVariable('taskId', taskId)
184 String type = "fallout"
185 String nfRole = execution.getVariable("vnfType")
186 String subscriptionServiceType = execution.getVariable("serviceType")
187 String originalRequestId = execution.getVariable("msoRequestId")
188 String originalRequestorId = execution.getVariable("requestorId")
189 String errorSource = execution.getVariable("failedActivity")
190 String errorCode = execution.getVariable("errorCode")
191 String errorMessage = execution.getVariable("errorText")
192 String buildingBlockName = execution.getVariable("currentActivity")
193 String buildingBlockStep = execution.getVariable("workStep")
194 String validResponses = execution.getVariable("validResponses")
196 msoLogger.debug("Before creating task")
198 Map<String, String> taskVariables = new HashMap<String, String>()
199 taskVariables.put("type", type)
200 taskVariables.put("nfRole", nfRole)
201 taskVariables.put("subscriptionServiceType", subscriptionServiceType)
202 taskVariables.put("originalRequestId", originalRequestId)
203 taskVariables.put("originalRequestorId", originalRequestorId)
204 taskVariables.put("errorSource", errorSource)
205 taskVariables.put("errorCode", errorCode)
206 taskVariables.put("errorMessage", errorMessage)
207 taskVariables.put("buildingBlockName", buildingBlockName)
208 taskVariables.put("buildingBlockStep", buildingBlockStep)
209 taskVariables.put("validResponses", validResponses)
210 TaskService taskService = execution.getProcessEngineServices().getTaskService()
213 taskService.setVariables(taskId, taskVariables)
214 msoLogger.debug("successfully created task: "+ taskId)
215 } catch (BpmnError e) {
216 msoLogger.debug("BPMN exception: " + e.errorMessage)
218 } catch (Exception ex){
219 msg = "Exception in createManualTask " + ex.getMessage()
221 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
223 msoLogger.trace("Exit createManualTask of ManualHandling ")
226 public void completeTask (DelegateTask task) {
228 DelegateExecution execution = task.getExecution()
231 msoLogger.trace("completeTask of ManualHandling ")
232 String taskId = task.getId()
233 msoLogger.debug("taskId is: " + taskId)
236 TaskService taskService = execution.getProcessEngineServices().getTaskService()
238 Map<String, String> taskVariables = taskService.getVariables(taskId)
239 String responseValue = taskVariables.get("responseValue")
241 msoLogger.debug("Received responseValue on completion: "+ responseValue)
242 // Have to set the first letter of the response to upper case
243 String responseValueForRainyDay = responseValue.substring(0, 1).toUpperCase() + responseValue.substring(1)
244 msoLogger.debug("ResponseValue to RainyDayHandler: "+ responseValueForRainyDay)
245 execution.setVariable("responseValue", responseValueForRainyDay)
247 } catch (BpmnError e) {
248 msoLogger.debug("BPMN exception: " + e.errorMessage)
250 } catch (Exception ex){
251 msg = "Exception in createManualTask " + ex.getMessage()
253 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
255 msoLogger.trace("Exit completeTask of ManualHandling ")
258 public void prepareRequestsDBStatusUpdate (DelegateExecution execution, String requestStatus){
260 def method = getClass().getSimpleName() + '.prepareRequestsDBStatusUpdate(' +'execution=' + execution.getId() +')'
261 msoLogger.trace("prepareRequestsDBStatusUpdate of ManualHandling ")
263 def requestId = execution.getVariable("msoRequestId")
265 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://org.onap.so/requestsdb">
268 <req:updateInfraRequest>
269 <requestId>${MsoUtils.xmlEscape(requestId)}</requestId>
270 <lastModifiedBy>ManualHandling</lastModifiedBy>
271 <requestStatus>${MsoUtils.xmlEscape(requestStatus)}</requestStatus>
272 </req:updateInfraRequest>
277 execution.setVariable("setUpdateDBstatusPayload", payload)
278 msoLogger.debug("Outgoing Update Mso Request Payload is: " + payload)
279 msoLogger.debug("setUpdateDBstatusPayload: " + payload)
280 } catch (BpmnError e) {
282 } catch (Exception e) {
283 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
284 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in" + method)
287 msoLogger.trace("Exit prepareRequestsDBStatusUpdate of ManualHandling ")
290 public void createAOTSTicket (DelegateExecution execution) {
292 msoLogger.trace("createAOTSTicket of ManualHandling ")
293 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
294 // This method will not be throwing an exception, but rather log the error
297 execution.setVariable("prefix", Prefix)
298 setBasicDBAuthHeader(execution,isDebugLogEnabled)
299 // check for required input
300 String requestId = execution.getVariable("msoRequestId")
301 msoLogger.debug("requestId is: " + requestId)
302 def currentActivity = execution.getVariable("currentActivity")
303 msoLogger.debug("currentActivity is: " + currentActivity)
304 def workStep = execution.getVariable("workStep")
305 msoLogger.debug("workStep is: " + workStep)
306 def failedActivity = execution.getVariable("failedActivity")
307 msoLogger.debug("failedActivity is: " + failedActivity)
308 def errorCode = execution.getVariable("errorCode")
309 msoLogger.debug("errorCode is: " + errorCode)
310 def errorText = execution.getVariable("errorText")
311 msoLogger.debug("errorText is: " + errorText)
312 def vnfName = execution.getVariable("vnfName")
313 msoLogger.debug("vnfName is: " + vnfName)
315 String rubyRequestId = UUID.randomUUID()
316 msoLogger.debug("rubyRequestId: " + rubyRequestId)
317 String sourceName = vnfName
318 msoLogger.debug("sourceName: " + sourceName)
319 String reason = "VID Workflow failed at " + failedActivity + " " + workStep + " call with error " + errorCode
320 msoLogger.debug("reason: " + reason)
321 String workflowId = requestId
322 msoLogger.debug("workflowId: " + workflowId)
323 String notification = "Request originated from VID | Workflow fallout on " + vnfName + " | Workflow step failure: " + workStep + " failed | VID workflow ID: " + workflowId
324 msoLogger.debug("notification: " + notification)
326 msoLogger.debug("Creating AOTS Ticket request")
328 RubyClient rubyClient = new RubyClient()
329 rubyClient.rubyCreateTicketCheckRequest(rubyRequestId, sourceName, reason, workflowId, notification)
331 } catch (BpmnError e) {
332 msg = "BPMN error in createAOTSTicket " + ex.getMessage()
333 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "");
334 } catch (Exception ex){
335 msg = "Exception in createAOTSTicket " + ex.getMessage()
336 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "");
338 msoLogger.trace("Exit createAOTSTicket of ManualHandling ")