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.entities.GeneralBuildingBlock;
28 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
29 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
30 import org.onap.so.client.exception.PayloadGenerationException;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.beans.factory.config.ConfigurableBeanFactory;
33 import org.springframework.context.annotation.Scope;
34 import org.springframework.stereotype.Component;
35 import java.util.List;
37 import java.util.Optional;
38 import static org.onap.so.client.cds.PayloadConstants.PROPERTIES;
39 import static org.onap.so.client.cds.PayloadConstants.SEPARATOR;
42 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
43 public class VnfCDSRequestProvider implements CDSRequestProvider {
44 private String blueprintName;
45 private String blueprintVersion;
46 private BuildingBlockExecution execution;
49 private ExtractPojosForBB extractPojosForBB;
52 private ConfigureInstanceParamsForVnf configureInstanceParamsForVnf;
55 public String getBlueprintName() {
60 public String getBlueprintVersion() {
61 return blueprintVersion;
65 public <T> void setExecutionObject(T executionObject) {
66 execution = (BuildingBlockExecution) executionObject;
70 public Optional<String> buildRequestPayload(String action) throws PayloadGenerationException {
71 JsonObject cdsPropertyObject = new JsonObject();
72 JsonObject vnfObject = new JsonObject();
75 ServiceInstance serviceInstance =
76 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
77 GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
79 final String modelCustomizationUuid = genericVnf.getModelInfoGenericVnf().getModelCustomizationUuid();
81 resolutionKey = genericVnf.getVnfName();
82 blueprintName = genericVnf.getBlueprintName();
83 blueprintVersion = genericVnf.getBlueprintVersion();
85 vnfObject.addProperty("service-instance-id", serviceInstance.getServiceInstanceId());
86 vnfObject.addProperty("service-model-uuid", serviceInstance.getModelInfoServiceInstance().getModelUuid());
87 vnfObject.addProperty("vnf-id", genericVnf.getVnfId());
88 vnfObject.addProperty("vnf-name", genericVnf.getVnfName());
89 vnfObject.addProperty("vnf-customization-uuid", modelCustomizationUuid);
91 final GeneralBuildingBlock buildingBlock = execution.getGeneralBuildingBlock();
92 List<Map<String, Object>> userParamsFromRequest =
93 buildingBlock.getRequestContext().getRequestParameters().getUserParams();
95 configureInstanceParamsForVnf.populateInstanceParams(vnfObject, userParamsFromRequest,
96 modelCustomizationUuid);
97 } catch (Exception e) {
98 throw new PayloadGenerationException("Failed to buildPropertyObjectForVnf", e);
101 cdsPropertyObject.addProperty("resolution-key", resolutionKey);
102 cdsPropertyObject.add(action + SEPARATOR + PROPERTIES, vnfObject);
104 return Optional.of(buildRequestJsonObject(cdsPropertyObject, action));