diff options
author | Pavel Aharoni <pa0916@att.com> | 2017-05-17 15:10:58 +0300 |
---|---|---|
committer | Pavel Aharoni <pa0916@att.com> | 2017-05-17 15:12:27 +0300 |
commit | e82432429b960c9de5be12360bded3e89c45ead3 (patch) | |
tree | 450905ec91cffecea5e3283393d0df8c4a2c05d9 /jtosca/src/main | |
parent | 0e4e255b8c69d55ccb1a73cdb4d8682fecd51620 (diff) |
[SDC-20] fix toString loop and validation
Change-Id: I24f5cdc52bf1c054fed1557ecf877d87c1fa6a34
Signed-off-by: Pavel Aharoni <pa0916@att.com>
Diffstat (limited to 'jtosca/src/main')
5 files changed, 49 insertions, 37 deletions
diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/DataEntity.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/DataEntity.java index a96b36a..a081f89 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/DataEntity.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/DataEntity.java @@ -52,12 +52,14 @@ public class DataEntity { ExceptionCollector.appendWarning(String.format( "TypeMismatchError: \"%s\" is not a map. The type is \"%s\"", value.toString(),dataType.getType())); - - if (value instanceof List) + + if (value instanceof List && ((List) value).size() > 0) { value = ((List) value).get(0); + } - if (!(value instanceof LinkedHashMap)) + if (!(value instanceof LinkedHashMap)) { return value; + } } diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/NodeTemplate.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/NodeTemplate.java index 2c9d981..4d0baaf 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/NodeTemplate.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/NodeTemplate.java @@ -467,19 +467,9 @@ public class NodeTemplate extends EntityTemplate { @Override public String toString() { - return "NodeTemplate{" + - //"templates=" + templates + - //", customDef=" + customDef + - //", availableRelTpls=" + availableRelTpls + - //", availableRelTypes=" + availableRelTypes + - //", related=" + related + - //", relationshipTpl=" + relationshipTpl + - //", _relationships=" + _relationships + - ", subMappingToscaTemplate=" + (subMappingToscaTemplate==null?"":subMappingToscaTemplate.toLimitedString()) + - //", subMappingToscaTemplate2=" +( subMappingToscaTemplate2 ==null?"":subMappingToscaTemplate2.toLimitedString()) + - ", metadata=" + metadata + - '}'; + return getName(); } + } /*python diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/SubstitutionMappings.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/SubstitutionMappings.java index f02ec2a..153bd89 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/SubstitutionMappings.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/SubstitutionMappings.java @@ -286,18 +286,19 @@ public class SubstitutionMappings { @Override public String toString() { return "SubstitutionMappings{" + - "subMappingDef=" + subMappingDef + - ", nodetemplates=" + nodetemplates + - ", inputs=" + inputs + - ", outputs=" + outputs + - ", groups=" + groups + - ", subMappedNodeTemplate=" + subMappedNodeTemplate + - ", customDefs=" + customDefs + - ", _capabilities=" + _capabilities + - ", _requirements=" + _requirements + +// "subMappingDef=" + subMappingDef + +// ", nodetemplates=" + nodetemplates + +// ", inputs=" + inputs + +// ", outputs=" + outputs + +// ", groups=" + groups + + ", subMappedNodeTemplate=" + (subMappedNodeTemplate==null?"":subMappedNodeTemplate.getName()) + +// ", customDefs=" + customDefs + +// ", _capabilities=" + _capabilities + +// ", _requirements=" + _requirements + '}'; } + @Deprecated public String toLimitedString() { return "SubstitutionMappings{" + "subMappingDef=" + subMappingDef + @@ -305,7 +306,7 @@ public class SubstitutionMappings { ", inputs=" + inputs + ", outputs=" + outputs + ", groups=" + groups + - ", subMappedNodeTemplate=" + subMappedNodeTemplate.getName() + + ", subMappedNodeTemplate=" + (subMappedNodeTemplate==null?"":subMappedNodeTemplate.getName()) + ", customDefs=" + customDefs + ", _capabilities=" + _capabilities + ", _requirements=" + _requirements + diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/TopologyTemplate.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/TopologyTemplate.java index 39536ca..4050643 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/TopologyTemplate.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/TopologyTemplate.java @@ -84,7 +84,7 @@ public class TopologyTemplate { ArrayList<Input> alInputs = new ArrayList<>(); for(String name: _tplInputs().keySet()) { Object attrs = _tplInputs().get(name); - Input input = new Input(name,(LinkedHashMap<String,Object>)attrs,customDefs);//ATT-CDT + Input input = new Input(name,(LinkedHashMap<String,Object>)attrs,customDefs); if(parsedParams != null && parsedParams.get(name) != null) { input.validate(parsedParams.get(name)); } @@ -173,7 +173,7 @@ public class TopologyTemplate { nodeTemplates, inputs, outputs, - groups, //ATT addition + groups, subMappedNodeTemplate, customDefs); } @@ -232,7 +232,7 @@ public class TopologyTemplate { DataEntity.validateDatatype("list", memberNames,null,null,null); if(memberNames.size() < 1 || (new HashSet<String>(memberNames)).size() != memberNames.size()) { - ExceptionCollector.appendException(String.format( + ExceptionCollector.appendWarning(String.format( "InvalidGroupTargetException: Member nodes \"%s\" should be >= 1 and not repeated", memberNames.toString())); } diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/parameters/Input.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/parameters/Input.java index 2eb64e8..96958ce 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/parameters/Input.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/parameters/Input.java @@ -1,6 +1,7 @@ package org.openecomp.sdc.toscaparser.api.parameters; import java.util.ArrayList; +import java.util.Arrays; import java.util.LinkedHashMap; import org.openecomp.sdc.toscaparser.api.DataEntity; @@ -18,19 +19,31 @@ public class Input { private static final String REQUIRED = "required"; private static final String STATUS = "status"; private static final String ENTRY_SCHEMA = "entry_schema"; + + public static final String INTEGER = "integer"; + public static final String STRING = "string"; + public static final String BOOLEAN = "boolean"; + public static final String FLOAT = "float"; + public static final String LIST = "list"; + public static final String MAP = "map"; + public static final String JSON = "json"; private static String INPUTFIELD[] = { TYPE, DESCRIPTION, DEFAULT, CONSTRAINTS, REQUIRED,STATUS, ENTRY_SCHEMA }; + + private static String PRIMITIVE_TYPES[] = { + INTEGER, STRING, BOOLEAN, FLOAT, LIST, MAP, JSON + }; private String name; private Schema schema; - private LinkedHashMap<String,Object> customDefs;//ATT-CDT + private LinkedHashMap<String,Object> customDefs; - public Input(String _name,LinkedHashMap<String,Object> _schemaDict,LinkedHashMap<String,Object> _customDefs) {//ATT-CDT + public Input(String _name,LinkedHashMap<String,Object> _schemaDict,LinkedHashMap<String,Object> _customDefs) { name = _name; schema = new Schema(_name,_schemaDict); - customDefs = _customDefs;//ATT-CDT + customDefs = _customDefs; } public String getName() { @@ -90,13 +103,13 @@ public class Input { break; } } - //ATT-CDT + if(!bFound) { if(customDefs.get(inputType) != null) { bFound = true; } } - //ATT-CDT + if(!bFound) { ExceptionCollector.appendException(String.format( "ValueError: Invalid type \"%s\"",inputType)); @@ -111,14 +124,20 @@ public class Input { else if(EntityType.TOSCA_DEF.get(EntityType.DATATYPE_NETWORK_PREFIX + getType()) != null) { datatype = EntityType.TOSCA_DEF.get(EntityType.DATATYPE_NETWORK_PREFIX + getType()); } - //ATT-CDT + + String type = getType(); + // if it's one of the basic types DON'T look in customDefs + if(Arrays.asList(PRIMITIVE_TYPES).contains(type)) { + DataEntity.validateDatatype(getType(), value, null, (LinkedHashMap<String,Object>)datatype, null); + return; + } else if(customDefs.get(getType()) != null) { datatype = customDefs.get(getType()); - DataEntity.validateDatatype(getType(),value,(LinkedHashMap<String,Object>)datatype,customDefs,null); + DataEntity.validateDatatype(getType(), value, (LinkedHashMap<String,Object>)datatype, customDefs, null); return; } - //ATT-CDT - DataEntity.validateDatatype(getType(),value,null,(LinkedHashMap<String,Object>)datatype,null); + + DataEntity.validateDatatype(getType(), value, null, (LinkedHashMap<String,Object>)datatype, null); } } |