2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
21 package org.openecomp.mso.bpmn.common.scripts
\r
23 import java.text.SimpleDateFormat
\r
25 import org.apache.commons.lang3.*
\r
26 import org.camunda.bpm.engine.runtime.Execution
\r
28 public class FalloutHandler extends AbstractServiceTaskProcessor {
\r
30 ExceptionUtil exceptionUtil = new ExceptionUtil()
\r
32 public initializeProcessVariables(Execution execution){
\r
33 def method = getClass().getSimpleName() + '.initializeProcessVariables(' +'execution=' + execution.getId() +')'
\r
34 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
35 logDebug('Entered ' + method, isDebugLogEnabled)
\r
38 execution.setVariable("prefix",Prefix)
\r
40 //These variables are form the input Message to the BPMN
\r
41 execution.setVariable("FH_request_id","")
\r
42 execution.setVariable("FH_request_action","")
\r
43 execution.setVariable("FH_notification-url","")
\r
44 execution.setVariable("FH_mso-bpel-name","")
\r
45 execution.setVariable("FH_ErrorCode", "")
\r
46 execution.setVariable("FH_ErrorMessage", "")
\r
48 execution.setVariable("FH_notification-url-Ok", false)
\r
49 execution.setVariable("FH_request_id-Ok", false)
\r
51 //These variables are for Get Mso Aai Password Adapter
\r
52 execution.setVariable("FH_deliveryStatus", true)
\r
54 //update Response Status to pending ...Adapter variables
\r
55 execution.setVariable("FH_updateResponseStatusPayload", null)
\r
56 execution.setVariable("FH_updateResponseStatusResponse", null)
\r
58 //update Request Gamma ...Adapter variables
\r
59 execution.setVariable("FH_updateRequestGammaPayload", "")
\r
60 execution.setVariable("FH_updateRequestGammaResponse", null)
\r
61 execution.setVariable("FH_updateRequestGammaResponseCode", null)
\r
63 //update Request Infra ...Adapter variables
\r
64 execution.setVariable("FH_updateRequestInfraPayload", "")
\r
65 execution.setVariable("FH_updateRequestInfraResponse", null)
\r
66 execution.setVariable("FH_updateRequestInfraResponseCode", null)
\r
68 //assign True to success variable
\r
69 execution.setVariable("FH_success", true)
\r
71 //Set notify status to Failed variable
\r
72 execution.setVariable("FH_NOTIFY_STATUS", "SUCCESS")
\r
74 //Set DB update variable
\r
75 execution.setVariable("FH_updateRequestPayload", "")
\r
76 execution.setVariable("FH_updateRequestResponse", null)
\r
77 execution.setVariable("FH_updateRequestResponseCode", null)
\r
80 execution.setVariable("BasicAuthHeaderValue","")
\r
83 execution.setVariable("FH_parameterList", "")
\r
85 //Response variables
\r
86 execution.setVariable("FalloutHandlerResponse","")
\r
87 execution.setVariable("FH_ErrorResponse", null)
\r
88 execution.setVariable("FH_ResponseCode", "")
\r
90 } catch (Exception e) {
\r
91 logError('Caught exception in ' + method, e)
\r
92 // exceptionUtil.buildWorkflowException(execution, 2000, "Internal Error - Occured in " + method)
\r
96 public void preProcessRequest (Execution execution) {
\r
97 def method = getClass().getSimpleName() + '.preProcessRequest(' +'execution=' + execution.getId() +')'
\r
98 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
99 logDebug('Entered ' + method, isDebugLogEnabled)
\r
101 // Initialize flow variables
\r
102 initializeProcessVariables(execution)
\r
103 setSuccessIndicator(execution, false)
\r
105 setBasicDBAuthHeader(execution, isDebugLogEnabled)
\r
108 def xml = execution.getVariable("FalloutHandlerRequest")
\r
109 utils.log("DEBUG", " XML --> " + xml, isDebugLogEnabled)
\r
110 utils.logAudit("FalloutHandler request: " + xml)
\r
112 //Check the incoming request type
\r
113 //Incoming request can be ACTIVE_REQUESTS (request-information node) or INFRA_ACTIVE_REQUESTS (request-info node)
\r
114 if (utils.nodeExists(xml, "request-information")) {
\r
115 execution.setVariable("FH_request_id-Ok", true) // Incoming request is for ACTIVE_REQUESTS
\r
118 //Check notification-url for the incoming request type
\r
119 //ACTIVE_REQUESTS may have notificationurl node
\r
120 //INFRA_ACTIVE_REQUESTS notificationurl node does not exist
\r
121 def notificationurl = ""
\r
122 if (utils.nodeExists(xml, "notification-url")) {
\r
123 notificationurl = utils.getNodeText(xml,"notification-url")
\r
124 if(notificationurl != null && !notificationurl.isEmpty()) {
\r
125 utils.log("DEBUG", "********** Incoming notification Url is: " + notificationurl,isDebugLogEnabled);
\r
126 execution.setVariable("FH_notification-url-Ok", true)
\r
127 execution.setVariable("FH_notification-url",notificationurl)
\r
131 //Check request_id for the incoming request type
\r
132 //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)
\r
133 //For ACTIVE_REQUESTS payload request-id is NOT optional
\r
134 def request_id = ""
\r
135 if (utils.nodeExists(xml, "request-id")) {
\r
136 execution.setVariable("FH_request_id",utils.getNodeText(xml,"request-id"))
\r
138 utils.logAudit("FH_request_id: " + execution.getVariable("FH_request_id"))
\r
140 // INFRA_ACTIVE_REQUESTS have "action" element ... mandatory
\r
141 // ACTIVE_REQUEST have "request-action" ... mandatory
\r
142 if (utils.nodeExists(xml, "request-action")) {
\r
143 execution.setVariable("FH_request_action",utils.getNodeText(xml,"request-action"))
\r
144 } else if (utils.nodeExists(xml, "action")) {
\r
145 execution.setVariable("FH_request_action",utils.getNodeText(xml,"action"))
\r
149 //Check source for the incoming request type
\r
150 //For INFRA_ACTIVE_REQUESTS payload source IS optional
\r
151 //For ACTIVE_REQUESTS payload source is NOT optional
\r
153 if (utils.nodeExists(xml, "source")) {
\r
154 execution.setVariable("FH_source",utils.getNodeText(xml,"source"))
\r
157 //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.
\r
159 if (utils.nodeExists(xml, "ErrorCode")) {
\r
160 errorCode = utils.getNodeText(xml,"ErrorCode")
\r
161 if(errorCode != null && !errorCode.isEmpty()) {
\r
162 execution.setVariable("FH_ErrorCode", errorCode)
\r
165 utils.logAudit("FH_ErrorCode: " + errorCode)
\r
167 //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.
\r
168 def errorMessage = ""
\r
169 if (utils.nodeExists(xml, "ErrorMessage")) {
\r
170 errorCode = utils.getNodeText(xml,"ErrorMessage")
\r
171 if(errorCode != null && !errorCode.isEmpty()) {
\r
172 errorCode = errorCode.replace("&", "&").replace("<", "<").replace(">", ">")
\r
173 execution.setVariable("FH_ErrorMessage", errorCode)
\r
177 //Check for Parameter List
\r
178 if (utils.nodeExists(xml, "parameter-list")) {
\r
179 def parameterList = utils.getNodeXml(xml, "parameter-list", false)
\r
180 execution.setVariable("FH_parameterList", parameterList)
\r
183 utils.log("DEBUG","FH_notification-url-Ok --> " + execution.getVariable("FH_notification-url-Ok"),isDebugLogEnabled)
\r
184 utils.log("DEBUG","FH_request_id-OK --> " + execution.getVariable("FH_request_id-Ok"),isDebugLogEnabled)
\r
186 // set the DHV/Service Instantiation values if specified in the request
\r
187 execution.setVariable("FH_is_srv_inst_req", String.valueOf("true".equals(utils.getNodeText1(xml, "is-srv-inst-req"))))
\r
188 utils.log("DEBUG", "FH_is_srv_inst_req --> " + execution.getVariable("FH_is_srv_inst_req"), isDebugLogEnabled)
\r
189 execution.setVariable("FH_is_json_content", String.valueOf("JSON".equals(utils.getNodeText1(xml, "resp-content-type"))))
\r
190 utils.log("DEBUG", "FH_is_json_content --> " + execution.getVariable("FH_is_json_content"), isDebugLogEnabled)
\r
191 execution.setVariable("FH_service_inst_id", utils.getNodeText1(xml, "service-instance-id"))
\r
192 utils.log("DEBUG", "FH_service_inst_id --> " + execution.getVariable("FH_service_inst_id"), isDebugLogEnabled)
\r
193 execution.setVariable("FH_start_time", utils.getNodeText1(xml, "start-time"))
\r
194 utils.log("DEBUG", "FH_start_time --> " + execution.getVariable("FH_start_time"), isDebugLogEnabled)
\r
195 // this variable is used by the camunda flow to set the Content-Type for the async response
\r
196 if (execution.getVariable("FH_is_srv_inst_req").equals("true") &&
\r
197 execution.getVariable("FH_is_json_content").equals("true")) {
\r
198 execution.setVariable("FH_content_type", "application/json")
\r
200 execution.setVariable("FH_content_type", "text/xml")
\r
202 } catch (Exception e) {
\r
203 logError('Caught exception in ' + method, e)
\r
204 // exceptionUtil.buildWorkflowException(execution, 2000, "Internal Error - Occured in" + method)
\r
207 utils.log("DEBUG","OUTOF --> Initialize Variables Fallout Handler #########",isDebugLogEnabled);
\r
210 public String updateRequestPayload (Execution execution){
\r
211 def method = getClass().getSimpleName() + '.updateRequestPayload(' +'execution=' + execution.getId() +')'
\r
212 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
213 logDebug('Entered ' + method, isDebugLogEnabled)
\r
216 String payload = """
\r
217 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://org.openecomp.mso/requestsdb">
\r
220 <req:updateRequest>
\r
221 <requestId>${execution.getVariable("FH_request_id")}</requestId>
\r
222 <lastModifiedBy>BPEL</lastModifiedBy>
\r
223 <finalErrorMessage>${execution.getVariable("FH_ErrorMessage")}</finalErrorMessage>
\r
224 <finalErrorCode>${execution.getVariable("FH_ErrorCode")}</finalErrorCode>
\r
225 <status>FAILED</status>
\r
226 <responseStatus>${execution.getVariable("FH_NOTIFY_STATUS")}</responseStatus>
\r
227 </req:updateRequest>
\r
229 </soapenv:Envelope>
\r
232 utils.logAudit("updateRequestPayload: " + payload)
\r
233 execution.setVariable("FH_updateRequestPayload", payload)
\r
234 return execution.getVariable("FH_updateRequestPayload")
\r
235 } catch (Exception e) {
\r
236 logError('Caught exception in ' + method, e)
\r
237 // exceptionUtil.buildWorkflowException(execution, 2000, "Internal Error - Occured in " + method)
\r
241 public String updateRequestInfraPayload (Execution execution){
\r
242 def method = getClass().getSimpleName() + '.updateRequestInfraPayload(' +'execution=' + execution.getId() +')'
\r
243 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
244 logDebug('Entered ' + method, isDebugLogEnabled)
\r
247 String payload = """
\r
248 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://org.openecomp.mso/requestsdb">
\r
251 <req:updateInfraRequest>
\r
252 <requestId>${execution.getVariable("FH_request_id")}</requestId>
\r
253 <lastModifiedBy>BPEL</lastModifiedBy>
\r
254 <statusMessage>${execution.getVariable("FH_ErrorMessage")}</statusMessage>
\r
255 <requestStatus>FAILED</requestStatus>
\r
256 <progress>100</progress>
\r
257 </req:updateInfraRequest>
\r
259 </soapenv:Envelope>
\r
262 execution.setVariable("FH_updateRequestInfraPayload", payload)
\r
263 utils.logAudit("updateRequestInfraPayload: " + payload)
\r
264 return execution.getVariable("FH_updateRequestInfraPayload")
\r
265 } catch (Exception e) {
\r
266 logError('Caught exception in ' + method, e)
\r
267 // exceptionUtil.buildWorkflowException(execution, 2000, "Internal Error - Occured in " + method)
\r
271 public String updateRequestGammaPayload (Execution execution){
\r
272 def method = getClass().getSimpleName() + '.updateRequestGammaPayload(' +'execution=' + execution.getId() +')'
\r
273 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
274 logDebug('Entered ' + method, isDebugLogEnabled)
\r
277 String payload = """
\r
278 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="${execution.getVariable("URN_mso_default_adapter_namespace")}/requestsdb">
\r
281 <req:updateRequest>
\r
282 <requestId>${execution.getVariable("FH_request_id")}</requestId>
\r
283 <lastModifiedBy>BPEL</lastModifiedBy>
\r
284 <finalErrorMessage>${execution.getVariable("FH_ErrorMessage")}</finalErrorMessage>
\r
285 <finalErrorCode>${execution.getVariable("FH_ErrorCode")}</finalErrorCode>
\r
286 <status>FAILED</status>
\r
287 </req:updateRequest>
\r
289 </soapenv:Envelope>
\r
292 execution.setVariable("FH_updateRequestGammaPayload", payload)
\r
293 utils.logAudit("updateRequestGammaPayload: " + payload)
\r
294 return execution.getVariable("FH_updateRequestGammaPayload")
\r
295 } catch (Exception e) {
\r
296 logError('Caught exception in ' + method, e)
\r
297 // exceptionUtil.buildWorkflowException(execution, 2000, "Internal Error - Occured in " + method)
\r
301 public String updateResponseStatusPayload (Execution execution){
\r
302 def method = getClass().getSimpleName() + '.updateResponseStatusPayload(' +'execution=' + execution.getId() +')'
\r
303 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
304 logDebug('Entered ' + method, isDebugLogEnabled)
\r
307 String payload = """
\r
308 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://org.openecomp.mso/requestsdb">
\r
311 <req:updateResponseStatus>
\r
312 <requestId>${execution.getVariable("FH_request_id")}</requestId>
\r
313 <lastModifiedBy>BPEL</lastModifiedBy>
\r
314 <responseStatus>SENDING_FINAL_NOTIFY</responseStatus>
\r
315 </req:updateResponseStatus>
\r
317 </soapenv:Envelope>
\r
320 execution.setVariable("FH_updateResponseStatusPayload", payload)
\r
321 utils.logAudit("updateResponseStatusPayload: " + payload)
\r
322 return execution.getVariable("FH_updateResponseStatusPayload")
\r
323 } catch (Exception e) {
\r
324 logError('Caught exception in ' + method, e)
\r
325 // exceptionUtil.buildWorkflowException(execution, 2000, "Internal Error - Occured in " + method)
\r
329 public void buildDBWorkflowException(Execution execution, String responseCodeVariable) {
\r
330 def method = getClass().getSimpleName() + '.buildDBWorkflowException(' +
\r
331 'execution=' + execution.getId() +
\r
332 ', responseCodeVariable=' + responseCodeVariable + ')'
\r
333 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
334 logDebug('Entered ' + method, isDebugLogEnabled)
\r
337 def responseCode = execution.getVariable(responseCodeVariable)
\r
338 // If the HTTP response code was null, it means a connection fault occurred (a java exception)
\r
339 def errorMessage = responseCode == null ? "Could not connect to DB Adapter" : "DB Adapter returned ${responseCode} response"
\r
340 def errorCode = responseCode == null ? 7000 : 7020
\r
341 // exceptionUtil.buildWorkflowException(execution, errorCode, errorMessage)
\r
342 } catch (Exception e) {
\r
343 logError('Caught exception in ' + method, e)
\r
344 // exceptionUtil.buildWorkflowException(execution, 2000, "Internal Error - Occured in " + method)
\r
349 * Used to create a workflow response in success and failure cases.
\r
351 public void postProcessResponse (Execution execution) {
\r
352 def method = getClass().getSimpleName() + '.postProcessResponse(' +'execution=' + execution.getId() +')'
\r
353 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
354 logDebug('Entered ' + method, isDebugLogEnabled)
\r
357 Boolean success = (Boolean) execution.getVariable("FH_success")
\r
358 String out = success ? "Fallout Handler Succeeded" : "Fallout Handler Failed";
\r
360 def falloutHandlerResponse = """
\r
361 <workflow:FalloutHandlerResponse xmlns:workflow="http://org.openecomp/mso/workflow/schema/v1">
\r
362 <workflow:out>${out}</workflow:out>
\r
363 </workflow:FalloutHandlerResponse>
\r
366 falloutHandlerResponse = utils.formatXml(falloutHandlerResponse)
\r
367 utils.logAudit("FalloutHandler Response: " + falloutHandlerResponse);
\r
369 execution.setVariable("FalloutHandlerResponse", falloutHandlerResponse)
\r
370 execution.setVariable("WorkflowResponse", falloutHandlerResponse)
\r
371 execution.setVariable("FH_ResponseCode", success ? "200" : "500")
\r
372 setSuccessIndicator(execution, success)
\r
374 logDebug("FalloutHandlerResponse =\n" + falloutHandlerResponse, isDebugLogEnabled)
\r
375 } catch (Exception e) {
\r
376 // Do NOT throw WorkflowException!
\r
377 logError('Caught exception in ' + method, e)
\r