90c2b923b0067107a7981e3305435e85641ab821
[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.CatalogDbUtils
27 import org.onap.so.bpmn.common.scripts.ExceptionUtil
28 import org.onap.so.bpmn.core.json.JsonUtils
29 import org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames
30 import org.slf4j.Logger
31 import org.slf4j.LoggerFactory
32
33 public class HandlePNF extends AbstractServiceTaskProcessor{
34     private static final Logger logger = LoggerFactory.getLogger( HandlePNF.class);
35
36     ExceptionUtil exceptionUtil = new ExceptionUtil()
37     JsonUtils jsonUtil = new JsonUtils()
38     CatalogDbUtils cutils = new CatalogDbUtils()
39
40     @Override
41     void preProcessRequest(DelegateExecution execution) {
42         msoLogger.debug("Start preProcess for HandlePNF")
43
44         // set correlation ID
45         def resourceInput = execution.getVariable("resourceInput")
46         String serInput = jsonUtil.getJsonValue(resourceInput, "requestsInputs")
47         String correlationId = jsonUtil.getJsonValue(serInput, "service.parameters.requestInputs.ont_ont_pnf_name")
48         if (!StringUtils.isEmpty(correlationId)) {
49             execution.setVariable(ExecutionVariableNames.CORRELATION_ID, correlationId)
50             msoLogger.debug("Found correlation id : " + correlationId)
51         } else {
52             msoLogger.error("== correlation id is empty ==")
53             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "correlation id is not provided")
54         }
55
56         // next task will set the uuid
57         msoLogger.debug("exit preProcess for HandlePNF")
58     }
59
60     void postProcessRequest(DelegateExecution execution) {
61         msoLogger.debug("start postProcess for HandlePNF")
62
63         msoLogger.debug("exit postProcess for HandlePNF")
64     }
65
66     public void sendSyncResponse (DelegateExecution execution) {
67         msoLogger.debug(" *** sendSyncResponse *** ")
68
69         try {
70             String operationStatus = "finished"
71             // RESTResponse for main flow
72             String resourceOperationResp = """{"operationStatus":"${operationStatus}"}""".trim()
73             msoLogger.debug(" sendSyncResponse to APIH:" + "\n" + resourceOperationResp)
74             sendWorkflowResponse(execution, 202, resourceOperationResp)
75             execution.setVariable("sentSyncResponse", true)
76
77         } catch (Exception ex) {
78             String msg = "Exception in sendSyncResponse:" + ex.getMessage()
79             msoLogger.debug(msg)
80             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
81         }
82         msoLogger.debug(" ***** Exit sendSyncResponse *****")
83     }
84 }