PNF WF post instantiation configuration
[so.git] / bpmn / so-bpmn-infrastructure-common / src / main / java / org / onap / so / bpmn / infrastructure / pnf / delegate / PrepareConfigAssignDelegate.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.MODEL_UUID;
23 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_CORRELATION_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_CUSTOMIZATION_UUID;
26 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PRC_INSTANCE_NAME;
27 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.SERVICE_INSTANCE_ID;
28
29 import org.camunda.bpm.engine.delegate.DelegateExecution;
30 import org.camunda.bpm.engine.delegate.JavaDelegate;
31 import org.onap.so.client.cds.beans.AbstractCDSPropertiesBean;
32 import org.onap.so.client.cds.beans.ConfigAssignPropertiesForPnf;
33 import org.onap.so.client.cds.beans.ConfigAssignRequestPnf;
34 import org.springframework.stereotype.Component;
35
36 /**
37  * This implementation of {@link JavaDelegate} is used to prepare for config Assign.
38  *
39  * It queries the PNF resource customization table and construct the {@link AbstractCDSPropertiesBean} as
40  * executionObject.
41  */
42 @Component
43 public class PrepareConfigAssignDelegate extends PrepareCdsCallDelegate {
44
45     public PrepareConfigAssignDelegate() {
46         this.actionName = "config-assign";
47         this.mode = "sync";
48     }
49
50     @Override
51     protected String getRequestObject(final DelegateExecution delegateExecution){
52
53         ConfigAssignPropertiesForPnf configAssignProperties = new ConfigAssignPropertiesForPnf();
54         configAssignProperties.setServiceInstanceId((String) delegateExecution.getVariable(SERVICE_INSTANCE_ID));
55
56         /**
57          * PNF Name matches the name in AAI, i.e., correlationID as in customized workflow.
58          */
59         configAssignProperties.setPnfName((String) delegateExecution.getVariable(PNF_CORRELATION_ID));
60
61         /**
62          * PNF id match AAI entry, i.e, PNF UUID.
63          */
64         configAssignProperties.setPnfId((String) delegateExecution.getVariable(PNF_UUID));
65         configAssignProperties.setPnfCustomizationUuid((String) delegateExecution.getVariable(PRC_CUSTOMIZATION_UUID));
66         configAssignProperties.setServiceModelUuid((String) delegateExecution.getVariable(MODEL_UUID));
67
68         ConfigAssignRequestPnf configAssignRequest = new ConfigAssignRequestPnf();
69         configAssignRequest.setConfigAssignPropertiesForPnf(configAssignProperties);
70
71         /**
72          * resolution key is the same as PNF name.
73          */
74         configAssignRequest.setResolutionKey((String) delegateExecution.getVariable(PNF_CORRELATION_ID));
75
76         return configAssignRequest.toString();
77     }
78
79 }