aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/onap')
-rw-r--r--src/main/java/org/onap/clamp/clds/tosca/ToscaYamlToJsonConvertor.java121
-rw-r--r--src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java2
2 files changed, 59 insertions, 64 deletions
diff --git a/src/main/java/org/onap/clamp/clds/tosca/ToscaYamlToJsonConvertor.java b/src/main/java/org/onap/clamp/clds/tosca/ToscaYamlToJsonConvertor.java
index f5c21c135..43dd5f451 100644
--- a/src/main/java/org/onap/clamp/clds/tosca/ToscaYamlToJsonConvertor.java
+++ b/src/main/java/org/onap/clamp/clds/tosca/ToscaYamlToJsonConvertor.java
@@ -61,10 +61,12 @@ public class ToscaYamlToJsonConvertor {
/**
* Parses Tosca YAML string.
*
- * @param yamlString YAML string
+ * @param yamlString YAML string
+ * @param modelTypeToUse The model type that must be used to obtain the Json
+ * Schema
* @return JSON string
*/
- public String parseToscaYaml(String yamlString) {
+ public String parseToscaYaml(String yamlString, String modelTypeToUse) {
Yaml yaml = new Yaml();
LinkedHashMap<String, Object> loadedYaml = yaml.load(yamlString);
@@ -76,7 +78,7 @@ public class ToscaYamlToJsonConvertor {
JSONObject jsonParentObject = new JSONObject();
JSONObject jsonTempObject = new JSONObject();
parseNodeAndDataType(loadedYaml, nodeTypes, dataNodes);
- populateJsonEditorObject(loadedYaml, nodeTypes, dataNodes, jsonParentObject, jsonTempObject);
+ populateJsonEditorObject(loadedYaml, nodeTypes, dataNodes, jsonParentObject, jsonTempObject, modelTypeToUse);
if (jsonTempObject.length() > 0) {
jsonParentObject = jsonTempObject;
}
@@ -99,75 +101,68 @@ public class ToscaYamlToJsonConvertor {
} else if (n.getKey().contains(ToscaSchemaConstants.POLICY_DATA)) {
dataNodes.put(n.getKey(), n.getValue());
}
-
});
}
@SuppressWarnings("unchecked")
private void populateJsonEditorObject(LinkedHashMap<String, Object> map, LinkedHashMap<String, Object> nodeTypes,
- LinkedHashMap<String, Object> dataNodes, JSONObject jsonParentObject, JSONObject jsonTempObject) {
+ LinkedHashMap<String, Object> dataNodes, JSONObject jsonParentObject, JSONObject jsonTempObject,
+ String modelTypeToUse) {
- Map<String, JSONObject> jsonEntrySchema = new HashMap();
+ Map<String, JSONObject> jsonEntrySchema = new HashMap<>();
jsonParentObject.put(JsonEditorSchemaConstants.TYPE, JsonEditorSchemaConstants.TYPE_OBJECT);
- nodeTypes.entrySet().stream().forEach(nt -> {
- if (nt.getValue() instanceof Map) {
- ((LinkedHashMap<String, Object>) nt.getValue()).entrySet().forEach(ntElement -> {
- if (ntElement.getKey().equalsIgnoreCase(ToscaSchemaConstants.PROPERTIES)) {
- JSONArray rootNodeArray = new JSONArray();
- if (ntElement.getValue() instanceof Map) {
- ((LinkedHashMap<String, Object>) ntElement.getValue()).entrySet()
- .forEach((ntPropertiesElement) -> {
- boolean isListNode = false;
+ if (nodeTypes.get(modelTypeToUse) instanceof Map) {
+ ((LinkedHashMap<String, Object>) nodeTypes.get(modelTypeToUse)).entrySet().forEach(ntElement -> {
+ if (ntElement.getKey().equalsIgnoreCase(ToscaSchemaConstants.PROPERTIES)) {
+ JSONArray rootNodeArray = new JSONArray();
+ if (ntElement.getValue() instanceof Map) {
+ ((LinkedHashMap<String, Object>) ntElement.getValue()).entrySet()
+ .forEach((ntPropertiesElement) -> {
+ boolean isListNode = false;
+ parseDescription((LinkedHashMap<String, Object>) ntPropertiesElement.getValue(),
+ jsonParentObject);
+ LinkedHashMap<String, Object> parentPropertiesMap = (LinkedHashMap<String, Object>) ntPropertiesElement
+ .getValue();
+ if (parentPropertiesMap.containsKey(ToscaSchemaConstants.TYPE)
+ && ((String) parentPropertiesMap.get(ToscaSchemaConstants.TYPE))
+ .contains(ToscaSchemaConstants.TYPE_MAP)
+ && parentPropertiesMap.containsKey(ToscaSchemaConstants.ENTRY_SCHEMA)) {
+ parentPropertiesMap = (LinkedHashMap<String, Object>) parentPropertiesMap
+ .get(ToscaSchemaConstants.ENTRY_SCHEMA);
+ isListNode = true;
+ }
+ if (parentPropertiesMap.containsKey(ToscaSchemaConstants.TYPE)
+ && ((String) parentPropertiesMap.get(ToscaSchemaConstants.TYPE))
+ .contains(ToscaSchemaConstants.POLICY_DATA)) {
+ ((LinkedHashMap<String, Object>) dataNodes
+ .get(parentPropertiesMap.get(ToscaSchemaConstants.TYPE))).entrySet()
+ .stream().forEach(pmap -> {
+ if (pmap.getKey().equalsIgnoreCase(
+ ToscaSchemaConstants.PROPERTIES)) {
+ parseToscaProperties(ToscaSchemaConstants.POLICY_NODE,
+ (LinkedHashMap<String, Object>) pmap.getValue(),
+ jsonParentObject, rootNodeArray,
+ jsonEntrySchema, dataNodes,
+ incrementSimpleTypeOrder());
+ }
+ });
+ }
+ if (isListNode) {
+ jsonTempObject.put(JsonEditorSchemaConstants.TYPE,
+ JsonEditorSchemaConstants.TYPE_ARRAY);
parseDescription((LinkedHashMap<String, Object>) ntPropertiesElement.getValue(),
- jsonParentObject);
- LinkedHashMap<String, Object> parentPropertiesMap = (LinkedHashMap<String, Object>) ntPropertiesElement
- .getValue();
- if (parentPropertiesMap.containsKey(ToscaSchemaConstants.TYPE)
- && ((String) parentPropertiesMap.get(ToscaSchemaConstants.TYPE))
- .contains(ToscaSchemaConstants.TYPE_MAP)
- && parentPropertiesMap.containsKey(ToscaSchemaConstants.ENTRY_SCHEMA)) {
- parentPropertiesMap = (LinkedHashMap<String, Object>) parentPropertiesMap
- .get(ToscaSchemaConstants.ENTRY_SCHEMA);
- isListNode = true;
- }
- if (parentPropertiesMap.containsKey(ToscaSchemaConstants.TYPE)
- && ((String) parentPropertiesMap.get(ToscaSchemaConstants.TYPE))
- .contains(ToscaSchemaConstants.POLICY_DATA)) {
- ((LinkedHashMap<String, Object>) dataNodes
- .get(parentPropertiesMap.get(ToscaSchemaConstants.TYPE))).entrySet()
- .stream().forEach(pmap -> {
- if (pmap.getKey().equalsIgnoreCase(
- ToscaSchemaConstants.PROPERTIES)) {
- parseToscaProperties(
- ToscaSchemaConstants.POLICY_NODE,
- (LinkedHashMap<String, Object>) pmap
- .getValue(),
- jsonParentObject, rootNodeArray,
- jsonEntrySchema, dataNodes,
- incrementSimpleTypeOrder());
- }
-
- });
-
- }
- if (isListNode) {
- jsonTempObject.put(JsonEditorSchemaConstants.TYPE,
- JsonEditorSchemaConstants.TYPE_ARRAY);
- parseDescription(
- (LinkedHashMap<String, Object>) ntPropertiesElement.getValue(),
- jsonTempObject);
- jsonTempObject.put(JsonEditorSchemaConstants.ITEMS, jsonParentObject);
- jsonTempObject.put(JsonEditorSchemaConstants.FORMAT,
- JsonEditorSchemaConstants.CUSTOM_KEY_FORMAT_TABS_TOP);
- jsonTempObject.put(JsonEditorSchemaConstants.UNIQUE_ITEMS,
- JsonEditorSchemaConstants.TRUE);
- }
- });
- }
+ jsonTempObject);
+ jsonTempObject.put(JsonEditorSchemaConstants.ITEMS, jsonParentObject);
+ jsonTempObject.put(JsonEditorSchemaConstants.FORMAT,
+ JsonEditorSchemaConstants.CUSTOM_KEY_FORMAT_TABS_TOP);
+ jsonTempObject.put(JsonEditorSchemaConstants.UNIQUE_ITEMS,
+ JsonEditorSchemaConstants.TRUE);
+ }
+ });
}
- });
- }
- });
+ }
+ });
+ }
}
@SuppressWarnings("unchecked")
diff --git a/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java b/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java
index b1cea34b8..2943c39a2 100644
--- a/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java
+++ b/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java
@@ -117,7 +117,7 @@ public class MicroServicePolicy implements Serializable, Policy {
this.policyTosca = policyTosca;
this.shared = shared;
this.jsonRepresentation = JsonUtils.GSON_JPA_MODEL
- .fromJson(new ToscaYamlToJsonConvertor().parseToscaYaml(policyTosca), JsonObject.class);
+ .fromJson(new ToscaYamlToJsonConvertor().parseToscaYaml(policyTosca, modelType), JsonObject.class);
this.usedByLoops = usedByLoops;
}