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 org.onap.so.bpmn.common.BuildingBlockExecution;
25 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
26 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
27 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
28 import org.onap.so.client.exception.PayloadGenerationException;
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.beans.factory.config.ConfigurableBeanFactory;
31 import org.springframework.context.annotation.Scope;
32 import org.springframework.stereotype.Component;
33 import java.util.Optional;
34 import static org.onap.so.client.cds.PayloadConstants.PROPERTIES;
35 import static org.onap.so.client.cds.PayloadConstants.SEPARATOR;
38 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
39 public class ServiceCDSRequestProvider implements CDSRequestProvider {
41 private static final String EMPTY_STRING = "";
42 private String resolutionKey;
43 private BuildingBlockExecution execution;
46 private ExtractPojosForBB extractPojosForBB;
49 public String getBlueprintName() {
54 public String getBlueprintVersion() {
59 public <T> void setExecutionObject(T executionObject) {
60 execution = (BuildingBlockExecution) executionObject;
64 public Optional<String> buildRequestPayload(String action) throws PayloadGenerationException {
65 JsonObject cdsPropertyObject = new JsonObject();
66 JsonObject serviceObject = new JsonObject();
68 ServiceInstance serviceInstance =
69 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
71 resolutionKey = serviceInstance.getServiceInstanceName();
73 // TODO Need to figure out how to populate blueprint name and version for service.
75 serviceObject.addProperty("service-instance-id", serviceInstance.getServiceInstanceId());
76 serviceObject.addProperty("service-model-uuid",
77 serviceInstance.getModelInfoServiceInstance().getModelUuid());
79 } catch (Exception e) {
80 throw new PayloadGenerationException("Failed to buildPropertyObjectForService", e);
83 cdsPropertyObject.addProperty("resolution-key", resolutionKey);
84 cdsPropertyObject.add(action + SEPARATOR + PROPERTIES, serviceObject);
86 return Optional.of(buildRequestJsonObject(cdsPropertyObject, action));