2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END============================================
20 * ===================================================================
24 package org.onap.clamp.clds.tosca.update.execution.cds;
26 import com.google.gson.JsonArray;
27 import com.google.gson.JsonElement;
28 import com.google.gson.JsonObject;
30 import org.onap.clamp.clds.tosca.update.execution.ToscaMetadataProcess;
31 import org.onap.clamp.loop.service.Service;
32 import org.onap.clamp.tosca.DictionaryService;
33 import org.springframework.beans.factory.annotation.Autowired;
36 * This class is there to add the JsonObject for CDS in the json Schema according to what is found in the Tosca model.
38 public class ToscaMetadataCdsProcess extends ToscaMetadataProcess {
41 private DictionaryService dictionaryService;
44 public void executeProcess(String parameters, JsonObject childObject, Service serviceModel) {
47 childObject.add("anyOf", generatePayload(serviceModel));
50 childObject.add("enum", generateOperation(serviceModel));
55 private static JsonArray generatePayload(Service serviceModel) {
56 JsonArray schemaAnyOf = new JsonArray();
57 schemaAnyOf.addAll(generatePayloadPerResource("VF", serviceModel));
58 schemaAnyOf.addAll(generatePayloadPerResource("PNF", serviceModel));
62 private static JsonArray generateOperation(Service serviceModel) {
63 JsonArray schemaEnum = new JsonArray();
64 schemaEnum.addAll(generateOperationPerResource("VF", serviceModel));
65 schemaEnum.addAll(generateOperationPerResource("PNF", serviceModel));
69 private static JsonArray generateOperationPerResource(String resourceName, Service serviceModel) {
70 JsonArray schemaEnum = new JsonArray();
71 for (Map.Entry<String, JsonElement> entry : serviceModel.getResourceDetails().getAsJsonObject(resourceName)
73 JsonObject controllerProperties = entry.getValue().getAsJsonObject()
74 .getAsJsonObject("controllerProperties");
75 if (controllerProperties != null) {
76 for (String workflowsEntry : controllerProperties.getAsJsonObject("workflows").keySet()) {
77 schemaEnum.add(workflowsEntry);
84 private static JsonArray generatePayloadPerResource(String resourceName, Service serviceModel) {
85 JsonArray schemaAnyOf = new JsonArray();
86 for (Map.Entry<String, JsonElement> entry : serviceModel.getResourceDetails().getAsJsonObject(resourceName)
88 JsonObject controllerProperties = entry.getValue().getAsJsonObject()
89 .getAsJsonObject("controllerProperties");
90 if (controllerProperties != null) {
91 for (Map.Entry<String, JsonElement> workflowsEntry : controllerProperties.getAsJsonObject("workflows")
93 JsonObject obj = new JsonObject();
94 obj.addProperty("title", workflowsEntry.getKey());
95 obj.add("properties", createPayloadProperty(workflowsEntry.getValue().getAsJsonObject(),
96 controllerProperties));
104 private static JsonObject createPayloadProperty(JsonObject workFlow, JsonObject controllerProperties) {
105 JsonObject payloadResult = new JsonObject();
107 payloadResult.addProperty("artifact_name", controllerProperties.get("sdnc_model_name").getAsString());
108 payloadResult.addProperty("artifact_version", controllerProperties.get("sdnc_model_version").getAsString());
109 payloadResult.addProperty("mode", "async");
110 payloadResult.add("data", workFlow.getAsJsonObject("inputs"));
111 return payloadResult;