aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPamela Dragosh <pdragosh@research.att.com>2018-05-24 11:02:59 +0000
committerGerrit Code Review <gerrit@onap.org>2018-05-24 11:02:59 +0000
commita08e498c52e5f778ec85cb698ac985488319b9f3 (patch)
tree4984912b3cfd22b23a7e91daed00875e570f8e9a
parent20beb12cad63e778c837eb0f4106acd74019d340 (diff)
parentf27a65f682adee4f30a72515d9ec3916722884b3 (diff)
Merge "Fix Issues in TOSCA Parser"
-rw-r--r--ONAP-REST/src/main/java/org/onap/policy/rest/util/MSModelUtils.java43
-rw-r--r--ONAP-REST/src/main/java/org/onap/policy/rest/util/ParserException.java30
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/util/MSModelUtilsTest.java2
3 files changed, 65 insertions, 10 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 7db16bda5..1a62ccc88 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
@@ -763,13 +763,16 @@ public class MSModelUtils {
} catch (IOException e) {
logger.error(e);
+ }catch(ParserException e){
+ logger.error(e);
+ return e.getMessage();
}
return null;
}
@SuppressWarnings("unchecked")
- public LinkedHashMap<String, String> load(String fileName) throws IOException {
+ public LinkedHashMap<String, String> load(String fileName) throws IOException,ParserException {
File newConfiguration = new File(fileName);
StringBuilder orderInfo = new StringBuilder("[");
Yaml yaml = new Yaml();
@@ -778,6 +781,8 @@ public class MSModelUtils {
yamlMap = (LinkedHashMap<Object, Object>) yaml.load(is);
} catch (FileNotFoundException e) {
logger.error(e);
+ }catch(Exception e){
+ throw new ParserException("Invalid TOSCA Model format. Please make sure it is a valid YAML file");
}
StringBuilder sb = new StringBuilder();
@@ -1098,17 +1103,25 @@ public class MSModelUtils {
stringListItems.append(uniqueDataKeySplit[1].toUpperCase()+":required-"+requiredValue +":MANY-true");
}
dataMapForJson.put(uniqueDataKey, stringListItems.toString());
- dataListBuffer.append(uniqueDataKeySplit[1].toUpperCase()+"=[");
+ boolean isConstraintsFound = false;
for(int i=0;i<10;i++){
String findConstraints= DATATYPE+uniqueDataKeySplit[0]+PROPERTIES+uniqueDataKeySplit[1]+".entry_schema.constraints.0.valid_values."+i;
logger.info("findConstraints => " + findConstraints);
String constraintsValue=map.get(findConstraints);
logger.info("constraintsValue => " + constraintsValue);
- if(constraintsValue==null){
+ if((constraintsValue==null || constraintsValue.isEmpty()) && i==0){ //if no constraints at all ( index i as 0 can tell this )
+ isConstraintsFound = false;
+ //if type is list but no constraints
+ String newValue = dataMapForJson.get(uniqueDataKey).replace("MANY-false", "MANY-true");
+ newValue = newValue.replace(uniqueDataKeySplit[1].toUpperCase()+":", "");
+ dataMapForJson.put(uniqueDataKey, newValue);
break;
- }
- else{
- logger.info("constraintsValue => " + constraintsValue);
+ } else{
+ isConstraintsFound = true;
+ if(i == 0){ // only need to add one time for the same attribute
+ dataListBuffer.append(uniqueDataKeySplit[1].toUpperCase()+"=[");
+ }
+
if(constraintsValue.contains("=")){
constraintsValue = constraintsValue.replace("=", "equal-sign");
}
@@ -1116,9 +1129,12 @@ public class MSModelUtils {
dataListBuffer.append(constraintsValue+",");
}
}
- dataListBuffer.append("]#");
- logger.info(dataListBuffer);
+ if(isConstraintsFound){
+ dataListBuffer.append("]#");
+ }
}
+ }else{
+ logger.info("entry_schema.type is not defined correctly");
}
}
else{
@@ -1138,7 +1154,7 @@ public class MSModelUtils {
}
- LinkedHashMap<String, LinkedHashMap<String, String>> parsePolicyNodes(Map<String,String> map){
+ LinkedHashMap<String, LinkedHashMap<String, String>> parsePolicyNodes(Map<String,String> map) throws ParserException{
LinkedHashMap<String,LinkedHashMap<String,String>> mapKey= new LinkedHashMap <>();
for(String uniqueKey: uniqueKeys){
LinkedHashMap<String,String> hm;
@@ -1150,7 +1166,11 @@ public class MSModelUtils {
hm = mapKey.get(uniqueKey);
String keyStr= key.substring(key.lastIndexOf('.')+1);
String valueStr= map.get(key);
- if(("type").equals(keyStr)){
+ if("type".equalsIgnoreCase(keyStr) && ((key.contains("entry_schema.0.type") || key.contains("entry_schema.type") && valueStr.contains("policy.data.")))){
+ throw new ParserException("For using user defined object type, Please make sure no space between 'type:' and object " + valueStr );
+
+ }
+ if("type".equals(keyStr)){
if(!key.contains("entry_schema"))
{
hm.put(keyStr,valueStr);
@@ -1163,6 +1183,9 @@ public class MSModelUtils {
hm = new LinkedHashMap <>();
String keyStr= key.substring(key.lastIndexOf('.')+1);
String valueStr= map.get(key);
+ if(key.contains(".objective.")){
+ throw new ParserException("Attribute objective is a key word. Please use a different name");
+ }
if(("type").equals(keyStr)){
if(!key.contains("entry_schema"))
{
diff --git a/ONAP-REST/src/main/java/org/onap/policy/rest/util/ParserException.java b/ONAP-REST/src/main/java/org/onap/policy/rest/util/ParserException.java
new file mode 100644
index 000000000..be7acb4f2
--- /dev/null
+++ b/ONAP-REST/src/main/java/org/onap/policy/rest/util/ParserException.java
@@ -0,0 +1,30 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP-REST
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.policy.rest.util;
+
+public class ParserException extends Exception{
+ String message;
+ ParserException(String message) {
+ this.message = message;
+ }
+ public String getMessage(){
+ return message ;
+ }
+} \ No newline at end of file
diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/util/MSModelUtilsTest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/util/MSModelUtilsTest.java
index aa41429b9..6a9c4c4ec 100644
--- a/ONAP-REST/src/test/java/org/onap/policy/rest/util/MSModelUtilsTest.java
+++ b/ONAP-REST/src/test/java/org/onap/policy/rest/util/MSModelUtilsTest.java
@@ -95,6 +95,8 @@ public class MSModelUtilsTest {
} catch (IOException e) {
logger.error("testLoad", e);
result = null;
+ }catch(ParserException e){
+ logger.error("testLoad", e);
}
assertTrue(result != null && !result.isEmpty());