X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Fclamp%2Fclds%2Ftosca%2Fupdate%2FParserToJson.java;h=7bf629d61b6b2f190032ddc4bf686ea8c8f86d6b;hb=2dd4e997c1ccf5dab4dfb7665ce74c0fd1f13e49;hp=6da55eaecb9c1a8fad575d5ab077f5e93934dc21;hpb=897a3e004a858ef68d989dad15dde91a69e151a5;p=clamp.git diff --git a/src/main/java/org/onap/clamp/clds/tosca/update/ParserToJson.java b/src/main/java/org/onap/clamp/clds/tosca/update/ParserToJson.java index 6da55eae..7bf629d6 100644 --- a/src/main/java/org/onap/clamp/clds/tosca/update/ParserToJson.java +++ b/src/main/java/org/onap/clamp/clds/tosca/update/ParserToJson.java @@ -45,14 +45,16 @@ public class ParserToJson { * @param nameComponent name components * @return return */ - public JsonObject getJsonProcess(String nameComponent) { - JsonObject glob = this.getGeneralField(matchComponent(nameComponent)); - if (templates.get("object").hasFields("required")) { - glob.add("required", this.getRequirements(nameComponent)); + public JsonObject getJsonProcess(String nameComponent, String typeComponent) { + JsonObject glob = new JsonObject(); + + if (typeComponent.equals("object")) { + glob = this.getFieldAsObject(matchComponent(nameComponent)); } - if (templates.get("object").hasFields("properties")) { - glob.add("properties", this.deploy(nameComponent)); + else { + /*glob = this.getFieldAsArray(matchComponent(nameComponent));*/ } + return glob; } @@ -62,7 +64,7 @@ public class ParserToJson { * @param component the compo * @return a json object */ - public JsonObject getGeneralField(Component component) { + public JsonObject getFieldAsObject(Component component) { JsonObject globalFields = new JsonObject(); if (templates.get("object").hasFields("title")) { @@ -76,6 +78,12 @@ public class ParserToJson { globalFields.addProperty("description", component.getDescription()); } } + if (templates.get("object").hasFields("required")) { + globalFields.add("required", this.getRequirements(component.getName())); + } + if (templates.get("object").hasFields("properties")) { + globalFields.add("properties", this.deploy(component.getName())); + } return globalFields; } @@ -124,7 +132,7 @@ public class ParserToJson { for (Entry property : toParse.getProperties().entrySet()) { if (matchComponent((String) property.getValue().getItems().get("type")) != null) { jsonSchema.add(property.getValue().getName(), - this.getJsonProcess((String) property.getValue().getItems().get("type"))); + this.getJsonProcess((String) property.getValue().getItems().get("type"), "object")); } else { jsonSchema.add(property.getValue().getName(), this.complexParse(property.getValue())); @@ -166,8 +174,11 @@ public class ParserToJson { switch (propertyField) { case "type": if (currentPropertyTemplate.hasFields(propertyField)) { - switch ((String) property.getItems().get(propertyField)) { + String fieldtype = (String) property.getItems().get(propertyField); + switch (fieldtype.toLowerCase()) { case "list": + propertiesInJson.addProperty("type", "array"); + break; case "map": propertiesInJson.addProperty("type", "object"); break; @@ -180,6 +191,9 @@ public class ParserToJson { propertiesInJson.addProperty("type", "string"); propertiesInJson.addProperty("format", "date-time"); break; + case "float": + propertiesInJson.addProperty("type", "number"); + break; case "range": propertiesInJson.addProperty("type", "integer"); if (!checkConstraintPresence(property, "greater_than") @@ -205,16 +219,38 @@ public class ParserToJson { currentPropertyTemplate); break; case "entry_schema": + //Here, a way to check if entry is a component (datatype) or a simple string if (matchComponent(this.extractSpecificFieldFromMap(property, "entry_schema")) != null) { + String nameComponent = this.extractSpecificFieldFromMap(property, "entry_schema"); ParserToJson child = new ParserToJson(components, templates); - JsonObject componentAsProperty = - child.getJsonProcess(this.extractSpecificFieldFromMap(property, "entry_schema")); JsonObject propertiesContainer = new JsonObject(); - propertiesContainer - .add(this.extractSpecificFieldFromMap(property, "entry_schema"), componentAsProperty); - if (currentPropertyTemplate.hasFields("properties")) { - propertiesInJson.add("properties", propertiesContainer); + + switch ((String) property.getItems().get("type")) { + case "map": // Get it as an object + JsonObject componentAsProperty = child.getJsonProcess(nameComponent,"object"); + propertiesContainer.add(nameComponent, componentAsProperty); + if (currentPropertyTemplate.hasFields("properties")) { + propertiesInJson.add("properties", propertiesContainer); + } + break; + default://list : get it as an Array + JsonObject componentAsItem = child.getJsonProcess(nameComponent, "object"); + if (currentPropertyTemplate.hasFields("properties")) { + propertiesInJson.add("items", componentAsItem); + } + break; } + + } + // Native cases + else if (property.getItems().get("type").equals("list")) { + JsonObject itemContainer = new JsonObject(); + String valueInEntrySchema = this.extractSpecificFieldFromMap(property, "entry_schema"); + itemContainer.addProperty("type", valueInEntrySchema); + propertiesInJson.add("items", itemContainer); + } + else {//map + // propertiesInJson.add("key?", valueInEntrySchema); } break; default://Each classical field : type, description, default.. @@ -236,8 +272,10 @@ public class ParserToJson { */ public Component matchComponent(String name) { Component correspondingComponent = null; - Collection listofComponent = components.values(); - for (Component component : listofComponent) { + if (components == null) { + return null; + } + for (Component component : components.values()) { if (component.getName().equals(name)) { correspondingComponent = component; }