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 com.google.gson.JsonObject;
24 import org.onap.so.bpmn.common.BuildingBlockExecution;
25 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
26 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
27 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
28 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
29 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
30 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
31 import org.onap.so.client.exception.PayloadGenerationException;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.beans.factory.config.ConfigurableBeanFactory;
34 import org.springframework.context.annotation.Scope;
35 import org.springframework.stereotype.Component;
36 import java.util.List;
38 import java.util.Optional;
39 import static org.onap.so.client.cds.PayloadConstants.PROPERTIES;
40 import static org.onap.so.client.cds.PayloadConstants.SEPARATOR;
43 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
44 public class VfModuleCDSRequestProvider implements CDSRequestProvider {
45 private String blueprintName;
46 private String blueprintVersion;
47 private BuildingBlockExecution execution;
50 private ExtractPojosForBB extractPojosForBB;
53 private ConfigureInstanceParamsForVfModule configureInstanceParamsForVfModule;
56 public String getBlueprintName() {
61 public String getBlueprintVersion() {
62 return blueprintVersion;
66 public <T> void setExecutionObject(T executionObject) {
67 execution = (BuildingBlockExecution) executionObject;
71 public Optional<String> buildRequestPayload(String action) throws PayloadGenerationException {
72 JsonObject cdsPropertyObject = new JsonObject();
73 JsonObject vfModuleObject = new JsonObject();
77 ServiceInstance serviceInstance =
78 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
79 GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
81 final String modelCustomizationUuidForVnf = genericVnf.getModelInfoGenericVnf().getModelCustomizationUuid();
83 blueprintName = genericVnf.getBlueprintName();
84 blueprintVersion = genericVnf.getBlueprintVersion();
86 VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
87 vfModuleName = vfModule.getVfModuleName();
89 final String modelCustomizationUuidForVfModule =
90 vfModule.getModelInfoVfModule().getModelCustomizationUUID();
92 vfModuleObject.addProperty("service-instance-id", serviceInstance.getServiceInstanceId());
93 vfModuleObject.addProperty("service-model-uuid",
94 serviceInstance.getModelInfoServiceInstance().getModelUuid());
95 vfModuleObject.addProperty("vnf-id", genericVnf.getVnfId());
96 vfModuleObject.addProperty("vnf-name", genericVnf.getVnfName());
97 vfModuleObject.addProperty("vf-module-id", vfModule.getVfModuleId());
98 vfModuleObject.addProperty("vf-module-name", vfModule.getVfModuleName());
99 vfModuleObject.addProperty("vf-module-customization-uuid",
100 vfModule.getModelInfoVfModule().getModelCustomizationUUID());
102 final GeneralBuildingBlock buildingBlock = execution.getGeneralBuildingBlock();
103 List<Map<String, Object>> userParamsFromRequest =
104 buildingBlock.getRequestContext().getRequestParameters().getUserParams();
106 configureInstanceParamsForVfModule.populateInstanceParams(vfModuleObject, userParamsFromRequest,
107 modelCustomizationUuidForVnf, modelCustomizationUuidForVfModule);
108 } catch (Exception e) {
109 throw new PayloadGenerationException("Failed to buildPropertyObject for VF-Module", e);
112 // Not sure for resolutionKey should be same as vfModule name.
113 cdsPropertyObject.addProperty("resolution-key", vfModuleName);
114 cdsPropertyObject.addProperty("template-prefix", vfModuleName + action);
115 cdsPropertyObject.add(action + SEPARATOR + PROPERTIES, vfModuleObject);
117 return Optional.of(buildRequestJsonObject(cdsPropertyObject, action));