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 com.att.bpm.scripts
23 import java.text.SimpleDateFormat
25 import org.apache.commons.lang3.*
26 import org.camunda.bpm.engine.runtime.Execution
28 public class FalloutHandler extends AbstractServiceTaskProcessor {
31 ExceptionUtil exceptionUtil = new ExceptionUtil()
33 public initializeProcessVariables(Execution execution){
34 def method = getClass().getSimpleName() + '.initializeProcessVariables(' +'execution=' + execution.getId() +')'
35 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
36 logDebug('Entered ' + method, isDebugLogEnabled)
39 execution.setVariable("prefix",Prefix)
41 //These variables are form the input Message to the BPMN
42 execution.setVariable("FH_request_id","")
43 execution.setVariable("FH_request_action","")
44 execution.setVariable("FH_notification-url","")
45 execution.setVariable("FH_mso-bpel-name","")
46 execution.setVariable("FH_ErrorCode", "")
47 execution.setVariable("FH_ErrorMessage", "")
49 execution.setVariable("FH_notification-url-Ok", false)
50 execution.setVariable("FH_request_id-Ok", false)
52 //These variables are for Get Mso Aai Password Adapter
53 execution.setVariable("FH_deliveryStatus", true)
55 //Notify CSI Adapter variables
56 execution.setVariable("FH_notifyCSIPayload", "")
57 execution.setVariable("FH_notifyCSIResponseCode", null)
58 execution.setVariable("FH_notifyCSIResponse", "")
60 //update Response Status to pending ...Adapter variables
61 execution.setVariable("FH_updateResponseStatusPayload", null)
62 execution.setVariable("FH_updateResponseStatusResponse", null)
64 //update Request Gamma ...Adapter variables
65 execution.setVariable("FH_updateRequestGammaPayload", "")
66 execution.setVariable("FH_updateRequestGammaResponse", null)
67 execution.setVariable("FH_updateRequestGammaResponseCode", null)
69 //update Request Infra ...Adapter variables
70 execution.setVariable("FH_updateRequestInfraPayload", "")
71 execution.setVariable("FH_updateRequestInfraResponse", null)
72 execution.setVariable("FH_updateRequestInfraResponseCode", null)
74 //assign True to success variable
75 execution.setVariable("FH_success", true)
77 //Set notify status to Failed variable
78 execution.setVariable("FH_NOTIFY_STATUS", "SUCCESS")
80 //Set DB update variable
81 execution.setVariable("FH_updateRequestPayload", "")
82 execution.setVariable("FH_updateRequestResponse", null)
83 execution.setVariable("FH_updateRequestResponseCode", null)
86 execution.setVariable("BasicAuthHeaderValue","")
89 execution.setVariable("FH_parameterList", "")
92 execution.setVariable("FalloutHandlerResponse","")
93 execution.setVariable("FH_ErrorResponse", null)
94 execution.setVariable("FH_ResponseCode", "")
96 } catch (Exception e) {
97 logError('Caught exception in ' + method, e)
98 exceptionUtil.buildWorkflowException(execution, 2000, "Internal Error - Occured in " + method)
102 public void preProcessRequest (Execution execution) {
103 def method = getClass().getSimpleName() + '.preProcessRequest(' +'execution=' + execution.getId() +')'
104 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
105 logDebug('Entered ' + method, isDebugLogEnabled)
107 // Initialize flow variables
108 initializeProcessVariables(execution)
109 setSuccessIndicator(execution, false)
112 def xml = execution.getVariable("FalloutHandlerRequest")
113 utils.log("DEBUG", " XML --> " + xml, isDebugLogEnabled)
114 utils.logAudit("FalloutHandler request: " + xml)
116 //Check the incoming request type
117 //Incoming request can be ACTIVE_REQUESTS (request-information node) or INFRA_ACTIVE_REQUESTS (request-info node)
118 if (utils.nodeExists(xml, "request-information")) {
119 execution.setVariable("FH_request_id-Ok", true) // Incoming request is for ACTIVE_REQUESTS
122 //Check notification-url for the incoming request type
123 //ACTIVE_REQUESTS may have notificationurl node
124 //INFRA_ACTIVE_REQUESTS notificationurl node does not exist
125 def notificationurl = ""
126 if (utils.nodeExists(xml, "notification-url")) {
127 notificationurl = utils.getNodeText(xml,"notification-url")
128 if(notificationurl != null && !notificationurl.isEmpty()) {
129 execution.setVariable("FH_notification-url-Ok", true)
130 execution.setVariable("FH_notification-url",notificationurl)
134 //Check request_id for the incoming request type
135 //For INFRA_ACTIVE_REQUESTS payload request-id IS optional (Not sure why this is option since req id is primary key ... also tried exe through SOAP UI to check if MSO code handles null like auto generated seq not it does not)
136 //For ACTIVE_REQUESTS payload request-id is NOT optional
138 if (utils.nodeExists(xml, "request-id")) {
139 execution.setVariable("FH_request_id",utils.getNodeText(xml,"request-id"))
141 utils.logAudit("FH_request_id: " + execution.getVariable("FH_request_id"))
143 // INFRA_ACTIVE_REQUESTS have "action" element ... mandatory
144 // ACTIVE_REQUEST have "request-action" ... mandatory
145 if (utils.nodeExists(xml, "request-action")) {
146 execution.setVariable("FH_request_action",utils.getNodeText(xml,"request-action"))
147 } else if (utils.nodeExists(xml, "action")) {
148 execution.setVariable("FH_request_action",utils.getNodeText(xml,"action"))
152 //Check source for the incoming request type
153 //For INFRA_ACTIVE_REQUESTS payload source IS optional
154 //For ACTIVE_REQUESTS payload source is NOT optional
156 if (utils.nodeExists(xml, "source")) {
157 execution.setVariable("FH_source",utils.getNodeText(xml,"source"))
160 //Check if ErrorCode node exists. If yes, initialize it from request xml, if no, it will stay with defaulf value already set in initializeProcessVariables() method above.
162 if (utils.nodeExists(xml, "ErrorCode")) {
163 errorCode = utils.getNodeText(xml,"ErrorCode")
164 if(errorCode != null && !errorCode.isEmpty()) {
165 execution.setVariable("FH_ErrorCode", errorCode)
168 utils.logAudit("FH_ErrorCode: " + errorCode)
170 //Check if ErrorMessage node exists. If yes, initialize it from request xml, if no, it will stay with defaulf value already set in initializeProcessVariables() method above.
171 def errorMessage = ""
172 if (utils.nodeExists(xml, "ErrorMessage")) {
173 errorCode = utils.getNodeText(xml,"ErrorMessage")
174 if(errorCode != null && !errorCode.isEmpty()) {
175 errorCode = errorCode.replace("&", "&").replace("<", "<").replace(">", ">")
176 execution.setVariable("FH_ErrorMessage", errorCode)
180 //Check for Parameter List
181 if (utils.nodeExists(xml, "parameter-list")) {
182 def parameterList = utils.getNodeXml(xml, "parameter-list", false)
183 execution.setVariable("FH_parameterList", parameterList)
186 utils.log("DEBUG","FH_notification-url-Ok --> " + execution.getVariable("FH_notification-url-Ok"),isDebugLogEnabled)
187 utils.log("DEBUG","FH_request_id-OK --> " + execution.getVariable("FH_request_id-Ok"),isDebugLogEnabled)
189 } catch (Exception e) {
190 logError('Caught exception in ' + method, e)
191 exceptionUtil.buildWorkflowException(execution, 2000, "Internal Error - Occured in" + method)
194 utils.log("DEBUG","OUTOF --> Initialize Variables Fallout Handler #########",isDebugLogEnabled);
197 public String updateRequestPayload (Execution execution){
198 def method = getClass().getSimpleName() + '.updateRequestPayload(' +'execution=' + execution.getId() +')'
199 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
200 logDebug('Entered ' + method, isDebugLogEnabled)
204 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://com.att.mso/requestsdb">
208 <requestId>${execution.getVariable("FH_request_id")}</requestId>
209 <lastModifiedBy>BPEL</lastModifiedBy>
210 <finalErrorMessage>${execution.getVariable("FH_ErrorMessage")}</finalErrorMessage>
211 <finalErrorCode>${execution.getVariable("FH_ErrorCode")}</finalErrorCode>
212 <status>FAILED</status>
213 <responseStatus>${execution.getVariable("FH_NOTIFY_STATUS")}</responseStatus>
219 utils.logAudit("updateRequestPayload: " + payload)
220 execution.setVariable("FH_updateRequestPayload", payload)
221 return execution.getVariable("FH_updateRequestPayload")
222 } catch (Exception e) {
223 logError('Caught exception in ' + method, e)
224 exceptionUtil.buildWorkflowException(execution, 2000, "Internal Error - Occured in " + method)
228 public String updateRequestInfraPayload (Execution execution){
229 def method = getClass().getSimpleName() + '.updateRequestInfraPayload(' +'execution=' + execution.getId() +')'
230 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
231 logDebug('Entered ' + method, isDebugLogEnabled)
235 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://com.att.mso/requestsdb">
238 <req:updateInfraRequest>
239 <requestId>${execution.getVariable("FH_request_id")}</requestId>
240 <lastModifiedBy>BPEL</lastModifiedBy>
241 <statusMessage>${execution.getVariable("FH_ErrorMessage")}</statusMessage>
242 <requestStatus>FAILED</requestStatus>
243 <progress>100</progress>
244 </req:updateInfraRequest>
249 execution.setVariable("FH_updateRequestInfraPayload", payload)
250 utils.logAudit("updateRequestInfraPayload: " + payload)
251 return execution.getVariable("FH_updateRequestInfraPayload")
252 } catch (Exception e) {
253 logError('Caught exception in ' + method, e)
254 exceptionUtil.buildWorkflowException(execution, 2000, "Internal Error - Occured in " + method)
258 public String updateRequestGammaPayload (Execution execution){
259 def method = getClass().getSimpleName() + '.updateRequestGammaPayload(' +'execution=' + execution.getId() +')'
260 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
261 logDebug('Entered ' + method, isDebugLogEnabled)
265 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://com.att.mso/requestsdb">
269 <requestId>${execution.getVariable("FH_request_id")}</requestId>
270 <lastModifiedBy>BPEL</lastModifiedBy>
271 <finalErrorMessage>${execution.getVariable("FH_ErrorMessage")}</finalErrorMessage>
272 <finalErrorCode>${execution.getVariable("FH_ErrorCode")}</finalErrorCode>
273 <status>FAILED</status>
279 execution.setVariable("FH_updateRequestGammaPayload", payload)
280 utils.logAudit("updateRequestGammaPayload: " + payload)
281 return execution.getVariable("FH_updateRequestGammaPayload")
282 } catch (Exception e) {
283 logError('Caught exception in ' + method, e)
284 exceptionUtil.buildWorkflowException(execution, 2000, "Internal Error - Occured in " + method)
288 public String updateResponseStatusPayload (Execution execution){
289 def method = getClass().getSimpleName() + '.updateResponseStatusPayload(' +'execution=' + execution.getId() +')'
290 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
291 logDebug('Entered ' + method, isDebugLogEnabled)
295 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://com.att.mso/requestsdb">
298 <req:updateResponseStatus>
299 <requestId>${execution.getVariable("FH_request_id")}</requestId>
300 <lastModifiedBy>BPEL</lastModifiedBy>
301 <responseStatus>SENDING_FINAL_NOTIFY</responseStatus>
302 </req:updateResponseStatus>
307 execution.setVariable("FH_updateResponseStatusPayload", payload)
308 utils.logAudit("updateResponseStatusPayload: " + payload)
309 return execution.getVariable("FH_updateResponseStatusPayload")
310 } catch (Exception e) {
311 logError('Caught exception in ' + method, e)
312 exceptionUtil.buildWorkflowException(execution, 2000, "Internal Error - Occured in " + method)
316 public String notifyCSIPayload (Execution execution) {
320 public String notifyCCDFailurePayload (Execution execution) {
321 def method = getClass().getSimpleName() + '.notifyCCDFailurePayload(' +'execution=' + execution.getId() +')'
322 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
323 logDebug('Entered ' + method, isDebugLogEnabled)
326 def parameterList = execution.getVariable('FH_parameterList')
328 <ns:status-notification xmlns:ns="http://ecomp.att.com/mso/statusnotification/schema/v1" xmlns:msoservtypes="http://ecomp.att.com/mso/request/types/v1">
329 <msoservtypes:request-id>${execution.getVariable("FH_request_id")}</msoservtypes:request-id>
330 <msoservtypes:request-action>${execution.getVariable("FH_request_action")}</msoservtypes:request-action>
331 <msoservtypes:source>${execution.getVariable("FH_source")}</msoservtypes:source>
332 <msoservtypes:error-code>${execution.getVariable("FH_ErrorCode")}</msoservtypes:error-code>
333 <msoservtypes:error-message>${execution.getVariable("FH_ErrorMessage")}</msoservtypes:error-message>
334 <msoservtypes:ack-final-indicator>Y</msoservtypes:ack-final-indicator>
336 </ns:status-notification>
339 payload = utils.formatXml(payload)
340 utils.logAudit("notifyCCDFailurePayload: " + payload)
342 execution.setVariable("FH_notifyCCDFailurePayload", payload)
343 utils.log("DEBUG", "FH_notifyCCDFailurePayload --> " + "\n" + execution.getVariable("FH_notifyCCDFailurePayload"), isDebugLogEnabled)
344 return execution.getVariable("FH_notifyCCDFailurePayload")
345 } catch (Exception e) {
346 logError('Caught exception in ' + method, e)
347 exceptionUtil.buildWorkflowException(execution, 2000, "Internal Error - Occured in " + method)
351 public void buildDBWorkflowException(Execution execution, String responseCodeVariable) {
352 def method = getClass().getSimpleName() + '.buildDBWorkflowException(' +
353 'execution=' + execution.getId() +
354 ', responseCodeVariable=' + responseCodeVariable + ')'
355 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
356 logDebug('Entered ' + method, isDebugLogEnabled)
359 def responseCode = execution.getVariable(responseCodeVariable)
360 // If the HTTP response code was null, it means a connection fault occurred (a java exception)
361 def errorMessage = responseCode == null ? "Could not connect to DB Adapter" : "DB Adapter returned ${responseCode} response"
362 def errorCode = responseCode == null ? 7000 : 7020
363 exceptionUtil.buildWorkflowException(execution, errorCode, errorMessage)
364 } catch (Exception e) {
365 logError('Caught exception in ' + method, e)
366 exceptionUtil.buildWorkflowException(execution, 2000, "Internal Error - Occured in " + method)
371 * Used to create a workflow response in success and failure cases.
373 public void postProcessResponse (Execution execution) {
374 def method = getClass().getSimpleName() + '.postProcessResponse(' +'execution=' + execution.getId() +')'
375 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
376 logDebug('Entered ' + method, isDebugLogEnabled)
379 Boolean success = (Boolean) execution.getVariable("FH_success")
380 String out = success ? "Fallout Handler Succeeded" : "Fallout Handler Failed";
382 def falloutHandlerResponse = """
383 <workflow:FalloutHandlerResponse xmlns:workflow="http://ecomp.att.com/mso/workflow/schema/v1">
384 <workflow:out>${out}</workflow:out>
385 </workflow:FalloutHandlerResponse>
388 falloutHandlerResponse = utils.formatXml(falloutHandlerResponse)
389 utils.logAudit("FalloutHandler Response: " + falloutHandlerResponse);
391 execution.setVariable("FalloutHandlerResponse", falloutHandlerResponse)
392 execution.setVariable("WorkflowResponse", falloutHandlerResponse)
393 execution.setVariable("FH_ResponseCode", success ? "200" : "500")
394 setSuccessIndicator(execution, success)
396 logDebug("FalloutHandlerResponse =\n" + falloutHandlerResponse, isDebugLogEnabled)
397 } catch (Exception e) {
398 // Do NOT throw WorkflowException!
399 logError('Caught exception in ' + method, e)