\r
package org.onap.clamp.clds.client;\r
\r
+import static java.lang.Boolean.parseBoolean;\r
+\r
import com.att.eelf.configuration.EELFLogger;\r
import com.att.eelf.configuration.EELFManager;\r
import com.google.gson.JsonElement;\r
\r
protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CdsServices.class);\r
\r
+ private static final String TYPE = "type";\r
+ private static final String PROPERTIES = "properties";\r
+ private static final String LIST = "list";\r
+\r
/**\r
* Constructor.\r
*/\r
JsonObject dataTypes = root.getAsJsonObject("dataTypes");\r
\r
JsonObject workFlowProperties = new JsonObject();\r
- workFlowProperties.add("inputs", getInputProperties(inputs, dataTypes));\r
+ workFlowProperties.add("inputs", getInputProperties(inputs, dataTypes, new JsonObject()));\r
return workFlowProperties;\r
}\r
\r
- private JsonObject getInputProperties(JsonObject inputs, JsonObject dataTypes) {\r
- JsonObject inputObject = new JsonObject();\r
+ private JsonObject getInputProperties(JsonObject inputs, JsonObject dataTypes,\r
+ JsonObject inputObject) {\r
+ if (inputs == null) {\r
+ return inputObject;\r
+ }\r
+\r
for (Map.Entry<String, JsonElement> entry : inputs.entrySet()) {\r
String key = entry.getKey();\r
JsonObject inputProperty = inputs.getAsJsonObject(key);\r
- String type = inputProperty.get("type").getAsString();\r
+ String type = inputProperty.get(TYPE).getAsString();\r
if (isComplexType(type, dataTypes)) {\r
inputObject.add(key, handleComplexType(type, dataTypes));\r
- } else if (type.equalsIgnoreCase("list")) {\r
- inputObject.add(key, handleListType(key, inputProperty,\r
- dataTypes));\r
- } else {\r
+ } else if (LIST.equalsIgnoreCase(type)) {\r
+ handleListType(key, inputProperty, dataTypes, inputObject);\r
+ } else if (isInputParam(inputProperty)) {\r
inputObject.add(key, entry.getValue());\r
}\r
}\r
return inputObject;\r
}\r
\r
- private JsonObject handleListType(String propertyName,\r
+ private void handleListType(String propertyName,\r
JsonObject inputProperty,\r
- JsonObject dataTypes) {\r
- if (inputProperty.get("entry_schema") != null) {\r
- String type = inputProperty.get("entry_schema").getAsJsonObject().get(\r
- "type").getAsString();\r
- if (dataTypes.get(type) != null) {\r
- JsonObject jsonObject = new JsonObject();\r
- jsonObject.addProperty("type", "list");\r
- jsonObject.add("properties", handleComplexType(type, dataTypes));\r
- return jsonObject;\r
- } else {\r
- return inputProperty;\r
- }\r
+ JsonObject dataTypes,\r
+ JsonObject inputObject) {\r
+ if (inputProperty.get("entry_schema") == null) {\r
+ throw new CdsParametersException("Entry schema is null for " + propertyName);\r
+ }\r
+\r
+ String type = inputProperty.get("entry_schema").getAsJsonObject().get(\r
+ TYPE).getAsString();\r
+ if (dataTypes.get(type) != null) {\r
+ JsonObject jsonObject = new JsonObject();\r
+ jsonObject.addProperty(TYPE, LIST);\r
+ jsonObject.add(PROPERTIES, getPropertiesObject(type, dataTypes));\r
+ inputObject.add(propertyName, jsonObject);\r
+ } else if (isInputParam(inputProperty)) {\r
+ inputObject.add(propertyName, inputProperty);\r
}\r
- throw new CdsParametersException("Entry schema is null for " + propertyName);\r
}\r
\r
private JsonObject handleComplexType(String key, JsonObject dataTypes) {\r
- JsonObject properties = dataTypes.get(key).getAsJsonObject().get("properties").getAsJsonObject();\r
- return getInputProperties(properties, dataTypes);\r
+ JsonObject jsonObject = new JsonObject();\r
+ jsonObject.addProperty(TYPE, "object");\r
+ jsonObject.add(PROPERTIES, getPropertiesObject(key, dataTypes));\r
+ return jsonObject;\r
+ }\r
+\r
+ private JsonObject getPropertiesObject(String key, JsonObject dataTypes) {\r
+ JsonObject properties = dataTypes.get(key).getAsJsonObject().get(PROPERTIES).getAsJsonObject();\r
+ JsonObject object = new JsonObject();\r
+ getInputProperties(properties, dataTypes, object);\r
+ return object;\r
}\r
\r
private boolean isComplexType(String type, JsonObject dataTypes) {\r
+ if (dataTypes == null) {\r
+ return false;\r
+ }\r
return dataTypes.get(type) != null;\r
}\r
\r
+ private boolean isInputParam(JsonObject inputProperty) {\r
+ JsonElement inputParam = inputProperty.get("input-param");\r
+ if (inputParam == null) {\r
+ return false;\r
+ }\r
+ return parseBoolean(inputParam.getAsString());\r
+ }\r
+\r
/**\r
* Creates payload to query CDS to get workflow input properties.\r
*\r