2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.bpmn.infrastructure.scripts
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
32 public class HandlePNF extends AbstractServiceTaskProcessor{
33 private static final Logger logger = LoggerFactory.getLogger( HandlePNF.class);
35 ExceptionUtil exceptionUtil = new ExceptionUtil()
36 JsonUtils jsonUtil = new JsonUtils()
39 void preProcessRequest(DelegateExecution execution) {
40 logger.debug("Start preProcess for HandlePNF")
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)
49 logger.error("== correlation id is empty ==")
50 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "correlation id is not provided")
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)
58 logger.error("== serviceInstance ID is empty ==")
59 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "serviceInstance ID is not provided")
62 // next task will set the uuid
63 logger.debug("exit preProcess for HandlePNF")
66 void postProcessRequest(DelegateExecution execution) {
67 logger.debug("start postProcess for HandlePNF")
69 logger.debug("exit postProcess for HandlePNF")
72 public void sendSyncResponse (DelegateExecution execution) {
73 logger.debug(" *** sendSyncResponse *** ")
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)
83 } catch (Exception ex) {
84 String msg = "Exception in sendSyncResponse:" + ex.getMessage()
86 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
88 logger.debug(" ***** Exit sendSyncResponse *****")