aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap/clamp/clds/tosca
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/onap/clamp/clds/tosca')
-rw-r--r--src/main/java/org/onap/clamp/clds/tosca/update/Extractor.java18
-rw-r--r--src/main/java/org/onap/clamp/clds/tosca/update/ParserToJson.java72
-rw-r--r--src/main/java/org/onap/clamp/clds/tosca/update/TemplateManagement.java7
3 files changed, 74 insertions, 23 deletions
diff --git a/src/main/java/org/onap/clamp/clds/tosca/update/Extractor.java b/src/main/java/org/onap/clamp/clds/tosca/update/Extractor.java
index 032edbaa8..b0bf82780 100644
--- a/src/main/java/org/onap/clamp/clds/tosca/update/Extractor.java
+++ b/src/main/java/org/onap/clamp/clds/tosca/update/Extractor.java
@@ -23,19 +23,24 @@
package org.onap.clamp.clds.tosca.update;
+import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map.Entry;
import org.yaml.snakeyaml.Yaml;
public class Extractor {
-
- private LinkedHashMap<String, Component> allItems = new LinkedHashMap<>();
+ private LinkedHashMap<String, Component> allItems;
private String source;
+ private String nativeComponent;
@SuppressWarnings("unchecked")
- public Extractor(String toParse) {
+ public Extractor(String toParse, String nativeComponent) throws IOException {
+
this.source = toParse;
+ this.nativeComponent = nativeComponent;
+ allItems = new LinkedHashMap<String, Component>();
getAllAsMaps();
+
}
public LinkedHashMap<String, Component> getAllItems() {
@@ -60,10 +65,17 @@ public class Extractor {
(LinkedHashMap<String, LinkedHashMap<String, Object>>) contentFile;
// Get DataTypes
LinkedHashMap<String, Object> dataTypes = file.get("data_types");
+ dataTypes = (dataTypes == null) ? (new LinkedHashMap<>()) : dataTypes;
// Get Policies : first, get topology and after extract policies from it
LinkedHashMap<String, Object> policyTypes = file.get("policy_types");
// Put the policies and datatypes in the same collection
dataTypes.putAll(policyTypes);
+
+ Object contentNativeFile = yaml.load(nativeComponent);
+ LinkedHashMap<String, Object> dataTypesEmbedded =
+ ((LinkedHashMap<String, LinkedHashMap<String, Object>>) contentNativeFile).get("data_types");
+ dataTypes.putAll(dataTypesEmbedded);
+
parseInComponent(dataTypes);
return dataTypes;
}
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 6da55eaec..7bf629d61 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<String, Property> 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<Component> listofComponent = components.values();
- for (Component component : listofComponent) {
+ if (components == null) {
+ return null;
+ }
+ for (Component component : components.values()) {
if (component.getName().equals(name)) {
correspondingComponent = component;
}
diff --git a/src/main/java/org/onap/clamp/clds/tosca/update/TemplateManagement.java b/src/main/java/org/onap/clamp/clds/tosca/update/TemplateManagement.java
index 4b510cb75..ce5cdb817 100644
--- a/src/main/java/org/onap/clamp/clds/tosca/update/TemplateManagement.java
+++ b/src/main/java/org/onap/clamp/clds/tosca/update/TemplateManagement.java
@@ -46,9 +46,10 @@ public class TemplateManagement {
* @param templateProperties template properties as string
* @throws IOException in case of failure
*/
- public TemplateManagement(String yamlContent, String templateProperties) throws IOException {
+ public TemplateManagement(String yamlContent, String nativeComponent, String templateProperties)
+ throws IOException {
if (yamlContent != null && !yamlContent.isEmpty()) {
- this.extractor = new Extractor(yamlContent);
+ this.extractor = new Extractor(yamlContent, nativeComponent);
this.components = extractor.getAllItems();
this.templates = initializeTemplates(templateProperties);
}
@@ -155,7 +156,7 @@ public class TemplateManagement {
if (parserToJson.matchComponent(componentName) == null) {
throw new UnknownComponentException(componentName);
}
- return parserToJson.getJsonProcess(componentName);
+ return parserToJson.getJsonProcess(componentName, "object");
}
/**