f06d71cec4e257116adc27b54f238760f754e4e1
[so.git] / bpmn / so-bpmn-infrastructure-common / src / main / groovy / org / onap / so / bpmn / infrastructure / scripts / HandlePNF.groovy
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 - 2019 Huawei 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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.scripts
22
23 import org.apache.commons.lang3.StringUtils
24 import org.camunda.bpm.engine.delegate.DelegateExecution
25 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
26 import org.onap.so.bpmn.common.scripts.ExceptionUtil
27 import org.onap.so.bpmn.core.json.JsonUtils
28 import org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames
29 import org.slf4j.Logger
30 import org.slf4j.LoggerFactory
31
32 public class HandlePNF extends AbstractServiceTaskProcessor{
33     private static final Logger logger = LoggerFactory.getLogger( HandlePNF.class);
34
35     ExceptionUtil exceptionUtil = new ExceptionUtil()
36     JsonUtils jsonUtil = new JsonUtils()
37
38     @Override
39     void preProcessRequest(DelegateExecution execution) {
40         logger.debug("Start preProcess for HandlePNF")
41         // set correlation ID
42         def resourceInput = execution.getVariable("resourceInput")
43         String serInput = jsonUtil.getJsonValue(resourceInput, "requestsInputs")
44         String correlationId = jsonUtil.getJsonValue(serInput, "service.parameters.requestInputs.ont_ont_pnf_name")
45         if (!StringUtils.isEmpty(correlationId)) {
46             execution.setVariable(ExecutionVariableNames.PNF_CORRELATION_ID, correlationId)
47             logger.debug("Found correlation id : " + correlationId)
48         } else {
49             logger.error("== correlation id is empty ==")
50             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "correlation id is not provided")
51         }
52         
53         String serviceInstanceID = jsonUtil.getJsonValue(resourceInput, ExecutionVariableNames.SERVICE_INSTANCE_ID)
54         if (!StringUtils.isEmpty(serviceInstanceID)) {
55             execution.setVariable(ExecutionVariableNames.SERVICE_INSTANCE_ID, serviceInstanceID)
56             logger.debug("found serviceInstanceID: "+serviceInstanceID)
57         } else {
58             logger.error("== serviceInstance ID is empty ==")
59             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "serviceInstance ID is not provided")
60         }
61
62         // next task will set the uuid
63         logger.debug("exit preProcess for HandlePNF")
64     }
65
66     void postProcessRequest(DelegateExecution execution) {
67         logger.debug("start postProcess for HandlePNF")
68
69         logger.debug("exit postProcess for HandlePNF")
70     }
71
72     public void sendSyncResponse (DelegateExecution execution) {
73         logger.debug(" *** sendSyncResponse *** ")
74
75         try {
76             String operationStatus = "finished"
77             // RESTResponse for main flow
78             String resourceOperationResp = """{"operationStatus":"${operationStatus}"}""".trim()
79             logger.debug(" sendSyncResponse to APIH:" + "\n" + resourceOperationResp)
80             sendWorkflowResponse(execution, 202, resourceOperationResp)
81             execution.setVariable("sentSyncResponse", true)
82
83         } catch (Exception ex) {
84             String msg = "Exception in sendSyncResponse:" + ex.getMessage()
85             logger.debug(msg)
86             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
87         }
88         logger.debug(" ***** Exit sendSyncResponse *****")
89     }
90 }