aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorVidyashree-Huawei <vidyashree.rama@huawei.com>2020-04-20 12:18:50 +0530
committerVidyashree-Huawei <vidyashree.rama@huawei.com>2020-04-21 20:28:13 +0530
commit472dc126eb9f30c09df344357db2c62f20d0b92c (patch)
treeee2ab2696d67547c2822fb5e22d618bc51f9fd5e /src/main/java
parentbd6abe51f90936ecb4a7de92a3f40978675a2886 (diff)
Payload is expected as string in operational policy
1. converted json to string for legacy operational policy 2. added payload data as default string value for generic operational policy Change-Id: If63423c24d736623b227537f0f83edeaac819215 Issue-ID: CLAMP-831 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/tosca/update/execution/cds/ToscaMetadataCdsProcess.java71
-rw-r--r--src/main/java/org/onap/clamp/policy/operational/LegacyOperationalPolicy.java5
-rw-r--r--src/main/java/org/onap/clamp/policy/operational/OperationalPolicyRepresentationBuilder.java88
3 files changed, 107 insertions, 57 deletions
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 c15641413..c92cad1f5 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
@@ -23,9 +23,7 @@
package org.onap.clamp.clds.tosca.update.execution.cds;
-import static org.onap.clamp.clds.tosca.ToscaSchemaConstants.PROPERTIES;
import static org.onap.clamp.clds.tosca.ToscaSchemaConstants.TYPE;
-import static org.onap.clamp.clds.tosca.ToscaSchemaConstants.TYPE_LIST;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
@@ -133,20 +131,14 @@ public class ToscaMetadataCdsProcess extends ToscaMetadataProcess {
return result;
}
- private static JsonObject createAnyOfJsonProperty(String name, String defaultValue) {
+ private static JsonObject createAnyOfJsonProperty(String name,
+ String defaultValue,
+ boolean readOnlyFlag) {
JsonObject result = new JsonObject();
result.addProperty("title", name);
result.addProperty("type", "string");
result.addProperty("default", defaultValue);
- result.addProperty("readOnly", "True");
- return result;
- }
-
- private static JsonObject createAnyOfJsonObject(String name, JsonObject allProperties) {
- JsonObject result = new JsonObject();
- result.addProperty("title", name);
- result.addProperty("type", "object");
- result.add("properties", allProperties);
+ result.addProperty("readOnly", readOnlyFlag);
return result;
}
@@ -173,66 +165,37 @@ public class ToscaMetadataCdsProcess extends ToscaMetadataProcess {
JsonObject inputs = workFlow.getAsJsonObject("inputs");
JsonObject jsonObject = new JsonObject();
jsonObject.add("artifact_name", createAnyOfJsonProperty(
- "artifact name", artifactName));
+ "artifact name", artifactName, true));
jsonObject.add("artifact_version", createAnyOfJsonProperty(
- "artifact version", artifactVersion));
- jsonObject.add("mode", createCdsInputProperty(
- "mode", "string", "async", null));
+ "artifact version", artifactVersion, true));
+ jsonObject.add("mode", createAnyOfJsonProperty(
+ "mode", "async", false));
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));
+ data.addProperty("type", "string");
+ data.addProperty("format", "textarea");
+ JsonObject defaultValue = new JsonObject();
+ addDefaultValueForData(inputs, defaultValue);
+ data.addProperty("default", defaultValue.toString());
return data;
}
- private static JsonObject addDataFields(JsonObject inputs) {
- JsonObject jsonObject = new JsonObject();
+ private static void addDefaultValueForData(JsonObject inputs,
+ JsonObject defaultValue) {
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())));
+ addDefaultValueForData(entry.getValue().getAsJsonObject(), defaultValue);
} else {
- jsonObject.add(entry.getKey(),
- createCdsInputProperty(key,
- inputProperty.get("type").getAsString(),
- null,
- entry.getValue().getAsJsonObject()));
+ defaultValue.addProperty(entry.getKey(), "");
}
}
- return jsonObject;
- }
-
- private static JsonObject createCdsInputProperty(String title,
- String type,
- String defaultValue,
- JsonObject cdsProperty) {
- JsonObject property = new JsonObject();
- property.addProperty("title", title);
-
- if (TYPE_LIST.equalsIgnoreCase(type)) {
- property.addProperty(TYPE, "array");
- if (cdsProperty.get(PROPERTIES) != null) {
- JsonObject listProperties = new JsonObject();
- listProperties.add(PROPERTIES,
- addDataFields(cdsProperty.get(PROPERTIES).getAsJsonObject()));
- property.add("items", listProperties);
- }
- } else {
- property.addProperty(TYPE, type);
- }
-
- if (defaultValue != null) {
- property.addProperty("default", defaultValue);
- }
- 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 3765277d8..a7a344df2 100644
--- a/src/main/java/org/onap/clamp/policy/operational/LegacyOperationalPolicy.java
+++ b/src/main/java/org/onap/clamp/policy/operational/LegacyOperationalPolicy.java
@@ -234,6 +234,11 @@ public class LegacyOperationalPolicy {
JsonObject payloadObject = payloadElem != null ?
payloadElem.getAsJsonObject() : null;
if (payloadObject != null) {
+ /* Since policy expects payload to be map of string,
+ converting data object to string. */
+ JsonObject dataObject = payloadObject.get("data").getAsJsonObject();
+ payloadObject.remove("data");
+ payloadObject.addProperty("data", dataObject.toString());
policy.getAsJsonObject().add(PAYLOAD,
payloadObject);
} else {
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 4e362d841..57d13ef17 100644
--- a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicyRepresentationBuilder.java
+++ b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicyRepresentationBuilder.java
@@ -24,8 +24,6 @@
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;
@@ -33,7 +31,9 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import java.io.IOException;
+import java.util.Map;
import java.util.Map.Entry;
+import java.util.Set;
import org.onap.clamp.clds.util.JsonUtils;
import org.onap.clamp.clds.util.ResourceFileUtil;
@@ -44,6 +44,10 @@ public class OperationalPolicyRepresentationBuilder {
private static final EELFLogger logger =
EELFManager.getInstance().getLogger(OperationalPolicyRepresentationBuilder.class);
+ public static final String PROPERTIES = "properties";
+ public static final String TYPE = "type";
+ public static final String TYPE_LIST = "list";
+
/**
* This method generates the operational policy json representation that will be
* used by ui for rendering. It uses the model (VF and VFModule) defined in the
@@ -213,7 +217,7 @@ public class OperationalPolicyRepresentationBuilder {
private static JsonObject createPayloadProperty(JsonObject workFlow,
JsonObject controllerProperties, String workFlowName) {
JsonObject payload = new JsonObject();
- payload.addProperty("title", "Payload (YAML)");
+ payload.addProperty("title", "Payload");
payload.addProperty("type", "object");
payload.add("properties", createInputPropertiesForPayload(workFlow,
controllerProperties));
@@ -233,4 +237,82 @@ public class OperationalPolicyRepresentationBuilder {
recipe.add("options", options);
return recipe;
}
+
+ /**
+ * 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", createSchemaProperty(
+ "artifact name", "string", artifactName, "True", null));
+ jsonObject.add("artifact_version", createSchemaProperty(
+ "artifact version", "string", artifactVersion, "True", null));
+ jsonObject.add("mode", createCdsInputProperty(
+ "mode", "string", "async" ,null));
+ jsonObject.add("data", createDataProperty(inputs));
+ return jsonObject;
+ }
+
+ private static JsonObject createDataProperty(JsonObject inputs) {
+ JsonObject data = new JsonObject();
+ data.addProperty("title", "data");
+ JsonObject dataObj = new JsonObject();
+ addDataFields(inputs, dataObj);
+ data.add(PROPERTIES, dataObj);
+ return data;
+ }
+
+ private static void addDataFields(JsonObject inputs,
+ JsonObject dataObj) {
+ 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) {
+ addDataFields(entry.getValue().getAsJsonObject(), dataObj);
+ } else {
+ dataObj.add(entry.getKey(),
+ createCdsInputProperty(key,
+ inputProperty.get(TYPE).getAsString(),
+ null,
+ entry.getValue().getAsJsonObject()));
+ }
+ }
+ }
+
+ private static JsonObject createCdsInputProperty(String title,
+ String type,
+ String defaultValue,
+ JsonObject cdsProperty) {
+ JsonObject property = new JsonObject();
+ property.addProperty("title", title);
+
+ if (TYPE_LIST.equalsIgnoreCase(type)) {
+ property.addProperty(TYPE, "array");
+ if (cdsProperty.get(PROPERTIES) != null) {
+ JsonObject dataObject = new JsonObject();
+ addDataFields(cdsProperty.get(PROPERTIES).getAsJsonObject(),
+ dataObject);
+ JsonObject listProperties = new JsonObject();
+ listProperties.add(PROPERTIES, dataObject);
+ property.add("items", listProperties);
+ }
+ } else {
+ property.addProperty(TYPE, type);
+ }
+
+ if (defaultValue != null) {
+ property.addProperty("default", defaultValue);
+ }
+ return property;
+ }
}