d5423b2ff76e2dc939b6e470df165df355e5e320
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2020 Nordix
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.flowspecific.tasks;
21
22 import org.camunda.bpm.engine.delegate.DelegateExecution;
23 import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerContext;
24 import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerRunnable;
25 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
26 import org.onap.so.client.cds.AbstractCDSProcessingBBUtils;
27 import org.onap.so.client.cds.GeneratePayloadForCds;
28 import org.onap.so.client.cds.PayloadConstants;
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  * For pnf, DelegateExecution is being used.
38  *
39  * @param - DelegateExecution
40  */
41 @Component
42 public class GenericPnfCDSProcessingDE implements ControllerRunnable<DelegateExecution> {
43     private static final Logger logger = LoggerFactory.getLogger(GenericPnfCDSProcessingDE.class);
44     private static final String EXECUTION_OBJECT = "executionObject";
45     private static final String ASSIGN_ACTION = "config-assign";
46     private static final String DEPLOY_ACTION = "config-deploy";
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<DelegateExecution> context) {
59         final String scope = context.getControllerScope();
60         return PayloadConstants.CDS_ACTOR.equalsIgnoreCase(context.getControllerActor())
61                 && PayloadConstants.PNF_SCOPE.equalsIgnoreCase(scope)
62                 && !(ASSIGN_ACTION.equalsIgnoreCase(context.getControllerAction())
63                         || DEPLOY_ACTION.equalsIgnoreCase(context.getControllerAction()));
64     }
65
66     @Override
67     public Boolean ready(ControllerContext<DelegateExecution> context) {
68         return true;
69     }
70
71     @Override
72     public void prepare(ControllerContext<DelegateExecution> context) {
73         DelegateExecution delegateExecution = context.getExecution();
74         try {
75             AbstractCDSPropertiesBean abstractCDSPropertiesBean =
76                     generatePayloadForCds.buildCdsPropertiesBean(delegateExecution);
77
78             delegateExecution.setVariable(EXECUTION_OBJECT, abstractCDSPropertiesBean);
79
80         } catch (Exception ex) {
81             logger.error("An exception occurred when creating payload for CDS request", ex);
82             exceptionBuilder.buildAndThrowWorkflowException(delegateExecution, 7000, ex);
83         }
84     }
85
86     @Override
87     public void run(ControllerContext<DelegateExecution> context) {
88         DelegateExecution obj = context.getExecution();
89         cdsDispather.constructExecutionServiceInputObject(obj);
90         cdsDispather.sendRequestToCDSClient(obj);
91     }
92 }