removed unused CatalogDbUtils instantiation
[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
42         // set correlation ID
43         def resourceInput = execution.getVariable("resourceInput")
44         String serInput = jsonUtil.getJsonValue(resourceInput, "requestsInputs")
45         String correlationId = jsonUtil.getJsonValue(serInput, "service.parameters.requestInputs.ont_ont_pnf_name")
46         if (!StringUtils.isEmpty(correlationId)) {
47             execution.setVariable(ExecutionVariableNames.CORRELATION_ID, correlationId)
48             logger.debug("Found correlation id : " + correlationId)
49         } else {
50             logger.error("== correlation id is empty ==")
51             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "correlation id is not provided")
52         }
53
54         // next task will set the uuid
55         logger.debug("exit preProcess for HandlePNF")
56     }
57
58     void postProcessRequest(DelegateExecution execution) {
59         logger.debug("start postProcess for HandlePNF")
60
61         logger.debug("exit postProcess for HandlePNF")
62     }
63
64     public void sendSyncResponse (DelegateExecution execution) {
65         logger.debug(" *** sendSyncResponse *** ")
66
67         try {
68             String operationStatus = "finished"
69             // RESTResponse for main flow
70             String resourceOperationResp = """{"operationStatus":"${operationStatus}"}""".trim()
71             logger.debug(" sendSyncResponse to APIH:" + "\n" + resourceOperationResp)
72             sendWorkflowResponse(execution, 202, resourceOperationResp)
73             execution.setVariable("sentSyncResponse", true)
74
75         } catch (Exception ex) {
76             String msg = "Exception in sendSyncResponse:" + ex.getMessage()
77             logger.debug(msg)
78             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
79         }
80         logger.debug(" ***** Exit sendSyncResponse *****")
81     }
82 }