2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 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 java.util.List;
26 import org.onap.so.bpmn.common.BuildingBlockExecution;
27 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
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.Optional;
37 import static org.onap.so.client.cds.PayloadConstants.PROPERTIES;
38 import static org.onap.so.client.cds.PayloadConstants.SEPARATOR;
41 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
42 public class ServiceCDSRequestProvider implements CDSRequestProvider {
44 private String resolutionKey;
45 private BuildingBlockExecution execution;
46 private String bluePrintName;
47 private String bluePrintVersion;
50 private ConfigureInstanceParamsForService configureInstanceParamsForService;
53 public String getBlueprintName() {
58 public String getBlueprintVersion() {
59 return bluePrintVersion;
63 public <T> void setExecutionObject(T executionObject) {
64 execution = (BuildingBlockExecution) executionObject;
68 public Optional<String> buildRequestPayload(String action) throws PayloadGenerationException {
69 JsonObject cdsPropertyObject = new JsonObject();
70 JsonObject serviceObject = new JsonObject();
72 ServiceInstance serviceInstance = execution.getGeneralBuildingBlock().getServiceInstance();
73 bluePrintName = serviceInstance.getModelInfoServiceInstance().getBlueprintName();
74 bluePrintVersion = serviceInstance.getModelInfoServiceInstance().getBlueprintVersion();
75 resolutionKey = serviceInstance.getServiceInstanceName();
77 serviceObject.addProperty("service-instance-id", serviceInstance.getServiceInstanceId());
78 serviceObject.addProperty("service-model-uuid",
79 serviceInstance.getModelInfoServiceInstance().getModelUuid());
81 final GeneralBuildingBlock buildingBlock = execution.getGeneralBuildingBlock();
82 List<Map<String, Object>> userParamsFromRequest =
83 buildingBlock.getRequestContext().getRequestParameters().getUserParams();
84 if (userParamsFromRequest != null && userParamsFromRequest.size() != 0) {
85 configureInstanceParamsForService.populateInstanceParams(serviceObject, userParamsFromRequest);
87 } catch (Exception e) {
88 throw new PayloadGenerationException("Failed to buildPropertyObjectForService", e);
91 cdsPropertyObject.addProperty("resolution-key", resolutionKey);
92 cdsPropertyObject.add(action + SEPARATOR + PROPERTIES, serviceObject);
94 return Optional.of(buildRequestJsonObject(cdsPropertyObject, action));