aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorroot1 <vidyashree.rama@huawei.com>2020-08-11 18:44:29 +0530
committerroot1 <vidyashree.rama@huawei.com>2020-08-28 12:01:34 +0530
commit2d9f989e0d37002c758bdf66a3f25fcfdac35b62 (patch)
treef498e3895bd048c9542ec1b0356013481dd5e74a /src/main
parentf095a271b67b3f2be3dbdcd00924cac3dd3209ec (diff)
CLAMP should not display all CDS workflow properties
CLAMP should not display all CDS workflow properties Issue-ID: CLAMP-856 Signed-off-by: root1 <vidyashree.rama@huawei.com> Change-Id: I98fc46c9c9ba574a3606740921d74743cb6f38ea
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/onap/clamp/clds/client/CdsServices.java79
-rw-r--r--src/main/java/org/onap/clamp/clds/tosca/update/execution/cds/ToscaMetadataCdsProcess.java41
-rw-r--r--src/main/java/org/onap/clamp/policy/operational/OperationalPolicyRepresentationBuilder.java49
3 files changed, 119 insertions, 50 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 fa15e2778..fd3b3539a 100644
--- a/src/main/java/org/onap/clamp/clds/client/CdsServices.java
+++ b/src/main/java/org/onap/clamp/clds/client/CdsServices.java
@@ -22,6 +22,8 @@
package org.onap.clamp.clds.client;
+import static java.lang.Boolean.parseBoolean;
+
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import com.google.gson.JsonElement;
@@ -52,6 +54,10 @@ public class CdsServices {
protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CdsServices.class);
+ private static final String TYPE = "type";
+ private static final String PROPERTIES = "properties";
+ private static final String LIST = "list";
+
/**
* Constructor.
*/
@@ -129,55 +135,80 @@ public class CdsServices {
JsonObject dataTypes = root.getAsJsonObject("dataTypes");
JsonObject workFlowProperties = new JsonObject();
- workFlowProperties.add("inputs", getInputProperties(inputs, dataTypes));
+ workFlowProperties.add("inputs", getInputProperties(inputs, dataTypes, new JsonObject()));
return workFlowProperties;
}
- private JsonObject getInputProperties(JsonObject inputs, JsonObject dataTypes) {
- JsonObject inputObject = new JsonObject();
+ private JsonObject getInputProperties(JsonObject inputs, JsonObject dataTypes,
+ JsonObject inputObject) {
+ if (inputs == null) {
+ return inputObject;
+ }
+
for (Map.Entry<String, JsonElement> entry : inputs.entrySet()) {
String key = entry.getKey();
JsonObject inputProperty = inputs.getAsJsonObject(key);
- String type = inputProperty.get("type").getAsString();
+ String type = inputProperty.get(TYPE).getAsString();
if (isComplexType(type, dataTypes)) {
inputObject.add(key, handleComplexType(type, dataTypes));
- } else if (type.equalsIgnoreCase("list")) {
- inputObject.add(key, handleListType(key, inputProperty,
- dataTypes));
- } else {
+ } else if (LIST.equalsIgnoreCase(type)) {
+ handleListType(key, inputProperty, dataTypes, inputObject);
+ } else if (isInputParam(inputProperty)) {
inputObject.add(key, entry.getValue());
}
}
return inputObject;
}
- private JsonObject handleListType(String propertyName,
+ private void handleListType(String propertyName,
JsonObject inputProperty,
- JsonObject dataTypes) {
- if (inputProperty.get("entry_schema") != null) {
- String type = inputProperty.get("entry_schema").getAsJsonObject().get(
- "type").getAsString();
- if (dataTypes.get(type) != null) {
- JsonObject jsonObject = new JsonObject();
- jsonObject.addProperty("type", "list");
- jsonObject.add("properties", handleComplexType(type, dataTypes));
- return jsonObject;
- } else {
- return inputProperty;
- }
+ JsonObject dataTypes,
+ JsonObject inputObject) {
+ if (inputProperty.get("entry_schema") == null) {
+ throw new CdsParametersException("Entry schema is null for " + propertyName);
+ }
+
+ String type = inputProperty.get("entry_schema").getAsJsonObject().get(
+ TYPE).getAsString();
+ if (dataTypes.get(type) != null) {
+ JsonObject jsonObject = new JsonObject();
+ jsonObject.addProperty(TYPE, LIST);
+ jsonObject.add(PROPERTIES, getPropertiesObject(type, dataTypes));
+ inputObject.add(propertyName, jsonObject);
+ } else if (isInputParam(inputProperty)) {
+ inputObject.add(propertyName, inputProperty);
}
- throw new CdsParametersException("Entry schema is null for " + propertyName);
}
private JsonObject handleComplexType(String key, JsonObject dataTypes) {
- JsonObject properties = dataTypes.get(key).getAsJsonObject().get("properties").getAsJsonObject();
- return getInputProperties(properties, dataTypes);
+ JsonObject jsonObject = new JsonObject();
+ jsonObject.addProperty(TYPE, "object");
+ jsonObject.add(PROPERTIES, getPropertiesObject(key, dataTypes));
+ return jsonObject;
+ }
+
+ private JsonObject getPropertiesObject(String key, JsonObject dataTypes) {
+ JsonObject properties = dataTypes.get(key).getAsJsonObject().get(PROPERTIES).getAsJsonObject();
+ JsonObject object = new JsonObject();
+ getInputProperties(properties, dataTypes, object);
+ return object;
}
private boolean isComplexType(String type, JsonObject dataTypes) {
+ if (dataTypes == null) {
+ return false;
+ }
return dataTypes.get(type) != null;
}
+ private boolean isInputParam(JsonObject inputProperty) {
+ JsonElement inputParam = inputProperty.get("input-param");
+ if (inputParam == null) {
+ return false;
+ }
+ return parseBoolean(inputParam.getAsString());
+ }
+
/**
* Creates payload to query CDS to get workflow input properties.
*
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 94a477fe5..39fa25a2b 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
@@ -24,6 +24,7 @@
package org.onap.clamp.clds.tosca.update.execution.cds;
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;
@@ -108,7 +109,8 @@ public class ToscaMetadataCdsProcess extends ToscaMetadataProcess {
obj.addProperty("title", workflowsEntry.getKey());
obj.add("properties",
createInputPropertiesForPayload(workflowsEntry.getValue().getAsJsonObject(),
- controllerProperties));
+ controllerProperties,
+ workflowsEntry.getKey()));
schemaAnyOf.add(obj);
}
}
@@ -150,10 +152,12 @@ public class ToscaMetadataCdsProcess extends ToscaMetadataProcess {
* @param workFlow cds work flows to update payload
* @param controllerProperties cds properties to get blueprint name and
* version
+ * @param workFlowName work flow name
* @return returns the properties of payload
*/
public static JsonObject createInputPropertiesForPayload(JsonObject workFlow,
- JsonObject controllerProperties) {
+ JsonObject controllerProperties,
+ String workFlowName) {
String artifactName = controllerProperties.get("sdnc_model_name").getAsString();
String artifactVersion = controllerProperties.get("sdnc_model_version").getAsString();
JsonObject inputs = workFlow.getAsJsonObject("inputs");
@@ -164,32 +168,53 @@ public class ToscaMetadataCdsProcess extends ToscaMetadataProcess {
"artifact version", artifactVersion, true));
jsonObject.add("mode", createAnyOfJsonProperty(
"mode", "async", false));
- jsonObject.add("data", createDataProperty(inputs));
+ jsonObject.add("data", createDataProperty(inputs, workFlowName));
return jsonObject;
}
- private static JsonObject createDataProperty(JsonObject inputs) {
+ private static JsonObject createDataProperty(JsonObject inputs, String workFlowName) {
JsonObject data = new JsonObject();
data.addProperty("title", "data");
data.addProperty("type", "string");
data.addProperty("format", "textarea");
JsonObject defaultValue = new JsonObject();
- addDefaultValueForData(inputs, defaultValue);
+ addDefaultValueForData(inputs, defaultValue, workFlowName);
data.addProperty("default", defaultValue.toString());
return data;
}
private static void addDefaultValueForData(JsonObject inputs,
- JsonObject defaultValue) {
+ JsonObject defaultValue,
+ String workFlowName) {
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) {
- addDefaultValueForData(entry.getValue().getAsJsonObject(), defaultValue);
+ if (key.equalsIgnoreCase(workFlowName + "-properties")) {
+ addDefaultValueForData(entry.getValue().getAsJsonObject().get("properties")
+ .getAsJsonObject(), defaultValue, workFlowName);
+ } else if ("object".equalsIgnoreCase(inputProperty.get(TYPE).getAsString())) {
+ JsonObject object = new JsonObject();
+ addDefaultValueForData(entry.getValue().getAsJsonObject().get("properties")
+ .getAsJsonObject(), object, workFlowName);
+ defaultValue.add(entry.getKey(), object);
+ } else if (TYPE_LIST.equalsIgnoreCase(inputProperty.get(TYPE).getAsString())) {
+ defaultValue.add(entry.getKey(), handleListType(entry.getValue().getAsJsonObject(), workFlowName));
} else {
defaultValue.addProperty(entry.getKey(), "");
}
}
}
+
+ private static JsonArray handleListType(JsonObject inputs,
+ String workFlowName) {
+
+ JsonObject object = new JsonObject();
+ if (inputs.get("properties") != null) {
+ addDefaultValueForData(inputs.get("properties").getAsJsonObject(), object, workFlowName);
+ }
+ JsonArray arr = new JsonArray();
+ arr.add(object);
+ return arr;
+ }
}
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 ee4030656..c0e1c019e 100644
--- a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicyRepresentationBuilder.java
+++ b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicyRepresentationBuilder.java
@@ -53,6 +53,8 @@ public class OperationalPolicyRepresentationBuilder {
public static final String STRING = "string";
public static final String TYPE = "type";
public static final String TYPE_LIST = "list";
+ public static final String TYPE_OBJECT = "object";
+ public static final String TYPE_ARRAY = "array";
private OperationalPolicyRepresentationBuilder() {
throw new IllegalStateException("This is Utility class, not supposed to be initiated.");
@@ -240,8 +242,8 @@ public class OperationalPolicyRepresentationBuilder {
JsonObject payload = new JsonObject();
payload.addProperty(TITLE, "Payload");
payload.addProperty(TYPE, "object");
- payload.add(PROPERTIES, createInputPropertiesForPayload(workFlow,
- controllerProperties));
+ payload.add(PROPERTIES, createInputPropertiesForPayload(workFlow, controllerProperties,
+ workFlowName));
JsonObject properties = new JsonObject();
properties.add(RECIPE, createRecipeForCdsWorkflow(workFlowName));
properties.add("payload", payload);
@@ -265,10 +267,12 @@ public class OperationalPolicyRepresentationBuilder {
* @param workFlow cds work flows to update payload
* @param controllerProperties cds properties to get blueprint name and
* version
+ * @param workFlowName work flow name
* @return returns the properties of payload
*/
public static JsonObject createInputPropertiesForPayload(JsonObject workFlow,
- JsonObject controllerProperties) {
+ JsonObject controllerProperties,
+ String workFlowName) {
String artifactName = controllerProperties.get("sdnc_model_name").getAsString();
String artifactVersion = controllerProperties.get("sdnc_model_version").getAsString();
JsonObject inputs = workFlow.getAsJsonObject("inputs");
@@ -279,33 +283,33 @@ public class OperationalPolicyRepresentationBuilder {
"artifact version", STRING, artifactVersion, "True", null));
jsonObject.add("mode", createCdsInputProperty(
"mode", STRING, "async" ,null));
- jsonObject.add("data", createDataProperty(inputs));
+ jsonObject.add("data", createDataProperty(inputs, workFlowName));
return jsonObject;
}
- private static JsonObject createDataProperty(JsonObject inputs) {
+ private static JsonObject createDataProperty(JsonObject inputs, String workflowName) {
JsonObject data = new JsonObject();
data.addProperty(TITLE, "data");
JsonObject dataObj = new JsonObject();
- addDataFields(inputs, dataObj);
+ addDataFields(inputs, dataObj, workflowName);
data.add(PROPERTIES, dataObj);
return data;
}
private static void addDataFields(JsonObject inputs,
- JsonObject dataObj) {
+ JsonObject dataObj,
+ String workFlowName) {
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);
+ if (key.equalsIgnoreCase(workFlowName + "-properties")) {
+ addDataFields(entry.getValue().getAsJsonObject().get("properties").getAsJsonObject(),
+ dataObj, workFlowName);
} else {
dataObj.add(entry.getKey(),
- createCdsInputProperty(key,
- inputProperty.get(TYPE).getAsString(),
- null,
- entry.getValue().getAsJsonObject()));
+ createCdsInputProperty(key, inputProperty.get(TYPE).getAsString(),null,
+ entry.getValue().getAsJsonObject()));
}
}
}
@@ -318,15 +322,15 @@ public class OperationalPolicyRepresentationBuilder {
property.addProperty(TITLE, title);
if (TYPE_LIST.equalsIgnoreCase(type)) {
- property.addProperty(TYPE, "array");
+ property.addProperty(TYPE, TYPE_ARRAY);
if (cdsProperty != null && cdsProperty.get(PROPERTIES) != null) {
- JsonObject dataObject = new JsonObject();
- addDataFields(cdsProperty.get(PROPERTIES).getAsJsonObject(),
- dataObject);
JsonObject listProperties = new JsonObject();
- listProperties.add(PROPERTIES, dataObject);
+ listProperties.add(PROPERTIES, getProperties(cdsProperty.get(PROPERTIES).getAsJsonObject()));
property.add(ITEMS, listProperties);
}
+ } else if (TYPE_OBJECT.equalsIgnoreCase(type)) {
+ property.addProperty(TYPE, TYPE_OBJECT);
+ property.add(PROPERTIES, getProperties(cdsProperty.get(PROPERTIES).getAsJsonObject()));
} else {
property.addProperty(TYPE, type);
}
@@ -336,4 +340,13 @@ public class OperationalPolicyRepresentationBuilder {
}
return property;
}
+
+ private static JsonObject getProperties(JsonObject inputProperties) {
+ if (inputProperties == null) {
+ return null;
+ }
+ JsonObject dataObject = new JsonObject();
+ addDataFields(inputProperties, dataObject, null);
+ return dataObject;
+ }
}