49887af4bea52e76da71a8562c459ee1baa9bdbf
[so.git] / bpmn / so-bpmn-infrastructure-common / src / main / java / org / onap / so / bpmn / infrastructure / pnf / delegate / PrepareCdsCallDelegate.java
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 Nordix Foundation.
4  *  ================================================================================
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  *
16  *  SPDX-License-Identifier: Apache-2.0
17  *  ============LICENSE_END=========================================================
18  */
19
20 package org.onap.so.bpmn.infrastructure.pnf.delegate;
21
22 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.EXECUTION_OBJECT;
23 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.MSO_REQUEST_ID;
24 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_UUID;
25 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PRC_BLUEPRINT_NAME;
26 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PRC_BLUEPRINT_VERSION;
27
28 import org.camunda.bpm.engine.delegate.DelegateExecution;
29 import org.camunda.bpm.engine.delegate.JavaDelegate;
30 import org.onap.so.client.cds.beans.AbstractCDSPropertiesBean;
31 import org.onap.so.client.exception.ExceptionBuilder;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34 import org.springframework.beans.factory.annotation.Autowired;
35
36 /**
37  * Abstract class for preparing CDS call.
38  */
39 public abstract class PrepareCdsCallDelegate implements JavaDelegate {
40
41     protected Logger logger = LoggerFactory.getLogger(this.getClass());
42
43     protected static final String ORIGINATOR_ID = "SO";
44     protected static final int ERROR_CODE = 7010;
45
46     protected String actionName;
47     protected String mode;
48
49     @Autowired
50     protected ExceptionBuilder exceptionUtil;
51
52     @Override
53     public void execute(DelegateExecution delegateExecution){
54
55         logger.debug("Running execute block for activity:{}", delegateExecution.getCurrentActivityId());
56         AbstractCDSPropertiesBean cdsPropertiesBean = new AbstractCDSPropertiesBean();
57         cdsPropertiesBean.setBlueprintName((String) delegateExecution.getVariable(PRC_BLUEPRINT_NAME));
58         cdsPropertiesBean.setBlueprintVersion((String) delegateExecution.getVariable(PRC_BLUEPRINT_VERSION));
59         cdsPropertiesBean.setOriginatorId(ORIGINATOR_ID);
60         cdsPropertiesBean.setActionName(getActionName());
61         cdsPropertiesBean.setMode(getMode());
62         cdsPropertiesBean.setRequestId((String) delegateExecution.getVariable(MSO_REQUEST_ID));
63         cdsPropertiesBean.setSubRequestId((String) delegateExecution.getVariable(PNF_UUID));
64         cdsPropertiesBean.setRequestObject(getRequestObject(delegateExecution));
65         delegateExecution.setVariable(EXECUTION_OBJECT, cdsPropertiesBean);
66     }
67
68     /**
69      * Return the request object sent to CDS call.
70      *
71      * @param delegateExecution BPMN delegateExecution context
72      * @return string value of the request object
73      */
74     protected abstract String getRequestObject(final DelegateExecution delegateExecution);
75
76     public String getActionName() {
77         return actionName;
78     }
79
80     public String getMode() {
81         return mode;
82     }
83
84 }