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