2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Bell Canada
6 * ================================================================================
7 * Modifications Copyright (c) 2020 Tech Mahindra
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.client.cds;
25 import com.google.gson.JsonObject;
26 import org.onap.so.bpmn.common.BuildingBlockExecution;
27 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
28 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
29 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
30 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
31 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
32 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
33 import org.onap.so.client.exception.PayloadGenerationException;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.beans.factory.config.ConfigurableBeanFactory;
36 import org.springframework.context.annotation.Scope;
37 import org.springframework.stereotype.Component;
38 import java.util.List;
40 import java.util.Optional;
41 import static org.onap.so.client.cds.PayloadConstants.PROPERTIES;
42 import static org.onap.so.client.cds.PayloadConstants.SEPARATOR;
45 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
46 public class VfModuleCDSRequestProvider implements CDSRequestProvider {
47 private String blueprintName;
48 private String blueprintVersion;
49 private BuildingBlockExecution execution;
52 private ExtractPojosForBB extractPojosForBB;
55 private ConfigureInstanceParamsForVfModule configureInstanceParamsForVfModule;
58 public String getBlueprintName() {
63 public String getBlueprintVersion() {
64 return blueprintVersion;
68 public <T> void setExecutionObject(T executionObject) {
69 execution = (BuildingBlockExecution) executionObject;
73 public Optional<String> buildRequestPayload(String action) throws PayloadGenerationException {
74 JsonObject cdsPropertyObject = new JsonObject();
75 JsonObject vfModuleObject = new JsonObject();
79 ServiceInstance serviceInstance =
80 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
81 GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
83 final String modelCustomizationUuidForVnf = genericVnf.getModelInfoGenericVnf().getModelCustomizationUuid();
85 blueprintName = genericVnf.getModelInfoGenericVnf().getBlueprintName();
86 blueprintVersion = genericVnf.getModelInfoGenericVnf().getBlueprintVersion();
88 VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
89 vfModuleName = vfModule.getVfModuleName();
91 final String modelCustomizationUuidForVfModule =
92 vfModule.getModelInfoVfModule().getModelCustomizationUUID();
94 vfModuleObject.addProperty("service-instance-id", serviceInstance.getServiceInstanceId());
95 vfModuleObject.addProperty("service-model-uuid",
96 serviceInstance.getModelInfoServiceInstance().getModelUuid());
97 vfModuleObject.addProperty("vnf-id", genericVnf.getVnfId());
98 vfModuleObject.addProperty("vnf-name", genericVnf.getVnfName());
99 vfModuleObject.addProperty("vf-module-id", vfModule.getVfModuleId());
100 vfModuleObject.addProperty("vf-module-name", vfModule.getVfModuleName());
101 vfModuleObject.addProperty("vf-module-customization-uuid",
102 vfModule.getModelInfoVfModule().getModelCustomizationUUID());
104 final GeneralBuildingBlock buildingBlock = execution.getGeneralBuildingBlock();
105 List<Map<String, Object>> userParamsFromRequest =
106 buildingBlock.getRequestContext().getRequestParameters().getUserParams();
107 if (userParamsFromRequest != null && userParamsFromRequest.size() != 0) {
108 configureInstanceParamsForVfModule.populateInstanceParams(vfModuleObject, userParamsFromRequest,
109 modelCustomizationUuidForVnf, modelCustomizationUuidForVfModule);
111 } catch (Exception e) {
112 throw new PayloadGenerationException("Failed to buildPropertyObject for VF-Module", e);
115 // Not sure for resolutionKey should be same as vfModule name.
116 cdsPropertyObject.addProperty("resolution-key", vfModuleName);
117 cdsPropertyObject.addProperty("template-prefix", vfModuleName + action);
118 cdsPropertyObject.add(action + SEPARATOR + PROPERTIES, vfModuleObject);
120 return Optional.of(buildRequestJsonObject(cdsPropertyObject, action));