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