aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorsebdet <sebastien.determe@intl.att.com>2019-10-09 14:34:16 +0200
committersebdet <sebastien.determe@intl.att.com>2019-10-09 16:05:38 +0200
commit4a00d035390b67c175669fb22e2455ce3e8bb667 (patch)
treeaae9069ca54424c76f25452de81c3770b5374c6d /src/main
parent7d277f0b30cd35b7e8d758863c8cc9eadb62eecd (diff)
Add policy model id in tosca parser
Add the parameter policy model id when converting the tosca to a Json schema for the UI so that it takes well what is provided in the blueprint Issue-ID: CLAMP-534 Change-Id: Ie5e9e0c495c3969f25cca36d8f3d74c82f1f63b6 Signed-off-by: sebdet <sebastien.determe@intl.att.com>
Diffstat (limited to 'src/main')
-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;
}