2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Bell Canada
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.client.cds;
23 import org.onap.so.bpmn.common.BuildingBlockExecution;
24 import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
25 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
26 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
27 import org.onap.so.client.cds.beans.AbstractCDSPropertiesBean;
28 import org.onap.so.client.exception.PayloadGenerationException;
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.stereotype.Component;
31 import java.util.UUID;
34 public class GeneratePayloadForCds {
36 private static final String ORIGINATOR_ID = "SO";
37 private static final String MODE = "sync";
38 private static final String BUILDING_BLOCK = "buildingBlock";
41 private VnfCDSRequestProvider vnfCDSRequestProvider;
44 private VfModuleCDSRequestProvider vfModuleCDSRequestProvider;
47 private ServiceCDSRequestProvider serviceCDSRequestProvider;
50 private ExtractPojosForBB extractPojosForBB;
53 * Build properties like (blueprint name, version, action etc..) along with the request payload.
55 * @param execution - A building block execution object.
56 * @return AbstractCDSPropertiesBean - A POJO which contains CDS related information.
57 * @throws PayloadGenerationException - Throw an exception if it fails to build payload for CDS.
59 public AbstractCDSPropertiesBean buildCdsPropertiesBean(BuildingBlockExecution execution)
60 throws PayloadGenerationException {
62 ExecuteBuildingBlock executeBuildingBlock = execution.getVariable(BUILDING_BLOCK);
63 BuildingBlock buildingBlock = executeBuildingBlock.getBuildingBlock();
64 String scope = buildingBlock.getBpmnScope();
65 String action = buildingBlock.getBpmnAction();
68 CDSRequestProvider requestProvider = getRequestProviderByScope(scope);
69 requestProvider.setExecutionObject(execution);
71 final String requestPayload = requestProvider.buildRequestPayload(action)
72 .orElseThrow(() -> new PayloadGenerationException("Failed to build payload for CDS"));
74 final String requestId = execution.getGeneralBuildingBlock().getRequestContext().getMsoRequestId();
75 final AbstractCDSPropertiesBean cdsPropertiesBean = new AbstractCDSPropertiesBean();
76 cdsPropertiesBean.setRequestObject(requestPayload);
77 cdsPropertiesBean.setBlueprintName(requestProvider.getBlueprintName());
78 cdsPropertiesBean.setBlueprintVersion(requestProvider.getBlueprintVersion());
79 cdsPropertiesBean.setRequestId(requestId);
80 cdsPropertiesBean.setOriginatorId(ORIGINATOR_ID);
81 cdsPropertiesBean.setSubRequestId(UUID.randomUUID().toString());
82 cdsPropertiesBean.setActionName(action);
83 cdsPropertiesBean.setMode(MODE);
85 return cdsPropertiesBean;
88 private CDSRequestProvider getRequestProviderByScope(String scope) throws PayloadGenerationException {
89 CDSRequestProvider requestProvider;
92 requestProvider = vnfCDSRequestProvider;
95 requestProvider = vfModuleCDSRequestProvider;
98 requestProvider = serviceCDSRequestProvider;
101 throw new PayloadGenerationException("No scope defined with " + scope);
103 return requestProvider;