Merge "Added post process to AAI in HandlePNF" into dublin
[so.git] / bpmn / so-bpmn-infrastructure-common / src / main / groovy / org / onap / so / bpmn / infrastructure / scripts / DeleteVFCNSResource.groovy
1
2 /*-
3  * ============LICENSE_START=======================================================
4  * ONAP - SO
5  * ================================================================================
6  * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
7  * ================================================================================
8  * Modifications Copyright (c) 2019 Samsung
9  * ================================================================================
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  * ============LICENSE_END=========================================================
22  */
23 package org.onap.so.bpmn.infrastructure.scripts
24
25 import com.fasterxml.jackson.databind.ObjectMapper
26 import org.onap.so.bpmn.common.recipe.ResourceInput
27 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
28 import org.camunda.bpm.engine.delegate.DelegateExecution
29 import org.onap.so.bpmn.core.json.JsonUtils
30 import org.onap.so.bpmn.common.scripts.ExceptionUtil
31 import org.slf4j.Logger
32 import org.slf4j.LoggerFactory
33
34
35 public class DeleteVFCNSResource extends AbstractServiceTaskProcessor {
36
37     String Prefix = "DCUSE_"
38     ExceptionUtil exceptionUtil = new ExceptionUtil()
39     JsonUtils jsonUtil = new JsonUtils()
40
41     private static final Logger logger = LoggerFactory.getLogger( DeleteVFCNSResource.class);
42
43     public void preProcessRequest (DelegateExecution execution) {
44         def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
45         logger.info(" ***** start preProcessRequest *****")
46
47         String resourceInputStr = execution.getVariable("resourceInput")
48         ResourceInput resourceInput = new ObjectMapper().readValue(resourceInputStr, ResourceInput.class)
49
50         String globalSubscriberId = resourceInput.getGlobalSubscriberId()
51         String serviceType = execution.getVariable("serviceType")
52         String operationId = resourceInput.getOperationId()
53         String resourceModeluuid = resourceInput.getResourceModelInfo().getModelCustomizationUuid()
54         String resourceInstanceId = resourceInput.getResourceInstancenUuid()
55
56
57         execution.setVariable("globalSubscriberId",globalSubscriberId)
58         execution.setVariable("serviceType", serviceType)
59         execution.setVariable("operationId", operationId)
60         execution.setVariable("resourceTemplateId", resourceModeluuid)
61         execution.setVariable("resourceInstanceId", resourceInstanceId)
62
63         logger.info(" ***** end preProcessRequest *****")
64     }
65
66     public void postProcessRequest (DelegateExecution execution) {
67         def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
68         logger.info(" ***** start postProcessRequest *****")
69
70         logger.info(" ***** end postProcessRequest *****")
71     }
72
73     public void sendSyncResponse (DelegateExecution execution) {
74         def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
75         logger.debug( " *** sendSyncResponse *** ")
76
77         try {
78             String nsInstanceId = execution.getVariable("nsInstanceId")
79             String operationStatus = execution.getVariable("operationStatus")
80             // RESTResponse for main flow
81             String createVFCResourceRestRsp = """{"nsInstanceId":"${nsInstanceId}","operationStatus":"${operationStatus}"}""".trim()
82             logger.debug( " sendSyncResponse to APIH:" + "\n" + createVFCResourceRestRsp)
83             sendWorkflowResponse(execution, 202, createVFCResourceRestRsp)
84             execution.setVariable("sentSyncResponse", true)
85
86         } catch (Exception ex) {
87             String msg = "Exceptuion in sendSyncResponse:" + ex.getMessage()
88             logger.debug( msg)
89             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
90         }
91         logger.debug(" ***** Exit sendSyncResopnse *****")
92     }
93 }