Code changes in BPMN infra for RAN Slice Use case
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / bpmn / infrastructure / flowspecific / tasks / NssiCDSProcessingBB.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (c) 2022 Deutsche telekom
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
22 package org.onap.so.bpmn.infrastructure.flowspecific.tasks;
23
24 import org.onap.so.bpmn.common.BuildingBlockExecution;
25 import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerContext;
26 import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerRunnable;
27 import org.onap.so.client.cds.AbstractCDSProcessingBBUtils;
28 import org.onap.so.client.cds.GeneratePayloadForCds;
29 import org.onap.so.client.cds.beans.AbstractCDSPropertiesBean;
30 import org.onap.so.client.exception.ExceptionBuilder;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.stereotype.Component;
35
36 /**
37  * This class is used in context of Building Block flow for configuration of vnf/vfmodule/service.
38  *
39  * @param - BuildingBlockExecution
40  */
41 @Component
42 public class NssiCDSProcessingBB implements ControllerRunnable<BuildingBlockExecution> {
43     private static final Logger logger = LoggerFactory.getLogger(NssiCDSProcessingBB.class);
44     private static final String EXECUTION_OBJECT = "executionObject";
45     public static final String CDS_ACTOR = "cds";
46     public static final String NSSI_SCOPE = "nssi";
47
48     @Autowired
49     private ExceptionBuilder exceptionBuilder;
50
51     @Autowired
52     private AbstractCDSProcessingBBUtils cdsDispather;
53
54     @Autowired
55     private GeneratePayloadForCds generatePayloadForCds;
56
57     @Override
58     public Boolean understand(ControllerContext<BuildingBlockExecution> context) {
59         String scope = context.getControllerScope();
60         return CDS_ACTOR.equalsIgnoreCase(context.getControllerActor()) && NSSI_SCOPE.equalsIgnoreCase(scope);
61     }
62
63     @Override
64     public Boolean ready(ControllerContext<BuildingBlockExecution> context) {
65         return true;
66     }
67
68     @Override
69     public void prepare(ControllerContext<BuildingBlockExecution> context) {
70         BuildingBlockExecution buildingBlockExecution = context.getExecution();
71         try {
72             AbstractCDSPropertiesBean abstractCDSPropertiesBean =
73                     generatePayloadForCds.buildCdsPropertiesBean(buildingBlockExecution);
74             buildingBlockExecution.setVariable(EXECUTION_OBJECT, abstractCDSPropertiesBean);
75         } catch (Exception ex) {
76             logger.error("An exception occurred when creating payload for CDS request", ex);
77             exceptionBuilder.buildAndThrowWorkflowException(buildingBlockExecution, 7000, ex);
78         }
79     }
80
81     @Override
82     public void run(ControllerContext<BuildingBlockExecution> context) {
83         BuildingBlockExecution obj = context.getExecution();
84         cdsDispather.constructExecutionServiceInputObjectBB(obj);
85         cdsDispather.sendRequestToCDSClientBB(obj);
86     }
87 }