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.infrastructure.scripts;
23 import static org.apache.commons.lang3.StringUtils.*;
25 import org.apache.commons.lang3.*
26 import org.camunda.bpm.engine.delegate.BpmnError
27 import org.camunda.bpm.engine.delegate.DelegateExecution
28 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
29 import org.onap.so.bpmn.common.scripts.ExceptionUtil
30 import org.onap.so.bpmn.common.scripts.MsoUtils
31 import org.onap.so.bpmn.common.scripts.VidUtils
32 import org.onap.so.bpmn.core.WorkflowException
33 import org.onap.so.bpmn.core.json.JsonUtils
34 import org.onap.so.logger.MsoLogger
39 * This groovy class supports the <class>DelServiceInstance.bpmn</class> process.
42 public class DeleteGenericALaCarteServiceInstance extends AbstractServiceTaskProcessor {
44 String Prefix="DELSI_"
45 ExceptionUtil exceptionUtil = new ExceptionUtil()
46 JsonUtils jsonUtil = new JsonUtils()
47 VidUtils vidUtils = new VidUtils()
49 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DeleteGenericALaCarteServiceInstance.class);
51 public void preProcessRequest (DelegateExecution execution) {
52 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
53 execution.setVariable("prefix",Prefix)
56 msoLogger.trace("Start preProcessRequest")
59 // check for incoming json message/input
60 String siRequest = execution.getVariable("bpmnRequest")
62 String requestId = execution.getVariable("mso-request-id")
63 execution.setVariable("msoRequestId", requestId)
64 msoLogger.debug("Input Request:" + siRequest + " reqId:" + requestId)
66 String serviceInstanceId = execution.getVariable("serviceInstanceId")
67 if (isBlank(serviceInstanceId)) {
68 msg = "Input serviceInstanceId' is null"
69 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
72 //String xmlRequestDetails = vidUtils.getJsonRequestDetailstoXml(siRequest)
73 //execution.setVariable("requestDetails", xmlRequestDetails)
76 String serviceModelInfo = jsonUtil.getJsonValue(siRequest, "requestDetails.modelInfo")
77 if (isBlank(serviceModelInfo)) {
78 msg = "Input serviceModelInfo is null"
82 execution.setVariable("serviceModelInfo", serviceModelInfo)
83 //msoLogger.debug("modelInfo" + serviceModelInfo)
87 String productFamilyId = jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.productFamilyId")
88 if (isBlank(productFamilyId))
90 msg = "Input productFamilyId is null"
92 //exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
94 execution.setVariable("productFamilyId", productFamilyId)
96 String source = jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.source")
97 execution.setVariable("source", source)
100 String globalSubscriberId = jsonUtil.getJsonValue(siRequest, "requestDetails.subscriberInfo.globalSubscriberId")
101 if (isBlank(globalSubscriberId)) {
102 msg = "Input globalSubscriberId' is null"
105 execution.setVariable("globalSubscriberId", globalSubscriberId)
109 String subscriptionServiceType = jsonUtil.getJsonValue(siRequest, "requestDetails.requestParameters.subscriptionServiceType")
110 if (isBlank(subscriptionServiceType)) {
111 msg = "Input subscriptionServiceType is null"
113 //exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
115 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
119 * Extracting User Parameters from incoming Request and converting into a Map
121 def jsonSlurper = new JsonSlurper()
122 def jsonOutput = new JsonOutput()
124 Map reqMap = jsonSlurper.parseText(siRequest)
127 def userParams = reqMap.requestDetails?.requestParameters?.userParams
129 Map<String, String> inputMap = [:]
132 userParam -> inputMap.put(userParam.name, userParam.value.toString())
136 msoLogger.debug("User Input Parameters map: " + userParams.toString())
137 execution.setVariable("serviceInputParams", inputMap)
139 } catch (BpmnError e) {
141 } catch (Exception ex){
142 msg = "Exception in preProcessRequest " + ex.getMessage()
144 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
146 msoLogger.trace("Exit preProcessRequest")
149 public void sendSyncResponse (DelegateExecution execution) {
150 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
151 msoLogger.trace("Start sendSyncResponse")
154 String requestId = execution.getVariable("msoRequestId")
155 String serviceInstanceId = execution.getVariable("serviceInstanceId")
157 // RESTResponse (for API Handler (APIH) Reply Task)
158 String syncResponse = """{"requestReferences":{"instanceId":"${serviceInstanceId}","requestId":"${requestId}"}}""".trim()
159 msoLogger.debug(" sendSynchResponse: xmlSyncResponse - " + "\n" + syncResponse)
160 sendWorkflowResponse(execution, 202, syncResponse)
162 } catch (Exception ex) {
163 String msg = "Exception in sendSyncResponse: " + ex.getMessage()
164 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
166 msoLogger.trace("Exit sendSyncResopnse")
169 public void sendSyncError (DelegateExecution execution) {
170 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
171 msoLogger.trace("Start sendSyncError")
174 String errorMessage = ""
175 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
176 WorkflowException wfe = execution.getVariable("WorkflowException")
177 errorMessage = wfe.getErrorMessage()
179 errorMessage = "Sending Sync Error."
182 String buildworkflowException =
183 """<aetgt:WorkflowException xmlns:aetgt="http://org.onap/so/workflow/schema/v1">
184 <aetgt:ErrorMessage>${MsoUtils.xmlEscape(errorMessage)}</aetgt:ErrorMessage>
185 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
186 </aetgt:WorkflowException>"""
188 MsoLogger.info(buildworkflowException)
189 sendWorkflowResponse(execution, 500, buildworkflowException)
191 } catch (Exception ex) {
192 msoLogger.debug(" Sending Sync Error Activity Failed. " + "\n" + ex.getMessage())
197 public void prepareCompletionRequest (DelegateExecution execution) {
198 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
199 msoLogger.trace("Start prepareCompletion")
202 String requestId = execution.getVariable("msoRequestId")
203 String source = execution.getVariable("source")
204 String msoCompletionRequest =
205 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
206 xmlns:ns="http://org.onap/so/request/types/v1">
207 <request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
208 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
209 <action>DELETE</action>
210 <source>${MsoUtils.xmlEscape(source)}</source>
212 <aetgt:status-message>Service Instance was deleted successfully.</aetgt:status-message>
213 <aetgt:mso-bpel-name>DeleteGenericALaCarteServiceInstance</aetgt:mso-bpel-name>
214 </aetgt:MsoCompletionRequest>"""
217 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
219 execution.setVariable("completionRequest", xmlMsoCompletionRequest)
220 msoLogger.debug(" Overall SUCCESS Response going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest)
222 } catch (Exception ex) {
223 String msg = " Exception in prepareCompletion:" + ex.getMessage()
225 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
227 msoLogger.trace("Exit prepareCompletionRequest")
230 public void prepareFalloutRequest(DelegateExecution execution){
231 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
232 msoLogger.trace("Start prepareFalloutRequest")
235 WorkflowException wfex = execution.getVariable("WorkflowException")
236 msoLogger.debug(" Input Workflow Exception: " + wfex.toString())
237 String requestId = execution.getVariable("msoRequestId")
238 String source = execution.getVariable("source")
240 """<request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
241 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
242 <action>DELETE</action>
243 <source>${MsoUtils.xmlEscape(source)}</source>
246 String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
247 execution.setVariable("falloutRequest", falloutRequest)
248 } catch (Exception ex) {
249 msoLogger.debug("Exception prepareFalloutRequest:" + ex.getMessage())
250 String errorException = " Bpmn error encountered in CreateServiceInstance flow. FalloutHandlerRequest, buildErrorResponse() - " + ex.getMessage()
251 String requestId = execution.getVariable("msoRequestId")
252 String falloutRequest =
253 """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
254 xmlns:ns="http://org.onap/so/request/types/v1"
255 xmlns:wfsch="http://org.onap/so/workflow/schema/v1">
256 <request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
257 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
258 <action>DELETE</action>
261 <aetgt:WorkflowException xmlns:aetgt="http://org.onap/so/workflow/schema/v1">
262 <aetgt:ErrorMessage>${MsoUtils.xmlEscape(errorException)}</aetgt:ErrorMessage>
263 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
264 </aetgt:WorkflowException>
265 </aetgt:FalloutHandlerRequest>"""
267 execution.setVariable("falloutRequest", falloutRequest)
269 msoLogger.trace("Exit prepareFalloutRequest ")
273 // *******************************
274 // Build DB request Section
275 // *******************************
276 public void prepareDBRequest (DelegateExecution execution) {
277 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
278 execution.setVariable("prefix", Prefix)
281 msoLogger.trace("Inside prepareDBRequest of DeleteGenericALaCarteServiceInstance ")
283 String requestId = execution.getVariable("DELSI_requestId")
284 String statusMessage = "Service Instance successfully deleted."
286 //TODO - verify the format for Service Instance Delete,
288 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
291 <ns:updateInfraRequest xmlns:ns="http://org.onap.so/requestsdb">
292 <requestId>${MsoUtils.xmlEscape(requestId)}</requestId>
293 <lastModifiedBy>BPMN</lastModifiedBy>
294 <statusMessage>${MsoUtils.xmlEscape(statusMessage)}</statusMessage>
295 <responseBody></responseBody>
296 <requestStatus>COMPLETED</requestStatus>
297 <progress>100</progress>
298 </ns:updateInfraRequest>
300 </soapenv:Envelope>"""
302 String buildDeleteDBRequestAsString = utils.formatXml(dbRequest)
303 execution.setVariable("DELSI_createDBRequest", buildDeleteDBRequestAsString)
304 msoLogger.info(buildDeleteDBRequestAsString)
306 } catch (Exception ex) {
307 // try error in method block
308 String exceptionMessage = "Bpmn error encountered in DeleteGenericALaCarteServiceInstance flow. Unexpected Error from method prepareDBRequest() - " + ex.getMessage()
309 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
315 // *******************************
316 // Build Error Section
317 // *******************************
318 public void prepareDBRequestError (DelegateExecution execution) {
319 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
320 execution.setVariable("prefix", Prefix)
322 msoLogger.trace("Inside prepareDBRequestError of DeleteGenericALaCarteServiceInstance ")
325 String requestId = execution.getVariable("DELSI_requestId")
326 String statusMessage = ""
327 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
328 WorkflowException wfe = execution.getVariable("WorkflowException")
329 statusMessage = wfe.getErrorMessage()
332 statusMessage = "Encountered Error during DeleteGenericALaCarteServiceInstance proccessing. "
335 //TODO - verify the format for Service Instance Create,
337 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
340 <ns:updateInfraRequest xmlns:ns="http://org.onap.so/requestsdb">
341 <requestId>${MsoUtils.xmlEscape(requestId)}</requestId>
342 <lastModifiedBy>BPMN</lastModifiedBy>
343 <statusMessage>${MsoUtils.xmlEscape(statusMessage)}</statusMessage>
344 <responseBody></responseBody>
345 <requestStatus>FAILED</requestStatus>
346 </ns:updateInfraRequest>
348 </soapenv:Envelope>"""
350 String buildDBRequestAsString = utils.formatXml(dbRequest)
351 execution.setVariable("DELSI_createDBInfraErrorRequest", buildDBRequestAsString)
352 msoLogger.info(buildDBRequestAsString)
354 } catch (Exception ex) {
355 // try error in method block
356 String exceptionMessage = "Bpmn error encountered in DeleteGenericALaCarteServiceInstance flow. Unexpected Error from method prepareDBRequestError() - " + ex.getMessage()
357 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)