summaryrefslogtreecommitdiffstats
path: root/ONAP-REST/src/main/java/org
diff options
context:
space:
mode:
authorWang,Frank(gw1218) <gw1218@att.com>2018-04-03 16:17:54 -0500
committerWang,Frank(gw1218) <gw1218@att.com>2018-04-03 17:00:10 -0500
commitff0146fb327dbe5f27b0bd29640f3ace54006d92 (patch)
tree751832c2d010ad43b5fbda75f3060cd5c16d8f56 /ONAP-REST/src/main/java/org
parent11eb39f53842dff62e81a38ab599ddbc97cf7b73 (diff)
Add More Validations on TOSCA Model Format
Add more validations on TOSCA MS model file name and content format Issue-ID: POLICY-721 Change-Id: Ic3dfe1887791be1e11bca5695866a77909334536 Signed-off-by: Wang,Frank(gw1218) <gw1218@att.com>
Diffstat (limited to 'ONAP-REST/src/main/java/org')
-rw-r--r--ONAP-REST/src/main/java/org/onap/policy/rest/util/MSModelUtils.java96
1 files changed, 93 insertions, 3 deletions
diff --git a/ONAP-REST/src/main/java/org/onap/policy/rest/util/MSModelUtils.java b/ONAP-REST/src/main/java/org/onap/policy/rest/util/MSModelUtils.java
index f8b8b5278..91e7626ea 100644
--- a/ONAP-REST/src/main/java/org/onap/policy/rest/util/MSModelUtils.java
+++ b/ONAP-REST/src/main/java/org/onap/policy/rest/util/MSModelUtils.java
@@ -738,12 +738,18 @@ public class MSModelUtils {
/*
* For TOSCA Model
*/
- public void parseTosca (String fileName){
+ public String parseTosca (String fileName){
LinkedHashMap<String,String> map= new LinkedHashMap<>();
try {
map=load(fileName);
+ if(map != null){
+ if(map.get("error") != null){
+ return map.get("error");
+ }
+ }
+
parseDataAndPolicyNodes(map);
LinkedHashMap<String,String> dataMapForJson=parseDataNodes(map);
@@ -757,7 +763,8 @@ public class MSModelUtils {
} catch (IOException e) {
logger.error(e);
}
-
+
+ return null;
}
@SuppressWarnings("unchecked")
@@ -777,6 +784,13 @@ public class MSModelUtils {
if (yamlMap == null) {
return settings;
}
+
+ String message = validations(yamlMap);
+
+ if(message != null){
+ settings.put("error", message);
+ return settings;
+ }
findNode(yamlMap);
@@ -796,7 +810,83 @@ public class MSModelUtils {
List<String> path = new ArrayList <>();
serializeMap(settings, sb, path, yamlMap);
return settings;
- }
+ }
+
+ @SuppressWarnings("unchecked")
+ private String validations(@SuppressWarnings("rawtypes") LinkedHashMap yamlMap){
+
+ boolean isNoteTypeFound = false;
+ boolean isDataTypeFound = false;
+ boolean isToscaVersionKeyFound = false;
+ boolean isToscaVersionValueFound = false;
+ @SuppressWarnings("rawtypes")
+ Map m1 = new HashMap();
+ short order =0;
+ if(yamlMap != null){
+ // Get a set of the entries
+ @SuppressWarnings("rawtypes")
+ Set set = yamlMap.entrySet();
+ // Get an iterator
+ @SuppressWarnings("rawtypes")
+ Iterator i = set.iterator();
+ // Display elements
+ while(i.hasNext()) {
+ @SuppressWarnings("rawtypes")
+ Map.Entry me = (Map.Entry)i.next();
+
+ if("tosca_definitions_version".equals(me.getKey())){
+ isToscaVersionKeyFound = true;
+ order++;
+ m1.put("tosca_definitions_version", order);
+ }
+
+ if("tosca_simple_yaml_1_0_0".equals(me.getValue())){
+ isToscaVersionValueFound = true;
+ }
+
+ if("node_types".equals(me.getKey())){
+ isNoteTypeFound = true;
+ order++;
+ m1.put("node_types", order);
+ }
+
+ if("data_types".equals(me.getKey())){
+ isDataTypeFound = true;
+ order++;
+ m1.put("data_types", order);
+ }
+
+ }
+
+
+ if(!isDataTypeFound){
+ return "data_types are missing or invalid.";
+ }
+
+ if(!isToscaVersionKeyFound || !isToscaVersionValueFound){
+ return "tosca_definitions_version is missing or invalid.";
+ }
+
+ if(!isNoteTypeFound){
+ return "node_types are missing or invalid.";
+ }
+
+ short version = (short) m1.get("tosca_definitions_version");
+
+ if(version > 1 ){
+ return "tosca_definitions_version should be defined first.";
+ }
+
+ short data = (short) m1.get("data_types");
+ short node = (short) m1.get("node_types");
+ if(node > data){
+ return "node_types should be defined before data_types.";
+ }
+
+ }
+
+ return null;
+ }
@SuppressWarnings({ "unchecked", "rawtypes" })
private void serializeMap(LinkedHashMap<String, String> settings, StringBuilder sb, List<String> path, Map<Object, Object> yamlMap) {