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/JsonEditorSchemaConstants.java15
-rw-r--r--src/main/java/org/onap/clamp/clds/tosca/ToscaSchemaConstants.java5
-rw-r--r--src/main/java/org/onap/clamp/clds/tosca/ToscaYamlToJsonConvertor.java106
3 files changed, 101 insertions, 25 deletions
diff --git a/src/main/java/org/onap/clamp/clds/tosca/JsonEditorSchemaConstants.java b/src/main/java/org/onap/clamp/clds/tosca/JsonEditorSchemaConstants.java
index fdc94231f..e3c661698 100644
--- a/src/main/java/org/onap/clamp/clds/tosca/JsonEditorSchemaConstants.java
+++ b/src/main/java/org/onap/clamp/clds/tosca/JsonEditorSchemaConstants.java
@@ -28,8 +28,10 @@ public class JsonEditorSchemaConstants {
//Data types in JSON Schema
public static final String TYPE_OBJECT = "object";
public static final String TYPE_ARRAY = "array";
+ public static final String TYPE_MAP = "map";
public static final String TYPE_STRING = "string";
public static final String TYPE_INTEGER = "integer";
+ public static final String TYPE_DATE_TIME = "datetime";
//Key elements in JSON Schema
public static final String TYPE = "type";
@@ -43,6 +45,9 @@ public class JsonEditorSchemaConstants {
public static final String ITEMS = "items";
public static final String PROPERTIES = "properties";
public static final String PROPERTY_ORDER = "propertyOrder";
+ public static final String VALUES = "values";
+ public static final String HEADER_TEMPLATE = "headerTemplate";
+ public static final String HEADER_TEMPLATE_VALUE = "{{self.name}}";
public static final String MINIMUM = "minimum";
public static final String MAXIMUM = "maximum";
@@ -50,9 +55,13 @@ public class JsonEditorSchemaConstants {
public static final String MAX_LENGTH = "maxLength";
public static final String EXCLUSIVE_MINIMUM = "exclusiveMinimum";
public static final String EXCLUSIVE_MAXIMUM = "exclusiveMaximum";
+ public static final String MINITEMS = "minItems";
+ public static final String MAXITEMS = "maxItems";
public static final String CUSTOM_KEY_FORMAT = "format";
public static final String CUSTOM_KEY_FORMAT_TABS_TOP = "tabs-top";
+ public static final String CUSTOM_KEY_FORMAT_TABS = "tabs";
+ public static final String CUSTOM_KEY_FORMAT_INPUT = "input";
public static final String FORMAT_SELECT = "select";
public static final String UNIQUE_ITEMS = "uniqueItems";
public static final String TRUE = "true";
@@ -67,5 +76,11 @@ public class JsonEditorSchemaConstants {
public static final String SCHEMA = "schema";
public static final String CURRENT_VALUES = "currentValues";
+ public static final String PLUGIN = "plugin";
+ public static final String DATE_TIME_PICKER = "datetimepicker";
+ public static final String VALIDATION = "validation";
+ public static final String DATE_TIME_FORMAT = "YYYY/MM/DD HH:mm:ss";
+ public static final String INPUT_EVENT = "input_event";
+ public static final String DP_CHANGE = "dp.change";
}
diff --git a/src/main/java/org/onap/clamp/clds/tosca/ToscaSchemaConstants.java b/src/main/java/org/onap/clamp/clds/tosca/ToscaSchemaConstants.java
index 9601649c9..d00c431c8 100644
--- a/src/main/java/org/onap/clamp/clds/tosca/ToscaSchemaConstants.java
+++ b/src/main/java/org/onap/clamp/clds/tosca/ToscaSchemaConstants.java
@@ -30,8 +30,11 @@ public class ToscaSchemaConstants {
public static final String TYPE_MAP = "map";
public static final String TYPE_STRING = "string";
public static final String TYPE_INTEGER = "integer";
+ public static final String TYPE_NUMBER = "number";
+ public static final String TYPE_DATE_TIME = "datetime";
public static final String TYPE_FLOAT = "float";
public static final String TYPE_BOOLEAN = "boolean";
+ public static final String TYPE_USER_DEFINED = "userDefined";
// Key elements in Tosca
public static final String NODE_TYPES = "policy_types";
@@ -46,6 +49,8 @@ public class ToscaSchemaConstants {
public static final String METADATA = "metadata";
public static final String METADATA_POLICY_MODEL_TYPE = "policy_model_type";
public static final String METADATA_ACRONYM = "acronym";
+ public static final String METADATA_ELEMENT_NAME = "element_name";
+ public static final String METADATA_HEADER_TEMPLATE = "header_template";
public static final String METADATA_CLAMP_POSSIBLE_VALUES = "clamp_possible_values";
// Constraints
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 666ca6702..45bb87ed8 100644
--- a/src/main/java/org/onap/clamp/clds/tosca/ToscaYamlToJsonConvertor.java
+++ b/src/main/java/org/onap/clamp/clds/tosca/ToscaYamlToJsonConvertor.java
@@ -38,6 +38,7 @@ import java.util.stream.Collectors;
import org.json.JSONArray;
import org.json.JSONObject;
import org.onap.clamp.clds.config.ClampProperties;
+import org.onap.clamp.tosca.Dictionary;
import org.onap.clamp.tosca.DictionaryElement;
import org.onap.clamp.tosca.DictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -142,6 +143,13 @@ public class ToscaYamlToJsonConvertor {
parseNodeAndDataType(loadedYaml, nodeTypes, dataNodes);
populateJsonEditorObject(loadedYaml, nodeTypes, dataNodes, jsonParentObject, jsonTempObject,
modelTypeToUse);
+
+ String headerTemplate = getValueFromMetadata(validateAndConvertToJson(yamlString),
+ ToscaSchemaConstants.METADATA_HEADER_TEMPLATE);
+ if (headerTemplate != null) {
+ jsonParentObject.put(JsonEditorSchemaConstants.HEADER_TEMPLATE,
+ JsonEditorSchemaConstants.HEADER_TEMPLATE_VALUE);
+ }
if (jsonTempObject.length() > 0) {
jsonParentObject = jsonTempObject;
}
@@ -234,7 +242,7 @@ public class ToscaYamlToJsonConvertor {
jsonTempObject.put(JsonEditorSchemaConstants.ITEMS,
jsonParentObject);
jsonTempObject.put(JsonEditorSchemaConstants.FORMAT,
- JsonEditorSchemaConstants.CUSTOM_KEY_FORMAT_TABS_TOP);
+ JsonEditorSchemaConstants.CUSTOM_KEY_FORMAT_TABS);
jsonTempObject.put(JsonEditorSchemaConstants.UNIQUE_ITEMS,
JsonEditorSchemaConstants.TRUE);
}
@@ -652,12 +660,43 @@ public class ToscaYamlToJsonConvertor {
Optional.ofNullable(cldsDictionaryElements).get().stream().forEach(c -> {
JSONObject jsonObject = new JSONObject();
+ if (c.getSubDictionary() != null) {
+ Dictionary subDictionary =
+ dictionaryService.getDictionary(c.getSubDictionary());
+ if (subDictionary != null
+ && !subDictionary.getDictionaryElements().isEmpty()) {
+
+ jsonObject.put(JsonEditorSchemaConstants.CUSTOM_KEY_FORMAT_INPUT,
+ JsonEditorSchemaConstants.FORMAT_SELECT);
+
+ List<String> shortNames = new ArrayList<>();
+ subDictionary.getDictionaryElements().stream().forEach(c1 -> {
+ shortNames.add(c1.getShortName());
+ });
+ jsonObject.put(JsonEditorSchemaConstants.VALUES, shortNames);
+ }
+ }
jsonObject.put(JsonEditorSchemaConstants.TYPE, getJsonType(c.getType()));
+
if (c.getType() != null
- && c.getType().equalsIgnoreCase(ToscaSchemaConstants.TYPE_STRING)) {
+ && (c.getType().equalsIgnoreCase(ToscaSchemaConstants.TYPE_STRING)
+ || c.getType().equalsIgnoreCase(ToscaSchemaConstants.TYPE_DATE_TIME)
+ || c.getType().equalsIgnoreCase(ToscaSchemaConstants.TYPE_MAP))) {
jsonObject.put(JsonEditorSchemaConstants.MIN_LENGTH, 1);
+ if (c.getType().equalsIgnoreCase(ToscaSchemaConstants.TYPE_DATE_TIME)) {
+ jsonObject.put(JsonEditorSchemaConstants.PLUGIN,
+ JsonEditorSchemaConstants.DATE_TIME_PICKER);
+ jsonObject.put(JsonEditorSchemaConstants.INPUT_EVENT,
+ JsonEditorSchemaConstants.DP_CHANGE);
+ JSONObject formatJsonObject = new JSONObject();
+ formatJsonObject.put(JsonEditorSchemaConstants.FORMAT,
+ JsonEditorSchemaConstants.DATE_TIME_FORMAT);
+ jsonObject.put(JsonEditorSchemaConstants.VALIDATION,
+ formatJsonObject);
+ }
}
+
jsonObject.put(JsonEditorSchemaConstants.ID, c.getName());
jsonObject.put(JsonEditorSchemaConstants.LABEL, c.getShortName());
jsonObject.put(JsonEditorSchemaConstants.OPERATORS, subCldsDictionaryNames);
@@ -678,32 +717,44 @@ public class ToscaYamlToJsonConvertor {
String dictionaryKey = dictionaryReference.substring(
dictionaryReference.indexOf(ToscaSchemaConstants.DICTIONARY) + 11,
dictionaryReference.length());
+
if (dictionaryKey != null) {
- List<DictionaryElement> cldsDictionaryElements =
- dictionaryService.getDictionary(dictionaryKey).getDictionaryElements().stream()
- .collect(Collectors.toList());
- if (cldsDictionaryElements != null) {
- List<String> cldsDictionaryNames = new ArrayList<>();
- List<String> cldsDictionaryFullNames = new ArrayList<>();
- cldsDictionaryElements.stream().forEach(c -> {
- // Json type will be translated before Policy creation
- if (c.getType() != null && !c.getType().equalsIgnoreCase("json")) {
- cldsDictionaryFullNames.add(c.getName());
+ if (dictionaryKey.contains(ToscaSchemaConstants.TYPE_USER_DEFINED)) {
+ childObject.put(JsonEditorSchemaConstants.ENUM, new ArrayList<>());
+ // Add Enum titles for generated translated values during
+ // JSON instance generation
+ JSONObject enumTitles = new JSONObject();
+ enumTitles.put(JsonEditorSchemaConstants.ENUM_TITLES, new ArrayList<>());
+ childObject.put(JsonEditorSchemaConstants.OPTIONS, enumTitles);
+ } else {
+ List<DictionaryElement> cldsDictionaryElements =
+ dictionaryService.getDictionary(dictionaryKey).getDictionaryElements()
+ .stream().collect(Collectors.toList());
+ if (cldsDictionaryElements != null) {
+ List<String> cldsDictionaryNames = new ArrayList<>();
+ List<String> cldsDictionaryFullNames = new ArrayList<>();
+ cldsDictionaryElements.stream().forEach(c -> {
+ // Json type will be translated before Policy creation
+ if (c.getType() != null && !c.getType().equalsIgnoreCase("json")) {
+ cldsDictionaryFullNames.add(c.getName());
+ }
+ cldsDictionaryNames.add(c.getShortName());
+ });
+
+ if (!cldsDictionaryFullNames.isEmpty()) {
+ childObject.put(JsonEditorSchemaConstants.ENUM,
+ cldsDictionaryFullNames);
+ // Add Enum titles for generated translated values during JSON instance
+ // generation
+ JSONObject enumTitles = new JSONObject();
+ enumTitles.put(JsonEditorSchemaConstants.ENUM_TITLES,
+ cldsDictionaryNames);
+ childObject.put(JsonEditorSchemaConstants.OPTIONS, enumTitles);
+ } else {
+ childObject.put(JsonEditorSchemaConstants.ENUM, cldsDictionaryNames);
}
- cldsDictionaryNames.add(c.getShortName());
- });
- if (!cldsDictionaryFullNames.isEmpty()) {
- childObject.put(JsonEditorSchemaConstants.ENUM, cldsDictionaryFullNames);
- // Add Enum titles for generated translated values during JSON instance
- // generation
- JSONObject enumTitles = new JSONObject();
- enumTitles.put(JsonEditorSchemaConstants.ENUM_TITLES, cldsDictionaryNames);
- childObject.put(JsonEditorSchemaConstants.OPTIONS, enumTitles);
- } else {
- childObject.put(JsonEditorSchemaConstants.ENUM, cldsDictionaryNames);
}
-
}
}
}
@@ -711,10 +762,15 @@ public class ToscaYamlToJsonConvertor {
private String getJsonType(String toscaType) {
String jsonType = null;
- if (toscaType.equalsIgnoreCase(ToscaSchemaConstants.TYPE_INTEGER)) {
+ if (toscaType.equalsIgnoreCase(ToscaSchemaConstants.TYPE_INTEGER)
+ || toscaType.equalsIgnoreCase(ToscaSchemaConstants.TYPE_NUMBER)) {
jsonType = JsonEditorSchemaConstants.TYPE_INTEGER;
+ } else if (toscaType.equalsIgnoreCase(ToscaSchemaConstants.TYPE_DATE_TIME)) {
+ jsonType = JsonEditorSchemaConstants.TYPE_DATE_TIME;
} else if (toscaType.equalsIgnoreCase(ToscaSchemaConstants.TYPE_LIST)) {
jsonType = JsonEditorSchemaConstants.TYPE_ARRAY;
+ } else if (toscaType.equalsIgnoreCase(ToscaSchemaConstants.TYPE_MAP)) {
+ jsonType = JsonEditorSchemaConstants.TYPE_MAP;
} else {
jsonType = JsonEditorSchemaConstants.TYPE_STRING;
}