summaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorVidyashree-Huawei <vidyashree.rama@huawei.com>2020-04-10 17:36:09 +0530
committerSébastien Determe <sebastien.determe@intl.att.com>2020-04-14 08:13:46 +0000
commit3ec03cca444a2810005053a308ed0f3ecb00b063 (patch)
tree228da36cb151a5676d7adf454299b9b280c80d48 /src/main/java
parentd2e5008edc93220a1117df5c864d828fbae9cc8d (diff)
CDS attributes are not shown properly in UI
Handled for legacy and operational policy Change-Id: I504c4aa2531b19b09965ad1dbc03c9944931f77b Issue-ID: CLAMP-809 Signed-off-by: Vidyashree-Huawei <vidyashree.rama@huawei.com>
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/onap/clamp/clds/client/CdsServices.java2
-rw-r--r--src/main/java/org/onap/clamp/clds/tosca/update/execution/cds/ToscaMetadataCdsProcess.java104
-rw-r--r--src/main/java/org/onap/clamp/policy/operational/LegacyOperationalPolicy.java21
-rw-r--r--src/main/java/org/onap/clamp/policy/operational/OperationalPolicyRepresentationBuilder.java44
4 files changed, 124 insertions, 47 deletions
diff --git a/src/main/java/org/onap/clamp/clds/client/CdsServices.java b/src/main/java/org/onap/clamp/clds/client/CdsServices.java
index fe1937ab1..f25e8b80f 100644
--- a/src/main/java/org/onap/clamp/clds/client/CdsServices.java
+++ b/src/main/java/org/onap/clamp/clds/client/CdsServices.java
@@ -136,7 +136,7 @@ public class CdsServices {
if (isComplexType(type, dataTypes)) {
inputObject.add(key, handleComplexType(type, dataTypes));
} else {
- inputObject.addProperty(key, "");
+ inputObject.add(key, entry.getValue());
}
}
return inputObject;
diff --git a/src/main/java/org/onap/clamp/clds/tosca/update/execution/cds/ToscaMetadataCdsProcess.java b/src/main/java/org/onap/clamp/clds/tosca/update/execution/cds/ToscaMetadataCdsProcess.java
index 81e30cf43..ce1f94699 100644
--- a/src/main/java/org/onap/clamp/clds/tosca/update/execution/cds/ToscaMetadataCdsProcess.java
+++ b/src/main/java/org/onap/clamp/clds/tosca/update/execution/cds/ToscaMetadataCdsProcess.java
@@ -26,7 +26,10 @@ package org.onap.clamp.clds.tosca.update.execution.cds;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
+
import java.util.Map;
+import java.util.Set;
+
import org.onap.clamp.clds.tosca.update.execution.ToscaMetadataProcess;
import org.onap.clamp.loop.service.Service;
import org.onap.clamp.tosca.DictionaryService;
@@ -58,9 +61,11 @@ public class ToscaMetadataCdsProcess extends ToscaMetadataProcess {
}
private static void generatePayload(JsonObject childObject, Service serviceModel) {
- generatePayloadPerResource(childObject, "VF", serviceModel);
- generatePayloadPerResource(childObject, "PNF", serviceModel);
- addToJsonArray(childObject, "anyOf", createBlankEntry());
+ JsonArray schemaAnyOf = new JsonArray();
+ schemaAnyOf.addAll(createBlankEntry());
+ schemaAnyOf.addAll(generatePayloadPerResource("VF", serviceModel));
+ schemaAnyOf.addAll(generatePayloadPerResource("PNF", serviceModel));
+ addToJsonArray(childObject, "anyOf", schemaAnyOf);
}
private static void generateOperation(JsonObject childObject, Service serviceModel) {
@@ -92,8 +97,8 @@ public class ToscaMetadataCdsProcess extends ToscaMetadataProcess {
}
- private static void generatePayloadPerResource(JsonObject childObject, String resourceName,
- Service serviceModel) {
+ private static JsonArray generatePayloadPerResource(String resourceName,
+ Service serviceModel) {
JsonArray schemaAnyOf = new JsonArray();
for (Map.Entry<String, JsonElement> entry : serviceModel.getResourceDetails().getAsJsonObject(resourceName)
@@ -105,13 +110,14 @@ public class ToscaMetadataCdsProcess extends ToscaMetadataProcess {
.entrySet()) {
JsonObject obj = new JsonObject();
obj.addProperty("title", workflowsEntry.getKey());
- obj.add("properties", createPayloadProperty(workflowsEntry.getValue().getAsJsonObject(),
- controllerProperties));
+ obj.add("properties",
+ createInputPropertiesForPayload(workflowsEntry.getValue().getAsJsonObject(),
+ controllerProperties));
schemaAnyOf.add(obj);
}
}
}
- addToJsonArray(childObject, "anyOf", schemaAnyOf);
+ return schemaAnyOf;
}
private static JsonArray createBlankEntry() {
@@ -123,20 +129,6 @@ public class ToscaMetadataCdsProcess extends ToscaMetadataProcess {
return result;
}
- private static JsonObject createPayloadProperty(JsonObject workFlow, JsonObject controllerProperties) {
- JsonObject payloadResult = new JsonObject();
-
- payloadResult.add("artifact_name",
- createAnyOfJsonProperty("artifact_name", controllerProperties.get("sdnc_model_name").getAsString()));
- payloadResult.add("artifact_version",
- createAnyOfJsonProperty("artifact_version",
- controllerProperties.get("sdnc_model_version").getAsString()));
- payloadResult.add("mode", createAnyOfJsonProperty("mode", "async"));
-
- payloadResult.add("data", createAnyOfJsonObject("data", workFlow.getAsJsonObject("inputs")));
- return payloadResult;
- }
-
private static JsonObject createAnyOfJsonProperty(String name, String defaultValue) {
JsonObject result = new JsonObject();
result.addProperty("title", name);
@@ -157,9 +149,73 @@ public class ToscaMetadataCdsProcess extends ToscaMetadataProcess {
private static void addToJsonArray(JsonObject childObject, String section, JsonArray value) {
if (childObject.getAsJsonArray(section) != null) {
childObject.getAsJsonArray(section).addAll(value);
- }
- else {
+ } else {
childObject.add(section, value);
}
}
+
+ /**
+ * Returns the properties of payload based on the cds work flows.
+ *
+ * @param workFlow cds work flows to update payload
+ * @param controllerProperties cds properties to get blueprint name and
+ * version
+ * @return returns the properties of payload
+ */
+ public static JsonObject createInputPropertiesForPayload(JsonObject workFlow,
+ JsonObject controllerProperties) {
+ String artifactName = controllerProperties.get("sdnc_model_name").getAsString();
+ String artifactVersion = controllerProperties.get("sdnc_model_version").getAsString();
+ JsonObject inputs = workFlow.getAsJsonObject("inputs");
+ JsonObject jsonObject = new JsonObject();
+ jsonObject.add("artifact_name", createAnyOfJsonProperty(
+ "artifact name", artifactName));
+ jsonObject.add("artifact_version", createAnyOfJsonProperty(
+ "artifact version", artifactVersion));
+ jsonObject.add("mode", createCdsInputProperty(
+ "mode", "string", "async"));
+ jsonObject.add("data", createDataProperty(inputs));
+
+ return jsonObject;
+ }
+
+ private static JsonObject createDataProperty(JsonObject inputs) {
+ JsonObject data = new JsonObject();
+ data.addProperty("title", "data");
+ data.add("properties", addDataFields(inputs));
+ return data;
+ }
+
+ private static JsonObject addDataFields(JsonObject inputs) {
+ JsonObject jsonObject = new JsonObject();
+ Set<Map.Entry<String, JsonElement>> entrySet = inputs.entrySet();
+ for (Map.Entry<String, JsonElement> entry : entrySet) {
+ String key = entry.getKey();
+ JsonObject inputProperty = inputs.getAsJsonObject(key);
+ if (inputProperty.get("type") == null) {
+ jsonObject.add(entry.getKey(),
+ createAnyOfJsonObject(key,
+ addDataFields(entry.getValue().getAsJsonObject())));
+ } else {
+ jsonObject.add(entry.getKey(),
+ createCdsInputProperty(key,
+ inputProperty.get("type").getAsString(),
+ null));
+ }
+ }
+ return jsonObject;
+ }
+
+ private static JsonObject createCdsInputProperty(String title,
+ String type,
+ String defaultValue) {
+ JsonObject property = new JsonObject();
+ property.addProperty("title", title);
+ property.addProperty("type", type);
+ if (defaultValue != null) {
+ property.addProperty("default", defaultValue);
+ }
+ property.addProperty("format", "textarea");
+ return property;
+ }
}
diff --git a/src/main/java/org/onap/clamp/policy/operational/LegacyOperationalPolicy.java b/src/main/java/org/onap/clamp/policy/operational/LegacyOperationalPolicy.java
index 033f2cebb..3765277d8 100644
--- a/src/main/java/org/onap/clamp/policy/operational/LegacyOperationalPolicy.java
+++ b/src/main/java/org/onap/clamp/policy/operational/LegacyOperationalPolicy.java
@@ -201,11 +201,13 @@ public class LegacyOperationalPolicy {
policy.getAsJsonObject().remove(ACTOR);
String actorStr = actor.getAsJsonObject().get(ACTOR).getAsString();
policy.getAsJsonObject().addProperty(ACTOR, actorStr);
- policy.getAsJsonObject().addProperty(RECIPE, getRecipe(actor));
if ("CDS".equalsIgnoreCase(actorStr)) {
- addPayloadAttributes(actor.getAsJsonObject(ACTOR).getAsJsonObject(RECIPE), policy);
+ policy.getAsJsonObject().addProperty(RECIPE, getRecipe(actor));
+ addCdsPayloadAttributes(actor.getAsJsonObject(RECIPE), policy);
} else {
+ policy.getAsJsonObject().addProperty(RECIPE,
+ actor.getAsJsonObject().get(RECIPE).getAsString());
addPayloadAttributes(actor, policy);
}
}
@@ -226,7 +228,20 @@ public class LegacyOperationalPolicy {
}
}
+ private static void addCdsPayloadAttributes(JsonObject jsonObject,
+ JsonElement policy) {
+ JsonElement payloadElem = jsonObject.getAsJsonObject().get(PAYLOAD);
+ JsonObject payloadObject = payloadElem != null ?
+ payloadElem.getAsJsonObject() : null;
+ if (payloadObject != null) {
+ policy.getAsJsonObject().add(PAYLOAD,
+ payloadObject);
+ } else {
+ policy.getAsJsonObject().addProperty(PAYLOAD, "");
+ }
+ }
+
private static String getRecipe(JsonObject actor) {
- return actor.getAsJsonObject().get("type").getAsString();
+ return actor.getAsJsonObject().get("recipe").getAsJsonObject().get("recipe").getAsString();
}
}
diff --git a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicyRepresentationBuilder.java b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicyRepresentationBuilder.java
index 44ee11970..4e362d841 100644
--- a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicyRepresentationBuilder.java
+++ b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicyRepresentationBuilder.java
@@ -24,13 +24,17 @@
package org.onap.clamp.policy.operational;
+import static org.onap.clamp.clds.tosca.update.execution.cds.ToscaMetadataCdsProcess.createInputPropertiesForPayload;
+
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
+
import java.io.IOException;
import java.util.Map.Entry;
+
import org.onap.clamp.clds.util.JsonUtils;
import org.onap.clamp.clds.util.ResourceFileUtil;
import org.onap.clamp.loop.service.Service;
@@ -70,7 +74,7 @@ public class OperationalPolicyRepresentationBuilder {
for (JsonElement actor : actors) {
if ("CDS".equalsIgnoreCase(actor.getAsJsonObject().get("title").getAsString())) {
- actor.getAsJsonObject().get("properties").getAsJsonObject().get("type").getAsJsonObject()
+ actor.getAsJsonObject().get("properties").getAsJsonObject().get("recipe").getAsJsonObject()
.get("anyOf").getAsJsonArray()
.addAll(createAnyOfArrayForCdsRecipe(modelJson));
}
@@ -195,8 +199,9 @@ public class OperationalPolicyRepresentationBuilder {
for (Entry<String, JsonElement> workflowsEntry : workflows.entrySet()) {
JsonObject obj = new JsonObject();
obj.addProperty("title", workflowsEntry.getKey());
+ obj.addProperty("type", "object");
obj.add("properties", createPayloadProperty(workflowsEntry.getValue().getAsJsonObject(),
- controllerProperties));
+ controllerProperties, workflowsEntry.getKey()));
schemaArray.add(obj);
}
@@ -205,26 +210,27 @@ public class OperationalPolicyRepresentationBuilder {
return schemaArray;
}
- private static JsonObject createPayloadProperty(JsonObject workFlow, JsonObject controllerProperties) {
- JsonObject type = new JsonObject();
- type.addProperty("title", "Payload (YAML)");
- type.addProperty("type", "string");
- type.addProperty("default", createDefaultStringForPayload(workFlow, controllerProperties));
- type.addProperty("format", "textarea");
+ private static JsonObject createPayloadProperty(JsonObject workFlow,
+ JsonObject controllerProperties, String workFlowName) {
+ JsonObject payload = new JsonObject();
+ payload.addProperty("title", "Payload (YAML)");
+ payload.addProperty("type", "object");
+ payload.add("properties", createInputPropertiesForPayload(workFlow,
+ controllerProperties));
JsonObject properties = new JsonObject();
- properties.add("type", type);
+ properties.add("recipe", createRecipeForCdsWorkflow(workFlowName));
+ properties.add("payload", payload);
return properties;
}
- private static String createDefaultStringForPayload(JsonObject workFlow, JsonObject controllerProperties) {
- String artifactName = controllerProperties.get("sdnc_model_name").toString();
- String artifactVersion = controllerProperties.get("sdnc_model_version").toString();
- String data = workFlow.getAsJsonObject("inputs").toString();
- StringBuilder builder = new StringBuilder("'").append("artifact_name : ").append(artifactName).append("\n")
- .append("artifact_version : ").append(artifactVersion).append("\n")
- .append("mode : async").append("\n")
- .append("data : ").append("'").append("\\").append("'").append(data).append("\\").append("'")
- .append("'");
- return builder.toString();
+ private static JsonObject createRecipeForCdsWorkflow(String workflow) {
+ JsonObject recipe = new JsonObject();
+ recipe.addProperty("title", "recipe");
+ recipe.addProperty("type", "string");
+ recipe.addProperty("default", workflow);
+ JsonObject options = new JsonObject();
+ options.addProperty("hidden", true);
+ recipe.add("options", options);
+ return recipe;
}
}