[SDC-380] jtosca errors cutomization
Change-Id: I18513daa0c3cdf99b5cf5b6732c7c5c57486c7d0
Signed-off-by: Pavel Aharoni <pa0916@att.com>
diff --git a/pom.xml b/pom.xml
index 69fb8b1..ba462d9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
<groupId>org.openecomp.sdc.jtosca</groupId>
<artifactId>jtosca</artifactId>
- <version>1.1.10-SNAPSHOT</version>
+ <version>1.1.11-SNAPSHOT</version>
<name>sdc-jtosca</name>
<properties>
@@ -53,6 +53,20 @@
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
+
+ <dependency>
+ <groupId>com.opencsv</groupId>
+ <artifactId>opencsv</artifactId>
+ <version>3.10</version>
+ </dependency>
+
+ <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-io -->
+<dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>1.3.2</version>
+</dependency>
+
</dependencies>
<reporting>
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/DataEntity.java b/src/main/java/org/openecomp/sdc/toscaparser/api/DataEntity.java
index 350068b..08e154f 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/DataEntity.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/DataEntity.java
@@ -1,11 +1,10 @@
-package org.openecomp.sdc.toscaparser.api;
+package org.openecomp.sdc.toscaparser.api;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
import org.openecomp.sdc.toscaparser.api.elements.*;
import org.openecomp.sdc.toscaparser.api.elements.constraints.Constraint;
import org.openecomp.sdc.toscaparser.api.elements.constraints.Schema;
@@ -50,9 +49,9 @@
else {
if(!(value instanceof LinkedHashMap)) {
//ERROR under investigation
- ThreadLocalsHolder.getCollector().appendWarning(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE001", String.format(
"TypeMismatchError: \"%s\" is not a map. The type is \"%s\"",
- value.toString(),dataType.getType()));
+ value.toString(),dataType.getType())));
if (value instanceof List && ((List) value).size() > 0) {
value = ((List) value).get(0);
@@ -86,9 +85,9 @@
for(String valueKey: valueDict.keySet()) {
//1710 devlop JSON validation
if(!("json").equals(dataType.getType()) && !allowedProps.contains(valueKey)) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "UnknownFieldError: Data value of type \"%s\" contains unknown field \"%s\"",
- dataType.getType(),valueKey));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE100", String.format(
+ "UnknownFieldError: Data value of type \"%s\" contains unknown field \"%s\"",
+ dataType.getType(),valueKey)));
}
}
@@ -109,9 +108,9 @@
}
}
if(missingProp.size() > 0) {
- ThreadLocalsHolder.getCollector().appendWarning(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE003",String.format(
"MissingRequiredFieldError: Data value of type \"%s\" is missing required field(s) \"%s\"",
- dataType.getType(),missingProp.toString()));
+ dataType.getType(),missingProp.toString())));
}
// check every field
@@ -169,9 +168,9 @@
}
else if (type == null) {
//NOT ANALYZED
- ThreadLocalsHolder.getCollector().appendWarning(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE002", String.format(
"MissingType: Type is missing for value \"%s\"",
- value.toString()));
+ value.toString())));
return value;
}
else if(type.equals(Schema.STRING)) {
@@ -277,7 +276,7 @@
/*python
-from toscaparser.common.exception import ExceptionCollector
+from toscaparser.common.exception import ValidationIssueCollector
from toscaparser.common.exception import MissingRequiredFieldError
from toscaparser.common.exception import TypeMismatchError
from toscaparser.common.exception import UnknownFieldError
@@ -318,7 +317,7 @@
# If the datatype has 'properties' definition
else:
if not isinstance(self.value, dict):
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
TypeMismatchError(what=self.value,
type=self.datatype.type))
allowed_props = []
@@ -335,7 +334,7 @@
# check allowed field
for value_key in list(self.value.keys()):
if value_key not in allowed_props:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
UnknownFieldError(what=(_('Data value of type "%s"')
% self.datatype.type),
field=value_key))
@@ -351,7 +350,7 @@
if req_key not in list(self.value.keys()):
missingprop.append(req_key)
if missingprop:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
MissingRequiredFieldError(
what=(_('Data value of type "%s"')
% self.datatype.type), required=missingprop))
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/DataEntity.java.orig b/src/main/java/org/openecomp/sdc/toscaparser/api/DataEntity.java.orig
index c3f8fb5..2c6d923 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/DataEntity.java.orig
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/DataEntity.java.orig
@@ -5,7 +5,7 @@
import java.util.LinkedHashMap;
import java.util.List;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
+import org.openecomp.sdc.toscaparser.api.common.ValidationIssueCollector;
import org.openecomp.sdc.toscaparser.api.elements.*;
import org.openecomp.sdc.toscaparser.api.elements.constraints.Constraint;
import org.openecomp.sdc.toscaparser.api.elements.constraints.Schema;
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/EntityTemplate.java b/src/main/java/org/openecomp/sdc/toscaparser/api/EntityTemplate.java
index 9220dac..32de069 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/EntityTemplate.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/EntityTemplate.java
@@ -1,13 +1,13 @@
package org.openecomp.sdc.toscaparser.api;
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
import org.openecomp.sdc.toscaparser.api.elements.*;
import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
public abstract class EntityTemplate {
// Base class for TOSCA templates
@@ -93,8 +93,8 @@
if(type == null) {
//msg = (_('Policy definition of "%(pname)s" must have'
// ' a "type" ''attribute.') % dict(pname=name))
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "ValidationError: Policy definition of \"%s\" must have a \"type\" attribute",name));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE140", String.format(
+ "ValidationError: Policy definition of \"%s\" must have a \"type\" attribute",name)));
}
typeDefinition = new PolicyType(type, customDef);
}
@@ -335,9 +335,9 @@
// '"default_instances" value is not between '
// '"min_instances" and "max_instances".' %
// self.name)
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE141", String.format(
"ValidationError: \"properties\" of template \"%s\": \"default_instances\" value is not between \"min_instances\" and \"max_instances\"",
- name));
+ name)));
}
}
}
@@ -366,17 +366,17 @@
}
// Required properties found without value or a default value
if(!reqPropsNoValueOrDefault.isEmpty()) {
- ThreadLocalsHolder.getCollector().appendWarning(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE003", String.format(
"MissingRequiredFieldError: properties of template \"%s\" are missing field(s): %s",
- name,reqPropsNoValueOrDefault.toString()));
+ name,reqPropsNoValueOrDefault.toString())));
}
}
else {
// Required properties in schema, but not in template
if(!requiredProps.isEmpty()) {
- ThreadLocalsHolder.getCollector().appendWarning(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE004", String.format(
"MissingRequiredFieldError2: properties of template \"%s\" are missing field(s): %s",
- name,requiredProps.toString()));
+ name,requiredProps.toString())));
}
}
}
@@ -384,8 +384,8 @@
@SuppressWarnings("unchecked")
private void _validateField(LinkedHashMap<String,Object> template) {
if(!(template instanceof LinkedHashMap)) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "MissingRequiredFieldError: Template \"%s\" is missing required field \"%s\"",name,TYPE));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE142", String.format(
+ "MissingRequiredFieldError: Template \"%s\" is missing required field \"%s\"",name,TYPE)));
return;//???
}
boolean bBad = false;
@@ -402,8 +402,8 @@
bBad = (template.get(TYPE) == null);
}
if(bBad) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "MissingRequiredFieldError: Template \"%s\" is missing required field \"%s\"",name,TYPE));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE143", String.format(
+ "MissingRequiredFieldError: Template \"%s\" is missing required field \"%s\"",name,TYPE)));
}
}
@@ -417,8 +417,8 @@
}
}
if(!bFound) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "UnknownFieldError: Section \"%s\" of template \"%s\" contains unknown field \"%s\"",section,name,sname));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE144", String.format(
+ "UnknownFieldError: Section \"%s\" of template \"%s\" contains unknown field \"%s\"",section,name,sname)));
}
}
@@ -585,7 +585,7 @@
if not type:
msg = (_('Policy definition of "%(pname)s" must have'
' a "type" ''attribute.') % dict(pname=name))
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValidationError(msg))
self.type_definition = PolicyType(type, custom_def)
@@ -729,7 +729,7 @@
'"default_instances" value is not between '
'"min_instances" and "max_instances".' %
self.name)
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValidationError(message=err_msg))
def _common_validate_properties(self, entitytype, properties):
@@ -751,21 +751,21 @@
req_props_no_value_or_default.append(r)
# Required properties found without value or a default value
if req_props_no_value_or_default:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
MissingRequiredFieldError(
what='"properties" of template "%s"' % self.name,
required=req_props_no_value_or_default))
else:
# Required properties in schema, but not in template
if required_props:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
MissingRequiredFieldError(
what='"properties" of template "%s"' % self.name,
required=required_props))
def _validate_field(self, template):
if not isinstance(template, dict):
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
MissingRequiredFieldError(
what='Template "%s"' % self.name, required=self.TYPE))
try:
@@ -777,14 +777,14 @@
else:
template[self.TYPE]
except KeyError:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
MissingRequiredFieldError(
what='Template "%s"' % self.name, required=self.TYPE))
def _common_validate_field(self, schema, allowedlist, section):
for name in schema:
if name not in allowedlist:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
UnknownFieldError(
what=('"%(section)s" of template "%(nodename)s"'
% {'section': section, 'nodename': self.name}),
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/Group.java b/src/main/java/org/openecomp/sdc/toscaparser/api/Group.java
index 8ed623f..d183ac7 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/Group.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/Group.java
@@ -1,10 +1,11 @@
package org.openecomp.sdc.toscaparser.api;
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
+
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
import org.openecomp.sdc.toscaparser.api.elements.Metadata;
import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;
import org.openecomp.sdc.toscaparser.api.utils.ValidateUtils;
@@ -70,9 +71,9 @@
}
}
if(!bFound) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE183", String.format(
"UnknownFieldError: Groups \"%s\" contains unknown field \"%s\"",
- name,key));
+ name,key)));
}
}
}
@@ -91,7 +92,7 @@
/*python
-from toscaparser.common.exception import ExceptionCollector
+from toscaparser.common.exception import ValidationIssueCollector
from toscaparser.common.exception import UnknownFieldError
from toscaparser.entity_template import EntityTemplate
from toscaparser.utils import validateutils
@@ -131,7 +132,7 @@
def _validate_keys(self):
for key in self.entity_tpl.keys():
if key not in SECTIONS:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
UnknownFieldError(what='Groups "%s"' % self.name,
field=key))
*/
\ No newline at end of file
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/ImportsLoader.java b/src/main/java/org/openecomp/sdc/toscaparser/api/ImportsLoader.java
index a97a360..6794f9a 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/ImportsLoader.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/ImportsLoader.java
@@ -1,6 +1,7 @@
package org.openecomp.sdc.toscaparser.api;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
+
import org.openecomp.sdc.toscaparser.api.elements.TypeValidation;
import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;
import org.openecomp.sdc.toscaparser.api.utils.UrlUtils;
@@ -42,7 +43,7 @@
if((_path == null || _path.isEmpty()) && tpl == null) {
//msg = _('Input tosca template is not provided.')
//log.warning(msg)
- ThreadLocalsHolder.getCollector().appendException("ValidationError: Input tosca template is not provided");
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE184", "ValidationError: Input tosca template is not provided"));
}
this.path = _path;
@@ -78,8 +79,8 @@
if(importslist == null) {
//msg = _('"imports" keyname is defined without including templates.')
//log.error(msg)
- ThreadLocalsHolder.getCollector().appendException(
- "ValidationError: \"imports\" keyname is defined without including templates");
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE185",
+ "ValidationError: \"imports\" keyname is defined without including templates"));
return;
}
@@ -93,8 +94,8 @@
if(importNames.contains(importName)) {
//msg = (_('Duplicate import name "%s" was found.') % import_name)
//log.error(msg)
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "ValidationError: Duplicate import name \"%s\" was found",importName));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE186", String.format(
+ "ValidationError: Duplicate import name \"%s\" was found",importName)));
}
importNames.add(importName); //???
@@ -169,8 +170,8 @@
private void _validateImportKeys(String importName, LinkedHashMap<String,Object> importUri) {
if(importUri.get(FILE) == null) {
//log.warning(_('Missing keyname "file" in import "%(name)s".') % {'name': import_name})
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "MissingRequiredFieldError: Import of template \"%s\" is missing field %s",importName,FILE));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE187", String.format(
+ "MissingRequiredFieldError: Import of template \"%s\" is missing field %s",importName,FILE)));
}
for(String key: importUri.keySet()) {
boolean bFound = false;
@@ -184,8 +185,8 @@
//log.warning(_('Unknown keyname "%(key)s" error in '
// 'imported definition "%(def)s".')
// % {'key': key, 'def': import_name})
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "UnknownFieldError: Import of template \"%s\" has unknown fiels %s",importName,key));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE188", String.format(
+ "UnknownFieldError: Import of template \"%s\" has unknown fiels %s",importName,key)));
}
}
}
@@ -221,9 +222,9 @@
repository = (String)((LinkedHashMap<String,Object>)importUriDef).get(REPOSITORY);
if(repository != null) {
if(!repositories.keySet().contains(repository)) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE189", String.format(
"InvalidPropertyValueError: Repository \"%s\" not found in \"%s\"",
- repository,repositories.keySet().toString()));
+ repository,repositories.keySet().toString())));
}
}
}
@@ -238,8 +239,8 @@
// 'definition "%(import_name)s".')
// % {'import_name': import_name})
//log.error(msg)
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "ValidationError: A template file name is not provided with import definition \"%s\"",importName));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE190", String.format(
+ "ValidationError: A template file name is not provided with import definition \"%s\"",importName)));
al[0] = al[1] = null;
return al;
}
@@ -253,8 +254,8 @@
return al;
}
catch(IOException e) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "ImportError: \"%s\" loading YAML import from \"%s\"",e.getClass().getSimpleName(),fileName));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE191", String.format(
+ "ImportError: \"%s\" loading YAML import from \"%s\"",e.getClass().getSimpleName(),fileName)));
al[0] = al[1] = null;
return al;
}
@@ -269,7 +270,7 @@
String msg = String.format(
"ImportError: Absolute file name \"%s\" cannot be used in the URL-based input template \"%s\"",
fileName,path);
- ThreadLocalsHolder.getCollector().appendException(msg);
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE192", msg));
al[0] = al[1] = null;
return al;
}
@@ -312,7 +313,7 @@
//log.error(msg)
String msg = String.format(
"ValueError: \"%s\" is not a valid file",importTemplate);
- ThreadLocalsHolder.getCollector().appendException(msg);
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE193", msg));
log.debug("ImportsLoader - _loadImportTemplate - {}", msg);
}
}
@@ -330,7 +331,7 @@
else {
String msg = String.format(
"Relative file name \"%s\" cannot be used in a pre-parsed input template",fileName);
- ThreadLocalsHolder.getCollector().appendException("ImportError: " + msg);
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE194", "ImportError: " + msg));
al[0] = al[1] = null;
return al;
}
@@ -339,8 +340,8 @@
if(importTemplate == null || importTemplate.isEmpty()) {
//log.error(_('Import "%(name)s" is not valid.') %
// {'name': import_uri_def})
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "ImportError: Import \"%s\" is not valid",importUriDef));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE195", String.format(
+ "ImportError: Import \"%s\" is not valid",importUriDef)));
al[0] = al[1] = null;
return al;
}
@@ -348,8 +349,8 @@
// for now, this must be a file
if(!aFile) {
log.error("ImportsLoader - _loadImportTemplate - Error!! Expected a file. importUriDef = {}, importTemplate = {}", importUriDef, importTemplate);
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "ImportError: Import \"%s\" is not a file",importName));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE196", String.format(
+ "ImportError: Import \"%s\" is not a file",importName)));
al[0] = al[1] = null;
return al;
}
@@ -361,14 +362,14 @@
return al;
}
catch(FileNotFoundException e) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "ImportError: Failed to load YAML from \"%s\"",importName));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE197", String.format(
+ "ImportError: Failed to load YAML from \"%s\"",importName)));
al[0] = al[1] = null;
return al;
}
catch(Exception e) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "ImportError: Exception from SnakeYAML file = \"%s\"",importName));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE198", String.format(
+ "ImportError: Exception from SnakeYAML file = \"%s\"",importName)));
al[0] = al[1] = null;
return al;
}
@@ -376,8 +377,8 @@
if(shortImportNotation) {
//log.error(_('Import "%(name)s" is not valid.') % import_uri_def)
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "ImportError: Import \"%s\" is not valid",importName));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE199", String.format(
+ "ImportError: Import \"%s\" is not valid",importName)));
al[0] = al[1] = null;
return al;
}
@@ -410,7 +411,7 @@
String msg = String.format(
"referenced repository \"%s\" in import definition \"%s\" not found",
repository,importName);
- ThreadLocalsHolder.getCollector().appendException("ImportError: " + msg);
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE200", "ImportError: " + msg));
al[0] = al[1] = null;
return al;
}
@@ -424,8 +425,8 @@
return al;
}
catch(IOException e) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "ImportError: Exception loading YAML import from \"%s\"",fullUrl));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE201", String.format(
+ "ImportError: Exception loading YAML import from \"%s\"",fullUrl)));
al[0] = al[1] = null;
return al;
}
@@ -434,13 +435,13 @@
String msg = String.format(
"repository URL \"%s\" in import definition \"%s\" is not valid",
repoUrl,importName);
- ThreadLocalsHolder.getCollector().appendException("ImportError: " + msg);
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE202", "ImportError: " + msg));
}
// if we got here something is wrong with the flow...
log.error("ImportsLoader - _loadImportTemplate - got to dead end (importName {})", importName);
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "ImportError: _loadImportTemplate got to dead end (importName %s)\n",importName));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE203", String.format(
+ "ImportError: _loadImportTemplate got to dead end (importName %s)\n",importName)));
al[0] = al[1] = null;
return al;
}
@@ -464,7 +465,7 @@
import logging
import os
-from toscaparser.common.exception import ExceptionCollector
+from toscaparser.common.exception import ValidationIssueCollector
from toscaparser.common.exception import InvalidPropertyValueError
from toscaparser.common.exception import MissingRequiredFieldError
from toscaparser.common.exception import UnknownFieldError
@@ -491,7 +492,7 @@
if not path and not tpl:
msg = _('Input tosca template is not provided.')
log.warning(msg)
- ExceptionCollector.appendException(ValidationError(message=msg))
+ ValidationIssueCollector.appendException(ValidationError(message=msg))
self.path = path
self.repositories = {}
if tpl and tpl.get('repositories'):
@@ -514,7 +515,7 @@
msg = _('"imports" keyname is defined without including '
'templates.')
log.error(msg)
- ExceptionCollector.appendException(ValidationError(message=msg))
+ ValidationIssueCollector.appendException(ValidationError(message=msg))
return
for import_def in self.importslist:
@@ -524,7 +525,7 @@
msg = (_('Duplicate import name "%s" was found.') %
import_name)
log.error(msg)
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValidationError(message=msg))
imports_names.add(import_name)
@@ -568,7 +569,7 @@
if self.FILE not in import_uri_def.keys():
log.warning(_('Missing keyname "file" in import "%(name)s".')
% {'name': import_name})
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
MissingRequiredFieldError(
what='Import of template "%s"' % import_name,
required=self.FILE))
@@ -577,7 +578,7 @@
log.warning(_('Unknown keyname "%(key)s" error in '
'imported definition "%(def)s".')
% {'key': key, 'def': import_name})
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
UnknownFieldError(
what='Import of template "%s"' % import_name,
field=key))
@@ -610,7 +611,7 @@
repos = self.repositories.keys()
if repository is not None:
if repository not in repos:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
InvalidPropertyValueError(
what=_('Repository is not found in "%s"') % repos))
else:
@@ -623,7 +624,7 @@
'definition "%(import_name)s".')
% {'import_name': import_name})
log.error(msg)
- ExceptionCollector.appendException(ValidationError(message=msg))
+ ValidationIssueCollector.appendException(ValidationError(message=msg))
return
if toscaparser.utils.urlutils.UrlUtils.validate_url(file_name):
@@ -638,7 +639,7 @@
'"%(template)s".')
% {'name': file_name, 'template': self.path})
log.error(msg)
- ExceptionCollector.appendException(ImportError(msg))
+ ValidationIssueCollector.appendException(ImportError(msg))
return
import_template = toscaparser.utils.urlutils.UrlUtils.\
join_url(self.path, file_name)
@@ -670,7 +671,7 @@
% {'import_template':
import_template})
log.error(msg)
- ExceptionCollector.appendException
+ ValidationIssueCollector.appendException
(ValueError(msg))
else: # template is pre-parsed
if os.path.isabs(file_name) and os.path.isfile(file_name):
@@ -681,13 +682,13 @@
'in a pre-parsed input template.')
% {'name': file_name})
log.error(msg)
- ExceptionCollector.appendException(ImportError(msg))
+ ValidationIssueCollector.appendException(ImportError(msg))
return
if not import_template:
log.error(_('Import "%(name)s" is not valid.') %
{'name': import_uri_def})
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ImportError(_('Import "%s" is not valid.') %
import_uri_def))
return
@@ -695,7 +696,7 @@
if short_import_notation:
log.error(_('Import "%(name)s" is not valid.') % import_uri_def)
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ImportError(_('Import "%s" is not valid.') % import_uri_def))
return
@@ -714,7 +715,7 @@
'definition "%(tpl)s" not found.')
% {'n_uri': repository, 'tpl': import_name})
log.error(msg)
- ExceptionCollector.appendException(ImportError(msg))
+ ValidationIssueCollector.appendException(ImportError(msg))
return
if toscaparser.utils.urlutils.UrlUtils.validate_url(full_url):
@@ -724,5 +725,5 @@
'definition "%(tpl)s".')
% {'n_uri': repo_url, 'tpl': import_name})
log.error(msg)
- ExceptionCollector.appendException(ImportError(msg))
+ ValidationIssueCollector.appendException(ImportError(msg))
*/
\ No newline at end of file
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/NodeTemplate.java b/src/main/java/org/openecomp/sdc/toscaparser/api/NodeTemplate.java
index 6606068..1e97572 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/NodeTemplate.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/NodeTemplate.java
@@ -1,5 +1,7 @@
package org.openecomp.sdc.toscaparser.api;
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
+
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
@@ -86,14 +88,14 @@
}
}
if(bFound || customDef.get(node) != null) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE205", String.format(
"NotImplementedError: Lookup by TOSCA types is not supported. Requirement for \"%s\" can not be full-filled",
- getName()));
+ getName())));
return null;
}
if(templates.get(node) == null) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "KeyError: Node template \"%s\" was not found",node));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE206", String.format(
+ "KeyError: Node template \"%s\" was not found",node)));
return null;
}
NodeTemplate relatedTpl = new NodeTemplate(node,templates,customDef,null,null);
@@ -105,7 +107,7 @@
if(relationship == null) {
ArrayList<Object> parentReqs = ((NodeType)typeDefinition).getAllRequirements();
if(parentReqs == null) {
- ThreadLocalsHolder.getCollector().appendException("ValidationError: parent_req is null");
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE207", "ValidationError: parent_req is null"));
}
else {
// for(String key: req.keySet()) {
@@ -165,9 +167,9 @@
}
}
else {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE208", String.format(
"MissingRequiredFieldError: \"relationship\" used in template \"%s\" is missing required field \"type\"",
- relatedTpl.getName()));
+ relatedTpl.getName())));
}
}
for(RelationshipType rtype: ((NodeType)typeDefinition).getRelationship().keySet()) {
@@ -275,8 +277,8 @@
ArrayList<Object> requires = (ArrayList<Object>)((NodeType)typeDefinition).getValue(REQUIREMENTS, entityTpl, false);
if(requires != null) {
if(!(requires instanceof ArrayList)) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "TypeMismatchError: \"requirements\" of template \"%s\" are not of type \"list\"",name));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE209", String.format(
+ "TypeMismatchError: \"requirements\" of template \"%s\" are not of type \"list\"",name)));
}
else {
for(Object ro: requires) {
@@ -320,8 +322,8 @@
if(occurrences.size() != 2 ||
!(0 <= (int)occurrences.get(0) && (int)occurrences.get(0) <= (int)occurrences.get(1)) ||
(int)occurrences.get(1) == 0) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "InvalidPropertyValueError: property has invalid value %s",occurrences.toString()));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE210", String.format(
+ "InvalidPropertyValueError: property has invalid value %s",occurrences.toString())));
}
}
@@ -335,8 +337,8 @@
}
}
if(!bFound) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "UnknownFieldError: \"requirements\" of template \"%s\" contains unknown field \"%s\"",name,key));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE211", String.format(
+ "UnknownFieldError: \"requirements\" of template \"%s\" contains unknown field \"%s\"",name,key)));
}
}
}
@@ -369,8 +371,8 @@
_commonValidateField(value,_collectCustomIfaceOperations(iname),"interfaces");
}
else {
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "UnknownFieldError: \"interfaces\" of template \"%s\" contains unknown field %s",name,iname));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE212", String.format(
+ "UnknownFieldError: \"interfaces\" of template \"%s\" contains unknown field %s",name,iname)));
}
}
}
@@ -421,8 +423,8 @@
}
if(!bFound) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "UnknownFieldError: Node template \"%s\" has unknown field \"%s\"",name,ntname));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE213", String.format(
+ "UnknownFieldError: Node template \"%s\" has unknown field \"%s\"",name,ntname)));
}
}
}
@@ -455,7 +457,7 @@
/*python
-from toscaparser.common.exception import ExceptionCollector
+from toscaparser.common.exception import ValidationIssueCollector
from toscaparser.common.exception import InvalidPropertyValueError
from toscaparser.common.exception import MissingRequiredFieldError
from toscaparser.common.exception import TypeMismatchError
@@ -524,11 +526,11 @@
'Requirement for "%s" can not be full-filled.') % self.name
if (node in list(self.type_definition.TOSCA_DEF.keys())
or node in self.custom_def):
- ExceptionCollector.appendException(NotImplementedError(msg))
+ ValidationIssueCollector.appendException(NotImplementedError(msg))
return
if node not in self.templates:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
KeyError(_('Node template "%s" was not found.') % node))
return
@@ -539,7 +541,7 @@
if not relationship:
parent_reqs = self.type_definition.get_all_requirements()
if parent_reqs is None:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValidationError(message='parent_req is ' +
str(parent_reqs)))
else:
@@ -574,7 +576,7 @@
elif not relationship.startswith(rel_prfx):
relationship = rel_prfx + relationship
else:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
MissingRequiredFieldError(
what=_('"relationship" used in template '
'"%s"') % related_tpl.name,
@@ -645,7 +647,7 @@
self.entity_tpl)
if requires:
if not isinstance(requires, list):
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
TypeMismatchError(
what='"requirements" of template "%s"' % self.name,
type='list'))
@@ -675,13 +677,13 @@
DataEntity.validate_datatype('integer', value)
if len(occurrences) != 2 or not (0 <= occurrences[0] <= occurrences[1]) \
or occurrences[1] == 0:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
InvalidPropertyValueError(what=(occurrences)))
def _validate_requirements_keys(self, requirement):
for key in requirement.keys():
if key not in self.REQUIREMENTS_SECTION:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
UnknownFieldError(
what='"requirements" of template "%s"' % self.name,
field=key))
@@ -707,7 +709,7 @@
self._collect_custom_iface_operations(name),
'interfaces')
else:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
UnknownFieldError(
what='"interfaces" of template "%s"' %
self.name, field=name))
@@ -730,6 +732,6 @@
def _validate_fields(self, nodetemplate):
for name in nodetemplate.keys():
if name not in self.SECTIONS and name not in self.SPECIAL_SECTIONS:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
UnknownFieldError(what='Node template "%s"' % self.name,
field=name))*/
\ No newline at end of file
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/Policy.java b/src/main/java/org/openecomp/sdc/toscaparser/api/Policy.java
index a59d9d5..26805bd 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/Policy.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/Policy.java
@@ -1,10 +1,11 @@
package org.openecomp.sdc.toscaparser.api;
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
+
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;
import org.openecomp.sdc.toscaparser.api.utils.ValidateUtils;
@@ -101,9 +102,9 @@
}
}
if(!bFound) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE219", String.format(
"UnknownFieldError: Policy \"%s\" contains unknown field \"%s\"",
- name,key));
+ name,key)));
}
}
}
@@ -122,7 +123,7 @@
/*python
-from toscaparser.common.exception import ExceptionCollector
+from toscaparser.common.exception import ValidationIssueCollector
from toscaparser.common.exception import UnknownFieldError
from toscaparser.entity_template import EntityTemplate
from toscaparser.triggers import Triggers
@@ -181,7 +182,7 @@
def _validate_keys(self):
for key in self.entity_tpl.keys():
if key not in SECTIONS:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
UnknownFieldError(what='Policy "%s"' % self.name,
field=key))
*/
\ No newline at end of file
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/Repository.java b/src/main/java/org/openecomp/sdc/toscaparser/api/Repository.java
index 92a90af..3ede22c 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/Repository.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/Repository.java
@@ -1,8 +1,9 @@
package org.openecomp.sdc.toscaparser.api;
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
+
import java.util.LinkedHashMap;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;
import org.openecomp.sdc.toscaparser.api.utils.UrlUtils;
@@ -24,9 +25,9 @@
if(reposit instanceof LinkedHashMap) {
url = (String)((LinkedHashMap<String,Object>)reposit).get("url");
if(url == null) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE229", String.format(
"MissingRequiredFieldError: Repository \"%s\" is missing required field \"url\"",
- name));
+ name)));
}
}
loadAndValidate(name,reposit);
@@ -45,9 +46,9 @@
}
}
if(!bFound) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE230", String.format(
"UnknownFieldError: repositories \"%s\" contains unknown field \"%s\"",
- keyname,key));
+ keyname,key)));
}
}
@@ -55,8 +56,8 @@
if(repositUrl != null) {
boolean urlVal = UrlUtils.validateUrl(repositUrl);
if(!urlVal) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "URLException: repsositories \"%s\" Invalid Url",keyname));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE231", String.format(
+ "URLException: repsositories \"%s\" Invalid Url",keyname)));
}
}
}
@@ -74,7 +75,7 @@
/*python
-from toscaparser.common.exception import ExceptionCollector
+from toscaparser.common.exception import ValidationIssueCollector
from toscaparser.common.exception import MissingRequiredFieldError
from toscaparser.common.exception import UnknownFieldError
from toscaparser.common.exception import URLException
@@ -91,7 +92,7 @@
self.reposit = values
if isinstance(self.reposit, dict):
if 'url' not in self.reposit.keys():
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
MissingRequiredFieldError(what=_('Repository "%s"')
% self.name, required='url'))
self.url = self.reposit['url']
@@ -102,7 +103,7 @@
if isinstance(reposit_def, dict):
for key in reposit_def.keys():
if key not in SECTIONS:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
UnknownFieldError(what=_('repositories "%s"')
% self.keyname, field=key))
@@ -111,7 +112,7 @@
url_val = toscaparser.utils.urlutils.UrlUtils.\
validate_url(reposit_url)
if url_val is not True:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
URLException(what=_('repsositories "%s" Invalid Url')
% self.keyname))
*/
\ No newline at end of file
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/SubstitutionMappings.java b/src/main/java/org/openecomp/sdc/toscaparser/api/SubstitutionMappings.java
index a68f9fb..e5e9d9a 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/SubstitutionMappings.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/SubstitutionMappings.java
@@ -1,13 +1,17 @@
package org.openecomp.sdc.toscaparser.api;
-import java.util.*;
-
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
import org.openecomp.sdc.toscaparser.api.elements.NodeType;
import org.openecomp.sdc.toscaparser.api.elements.PropertyDef;
import org.openecomp.sdc.toscaparser.api.parameters.Input;
import org.openecomp.sdc.toscaparser.api.parameters.Output;
import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+
public class SubstitutionMappings {
// SubstitutionMappings class declaration
@@ -126,9 +130,9 @@
}
}
if(!bFound) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE232", String.format(
"UnknownFieldError: SubstitutionMappings contain unknown field \"%s\"",
- key));
+ key)));
}
}
}
@@ -137,14 +141,14 @@
// validate the node_type of substitution mappings
String nodeType = (String)subMappingDef.get(NODE_TYPE);
if(nodeType == null) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE233", String.format(
"MissingRequiredFieldError: SubstitutionMappings used in topology_template is missing required field \"%s\"",
- NODE_TYPE));
+ NODE_TYPE)));
}
Object nodeTypeDef = customDefs.get(nodeType);
if(nodeTypeDef == null) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "InvalidNodeTypeError: \"%s\" is invalid",nodeType));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE234", String.format(
+ "InvalidNodeTypeError: \"%s\" is invalid",nodeType)));
}
}
@@ -170,9 +174,9 @@
for(String property: requiredProperties) {
// Check property which is 'required' and has no 'default' value
if(!allInputs.contains(property)) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE235", String.format(
"MissingRequiredInputError: SubstitutionMappings with node_type \"%s\" is missing required input \"%s\"",
- getNodeType(),property));
+ getNodeType(),property)));
}
}
// If the optional properties of node type need to be customized by
@@ -188,9 +192,9 @@
diffset.removeAll(allInputs);
for(String parameter: diffset) {
if(allProperties.contains(parameter)) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE236", String.format(
"MissingRequiredInputError: SubstitutionMappings with node_type \"%s\" is missing required input \"%s\"",
- getNodeType(),parameter));
+ getNodeType(),parameter)));
}
}
// Additional inputs are not in the properties of node type must
@@ -201,9 +205,9 @@
diffset = allInputs;
diffset.removeAll(allProperties);
if(diffset.contains(inp.getName()) && inp.getDefault() == null) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE237", String.format(
"MissingRequiredInputError: SubstitutionMappings with node_type \"%s\" is missing rquired input \"%s\"",
- getNodeType(),inp.getName()));
+ getNodeType(),inp.getName())));
}
}
}
@@ -222,7 +226,7 @@
for(CapabilityAssignment cap: nodeCapabilities) {
if(tplsCapabilities != null && tplsCapabilities.get(cap.getName()) == null) {
; //pass
- // ExceptionCollector.appendException(
+ // ValidationIssueCollector.appendException(
// UnknownFieldError(what='SubstitutionMappings',
// field=cap))
}
@@ -247,7 +251,7 @@
String cap = ro.getName();
if(tplsRequirements != null && tplsRequirements.get(cap) == null) {
; //pass
- // ExceptionCollector.appendException(
+ // ValidationIssueCollector.appendException(
// UnknownFieldError(what='SubstitutionMappings',
// field=cap))
}
@@ -272,9 +276,9 @@
for(Output output: outputs) {
Object ado = getNodeDefinition().getAttributesDef();
if(ado != null && ((LinkedHashMap<String,Object>)ado).get(output.getName()) == null) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE238", String.format(
"UnknownOutputError: Unknown output \"%s\" in SubstitutionMappings with node_type \"%s\"",
- output.getName(),getNodeType()));
+ output.getName(),getNodeType())));
}
}
}
@@ -313,7 +317,7 @@
/*python
-from toscaparser.common.exception import ExceptionCollector
+from toscaparser.common.exception import ValidationIssueCollector
from toscaparser.common.exception import InvalidNodeTypeError
from toscaparser.common.exception import MissingDefaultValueError
from toscaparser.common.exception import MissingRequiredFieldError
@@ -392,7 +396,7 @@
"""validate the keys of substitution mappings."""
for key in self.sub_mapping_def.keys():
if key not in self.SECTIONS:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
UnknownFieldError(what=_('SubstitutionMappings'),
field=key))
@@ -400,14 +404,14 @@
"""validate the node_type of substitution mappings."""
node_type = self.sub_mapping_def.get(self.NODE_TYPE)
if not node_type:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
MissingRequiredFieldError(
what=_('SubstitutionMappings used in topology_template'),
required=self.NODE_TYPE))
node_type_def = self.custom_defs.get(node_type)
if not node_type_def:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
InvalidNodeTypeError(what=node_type))
def _validate_inputs(self):
@@ -428,7 +432,7 @@
for property in required_properties:
# Check property which is 'required' and has no 'default' value
if property not in all_inputs:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
MissingRequiredInputError(
what=_('SubstitutionMappings with node_type ')
+ self.node_type,
@@ -443,7 +447,7 @@
all_properties = set(self.node_definition.get_properties_def())
for parameter in customized_parameters - all_inputs:
if parameter in all_properties:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
MissingRequiredInputError(
what=_('SubstitutionMappings with node_type ')
+ self.node_type,
@@ -456,7 +460,7 @@
for input in self.inputs:
if input.name in all_inputs - all_properties \
and input.default is None:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
MissingDefaultValueError(
what=_('SubstitutionMappings with node_type ')
+ self.node_type,
@@ -473,7 +477,7 @@
if (tpls_capabilities and
cap not in list(tpls_capabilities.keys())):
pass
- # ExceptionCollector.appendException(
+ # ValidationIssueCollector.appendException(
# UnknownFieldError(what='SubstitutionMappings',
# field=cap))
@@ -488,7 +492,7 @@
if (tpls_requirements and
req not in list(tpls_requirements.keys())):
pass
- # ExceptionCollector.appendException(
+ # ValidationIssueCollector.appendException(
# UnknownFieldError(what='SubstitutionMappings',
# field=req))
@@ -508,7 +512,7 @@
# has properties, the specification will be amended?
for output in self.outputs:
if output.name not in self.node_definition.get_attributes_def():
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
UnknownOutputError(
where=_('SubstitutionMappings with node_type ')
+ self.node_type,
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/TopologyTemplate.java b/src/main/java/org/openecomp/sdc/toscaparser/api/TopologyTemplate.java
index afedfdb..c19623f 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/TopologyTemplate.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/TopologyTemplate.java
@@ -1,7 +1,6 @@
package org.openecomp.sdc.toscaparser.api;
-import java.util.*;
-
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
import org.openecomp.sdc.toscaparser.api.elements.InterfacesDef;
import org.openecomp.sdc.toscaparser.api.elements.NodeType;
import org.openecomp.sdc.toscaparser.api.elements.RelationshipType;
@@ -12,6 +11,11 @@
import org.openecomp.sdc.toscaparser.api.parameters.Output;
import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
public class TopologyTemplate {
private static final String DESCRIPTION = "description";
@@ -232,9 +236,9 @@
DataEntity.validateDatatype("list", memberNames,null,null,null);
if(memberNames.size() < 1 ||
(new HashSet<String>(memberNames)).size() != memberNames.size()) {
- ThreadLocalsHolder.getCollector().appendWarning(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE005",String.format(
"InvalidGroupTargetException: Member nodes \"%s\" should be >= 1 and not repeated",
- memberNames.toString()));
+ memberNames.toString())));
}
else {
memberNodes = _getGroupMembers(memberNames);
@@ -281,8 +285,8 @@
}
for(String member: members) {
if(!nodeNames.contains(member)) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "InvalidGroupTargetException: Target member \"%s\" is not found in \"nodeTemplates\"",member));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE239", String.format(
+ "InvalidGroupTargetException: Target member \"%s\" is not found in \"nodeTemplates\"",member)));
}
}
}
@@ -383,8 +387,8 @@
}
}
if(!bFound) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "UnknownFieldError: TopologyTemplate contains unknown field \"%s\"",name));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE240", String.format(
+ "UnknownFieldError: TopologyTemplate contains unknown field \"%s\"",name)));
}
}
}
@@ -697,7 +701,7 @@
DataEntity.validate_datatype('list', member_names)
if len(member_names) < 1 or \
len(member_names) != len(set(member_names)):
- exception.ExceptionCollector.appendException(
+ exception.ValidationIssueCollector.appendException(
exception.InvalidGroupTargetException(
message=_('Member nodes "%s" should be >= 1 '
'and not repeated') % member_names))
@@ -732,7 +736,7 @@
node_names.append(node.name)
for member in members:
if member not in node_names:
- exception.ExceptionCollector.appendException(
+ exception.ValidationIssueCollector.appendException(
exception.InvalidGroupTargetException(
message=_('Target member "%s" is not found in '
'node_templates') % member))
@@ -780,7 +784,7 @@
def _validate_field(self):
for name in self.tpl:
if name not in SECTIONS:
- exception.ExceptionCollector.appendException(
+ exception.ValidationIssueCollector.appendException(
exception.UnknownFieldError(what='Template', field=name))
def _process_intrinsic_functions(self):
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/TopologyTemplate.java.orig b/src/main/java/org/openecomp/sdc/toscaparser/api/TopologyTemplate.java.orig
index 3af4b34..7e5f4af 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/TopologyTemplate.java.orig
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/TopologyTemplate.java.orig
@@ -1,11 +1,13 @@
package org.openecomp.sdc.toscaparser.api;
+import org.openecomp.sdc.toscaparser.api.common.JToscaError;
+
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
+import org.openecomp.sdc.toscaparser.api.common.ValidationIssueCollector;
import org.openecomp.sdc.toscaparser.api.elements.InterfacesDef;
import org.openecomp.sdc.toscaparser.api.elements.NodeType;
import org.openecomp.sdc.toscaparser.api.elements.RelationshipType;
@@ -233,9 +235,9 @@
DataEntity.validateDatatype("list", memberNames,null,null,null);
if(memberNames.size() < 1 ||
(new HashSet<String>(memberNames)).size() != memberNames.size()) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendError(new JToscaError("JE241", String.format(
"InvalidGroupTargetException: Member nodes \"%s\" should be >= 1 and not repeated",
- memberNames.toString()));
+ memberNames.toString())));
}
else {
memberNodes = _getGroupMembers(memberNames);
@@ -282,8 +284,8 @@
}
for(String member: members) {
if(!nodeNames.contains(member)) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "InvalidGroupTargetException: Target member \"%s\" is not found in \"nodeTemplates\"",member));
+ ThreadLocalsHolder.getCollector().appendError(new JToscaError("JE242", String.format(
+ "InvalidGroupTargetException: Target member \"%s\" is not found in \"nodeTemplates\"",member)));
}
}
}
@@ -384,8 +386,8 @@
}
}
if(!bFound) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "UnknownFieldError: TopologyTemplate contains unknown field \"%s\"",name));
+ ThreadLocalsHolder.getCollector().appendError(new JToscaError("JE243", String.format(
+ "UnknownFieldError: TopologyTemplate contains unknown field \"%s\"",name)));
}
}
}
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java b/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java
index 5d5cb87..f5902c4 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java
@@ -1,5 +1,7 @@
package org.openecomp.sdc.toscaparser.api;
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
+
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -8,7 +10,7 @@
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
+import org.openecomp.sdc.toscaparser.api.common.ValidationIssueCollector;
import org.openecomp.sdc.toscaparser.api.common.JToscaException;
import org.openecomp.sdc.toscaparser.api.elements.EntityType;
import org.openecomp.sdc.toscaparser.api.elements.Metadata;
@@ -110,7 +112,7 @@
boolean aFile,
LinkedHashMap<String, Object> yamlDictTpl, boolean _resolveGetInput) throws JToscaException {
- ThreadLocalsHolder.setCollector(new ExceptionCollector(_path));
+ ThreadLocalsHolder.setCollector(new ValidationIssueCollector());
VALID_TEMPLATE_VERSIONS = new ArrayList<>();
VALID_TEMPLATE_VERSIONS.add("tosca_simple_yaml_1_0");
@@ -174,8 +176,8 @@
tpl = yamlDictTpl;
}
else {
- ThreadLocalsHolder.getCollector().appendException(
- "ValueError: No path or yaml_dict_tpl was provided. There is nothing to parse");
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE244",
+ "ValueError: No path or yaml_dict_tpl was provided. There is nothing to parse"));
log.debug("ToscaTemplate ValueError: No path or yaml_dict_tpl was provided. There is nothing to parse");
}
@@ -449,8 +451,8 @@
private void _validateField() {
String sVersion = _tplVersion();
if(sVersion == null) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "MissingRequiredField: Template is missing required field \"%s\"",DEFINITION_VERSION));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE245", String.format(
+ "MissingRequiredField: Template is missing required field \"%s\"",DEFINITION_VERSION)));
}
else {
_validateVersion(sVersion);
@@ -473,9 +475,9 @@
}
}
if(!bFound) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE246", String.format(
"UnknownFieldError: Template contains unknown field \"%s\"",
- sKey));
+ sKey)));
}
}
}
@@ -489,9 +491,9 @@
}
}
if(!bFound) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE247", String.format(
"InvalidTemplateVersion: \"%s\" is invalid. Valid versions are %s",
- sVersion,VALID_TEMPLATE_VERSIONS.toString()));
+ sVersion,VALID_TEMPLATE_VERSIONS.toString())));
}
else if(!sVersion.equals("tosca_simple_yaml_1_0")) {
EntityType.updateDefinitions(sVersion);
@@ -521,39 +523,25 @@
}
}
else {
- ThreadLocalsHolder.getCollector().appendException("ValueError: " + _path + " is not a valid file");
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE248", "ValueError: " + _path + " is not a valid file"));
return null;
}
return null;
}
private void verifyTemplate() throws JToscaException {
- ThreadLocalsHolder.getCollector().setWantTrace(false);
-
- //Warnings
- int warningsCount = ThreadLocalsHolder.getCollector().warningsCaught();
- if (warningsCount > 0) {
- List<String> warningsStrings = ThreadLocalsHolder.getCollector().getWarningsReport();
- log.warn("####################################################################################################");
- log.warn("CSAR Warnings found! CSAR name - {}", inputPath);
- log.warn("ToscaTemplate - verifyTemplate - {} Parsing Warning{} occurred...", warningsCount, (warningsCount > 1 ? "s" : ""));
- for (String s : warningsStrings) {
- log.warn("{}. CSAR name - {}", s, inputPath);
- }
- log.warn("####################################################################################################");
- }
-
//Criticals
- int criticalsCount = ThreadLocalsHolder.getCollector().criticalsCaught();
- if (criticalsCount > 0) {
- List<String> criticalStrings = ThreadLocalsHolder.getCollector().getCriticalsReport();
- log.error("####################################################################################################");
- log.error("ToscaTemplate - verifyTemplate - {} Parsing Critical{} occurred...", criticalsCount, (criticalsCount > 1 ? "s" : ""));
- for (String s : criticalStrings) {
- log.error("{}. CSAR name - {}", s, inputPath);
+ int validationIssuesCaught = ThreadLocalsHolder.getCollector().validationIssuesCaught();
+ if (validationIssuesCaught > 0) {
+ List<String> validationIssueStrings = ThreadLocalsHolder.getCollector().getValidationIssueReport();
+ log.trace("####################################################################################################");
+ log.trace("ToscaTemplate - verifyTemplate - {} Parsing Critical{} occurred...", validationIssuesCaught, (validationIssuesCaught > 1 ? "s" : ""));
+ for (String s : validationIssueStrings) {
+ log.trace("{}. CSAR name - {}", s, inputPath);
}
- throw new JToscaException(String.format("CSAR Validation Failed. CSAR name - {}. Please check logs for details.", inputPath), JToscaErrorCodes.CSAR_TOSCA_VALIDATION_ERROR.getValue());
+ log.trace("####################################################################################################");
}
+
}
public String getPath() {
@@ -697,7 +685,7 @@
import os
from copy import deepcopy
-from toscaparser.common.exception import ExceptionCollector.collector
+from toscaparser.common.exception import ValidationIssueCollector.collector
from toscaparser.common.exception import InvalidTemplateVersion
from toscaparser.common.exception import MissingRequiredFieldError
from toscaparser.common.exception import UnknownFieldError
@@ -749,7 +737,7 @@
def __init__(self, path=None, parsed_params=None, a_file=True,
yaml_dict_tpl=None):
- ExceptionCollector.collector.start()
+ ValidationIssueCollector.collector.start()
self.a_file = a_file
self.input_path = None
self.path = None
@@ -770,7 +758,7 @@
if yaml_dict_tpl:
self.tpl = yaml_dict_tpl
else:
- ExceptionCollector.collector.appendException(
+ ValidationIssueCollector.collector.appendException(
ValueError(_('No path or yaml_dict_tpl was provided. '
'There is nothing to parse.')))
@@ -790,7 +778,7 @@
self._handle_nested_tosca_templates_with_topology()
self.graph = ToscaGraph(self.nodetemplates)
- ExceptionCollector.collector.stop()
+ ValidationIssueCollector.collector.stop()
self.verify_template()
def _topology_template(self):
@@ -926,7 +914,7 @@
def _validate_field(self):
version = self._tpl_version()
if not version:
- ExceptionCollector.collector.appendException(
+ ValidationIssueCollector.collector.appendException(
MissingRequiredFieldError(what='Template',
required=DEFINITION_VERSION))
else:
@@ -936,12 +924,12 @@
for name in self.tpl:
if (name not in SECTIONS and
name not in self.ADDITIONAL_SECTIONS.get(version, ())):
- ExceptionCollector.collector.appendException(
+ ValidationIssueCollector.collector.appendException(
UnknownFieldError(what='Template', field=name))
def _validate_version(self, version):
if version not in self.VALID_TEMPLATE_VERSIONS:
- ExceptionCollector.collector.appendException(
+ ValidationIssueCollector.collector.appendException(
InvalidTemplateVersion(
what=version,
valid_versions=', '. join(self.VALID_TEMPLATE_VERSIONS)))
@@ -960,23 +948,23 @@
self.a_file = True # the file has been decompressed locally
return os.path.join(csar.temp_dir, csar.get_main_template())
else:
- ExceptionCollector.collector.appendException(
+ ValidationIssueCollector.collector.appendException(
ValueError(_('"%(path)s" is not a valid file.')
% {'path': path}))
def verify_template(self):
- if ExceptionCollector.collector.exceptionsCaught():
+ if ValidationIssueCollector.collector.exceptionsCaught():
if self.input_path:
raise ValidationError(
message=(_('\nThe input "%(path)s" failed validation with '
'the following error(s): \n\n\t')
% {'path': self.input_path}) +
- '\n\t'.join(ExceptionCollector.collector.getExceptionsReport()))
+ '\n\t'.join(ValidationIssueCollector.collector.getExceptionsReport()))
else:
raise ValidationError(
message=_('\nThe pre-parsed input failed validation with '
'the following error(s): \n\n\t') +
- '\n\t'.join(ExceptionCollector.collector.getExceptionsReport()))
+ '\n\t'.join(ValidationIssueCollector.collector.getExceptionsReport()))
else:
if self.input_path:
msg = (_('The input "%(path)s" successfully passed '
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/Triggers.java b/src/main/java/org/openecomp/sdc/toscaparser/api/Triggers.java
index 0ec0b5a..1e82a6c 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/Triggers.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/Triggers.java
@@ -1,8 +1,9 @@
package org.openecomp.sdc.toscaparser.api;
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
+
import java.util.LinkedHashMap;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;
import org.openecomp.sdc.toscaparser.api.utils.ValidateUtils;
@@ -77,9 +78,9 @@
}
}
if(!bFound) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE249", String.format(
"UnknownFieldError: Triggers \"%s\" contains unknown field \"%s\"",
- name,key));
+ name,key)));
}
}
}
@@ -94,9 +95,9 @@
}
}
if(!bFound) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE250", String.format(
"UnknownFieldError: Triggers \"%s\" contains unknown field \"%s\"",
- name,key));
+ name,key)));
}
}
}
@@ -127,7 +128,7 @@
/*python
-from toscaparser.common.exception import ExceptionCollector
+from toscaparser.common.exception import ValidationIssueCollector
from toscaparser.common.exception import UnknownFieldError
from toscaparser.entity_template import EntityTemplate
@@ -170,14 +171,14 @@
def _validate_keys(self):
for key in self.trigger_tpl.keys():
if key not in SECTIONS:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
UnknownFieldError(what='Triggers "%s"' % self.name,
field=key))
def _validate_condition(self):
for key in self.get_condition():
if key not in CONDITION_KEYNAMES:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
UnknownFieldError(what='Triggers "%s"' % self.name,
field=key))
*/
\ No newline at end of file
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/UnsupportedType.java b/src/main/java/org/openecomp/sdc/toscaparser/api/UnsupportedType.java
index 2bd0197..73858c6 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/UnsupportedType.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/UnsupportedType.java
@@ -1,6 +1,7 @@
package org.openecomp.sdc.toscaparser.api;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
+
import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;
public class UnsupportedType {
@@ -27,8 +28,8 @@
public static boolean validateType(String entityType) {
for(String ust: unsupportedTypes) {
if(ust.equals(entityType)) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "UnsupportedTypeError: Entity type \"%s\" is not supported",entityType));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE251", String.format(
+ "UnsupportedTypeError: Entity type \"%s\" is not supported",entityType)));
return true;
}
}
@@ -38,7 +39,7 @@
/*python
-from toscaparser.common.exception import ExceptionCollector
+from toscaparser.common.exception import ValidationIssueCollector
from toscaparser.common.exception import UnsupportedTypeError
from toscaparser.utils.gettextutils import _
@@ -69,7 +70,7 @@
@staticmethod
def validate_type(entitytype):
if entitytype in UnsupportedType.un_supported_types:
- ExceptionCollector.appendException(UnsupportedTypeError(
+ ValidationIssueCollector.appendException(UnsupportedTypeError(
what=_('%s')
% entitytype))
return True
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/common/ExceptionCollector.java b/src/main/java/org/openecomp/sdc/toscaparser/api/common/ExceptionCollector.java
deleted file mode 100644
index fa65ae4..0000000
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/common/ExceptionCollector.java
+++ /dev/null
@@ -1,122 +0,0 @@
-package org.openecomp.sdc.toscaparser.api.common;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-// Perfectly good enough...
-
-public class ExceptionCollector {
-
- private static Logger log = LoggerFactory.getLogger(ExceptionCollector.class.getName());
-
- private Map<String, String> notAnalyzedExceptions = new HashMap<>();
- private Map<String, String> criticalExceptions = new HashMap<>();
- private Map<String, String> warningExceptions = new HashMap<>();
-
- private boolean bWantTrace = true;
- private String filePath;
-
- public enum ReportType {WARNING, CRITICAL, NOT_ANALYZED}
-
- public ExceptionCollector(String filePath) {
- this.filePath = filePath;
- }
-
- public void appendException(String exception) {
-
- addException(exception, ReportType.NOT_ANALYZED);
- }
-
- public void appendCriticalException(String exception) {
-
- addException(exception, ReportType.CRITICAL);
- }
-
- public void appendWarning(String exception) {
-
- addException(exception, ReportType.WARNING);
- }
-
- private void addException(String exception, ReportType type) {
-
- Map<String, String> exceptions = getExceptionCollection(type);
-
- if (!exceptions.containsKey(exception)) {
- // get stack trace
- StackTraceElement[] ste = Thread.currentThread().getStackTrace();
- StringBuilder sb = new StringBuilder();
- // skip the last 2 (getStackTrace and this)
- for (int i = 2; i < ste.length; i++) {
- sb.append(String.format(" %s(%s:%d)%s", ste[i].getClassName(), ste[i].getFileName(),
- ste[i].getLineNumber(), i == ste.length - 1 ? " " : "\n"));
- }
- exceptions.put(exception, sb.toString());
- }
- }
-
- public List<String> getCriticalsReport() {
-
- return getReport(ReportType.CRITICAL);
- }
-
- public List<String> getNotAnalyzedExceptionsReport() {
-
- return getReport(ReportType.NOT_ANALYZED);
- }
-
- public List<String> getWarningsReport() {
-
- return getReport(ReportType.WARNING);
- }
-
- private List<String> getReport(ReportType type) {
- Map<String, String> collectedExceptions = getExceptionCollection(type);
-
- List<String> report = new ArrayList<>();
- if (collectedExceptions.size() > 0) {
- for (Map.Entry<String, String> exception : collectedExceptions.entrySet()) {
- report.add(exception.getKey());
- if (bWantTrace) {
- report.add(exception.getValue());
- }
- }
- }
-
- return report;
- }
-
- private Map<String, String> getExceptionCollection(ReportType type) {
- switch (type) {
- case WARNING:
- return warningExceptions;
- case CRITICAL:
- return criticalExceptions;
- case NOT_ANALYZED:
- return notAnalyzedExceptions;
- default:
- return notAnalyzedExceptions;
- }
- }
-
- public int errorsNotAnalyzedCaught() {
- return notAnalyzedExceptions.size();
- }
-
- public int criticalsCaught() {
- return criticalExceptions.size();
- }
-
- public int warningsCaught() {
- return warningExceptions.size();
- }
-
- public void setWantTrace(boolean b) {
- bWantTrace = b;
- }
-
-}
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/common/JToscaException.java b/src/main/java/org/openecomp/sdc/toscaparser/api/common/JToscaException.java
index 6cd5872..f97e6ad 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/common/JToscaException.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/common/JToscaException.java
@@ -18,10 +18,10 @@
this.code = code;
}
- //JT1001 - Meta file missing
- //JT1002 - Invalid yaml content
- //JT1003 - Entry-Definition not defined in meta file
- //JT1004 - Entry-Definition file missing
- //JT1005 - General Error
- //JT1006 - General Error/Path not valid
+ //JE1001 - Meta file missing
+ //JE1002 - Invalid yaml content
+ //JE1003 - Entry-Definition not defined in meta file
+ //JE1004 - Entry-Definition file missing
+ //JE1005 - General Error
+ //JE1006 - General Error/Path not valid
}
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/common/JToscaValidationIssue.java b/src/main/java/org/openecomp/sdc/toscaparser/api/common/JToscaValidationIssue.java
new file mode 100644
index 0000000..5caba26
--- /dev/null
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/common/JToscaValidationIssue.java
@@ -0,0 +1,35 @@
+package org.openecomp.sdc.toscaparser.api.common;
+
+public class JToscaValidationIssue {
+
+ private String code;
+ private String message;
+
+
+ public JToscaValidationIssue(String code, String message) {
+ super();
+ this.code = code;
+ this.message = message;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ public String getCode() {
+ return code;
+ }
+
+ public void setCode(String code) {
+ this.code = code;
+ }
+
+ @Override
+ public String toString() {
+ return "JToscaError [code=" + code + ", message=" + message + "]";
+ }
+}
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/common/ValidationIssueCollector.java b/src/main/java/org/openecomp/sdc/toscaparser/api/common/ValidationIssueCollector.java
new file mode 100644
index 0000000..6e2961a
--- /dev/null
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/common/ValidationIssueCollector.java
@@ -0,0 +1,35 @@
+package org.openecomp.sdc.toscaparser.api.common;
+
+import java.util.*;
+
+// Perfectly good enough...
+
+public class ValidationIssueCollector {
+
+ private Map<String,JToscaValidationIssue> validationIssues = new HashMap<String,JToscaValidationIssue>();
+ public void appendValidationIssue(JToscaValidationIssue issue) {
+
+ validationIssues.put(issue.getMessage(),issue);
+
+ }
+
+ public List<String> getValidationIssueReport() {
+ List<String> report = new ArrayList<>();
+ if (!validationIssues.isEmpty()) {
+ for (JToscaValidationIssue exception : validationIssues.values()) {
+ report.add("["+exception.getCode()+"]: "+ exception.getMessage());
+ }
+ }
+
+ return report;
+ }
+ public Map<String,JToscaValidationIssue> getValidationIssues() {
+ return validationIssues;
+ }
+
+
+ public int validationIssuesCaught() {
+ return validationIssues.size();
+ }
+
+}
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/EntityType.java b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/EntityType.java
index 650166d..70f7ae7 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/EntityType.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/EntityType.java
@@ -203,7 +203,7 @@
// doesn't do anything except emit an exception anyway
//if not hasattr(self, 'defs'):
// defs = None
- // ExceptionCollector.appendException(
+ // ValidationIssueCollector.appendException(
// ValidationError(message="defs is " + str(defs)))
//else:
// defs = self.defs
@@ -266,7 +266,7 @@
/*python
-from toscaparser.common.exception import ExceptionCollector
+from toscaparser.common.exception import ValidationIssueCollector
from toscaparser.common.exception import ValidationError
from toscaparser.extensions.exttools import ExtTools
import org.openecomp.sdc.toscaparser.api.utils.yamlparser
@@ -384,7 +384,7 @@
value = None
if not hasattr(self, 'defs'):
defs = None
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValidationError(message="defs is " + str(defs)))
else:
defs = self.defs
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/GroupType.java b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/GroupType.java
index d226b78..0f6ae6d 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/GroupType.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/GroupType.java
@@ -1,8 +1,9 @@
package org.openecomp.sdc.toscaparser.api.elements;
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
+
import java.util.LinkedHashMap;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;
public class GroupType extends StatefulEntityType {
@@ -92,9 +93,9 @@
}
}
if(!bFound) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE120", String.format(
"UnknownFieldError: Group Type \"%s\" contains unknown field \"%s\"",
- groupType,name));
+ groupType,name)));
}
}
}
@@ -104,18 +105,18 @@
private void _validateMetadata(LinkedHashMap<String,Object> metadata) {
String mtt = (String) metadata.get("type");
if(mtt != null && !mtt.equals("map") && !mtt.equals("tosca:map")) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE121", String.format(
"InvalidTypeError: \"%s\" defined in group for metadata is invalid",
- mtt));
+ mtt)));
}
for(String entrySchema: metadata.keySet()) {
Object estob = metadata.get(entrySchema);
if(estob instanceof LinkedHashMap) {
String est = (String)((LinkedHashMap<String,Object>)estob).get("type");
if(!est.equals("string")) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE122", String.format(
"InvalidTypeError: \"%s\" defined in group for metadata \"%s\" is invalid",
- est,entrySchema));
+ est,entrySchema)));
}
}
}
@@ -130,7 +131,7 @@
/*python
-from toscaparser.common.exception import ExceptionCollector
+from toscaparser.common.exception import ValidationIssueCollector
from toscaparser.common.exception import InvalidTypeError
from toscaparser.common.exception import UnknownFieldError
from toscaparser.elements.statefulentitytype import StatefulEntityType
@@ -195,19 +196,19 @@
if self.defs:
for name in self.defs.keys():
if name not in self.SECTIONS:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
UnknownFieldError(what='Group Type %s'
% self.grouptype, field=name))
def _validate_metadata(self, meta_data):
if not meta_data.get('type') in ['map', 'tosca:map']:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
InvalidTypeError(what='"%s" defined in group for '
'metadata' % (meta_data.get('type'))))
for entry_schema, entry_schema_type in meta_data.items():
if isinstance(entry_schema_type, dict) and not \
entry_schema_type.get('type') == 'string':
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
InvalidTypeError(what='"%s" defined in group for '
'metadata "%s"'
% (entry_schema_type.get('type'),
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/InterfacesDef.java b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/InterfacesDef.java
index 8a2b4dd..c13fd96 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/InterfacesDef.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/InterfacesDef.java
@@ -1,11 +1,12 @@
package org.openecomp.sdc.toscaparser.api.elements;
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
+
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map;
import org.openecomp.sdc.toscaparser.api.EntityTemplate;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;
public class InterfacesDef extends StatefulEntityType {
@@ -91,9 +92,9 @@
inputs = (LinkedHashMap<String,Object>)me.getValue();
}
else {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE123", String.format(
"UnknownFieldError: \"interfaces\" of template \"%s\" contain unknown field \"%s\"",
- nodeTemplate.getName(),me.getKey()));
+ nodeTemplate.getName(),me.getKey())));
}
}
}
@@ -150,7 +151,7 @@
# License for the specific language governing permissions and limitations
# under the License.
-from toscaparser.common.exception import ExceptionCollector
+from toscaparser.common.exception import ValidationIssueCollector
from toscaparser.common.exception import UnknownFieldError
from toscaparser.elements.statefulentitytype import StatefulEntityType
@@ -203,7 +204,7 @@
else:
what = ('"interfaces" of template "%s"' %
self.node_template.name)
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
UnknownFieldError(what=what, field=i))
else:
self.implementation = value
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/NodeType.java b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/NodeType.java
index d5f1a18..157e016 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/NodeType.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/NodeType.java
@@ -1,11 +1,11 @@
package org.openecomp.sdc.toscaparser.api.elements;
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
+
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
-import org.openecomp.sdc.toscaparser.api.elements.InterfacesDef;
import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;
public class NodeType extends StatefulEntityType {
@@ -315,8 +315,8 @@
}
}
if(!bFound) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "UnknownFieldError: Nodetype \"%s\" has unknown field \"%s\"",ntype,key));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE124", String.format(
+ "UnknownFieldError: Nodetype \"%s\" has unknown field \"%s\"",ntype,key)));
}
}
}
@@ -326,7 +326,7 @@
/*python
-from toscaparser.common.exception import ExceptionCollector
+from toscaparser.common.exception import ValidationIssueCollector
from toscaparser.common.exception import UnknownFieldError
from toscaparser.elements.capabilitytype import CapabilityTypeDef
import org.openecomp.sdc.toscaparser.api.elements.interfaces as ifaces
@@ -517,7 +517,7 @@
if self.defs:
for key in self.defs.keys():
if key not in self.SECTIONS:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
UnknownFieldError(what='Nodetype"%s"' % self.ntype,
field=key))
*/
\ No newline at end of file
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/PolicyType.java b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/PolicyType.java
index c60bed1..b046a48 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/PolicyType.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/PolicyType.java
@@ -1,9 +1,10 @@
package org.openecomp.sdc.toscaparser.api.elements;
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
+
import java.util.ArrayList;
import java.util.LinkedHashMap;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
import org.openecomp.sdc.toscaparser.api.utils.TOSCAVersionProperty;
import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;
@@ -135,9 +136,9 @@
}
}
if(!bFound) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE125", String.format(
"UnknownFieldError: Policy \"%s\" contains unknown field \"%s\"",
- type,key));
+ type,key)));
}
}
}
@@ -146,9 +147,9 @@
LinkedHashMap<String,Object> _customDef) {
for(String nodetype: _targetsList) {
if(_customDef.get(nodetype) == null) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE126", String.format(
"InvalidTypeError: \"%s\" defined in targets for policy \"%s\"",
- nodetype,type));
+ nodetype,type)));
}
}
@@ -157,9 +158,9 @@
private void _validateMetadata(LinkedHashMap<String,Object> _metaData) {
String mtype = (String)_metaData.get("type");
if(mtype != null && !mtype.equals("map") && !mtype.equals("tosca:map")) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE127", String.format(
"InvalidTypeError: \"%s\" defined in policy for metadata",
- mtype));
+ mtype)));
}
for(String entrySchema: metaData.keySet()) {
Object estob = metaData.get(entrySchema);
@@ -167,9 +168,9 @@
String est = (String)
((LinkedHashMap<String,Object>)estob).get("type");
if(!est.equals("string")) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE128", String.format(
"InvalidTypeError: \"%s\" defined in policy for metadata \"%s\"",
- est,entrySchema));
+ est,entrySchema)));
}
}
}
@@ -179,7 +180,7 @@
/*python
-from toscaparser.common.exception import ExceptionCollector
+from toscaparser.common.exception import ValidationIssueCollector
from toscaparser.common.exception import InvalidTypeError
from toscaparser.common.exception import UnknownFieldError
from toscaparser.elements.statefulentitytype import StatefulEntityType
@@ -262,27 +263,27 @@
def _validate_keys(self):
for key in self.defs.keys():
if key not in self.SECTIONS:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
UnknownFieldError(what='Policy "%s"' % self.type,
field=key))
def _validate_targets(self, targets_list, custom_def):
for nodetype in targets_list:
if nodetype not in custom_def:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
InvalidTypeError(what='"%s" defined in targets for '
'policy "%s"' % (nodetype, self.type)))
def _validate_metadata(self, meta_data):
if not meta_data.get('type') in ['map', 'tosca:map']:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
InvalidTypeError(what='"%s" defined in policy for '
'metadata' % (meta_data.get('type'))))
for entry_schema, entry_schema_type in meta_data.items():
if isinstance(entry_schema_type, dict) and not \
entry_schema_type.get('type') == 'string':
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
InvalidTypeError(what='"%s" defined in policy for '
'metadata "%s"'
% (entry_schema_type.get('type'),
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/PortSpec.java b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/PortSpec.java
index 8d490ee..1a6745c 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/PortSpec.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/PortSpec.java
@@ -1,9 +1,10 @@
package org.openecomp.sdc.toscaparser.api.elements;
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
+
import java.util.LinkedHashMap;
import org.openecomp.sdc.toscaparser.api.DataEntity;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;
import org.openecomp.sdc.toscaparser.api.utils.ValidateUtils;
@@ -53,9 +54,9 @@
// verify one of the specified values is set
if(source == null && sourceRange == null &&
target == null && targetRange == null) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE129", String.format(
"InvalidTypeAdditionalRequirementsError: Additional requirements for type \"%s\" not met",
- TYPE_URI));
+ TYPE_URI)));
}
// Validate source value is in specified range
if(source != null && sourceRange != null) {
@@ -75,9 +76,9 @@
}
}
catch(Exception e) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE130", String.format(
"ValueError: \"%s\" do not meet requirements for type \"%s\"",
- _properties.toString(),SHORTNAME));
+ _properties.toString(),SHORTNAME)));
}
}
@@ -85,7 +86,7 @@
/*python
-from toscaparser.common.exception import ExceptionCollector
+from toscaparser.common.exception import ValidationIssueCollector
from toscaparser.common.exception import InvalidTypeAdditionalRequirementsError
from toscaparser.utils.gettextutils import _
import org.openecomp.sdc.toscaparser.api.utils.validateutils as validateutils
@@ -132,7 +133,7 @@
# verify one of the specified values is set
if source is None and source_range is None and \
target is None and target_range is None:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
InvalidTypeAdditionalRequirementsError(
type=PortSpec.TYPE_URI))
# Validate source value is in specified range
@@ -155,6 +156,6 @@
msg = _('"%(value)s" do not meet requirements '
'for type "%(type)s".') \
% {'value': properties, 'type': PortSpec.SHORTNAME}
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValueError(msg))
*/
\ No newline at end of file
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/PropertyDef.java b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/PropertyDef.java
index c139eb6..bdd376b 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/PropertyDef.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/PropertyDef.java
@@ -3,7 +3,7 @@
import java.util.LinkedHashMap;
import java.util.Map;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;
public class PropertyDef {
@@ -46,8 +46,8 @@
if(schema.get("type") == null) {
//msg = (_('Schema definition of "%(pname)s" must have a "type" '
// 'attribute.') % dict(pname=self.name))
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "InvalidSchemaError: Schema definition of \"%s\" must have a \"type\" attribute",name));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE131", String.format(
+ "InvalidSchemaError: Schema definition of \"%s\" must have a \"type\" attribute",name)));
}
_loadRequiredAttrFromSchema();
_loadStatusAttrFromSchema();
@@ -84,9 +84,9 @@
// attr,
// value,
// valid_values)
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE132", String.format(
"Schema definition of \"%s\" has \"required\" attribute with an invalid value",
- name));
+ name)));
}
}
}
@@ -117,9 +117,9 @@
// attr,
// value,
// valid_values)
- ThreadLocalsHolder.getCollector().appendWarning(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE006", String.format(
"Schema definition of \"%s\" has \"status\" attribute with an invalid value",
- name));
+ name)));
}
}
}
@@ -140,7 +140,7 @@
}
/*python
-from toscaparser.common.exception import ExceptionCollector
+from toscaparser.common.exception import ValidationIssueCollector
from toscaparser.common.exception import InvalidSchemaError
from toscaparser.common.exception import TOSCAException
from toscaparser.utils.gettextutils import _
@@ -176,7 +176,7 @@
except KeyError:
msg = (_('Schema definition of "%(pname)s" must have a "type" '
'attribute.') % dict(pname=self.name))
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
InvalidSchemaError(message=msg))
if self.schema:
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/RelationshipType.java b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/RelationshipType.java
index 3903941..3a56840 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/RelationshipType.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/RelationshipType.java
@@ -1,10 +1,9 @@
package org.openecomp.sdc.toscaparser.api.elements;
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
+
import java.util.LinkedHashMap;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
-import org.openecomp.sdc.toscaparser.api.elements.EntityType;
-import org.openecomp.sdc.toscaparser.api.elements.StatefulEntityType;
import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;
public class RelationshipType extends StatefulEntityType {
@@ -54,8 +53,8 @@
}
}
if(!bFound) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "UnknownFieldError: Relationshiptype \"%s\" has unknown field \"%s\"",type,key));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE133", String.format(
+ "UnknownFieldError: Relationshiptype \"%s\" has unknown field \"%s\"",type,key)));
}
}
}
@@ -63,7 +62,7 @@
/*python
-from toscaparser.common.exception import ExceptionCollector
+from toscaparser.common.exception import ValidationIssueCollector
from toscaparser.common.exception import UnknownFieldError
from toscaparser.elements.statefulentitytype import StatefulEntityType
@@ -97,7 +96,7 @@
def _validate_keys(self):
for key in self.defs.keys():
if key not in self.SECTIONS:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
UnknownFieldError(what='Relationshiptype "%s"' % self.type,
field=key))
*/
\ No newline at end of file
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/ScalarUnit.java b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/ScalarUnit.java
index de18cd6..77cd4c2 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/ScalarUnit.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/ScalarUnit.java
@@ -4,7 +4,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;
import org.openecomp.sdc.toscaparser.api.utils.ValidateUtils;
import org.slf4j.Logger;
@@ -52,9 +52,9 @@
return key;
}
}
- ThreadLocalsHolder.getCollector().appendWarning(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE007", String.format(
"'The unit \"%s\" is not valid. Valid units are \n%s",
- inputUnit,SCALAR_UNIT_DICT.keySet().toString()));
+ inputUnit,SCALAR_UNIT_DICT.keySet().toString())));
return inputUnit;
}
}
@@ -68,8 +68,8 @@
value = matcher.group(1) + " " + scalarUnit;
}
else {
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "ValueError: \"%s\" is not a valid scalar-unit",value.toString()));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE134", String.format(
+ "ValueError: \"%s\" is not a valid scalar-unit",value.toString())));
}
return value;
}
@@ -136,8 +136,8 @@
if(type.equals(SCALAR_UNIT_FREQUENCY)) {
return (new ScalarUnitFrequency(value)).getNumFromScalarUnit(unit);
}
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "TypeError: \"%s\" is not a valid scalar-unit type",type));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE135", String.format(
+ "TypeError: \"%s\" is not a valid scalar-unit type",type)));
return 0.0;
}
@@ -145,7 +145,7 @@
/*python
-from toscaparser.common.exception import ExceptionCollector
+from toscaparser.common.exception import ValidationIssueCollector
from toscaparser.utils.gettextutils import _
from toscaparser.utils import validateutils
@@ -184,7 +184,7 @@
'"%(valid_units)s".') %
{'unit': input_unit,
'valid_units': sorted(self.SCALAR_UNIT_DICT.keys())})
- ExceptionCollector.appendException(ValueError(msg))
+ ValidationIssueCollector.appendException(ValueError(msg))
def validate_scalar_unit(self):
regex = re.compile('([0-9.]+)\s*(\w+)')
@@ -196,7 +196,7 @@
return self.value
except Exception:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValueError(_('"%s" is not a valid scalar-unit.')
% self.value))
@@ -257,6 +257,6 @@
return (ScalarUnit_Class(value).
get_num_from_scalar_unit(unit))
else:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
TypeError(_('"%s" is not a valid scalar-unit type.') % type))
*/
\ No newline at end of file
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/StatefulEntityType.java b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/StatefulEntityType.java
index 5ab816f..0a83cb1 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/StatefulEntityType.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/StatefulEntityType.java
@@ -1,14 +1,12 @@
package org.openecomp.sdc.toscaparser.api.elements;
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
+
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map;
import org.openecomp.sdc.toscaparser.api.UnsupportedType;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
-import org.openecomp.sdc.toscaparser.api.elements.AttributeDef;
-import org.openecomp.sdc.toscaparser.api.elements.EntityType;
-import org.openecomp.sdc.toscaparser.api.elements.PropertyDef;
import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;
@@ -49,8 +47,8 @@
}
else{
defs = null;
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "InvalidTypeError: \"%s\" is not a valid type",entityType));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE136", String.format(
+ "InvalidTypeError: \"%s\" is not a valid type",entityType)));
}
}
type = entityType;
@@ -67,8 +65,8 @@
Object to = me.getValue();
if(to == null || !(to instanceof LinkedHashMap)) {
String s = to == null ? "null" : to.getClass().getSimpleName();
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "Unexpected type error: property \"%s\" has type \"%s\" (expected dict)",pdname,s));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE137", String.format(
+ "Unexpected type error: property \"%s\" has type \"%s\" (expected dict)",pdname,s)));
continue;
}
LinkedHashMap<String,Object> pdschema = (LinkedHashMap<String,Object>)to;
@@ -175,7 +173,7 @@
self.defs = custom_def[entitytype]
else:
self.defs = None
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
InvalidTypeError(what=entitytype))
self.type = entitytype
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/TypeValidation.java b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/TypeValidation.java
index 2caf5c4..50c9739 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/TypeValidation.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/TypeValidation.java
@@ -1,9 +1,10 @@
package org.openecomp.sdc.toscaparser.api.elements;
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
+
import java.util.ArrayList;
import java.util.LinkedHashMap;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
import org.openecomp.sdc.toscaparser.api.extensions.ExtTools;
import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;
@@ -71,9 +72,9 @@
}
}
if(!bFound) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE138", String.format(
"UnknownFieldError: Template \"%s\" contains unknown field \"%s\"",
- importDef.toString(),name));
+ importDef.toString(),name)));
}
}
}
@@ -89,17 +90,17 @@
}
}
if(!bFound) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE139", String.format(
"InvalidTemplateVersion: version \"%s\" in \"%s\" is not supported\n" +
"Allowed versions: [%s]",
- sVersion,importDef.toString(),allowed));
+ sVersion,importDef.toString(),allowed)));
}
}
}
/*python
-from toscaparser.common.exception import ExceptionCollector
+from toscaparser.common.exception import ValidationIssueCollector
from toscaparser.common.exception import InvalidTemplateVersion
from toscaparser.common.exception import UnknownFieldError
from toscaparser.extensions.exttools import ExtTools
@@ -136,14 +137,14 @@
for name in custom_type:
if name not in self.ALLOWED_TYPE_SECTIONS:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
# UnknownFieldError(what='Template ' + (self.import_def),
UnknownFieldError(what= (self.import_def),
field=name))
def _validate_type_version(self, version):
if version not in self.VALID_TEMPLATE_VERSIONS:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
InvalidTemplateVersion(
# what=version + ' in ' + self.import_def,
what=self.import_def,
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/Constraint.java b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/Constraint.java
index 3c60a66..253cc0c 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/Constraint.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/Constraint.java
@@ -3,7 +3,7 @@
import java.util.ArrayList;
import java.util.LinkedHashMap;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
import org.openecomp.sdc.toscaparser.api.elements.ScalarUnit;
import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;
@@ -35,8 +35,8 @@
if(!(constraint instanceof LinkedHashMap) ||
((LinkedHashMap<String,Object>)constraint).size() != 1) {
- ThreadLocalsHolder.getCollector().appendException(
- "InvalidSchemaError: Invalid constraint schema " + constraint.toString());
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE101",
+ "InvalidSchemaError: Invalid constraint schema " + constraint.toString()));
}
if(constraintClass.equals(EQUAL)) {
@@ -73,8 +73,8 @@
return new Pattern(propname,proptype,constraint);
}
else {
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "InvalidSchemaError: Invalid property \"%s\"",constraintClass));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE102", String.format(
+ "InvalidSchemaError: Invalid property \"%s\"",constraintClass)));
return null;
}
}
@@ -117,9 +117,9 @@
}
}
if(!bFound) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE103", String.format(
"InvalidSchemaError: Property \"%s\" is not valid for data type \"%s\"",
- constraintKey,propertyType));
+ constraintKey,propertyType)));
}
}
@@ -153,7 +153,7 @@
value = ScalarUnit.getScalarunitValue(propertyType,value,null);
}
if(!_isValid(value)) {
- ThreadLocalsHolder.getCollector().appendWarning("ValidationError: " + _errMsg(value));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE008", "ValidationError: " + _errMsg(value)));
}
}
@@ -183,14 +183,14 @@
if(not isinstance(constraint, collections.Mapping) or
len(constraint) != 1):
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
InvalidSchemaError(message=_('Invalid constraint schema.')))
for type in constraint.keys():
ConstraintClass = get_constraint_class(type)
if not ConstraintClass:
msg = _('Invalid property "%s".') % type
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
InvalidSchemaError(message=msg))
return ConstraintClass(property_name, property_type, constraint)
@@ -208,7 +208,7 @@
'"%(dtype)s".') % dict(
ctype=self.constraint_key,
dtype=property_type)
- ExceptionCollector.appendException(InvalidSchemaError(message=msg))
+ ValidationIssueCollector.appendException(InvalidSchemaError(message=msg))
def _get_scalarunit_constraint_value(self):
if self.property_type in scalarunit.ScalarUnit.SCALAR_UNIT_TYPES:
@@ -230,7 +230,7 @@
value = scalarunit.get_scalarunit_value(self.property_type, value)
if not self._is_valid(value):
err_msg = self._err_msg(value)
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValidationError(message=err_msg))
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/GreaterOrEqual.java b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/GreaterOrEqual.java
index 021bed3..ad6183e 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/GreaterOrEqual.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/GreaterOrEqual.java
@@ -1,8 +1,9 @@
package org.openecomp.sdc.toscaparser.api.elements.constraints;
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
+
import java.util.Date;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
import org.openecomp.sdc.toscaparser.api.functions.Function;
import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;
@@ -38,7 +39,7 @@
super(name,type,c);
if(!validTypes.contains(constraintValue.getClass().getSimpleName())) {
- ThreadLocalsHolder.getCollector().appendException("InvalidSchemaError: The property \"greater_or_equal\" expects comparable values");
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE104", "InvalidSchemaError: The property \"greater_or_equal\" expects comparable values"));
}
}
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/GreaterThan.java b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/GreaterThan.java
index d23d7ce..b9e06b3 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/GreaterThan.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/GreaterThan.java
@@ -1,8 +1,9 @@
package org.openecomp.sdc.toscaparser.api.elements.constraints;
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
+
import java.util.Date;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;
public class GreaterThan extends Constraint {
@@ -35,7 +36,7 @@
super(name,type,c);
if(!validTypes.contains(constraintValue.getClass().getSimpleName())) {
- ThreadLocalsHolder.getCollector().appendException("InvalidSchemaError: The property \"greater_than\" expects comparable values");
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE105", "InvalidSchemaError: The property \"greater_than\" expects comparable values"));
}
}
@@ -83,7 +84,7 @@
super(GreaterThan, self).__init__(property_name, property_type,
constraint)
if not isinstance(constraint[self.GREATER_THAN], self.valid_types):
- ExceptionCollector.appendException(
+ ValidationIsshueCollector.appendException(
InvalidSchemaError(message=_('The property "greater_than" '
'expects comparable values.')))
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/InRange.java b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/InRange.java
index 282267d..7d0d654 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/InRange.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/InRange.java
@@ -1,8 +1,9 @@
package org.openecomp.sdc.toscaparser.api.elements.constraints;
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
+
import java.util.Date;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;
import java.util.ArrayList;
@@ -46,7 +47,7 @@
super(name,type,c);
if(!(constraintValue instanceof ArrayList) || ((ArrayList<Object>)constraintValue).size() != 2) {
- ThreadLocalsHolder.getCollector().appendException("InvalidSchemaError: The property \"in_range\" expects a list");
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE106", "InvalidSchemaError: The property \"in_range\" expects a list"));
}
@@ -54,11 +55,11 @@
String msg = "The property \"in_range\" expects comparable values";
for(Object vo: alcv) {
if(!validTypes.contains(vo.getClass().getSimpleName())) {
- ThreadLocalsHolder.getCollector().appendException("InvalidSchemaError: " + msg);
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE107", "InvalidSchemaError: " + msg));
}
// The only string we allow for range is the special value 'UNBOUNDED'
if((vo instanceof String) && !((String)vo).equals(UNBOUNDED)) {
- ThreadLocalsHolder.getCollector().appendException("InvalidSchemaError: " + msg);
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE108", "InvalidSchemaError: " + msg));
}
}
min = alcv.get(0);
@@ -129,19 +130,19 @@
super(InRange, self).__init__(property_name, property_type, constraint)
if(not isinstance(self.constraint_value, collections.Sequence) or
(len(constraint[self.IN_RANGE]) != 2)):
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
InvalidSchemaError(message=_('The property "in_range" '
'expects a list.')))
msg = _('The property "in_range" expects comparable values.')
for value in self.constraint_value:
if not isinstance(value, self.valid_types):
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
InvalidSchemaError(message=msg))
# The only string we allow for range is the special value
# 'UNBOUNDED'
if(isinstance(value, str) and value != self.UNBOUNDED):
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
InvalidSchemaError(message=msg))
self.min = self.constraint_value[0]
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/Length.java b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/Length.java
index 4cfd1c0..c94cda5 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/Length.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/Length.java
@@ -1,6 +1,7 @@
package org.openecomp.sdc.toscaparser.api.elements.constraints;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
+
import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;
public class Length extends Constraint {
@@ -23,7 +24,7 @@
super(name,type,c);
if(!validTypes.contains(constraintValue.getClass().getSimpleName())) {
- ThreadLocalsHolder.getCollector().appendException("InvalidSchemaError: The property \"length\" expects an integer");
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE109", "InvalidSchemaError: The property \"length\" expects an integer"));
}
}
@@ -60,7 +61,7 @@
def __init__(self, property_name, property_type, constraint):
super(Length, self).__init__(property_name, property_type, constraint)
if not isinstance(self.constraint_value, self.valid_types):
- ExceptionCollector.appendException(
+ ValidationIsshueCollector.appendException(
InvalidSchemaError(message=_('The property "length" expects '
'an integer.')))
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/LessOrEqual.java b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/LessOrEqual.java
index 00cba36..1601e27 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/LessOrEqual.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/LessOrEqual.java
@@ -1,8 +1,9 @@
package org.openecomp.sdc.toscaparser.api.elements.constraints;
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
+
import java.util.Date;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;
public class LessOrEqual extends Constraint {
@@ -37,7 +38,7 @@
super(name,type,c);
if(!validTypes.contains(constraintValue.getClass().getSimpleName())) {
- ThreadLocalsHolder.getCollector().appendException("InvalidSchemaError: The property \"less_or_equal\" expects comparable values");
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE110", "InvalidSchemaError: The property \"less_or_equal\" expects comparable values"));
}
}
@@ -87,7 +88,7 @@
super(LessOrEqual, self).__init__(property_name, property_type,
constraint)
if not isinstance(self.constraint_value, self.valid_types):
- ExceptionCollector.appendException(
+ ValidationIsshueCollector.appendException(
InvalidSchemaError(message=_('The property "less_or_equal" '
'expects comparable values.')))
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/LessThan.java b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/LessThan.java
index eb5a41d..b867fa7 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/LessThan.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/LessThan.java
@@ -1,8 +1,9 @@
package org.openecomp.sdc.toscaparser.api.elements.constraints;
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
+
import java.util.Date;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;
public class LessThan extends Constraint {
@@ -35,7 +36,7 @@
super(name,type,c);
if(!validTypes.contains(constraintValue.getClass().getSimpleName())) {
- ThreadLocalsHolder.getCollector().appendException("InvalidSchemaError: The property \"less_than\" expects comparable values");
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE111", "InvalidSchemaError: The property \"less_than\" expects comparable values"));
}
}
@@ -85,7 +86,7 @@
super(LessThan, self).__init__(property_name, property_type,
constraint)
if not isinstance(self.constraint_value, self.valid_types):
- ExceptionCollector.appendException(
+ ValidationIsshueCollector.appendException(
InvalidSchemaError(message=_('The property "less_than" '
'expects comparable values.')))
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/MaxLength.java b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/MaxLength.java
index 278ae85..48ac349 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/MaxLength.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/MaxLength.java
@@ -1,8 +1,9 @@
package org.openecomp.sdc.toscaparser.api.elements.constraints;
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
+
import java.util.LinkedHashMap;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;
public class MaxLength extends Constraint {
@@ -26,7 +27,7 @@
super(name,type,c);
if(!validTypes.contains(constraintValue.getClass().getSimpleName())) {
- ThreadLocalsHolder.getCollector().appendException("InvalidSchemaError: The property \"max_length\" expects an integer");
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE112", "InvalidSchemaError: The property \"max_length\" expects an integer"));
}
}
@@ -70,7 +71,7 @@
super(MaxLength, self).__init__(property_name, property_type,
constraint)
if not isinstance(self.constraint_value, self.valid_types):
- ExceptionCollector.appendException(
+ ValidationIsshueCollector.appendException(
InvalidSchemaError(message=_('The property "max_length" '
'expects an integer.')))
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/MinLength.java b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/MinLength.java
index 480c878..0203484 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/MinLength.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/MinLength.java
@@ -1,8 +1,9 @@
package org.openecomp.sdc.toscaparser.api.elements.constraints;
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
+
import java.util.LinkedHashMap;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;
public class MinLength extends Constraint {
@@ -26,7 +27,7 @@
super(name,type,c);
if(!validTypes.contains(constraintValue.getClass().getSimpleName())) {
- ThreadLocalsHolder.getCollector().appendException("InvalidSchemaError: The property \"min_length\" expects an integer");
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE113", "InvalidSchemaError: The property \"min_length\" expects an integer"));
}
}
@@ -70,7 +71,7 @@
super(MinLength, self).__init__(property_name, property_type,
constraint)
if not isinstance(self.constraint_value, self.valid_types):
- ExceptionCollector.appendException(
+ ValidationIsshueCollector.appendException(
InvalidSchemaError(message=_('The property "min_length" '
'expects an integer.')))
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/Pattern.java b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/Pattern.java
index 444a73c..a29bac6 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/Pattern.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/Pattern.java
@@ -1,9 +1,10 @@
package org.openecomp.sdc.toscaparser.api.elements.constraints;
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
+
import java.util.regex.Matcher;
import java.util.regex.PatternSyntaxException;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;
public class Pattern extends Constraint {
@@ -24,7 +25,7 @@
super(name,type,c);
if(!validTypes.contains(constraintValue.getClass().getSimpleName())) {
- ThreadLocalsHolder.getCollector().appendException("InvalidSchemaError: The property \"pattern\" expects a string");
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE114", "InvalidSchemaError: The property \"pattern\" expects a string"));
}
}
@@ -32,8 +33,8 @@
protected boolean _isValid(Object value) {
try {
if(!(value instanceof String)) {
- ThreadLocalsHolder.getCollector().appendException(String.format("ValueError: Input value \"%s\" to \"pattern\" property \"%s\" must be a string",
- value.toString(),propertyName));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE115", String.format("ValueError: Input value \"%s\" to \"pattern\" property \"%s\" must be a string",
+ value.toString(),propertyName)));
return false;
}
String strp = constraintValue.toString();
@@ -46,8 +47,8 @@
return false;
}
catch(PatternSyntaxException pse) {
- ThreadLocalsHolder.getCollector().appendException(String.format("ValueError: Invalid regex \"%s\" in \"pattern\" property \"%s\"",
- constraintValue.toString(),propertyName));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE116", String.format("ValueError: Invalid regex \"%s\" in \"pattern\" property \"%s\"",
+ constraintValue.toString(),propertyName)));
return false;
}
}
@@ -78,7 +79,7 @@
def __init__(self, property_name, property_type, constraint):
super(Pattern, self).__init__(property_name, property_type, constraint)
if not isinstance(self.constraint_value, self.valid_types):
- ExceptionCollector.appendException(
+ ValidationIsshueCollector.appendException(
InvalidSchemaError(message=_('The property "pattern" '
'expects a string.')))
self.match = re.compile(self.constraint_value).match
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/Schema.java b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/Schema.java
index ca721e6..d0ee118 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/Schema.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/Schema.java
@@ -1,11 +1,12 @@
package org.openecomp.sdc.toscaparser.api.elements.constraints;
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
+
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;
@@ -71,15 +72,15 @@
if(!(_schemaDict instanceof LinkedHashMap)) {
//msg = (_('Schema definition of "%(pname)s" must be a dict.')
// % dict(pname=name))
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "InvalidSchemaError: Schema definition of \"%s\" must be a dict",name));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE117", String.format(
+ "InvalidSchemaError: Schema definition of \"%s\" must be a dict",name)));
}
if(_schemaDict.get("type") == null) {
//msg = (_('Schema definition of "%(pname)s" must have a "type" '
// 'attribute.') % dict(pname=name))
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "InvalidSchemaError: Schema definition of \"%s\" must have a \"type\" attribute",name));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE118", String.format(
+ "InvalidSchemaError: Schema definition of \"%s\" must have a \"type\" attribute",name)));
}
schema = _schemaDict;
@@ -122,9 +123,9 @@
}
else {
// error
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE119", String.format(
"UnknownFieldError: Constraint type \"%s\" for property \"%s\" is not supported",
- cClass,name));
+ cClass,name)));
}
break;
}
@@ -211,14 +212,14 @@
if not isinstance(schema_dict, collections.Mapping):
msg = (_('Schema definition of "%(pname)s" must be a dict.')
% dict(pname=name))
- ExceptionCollector.appendException(InvalidSchemaError(message=msg))
+ ValidationIssueCollector.appendException(InvalidSchemaError(message=msg))
try:
schema_dict['type']
except KeyError:
msg = (_('Schema definition of "%(pname)s" must have a "type" '
'attribute.') % dict(pname=name))
- ExceptionCollector.appendException(InvalidSchemaError(message=msg))
+ ValidationIssueCollector.appendException(InvalidSchemaError(message=msg))
self.schema = schema_dict
self._len = None
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/Schema.java.orig b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/Schema.java.orig
index 96eff34..355f505 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/Schema.java.orig
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/Schema.java.orig
@@ -5,7 +5,7 @@
import java.util.LinkedHashMap;
import java.util.Map;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
+import org.openecomp.sdc.toscaparser.api.common.ValidationIssueCollector;
public class Schema {
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/ValidValues.java b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/ValidValues.java
index 06622e4..60b6be2 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/ValidValues.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/ValidValues.java
@@ -62,7 +62,7 @@
super(ValidValues, self).__init__(property_name, property_type,
constraint)
if not isinstance(self.constraint_value, collections.Sequence):
- ExceptionCollector.appendException(
+ ValidationIsshueCollector.appendException(
InvalidSchemaError(message=_('The property "valid_values" '
'expects a list.')))
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/functions/Concat.java b/src/main/java/org/openecomp/sdc/toscaparser/api/functions/Concat.java
index 6dc7deb..84afbc9 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/functions/Concat.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/functions/Concat.java
@@ -1,9 +1,10 @@
package org.openecomp.sdc.toscaparser.api.functions;
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
+
import java.util.ArrayList;
import org.openecomp.sdc.toscaparser.api.TopologyTemplate;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;
public class Concat extends Function {
@@ -37,9 +38,9 @@
@Override
void validate() {
if(args.size() < 1) {
- ThreadLocalsHolder.getCollector().appendException(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE145",
"ValueError: Invalid arguments for function \"concat\". " +
- "Expected at least one argument");
+ "Expected at least one argument"));
}
}
@@ -68,7 +69,7 @@
def validate(self):
if len(self.args) < 1:
- ExceptionCollector.appendException(
+ ValidationIsshueCollector.appendException(
ValueError(_('Invalid arguments for function "{0}". Expected '
'at least one arguments.').format(CONCAT)))
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/functions/Function.java b/src/main/java/org/openecomp/sdc/toscaparser/api/functions/Function.java
index 7615a00..0278508 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/functions/Function.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/functions/Function.java
@@ -171,7 +171,7 @@
/*python
-from toscaparser.common.exception import ExceptionCollector
+from toscaparser.common.exception import ValidationIsshueCollector
from toscaparser.common.exception import UnknownInputError
from toscaparser.dataentity import DataEntity
from toscaparser.elements.constraints import Schema
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetAttribute.java b/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetAttribute.java
index 8a3d0b6..66e9320 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetAttribute.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetAttribute.java
@@ -1,5 +1,7 @@
package org.openecomp.sdc.toscaparser.api.functions;
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
+
import java.util.ArrayList;
import java.util.LinkedHashMap;
@@ -45,8 +47,8 @@
@Override
void validate() {
if(args.size() < 2) {
- ThreadLocalsHolder.getCollector().appendException(
- "ValueError: Illegal arguments for function \"get_attribute\". Expected arguments: \"node-template-name\", \"req-or-cap\" (optional), \"property name.\"");
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE146",
+ "ValueError: Illegal arguments for function \"get_attribute\". Expected arguments: \"node-template-name\", \"req-or-cap\" (optional), \"property name.\""));
return;
}
else if(args.size() == 2) {
@@ -76,9 +78,9 @@
for(Object elem: args.subList(index,args.size())) {
if(valueType.equals("list")) {
if(!(elem instanceof Integer)) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE147", String.format(
"ValueError: Illegal arguments for function \"get_attribute\" \"%s\". Expected positive integer argument",
- elem.toString()));
+ elem.toString())));
}
Object ob = attr.getSchema().get("entry_schema");
valueType = (String)
@@ -98,9 +100,9 @@
}
}
if(bFound) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "ValueError: 'Illegal arguments for function \"get_attribute\". Unexpected attribute/index value \"%d\"",
- elem));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE148", String.format(
+ "ValueError: 'Illegal arguments for function \"get_attribute\". Unexpected attribute/index value \"%s\"",
+ elem)));
return;
}
else { // It is a complex type
@@ -112,9 +114,9 @@
valueType = (String)prop.getSchema().get("type");
}
else {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE149", String.format(
"KeyError: Illegal arguments for function \"get_attribute\". Attribute name \"%s\" not found in \"%\"",
- elem,valueType));
+ elem,valueType)));
}
}
}
@@ -146,9 +148,9 @@
if(nodeTpl != null &&
!_attributeExistsInType(nodeTpl.getTypeDefinition()) &&
!nodeTpl.getProperties().keySet().contains(getAttributeName())) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE150", String.format(
"KeyError: Attribute \"%s\" was not found in node template \"%s\"",
- getAttributeName(),nodeTpl.getName()));
+ getAttributeName(),nodeTpl.getName())));
}
return nodeTpl;
}
@@ -187,34 +189,34 @@
// Currently this is the only way to tell whether the function
// is used within the outputs section of the TOSCA template.
if(context instanceof ArrayList) {
- ThreadLocalsHolder.getCollector().appendException(
- "ValueError: \"get_attribute: [ HOST, ... ]\" is not allowed in \"outputs\" section of the TOSCA template");
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE151",
+ "ValueError: \"get_attribute: [ HOST, ... ]\" is not allowed in \"outputs\" section of the TOSCA template"));
return null;
}
NodeTemplate nodeTpl = _findHostContainingAttribute(SELF);
if(nodeTpl == null) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE152", String.format(
"ValueError: \"get_attribute: [ HOST, ... ]\" was used in " +
"node template \"%s\" but \"%s\" was not found in " +
- "the relationship chain",((NodeTemplate)context).getName(),HOSTED_ON));
+ "the relationship chain",((NodeTemplate)context).getName(),HOSTED_ON)));
return null;
}
return nodeTpl;
}
if(nodeTemplateName.equals(TARGET)) {
if(!(((EntityTemplate)context).getTypeDefinition() instanceof RelationshipType)) {
- ThreadLocalsHolder.getCollector().appendException(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE153",
"KeyError: \"TARGET\" keyword can only be used in context " +
- " to \"Relationships\" target node");
+ " to \"Relationships\" target node"));
return null;
}
return ((RelationshipTemplate)context).getTarget();
}
if(nodeTemplateName.equals(SOURCE)) {
if(!(((EntityTemplate)context).getTypeDefinition() instanceof RelationshipType)) {
- ThreadLocalsHolder.getCollector().appendException(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE154",
"KeyError: \"SOURCE\" keyword can only be used in context " +
- " to \"Relationships\" source node");
+ " to \"Relationships\" source node"));
return null;
}
return ((RelationshipTemplate)context).getTarget();
@@ -231,8 +233,8 @@
return nt;
}
}
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "KeyError: Node template \"%s\" was not found",nodeTemplateName));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE155", String.format(
+ "KeyError: Node template \"%s\" was not found",nodeTemplateName)));
return null;
}
@@ -265,16 +267,16 @@
attribute = attrs.get(attrName);
}
if(attribute == null) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE156", String.format(
"KeyError: Attribute \"%s\" was not found in capability \"%s\" of node template \"%s\" referenced from node template \"%s\"",
- attrName,capabilityName,nodeTemplate.getName(),((NodeTemplate)context).getName()));
+ attrName,capabilityName,nodeTemplate.getName(),((NodeTemplate)context).getName())));
}
return attribute;
}
String msg = String.format(
"Requirement/CapabilityAssignment \"%s\" referenced from node template \"%s\" was not found in node template \"%s\"",
capabilityName,((NodeTemplate)context).getName(),nodeTemplate.getName());
- ThreadLocalsHolder.getCollector().appendException("KeyError: " + msg);
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE157", "KeyError: " + msg));
return null;
}
@@ -316,7 +318,7 @@
def validate(self):
if len(self.args) < 2:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValueError(_('Illegal arguments for function "{0}". Expected '
'arguments: "node-template-name", "req-or-cap"'
'(optional), "property name"'
@@ -344,7 +346,7 @@
for elem in self.args[index:]:
if value_type == "list":
if not isinstance(elem, int):
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValueError(_('Illegal arguments for function'
' "{0}". "{1}" Expected positive'
' integer argument'
@@ -353,7 +355,7 @@
elif value_type == "map":
value_type = attr.schema['entry_schema']['type']
elif value_type in Schema.PROPERTY_TYPES:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValueError(_('Illegal arguments for function'
' "{0}". Unexpected attribute/'
'index value "{1}"'
@@ -367,7 +369,7 @@
prop = found[0]
value_type = prop.schema['type']
else:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
KeyError(_('Illegal arguments for function'
' "{0}". Attribute name "{1}" not'
' found in "{2}"'
@@ -394,7 +396,7 @@
if node_tpl and \
not self._attribute_exists_in_type(node_tpl.type_definition) \
and self.attribute_name not in node_tpl.get_properties():
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
KeyError(_('Attribute "%(att)s" was not found in node '
'template "%(ntpl)s".') %
{'att': self.attribute_name,
@@ -428,14 +430,14 @@
# Currently this is the only way to tell whether the function
# is used within the outputs section of the TOSCA template.
if isinstance(self.context, list):
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValueError(_(
'"get_attribute: [ HOST, ... ]" is not allowed in '
'"outputs" section of the TOSCA template.')))
return
node_tpl = self._find_host_containing_attribute()
if not node_tpl:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValueError(_(
'"get_attribute: [ HOST, ... ]" was used in node '
'template "{0}" but "{1}" was not found in '
@@ -445,14 +447,14 @@
return node_tpl
if node_template_name == TARGET:
if not isinstance(self.context.type_definition, RelationshipType):
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
KeyError(_('"TARGET" keyword can only be used in context'
' to "Relationships" target node')))
return
return self.context.target
if node_template_name == SOURCE:
if not isinstance(self.context.type_definition, RelationshipType):
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
KeyError(_('"SOURCE" keyword can only be used in context'
' to "Relationships" source node')))
return
@@ -464,7 +466,7 @@
for node_template in self.tosca_tpl.nodetemplates:
if node_template.name == name:
return node_template
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
KeyError(_(
'Node template "{0}" was not found.'
).format(node_template_name)))
@@ -498,7 +500,7 @@
if attrs and attr_name in attrs.keys():
attribute = attrs[attr_name]
if not attribute:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
KeyError(_('Attribute "%(attr)s" was not found in '
'capability "%(cap)s" of node template '
'"%(ntpl1)s" referenced from node template '
@@ -512,7 +514,7 @@
capability_name,
self.context.name,
node_template.name)
- ExceptionCollector.appendException(KeyError(msg))
+ ValidationIssueCollector.appendException(KeyError(msg))
@property
def node_template_name(self):
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetInput.java b/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetInput.java
index dd6c05c..67cecd7 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetInput.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetInput.java
@@ -5,7 +5,7 @@
import org.openecomp.sdc.toscaparser.api.DataEntity;
import org.openecomp.sdc.toscaparser.api.TopologyTemplate;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
import org.openecomp.sdc.toscaparser.api.parameters.Input;
import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;
@@ -25,9 +25,9 @@
// args.toString()));
// }
if(args.size() > 2) {
- ThreadLocalsHolder.getCollector().appendWarning(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE009", String.format(
"ValueError: Expected max 2 arguments for function \"get_input\" but received \"%s\"",
- args.size()));
+ args.size())));
}
boolean bFound = false;
for(Input inp: toscaTpl.getInputs()) {
@@ -37,8 +37,8 @@
}
}
if(!bFound) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "UnknownInputError: Unknown input \"%s\"",args.get(0)));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE158", String.format(
+ "UnknownInputError: Unknown input \"%s\"",args.get(0))));
}
}
@@ -99,13 +99,13 @@
def validate(self):
if len(self.args) != 1:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValueError(_(
'Expected one argument for function "get_input" but '
'received "%s".') % self.args))
inputs = [input.name for input in self.tosca_tpl.inputs]
if self.args[0] not in inputs:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
UnknownInputError(input_name=self.args[0]))
def result(self):
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetOperationOutput.java b/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetOperationOutput.java
index 22f2cd7..7af7eeb 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetOperationOutput.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetOperationOutput.java
@@ -1,9 +1,10 @@
package org.openecomp.sdc.toscaparser.api.functions;
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
+
import java.util.ArrayList;
import org.openecomp.sdc.toscaparser.api.*;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
import org.openecomp.sdc.toscaparser.api.elements.InterfacesDef;
import org.openecomp.sdc.toscaparser.api.elements.RelationshipType;
import org.openecomp.sdc.toscaparser.api.elements.StatefulEntityType;
@@ -23,10 +24,10 @@
_findOperationName(interfaceName,(String)args.get(2));
}
else {
- ThreadLocalsHolder.getCollector().appendException(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE159",
"ValueError: Illegal arguments for function \"get_operation_output\". " +
"Expected arguments: \"template_name\",\"interface_name\"," +
- "\"operation_name\",\"output_variable_name\"");
+ "\"operation_name\",\"output_variable_name\""));
}
}
@@ -42,9 +43,9 @@
return _interfaceName;
}
else {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE160", String.format(
"ValueError: invalid interface name \"%s\" in \"get_operation_output\"",
- _interfaceName));
+ _interfaceName)));
return null;
}
}
@@ -64,9 +65,9 @@
return operationName;
}
else {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE161", String.format(
"ValueError: Invalid operation of Configure interface \"%s\" in \"get_operation_output\"",
- operationName));
+ operationName)));
return null;
}
}
@@ -83,16 +84,16 @@
return operationName;
}
else {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE162", String.format(
"ValueError: Invalid operation of Configure interface \"%s\" in \"get_operation_output\"",
- operationName));
+ operationName)));
return null;
}
}
else {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE163", String.format(
"ValueError: Invalid interface name \"%s\" in \"get_operation_output\"",
- interfaceName));
+ interfaceName)));
return null;
}
}
@@ -100,18 +101,18 @@
private NodeTemplate _findNodeTemplate(String nodeTemplateName) {
if(nodeTemplateName.equals(TARGET)) {
if(!(((EntityTemplate)context).getTypeDefinition() instanceof RelationshipType)) {
- ThreadLocalsHolder.getCollector().appendException(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE164",
"KeyError: \"TARGET\" keyword can only be used in context " +
- " to \"Relationships\" target node");
+ " to \"Relationships\" target node"));
return null;
}
return ((RelationshipTemplate)context).getTarget();
}
if(nodeTemplateName.equals(SOURCE)) {
if(!(((EntityTemplate)context).getTypeDefinition() instanceof RelationshipType)) {
- ThreadLocalsHolder.getCollector().appendException(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE165",
"KeyError: \"SOURCE\" keyword can only be used in context " +
- " to \"Relationships\" source node");
+ " to \"Relationships\" source node"));
return null;
}
return ((RelationshipTemplate)context).getTarget();
@@ -128,8 +129,8 @@
return nt;
}
}
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "KeyError: Node template \"%s\" was not found",nodeTemplateName));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE166", String.format(
+ "KeyError: Node template \"%s\" was not found",nodeTemplateName)));
return null;
}
@@ -149,7 +150,7 @@
interface_name = self._find_interface_name(self.args[1])
self._find_operation_name(interface_name, self.args[2])
else:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValueError(_('Illegal arguments for function "{0}". Expected '
'arguments: "template_name","interface_name",'
'"operation_name","output_variable_name"'
@@ -160,7 +161,7 @@
if interface_name in toscaparser.elements.interfaces.SECTIONS:
return interface_name
else:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValueError(_('Enter a valid interface name'
).format(GET_OPERATION_OUTPUT)))
return
@@ -173,7 +174,7 @@
interfaces_relationship_configure_operations):
return operation_name
else:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValueError(_('Enter an operation of Configure interface'
).format(GET_OPERATION_OUTPUT)))
return
@@ -183,12 +184,12 @@
StatefulEntityType.interfaces_node_lifecycle_operations):
return operation_name
else:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValueError(_('Enter an operation of Standard interface'
).format(GET_OPERATION_OUTPUT)))
return
else:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValueError(_('Enter a valid operation name'
).format(GET_OPERATION_OUTPUT)))
return
@@ -196,14 +197,14 @@
def _find_node_template(self, node_template_name):
if node_template_name == TARGET:
if not isinstance(self.context.type_definition, RelationshipType):
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
KeyError(_('"TARGET" keyword can only be used in context'
' to "Relationships" target node')))
return
return self.context.target
if node_template_name == SOURCE:
if not isinstance(self.context.type_definition, RelationshipType):
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
KeyError(_('"SOURCE" keyword can only be used in context'
' to "Relationships" source node')))
return
@@ -215,7 +216,7 @@
for node_template in self.tosca_tpl.nodetemplates:
if node_template.name == name:
return node_template
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
KeyError(_(
'Node template "{0}" was not found.'
).format(node_template_name)))
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetProperty.java b/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetProperty.java
index 41495bc..1abee6e 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetProperty.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetProperty.java
@@ -1,5 +1,7 @@
package org.openecomp.sdc.toscaparser.api.functions;
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
+
import java.util.ArrayList;
import java.util.LinkedHashMap;
@@ -46,8 +48,8 @@
@Override
void validate() {
if(args.size() < 2) {
- ThreadLocalsHolder.getCollector().appendException(
- "ValueError: Illegal arguments for function \"get_property\". Expected arguments: \"node-template-name\", \"req-or-cap\" (optional), \"property name.\"");
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE167",
+ "ValueError: Illegal arguments for function \"get_property\". Expected arguments: \"node-template-name\", \"req-or-cap\" (optional), \"property name.\""));
return;
}
if(args.size() == 2) {
@@ -129,16 +131,16 @@
property = ((Property)props.get(propertyName)).getValue();
}
if(property == null && throwErrors) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE168", String.format(
"KeyError: Property \"%s\" was not found in capability \"%s\" of node template \"%s\" referenced from node template \"%s\"",
- propertyName,capabilityName,nodeTemplate.getName(),((NodeTemplate)context).getName()));
+ propertyName,capabilityName,nodeTemplate.getName(),((NodeTemplate)context).getName())));
}
return property;
}
if(throwErrors) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE169", String.format(
"KeyError: Requirement/CapabilityAssignment \"%s\" referenced from node template \"%s\" was not found in node template \"%s\"",
- capabilityName,((NodeTemplate)context).getName(),nodeTemplate.getName()));
+ capabilityName,((NodeTemplate)context).getName(),nodeTemplate.getName())));
}
return null;
@@ -152,9 +154,9 @@
LinkedHashMap<String,Property> props = nodeTpl.getProperties();
Property found = props.get(propertyName);
if(found == null) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE170", String.format(
"KeyError: Property \"%s\" was not found in node template \"%s\"",
- propertyName,nodeTpl.getName()));
+ propertyName,nodeTpl.getName())));
}
return found;
}
@@ -167,25 +169,25 @@
if(nodeTemplateName.equals(HOST)) {
NodeTemplate node = _findHostContainingProperty(null);
if(node == null) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE171", String.format(
"KeyError: Property \"%s\" was not found in capability \"%s\" of node template \"%s\" referenced from node template \"%s\"",
- (String)args.get(2),(String)args.get(1),((NodeTemplate)context).getName()));
+ (String)args.get(2),(String)args.get(1),((NodeTemplate)context).getName())));
return null;
}
return node;
}
if(nodeTemplateName.equals(TARGET)) {
if(!(((RelationshipTemplate)context).getTypeDefinition() instanceof RelationshipType)) {
- ThreadLocalsHolder.getCollector().appendException(
- "KeyError: \"TARGET\" keyword can only be used in context to \"Relationships\" target node");
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE172",
+ "KeyError: \"TARGET\" keyword can only be used in context to \"Relationships\" target node"));
return null;
}
return ((RelationshipTemplate)context).getTarget();
}
if(nodeTemplateName.equals(SOURCE)) {
if(!(((RelationshipTemplate)context).getTypeDefinition() instanceof RelationshipType)) {
- ThreadLocalsHolder.getCollector().appendException(
- "KeyError: \"SOURCE\" keyword can only be used in context to \"Relationships\" target node");
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE173",
+ "KeyError: \"SOURCE\" keyword can only be used in context to \"Relationships\" target node"));
return null;
}
return ((RelationshipTemplate)context).getSource();
@@ -198,9 +200,9 @@
return nodeTemplate;
}
}
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE174", String.format(
"KeyError: Node template \"%s\" was not found. Referenced from Node Template \"%s\"",
- nodeTemplateName,((NodeTemplate)context).getName()));
+ nodeTemplateName,((NodeTemplate)context).getName())));
return null;
}
@@ -212,16 +214,16 @@
return ((ArrayList)value).get(index);
}
else {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE175", String.format(
"KeyError: Property \"%s\" found in capability \"%s\" referenced from node template \"%s\" must have an element with index %d",
- args.get(2),args.get(1),((NodeTemplate)context).getName(),index));
+ args.get(2),args.get(1),((NodeTemplate)context).getName(),index)));
}
}
else {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE176", String.format(
"KeyError: Property \"%s\" found in capability \"%s\" referenced from node template \"%s\" must be a list",
- args.get(2),args.get(1),((NodeTemplate)context).getName()));
+ args.get(2),args.get(1),((NodeTemplate)context).getName())));
}
return null;
}
@@ -234,15 +236,15 @@
return ov;
}
else {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE177", String.format(
"KeyError: Property \"%s\" found in capability \"%s\" referenced from node template \"%s\" must have an attribute named \"%s\"",
- args.get(2),args.get(1),((NodeTemplate)context).getName(),attribute));
+ args.get(2),args.get(1),((NodeTemplate)context).getName(),attribute)));
}
}
else {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE178", String.format(
"KeyError: Property \"%s\" found in capability \"%s\" referenced from node template \"%s\" must be a dict",
- args.get(2),args.get(1),((NodeTemplate)context).getName()));
+ args.get(2),args.get(1),((NodeTemplate)context).getName())));
}
return null;
}
@@ -379,7 +381,7 @@
def validate(self):
if len(self.args) < 2:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValueError(_(
'Expected arguments: "node-template-name", "req-or-cap" '
'(optional), "property name".')))
@@ -446,7 +448,7 @@
if props and property_name in props.keys():
property = props[property_name].value
if not property:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
KeyError(_('Property "%(prop)s" was not found in '
'capability "%(cap)s" of node template '
'"%(ntpl1)s" referenced from node template '
@@ -460,7 +462,7 @@
capability_name,
self.context.name,
node_template.name)
- ExceptionCollector.appendException(KeyError(msg))
+ ValidationIssueCollector.appendException(KeyError(msg))
def _find_property(self, property_name):
node_tpl = self._find_node_template(self.args[0])
@@ -469,7 +471,7 @@
props = node_tpl.get_properties()
found = [props[property_name]] if property_name in props else []
if len(found) == 0:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
KeyError(_('Property "%(prop)s" was not found in node '
'template "%(ntpl)s".') %
{'prop': property_name,
@@ -485,14 +487,14 @@
return self._find_host_containing_property()
if node_template_name == TARGET:
if not isinstance(self.context.type_definition, RelationshipType):
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
KeyError(_('"TARGET" keyword can only be used in context'
' to "Relationships" target node')))
return
return self.context.target
if node_template_name == SOURCE:
if not isinstance(self.context.type_definition, RelationshipType):
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
KeyError(_('"SOURCE" keyword can only be used in context'
' to "Relationships" source node')))
return
@@ -502,7 +504,7 @@
for node_template in self.tosca_tpl.nodetemplates:
if node_template.name == node_template_name:
return node_template
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
KeyError(_(
'Node template "{0}" was not found.'
).format(node_template_name)))
@@ -512,7 +514,7 @@
if index < len(value):
return value[index]
else:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
KeyError(_(
"Property '{0}' found in capability '{1}'"
" referenced from node template {2}"
@@ -522,7 +524,7 @@
self.context.name,
index)))
else:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
KeyError(_(
"Property '{0}' found in capability '{1}'"
" referenced from node template {2}"
@@ -535,7 +537,7 @@
if attibute in value:
return value[attibute]
else:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
KeyError(_(
"Property '{0}' found in capability '{1}'"
" referenced from node template {2}"
@@ -545,7 +547,7 @@
self.context.name,
attibute)))
else:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
KeyError(_(
"Property '{0}' found in capability '{1}'"
" referenced from node template {2}"
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/functions/Token.java b/src/main/java/org/openecomp/sdc/toscaparser/api/functions/Token.java
index 4438908..8f35a80 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/functions/Token.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/functions/Token.java
@@ -1,11 +1,10 @@
package org.openecomp.sdc.toscaparser.api.functions;
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
-import org.openecomp.sdc.toscaparser.api.NodeTemplate;
+import java.util.ArrayList;
+
import org.openecomp.sdc.toscaparser.api.TopologyTemplate;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;
public class Token extends Function {
@@ -42,21 +41,21 @@
@Override
void validate() {
if(args.size() < 3) {
- ThreadLocalsHolder.getCollector().appendException(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE180",
"ValueError: Invalid arguments for function \"token\". " +
- "Expected at least three arguments");
+ "Expected at least three arguments"));
}
else {
if(!(args.get(1) instanceof String) ||
((String)args.get(1)).length() != 1) {
- ThreadLocalsHolder.getCollector().appendException(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE181",
"ValueError: Invalid arguments for function \"token\". " +
- "Expected single char value as second argument");
+ "Expected single char value as second argument"));
}
if(!(args.get(2) instanceof Integer)) {
- ThreadLocalsHolder.getCollector().appendException(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE182",
"ValueError: Invalid arguments for function \"token\"" +
- "Expected integer value as third argument");
+ "Expected integer value as third argument"));
}
}
}
@@ -91,18 +90,18 @@
def validate(self):
if len(self.args) < 3:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValueError(_('Invalid arguments for function "{0}". Expected '
'at least three arguments.').format(TOKEN)))
else:
if not isinstance(self.args[1], str) or len(self.args[1]) != 1:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValueError(_('Invalid arguments for function "{0}". '
'Expected single char value as second '
'argument.').format(TOKEN)))
if not isinstance(self.args[2], int):
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValueError(_('Invalid arguments for function "{0}". '
'Expected integer value as third '
'argument.').format(TOKEN)))
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/parameters/Input.java b/src/main/java/org/openecomp/sdc/toscaparser/api/parameters/Input.java
index 28e57d2..15ca6da 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/parameters/Input.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/parameters/Input.java
@@ -1,11 +1,12 @@
package org.openecomp.sdc.toscaparser.api.parameters;
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
+
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import org.openecomp.sdc.toscaparser.api.DataEntity;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
import org.openecomp.sdc.toscaparser.api.elements.EntityType;
import org.openecomp.sdc.toscaparser.api.elements.constraints.Constraint;
import org.openecomp.sdc.toscaparser.api.elements.constraints.Schema;
@@ -95,9 +96,9 @@
}
}
if(!bFound) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE214", String.format(
"UnknownFieldError: Input \"%s\" contains unknown field \"%s\"",
- name,key));
+ name,key)));
}
}
}
@@ -118,8 +119,8 @@
}
if(!bFound) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "ValueError: Invalid type \"%s\"",inputType));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE215", String.format(
+ "ValueError: Invalid type \"%s\"",inputType)));
}
}
@@ -150,7 +151,7 @@
/*python
-from toscaparser.common.exception import ExceptionCollector
+from toscaparser.common.exception import ValidationIssueCollector
from toscaparser.common.exception import MissingRequiredFieldError
from toscaparser.common.exception import UnknownFieldError
from toscaparser.dataentity import DataEntity
@@ -207,13 +208,13 @@
def _validate_field(self):
for name in self.schema.schema:
if name not in self.INPUTFIELD:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
UnknownFieldError(what='Input "%s"' % self.name,
field=name))
def validate_type(self, input_type):
if input_type not in Schema.PROPERTY_TYPES:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValueError(_('Invalid type "%s".') % type))
# tODO(anyone) Need to test for any built-in datatype not just network
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/parameters/Output.java b/src/main/java/org/openecomp/sdc/toscaparser/api/parameters/Output.java
index 34ecf12..381388b 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/parameters/Output.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/parameters/Output.java
@@ -1,8 +1,9 @@
package org.openecomp.sdc.toscaparser.api.parameters;
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
+
import java.util.LinkedHashMap;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;
public class Output {
@@ -34,15 +35,15 @@
private void _validateField() {
if(!(attrs instanceof LinkedHashMap)) {
//TODO wrong error message...
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE216", String.format(
"ValidationError: Output \"%s\" has wrong type. Expecting a dict",
- name));
+ name)));
}
if(getValue() == null) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE217", String.format(
"MissingRequiredFieldError: Output \"%s\" is missing required \"%s\"",
- name,VALUE));
+ name,VALUE)));
}
for(String key: attrs.keySet()) {
boolean bFound = false;
@@ -53,9 +54,9 @@
}
}
if(!bFound) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE218", String.format(
"UnknownFieldError: Output \"%s\" contains unknown field \"%s\"",
- name,key));
+ name,key)));
}
}
}
@@ -94,16 +95,16 @@
def _validate_field(self):
if not isinstance(self.attrs, dict):
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
MissingRequiredFieldError(what='Output "%s"' % self.name,
required=self.VALUE))
if self.value is None:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
MissingRequiredFieldError(what='Output "%s"' % self.name,
required=self.VALUE))
for name in self.attrs:
if name not in self.OUTPUTFIELD:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
UnknownFieldError(what='Output "%s"' % self.name,
field=name))
*/
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/prereq/CSAR.java b/src/main/java/org/openecomp/sdc/toscaparser/api/prereq/CSAR.java
index 85b54ee..ef29b53 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/prereq/CSAR.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/prereq/CSAR.java
@@ -1,5 +1,7 @@
package org.openecomp.sdc.toscaparser.api.prereq;
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
+
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
@@ -61,7 +63,7 @@
if(isFile) {
File f = new File(path);
if (!f.isFile()) {
- ThreadLocalsHolder.getCollector().appendException(String.format("\"%s\" is not a file", path));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE220", String.format("\"%s\" is not a file", path)));
return false;
}
else {
@@ -70,7 +72,7 @@
}
else {
if(!UrlUtils.validateUrl(path)) {
- ThreadLocalsHolder.getCollector().appendException(String.format("ImportError: \"%s\" does not exist",path));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE221", String.format("ImportError: \"%s\" does not exist",path)));
return false;
}
// get it to a local file
@@ -82,7 +84,7 @@
Files.copy(in,ptf,StandardCopyOption.REPLACE_EXISTING);
}
catch(Exception e) {
- ThreadLocalsHolder.getCollector().appendException("ImportError: failed to load CSAR from " + path);
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE222", "ImportError: failed to load CSAR from " + path));
return false;
}
@@ -199,7 +201,7 @@
//ThreadLocalsHolder.getCollector().appendCriticalException(e.getMessage());
throw e;
} catch (Exception e) {
- ThreadLocalsHolder.getCollector().appendException("ValidationError: " + e.getMessage());
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE223", "ValidationError: " + e.getMessage()));
errorCaught = true;
}
@@ -281,10 +283,10 @@
return (LinkedHashMap<String,Object>)data;
}
catch(Exception e) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE224", String.format(
"The file \"%s\" in the CSAR \"%s\" does not " +
"contain valid TOSCA YAML content",
- mainTemplate,csar));
+ mainTemplate,csar)));
}
}
return null;
@@ -361,9 +363,9 @@
}
}
else {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE225", String.format(
"ValueError: Unexpected artifact definition for \"%s\"",
- artifactKey));
+ artifactKey)));
errorCaught = true;
}
}
@@ -429,12 +431,12 @@
return;
}
else {
- ThreadLocalsHolder.getCollector().appendException(msg);
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE226", msg));
errorCaught = true;
}
}
catch (Exception e) {
- ThreadLocalsHolder.getCollector().appendException(msg);
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE227", msg));
}
}
@@ -446,8 +448,8 @@
}
if(raiseExc) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "ValueError: The resource \"%s\" does not exist",resourceFile));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE228", String.format(
+ "ValueError: The resource \"%s\" does not exist",resourceFile)));
}
errorCaught = true;
}
@@ -511,7 +513,7 @@
/*python
-from toscaparser.common.exception import ExceptionCollector
+from toscaparser.common.exception import ValidationIssueCollector
from toscaparser.common.exception import URLException
from toscaparser.common.exception import ValidationError
from toscaparser.imports import ImportsLoader
@@ -543,14 +545,14 @@
missing_err_msg = (_('"%s" does not exist.') % self.path)
if self.a_file:
if not os.path.isfile(self.path):
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValidationError(message=missing_err_msg))
return False
else:
self.csar = self.path
else: # a URL
if not UrlUtils.validate_url(self.path):
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValidationError(message=missing_err_msg))
return False
else:
@@ -560,7 +562,7 @@
# validate that it is a valid zip file
if not zipfile.is_zipfile(self.csar):
err_msg = (_('"%s" is not a valid zip file.') % self.path)
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValidationError(message=err_msg))
return False
@@ -571,7 +573,7 @@
err_msg = (_('"%s" is not a valid CSAR as it does not contain the '
'required file "TOSCA.meta" in the folder '
'"TOSCA-Metadata".') % self.path)
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValidationError(message=err_msg))
return False
@@ -585,11 +587,11 @@
if type(meta) is dict:
self.metadata = meta
else:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValidationError(message=invalid_yaml_err_msg))
return False
except yaml.YAMLError:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValidationError(message=invalid_yaml_err_msg))
return False
@@ -598,7 +600,7 @@
'"Entry-Definitions" in '
'"TOSCA-Metadata/TOSCA.meta".')
% self.path)
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValidationError(message=err_msg))
return False
@@ -608,7 +610,7 @@
if entry and entry not in filelist:
err_msg = (_('The "Entry-Definitions" file defined in the '
'CSAR "%s" does not exist.') % self.path)
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValidationError(message=err_msg))
return False
@@ -654,11 +656,11 @@
try:
tosca_yaml = yaml.load(data)
if type(tosca_yaml) is not dict:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValidationError(message=invalid_tosca_yaml_err_msg))
return tosca_yaml
except Exception:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValidationError(message=invalid_tosca_yaml_err_msg))
def get_description(self):
@@ -718,7 +720,7 @@
main_tpl_file,
artifact['file'])
else:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValueError(_('Unexpected artifact '
'definition for "%s".')
% artifact_key))
@@ -759,11 +761,11 @@
if UrlUtils.url_accessible(resource_file):
return
else:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
URLException(what=msg))
self.error_caught = True
except Exception:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
URLException(what=msg))
self.error_caught = True
@@ -773,7 +775,7 @@
return
if raise_exc:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValueError(_('The resource "%s" does not exist.')
% resource_file))
self.error_caught = True
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/prereq/CSAR.java.orig b/src/main/java/org/openecomp/sdc/toscaparser/api/prereq/CSAR.java.orig
index aa36b9e..b4d2614 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/prereq/CSAR.java.orig
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/prereq/CSAR.java.orig
@@ -18,7 +18,7 @@
import java.util.zip.ZipInputStream;
import org.openecomp.sdc.toscaparser.api.ImportsLoader;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
+import org.openecomp.sdc.toscaparser.api.common.ValidationIssueCollector;
import org.openecomp.sdc.toscaparser.api.elements.Metadata;
import org.openecomp.sdc.toscaparser.api.utils.UrlUtils;
import org.slf4j.Logger;
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/utils/JToscaErrorCodes.java b/src/main/java/org/openecomp/sdc/toscaparser/api/utils/JToscaErrorCodes.java
index 354fef0..6fb4606 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/utils/JToscaErrorCodes.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/utils/JToscaErrorCodes.java
@@ -2,14 +2,14 @@
public enum JToscaErrorCodes {
- MISSING_META_FILE("JT1001"),
- INVALID_META_YAML_CONTENT("JT1002"),
- ENTRY_DEFINITION_NOT_DEFINED("JT1003"),
- MISSING_ENTRY_DEFINITION_FILE ("JT1004"),
- GENERAL_ERROR("JT1005"),
- PATH_NOT_VALID("JT1006"),
- CSAR_TOSCA_VALIDATION_ERROR("JT1007"),
- INVALID_CSAR_FORMAT("JT1008");
+ MISSING_META_FILE("JE1001"),
+ INVALID_META_YAML_CONTENT("JE1002"),
+ ENTRY_DEFINITION_NOT_DEFINED("JE1003"),
+ MISSING_ENTRY_DEFINITION_FILE ("JE1004"),
+ GENERAL_ERROR("JE1005"),
+ PATH_NOT_VALID("JE1006"),
+ CSAR_TOSCA_VALIDATION_ERROR("JE1007"),
+ INVALID_CSAR_FORMAT("JE1008");
private String value;
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/utils/TOSCAVersionProperty.java b/src/main/java/org/openecomp/sdc/toscaparser/api/utils/TOSCAVersionProperty.java
index 6b3c1ce..f749f7b 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/utils/TOSCAVersionProperty.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/utils/TOSCAVersionProperty.java
@@ -1,10 +1,10 @@
package org.openecomp.sdc.toscaparser.api.utils;
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
+
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
-
public class TOSCAVersionProperty {// test with functions/test_concat.yaml
private String version;
@@ -35,10 +35,10 @@
Pattern pattern = Pattern.compile(versionRe);
Matcher matcher = pattern.matcher(version);
if(!matcher.find()) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE252", String.format(
"InvalidTOSCAVersionPropertyException: " +
"Value of TOSCA version property \"%s\" is invalid",
- version));
+ version)));
return;
}
minorVersion = matcher.group("gMinorVersion");
@@ -77,10 +77,10 @@
if((fixVersion == null && value != null) ||
(minorVersion.equals("0") && majorVersion.equals("0") &&
fixVersion.equals("0") && value != null)) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE253", String.format(
"InvalidTOSCAVersionPropertyException: " +
"Value of TOSCA version property \"%s\" is invalid",
- version));
+ version)));
}
return value;
}
@@ -92,10 +92,10 @@
// Eg: version = 18.0.0-1 is invalid.
if(qualifier == null && value != null) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE254", String.format(
"InvalidTOSCAVersionPropertyException: " +
"Value of TOSCA version property \"%s\" is invalid",
- version));
+ version)));
}
return value;
}
@@ -120,7 +120,7 @@
self.version = str(version)
match = self.VERSION_RE.match(self.version)
if not match:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
InvalidTOSCAVersionPropertyException(what=(self.version)))
return
ver = match.groupdict()
@@ -161,7 +161,7 @@
if (self.fix_version is None and value) or \
(self.minor_version == self.major_version ==
self.fix_version == '0' and value):
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
InvalidTOSCAVersionPropertyException(what=(self.version)))
return value
@@ -173,7 +173,7 @@
Eg: version = 18.0.0-1 is invalid.
"""
if not self.qualifier and value:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
InvalidTOSCAVersionPropertyException(what=(self.version)))
return value
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/utils/ThreadLocalsHolder.java b/src/main/java/org/openecomp/sdc/toscaparser/api/utils/ThreadLocalsHolder.java
index 47ba972..0e1531f 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/utils/ThreadLocalsHolder.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/utils/ThreadLocalsHolder.java
@@ -1,20 +1,20 @@
package org.openecomp.sdc.toscaparser.api.utils;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
+import org.openecomp.sdc.toscaparser.api.common.ValidationIssueCollector;
public class ThreadLocalsHolder {
- private static final ThreadLocal<ExceptionCollector> exceptionCollectorThreadLocal = new ThreadLocal<>();
+ private static final ThreadLocal<ValidationIssueCollector> exceptionCollectorThreadLocal = new ThreadLocal<>();
private ThreadLocalsHolder(){}
- public static ExceptionCollector getCollector() {
+ public static ValidationIssueCollector getCollector() {
return exceptionCollectorThreadLocal.get();
}
- public static void setCollector(ExceptionCollector exceptionCollector) {
+ public static void setCollector(ValidationIssueCollector validationIssueCollector) {
cleanup();
- exceptionCollectorThreadLocal.set(exceptionCollector);
+ exceptionCollectorThreadLocal.set(validationIssueCollector);
}
public static void cleanup(){
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/utils/UrlUtils.java b/src/main/java/org/openecomp/sdc/toscaparser/api/utils/UrlUtils.java
index 092f827..3383bd7 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/utils/UrlUtils.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/utils/UrlUtils.java
@@ -1,12 +1,12 @@
package org.openecomp.sdc.toscaparser.api.utils;
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
+
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
-
public class UrlUtils {
public static boolean validateUrl(String sUrl) {
@@ -34,16 +34,16 @@
// relative_path: heat-translator
// - joined: http://www.githib.com/openstack/heat-translator
if(!validateUrl(sUrl)) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "ValueError: The URL \"%s\" is malformed",sUrl));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE255", String.format(
+ "ValueError: The URL \"%s\" is malformed",sUrl)));
}
try {
URL base = new URL(sUrl);
return (new URL(base,relativePath)).toString();
}
catch(MalformedURLException e) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "ValueError: Joining URL \"%s\" and relative path \"%s\" caused an exception",sUrl,relativePath));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE256", String.format(
+ "ValueError: Joining URL \"%s\" and relative path \"%s\" caused an exception",sUrl,relativePath)));
return sUrl;
}
}
@@ -70,7 +70,7 @@
from six.moves.urllib.parse import urljoin
from six.moves.urllib.parse import urlparse
-from toscaparser.common.exception import ExceptionCollector
+from toscaparser.common.exception import ValidationIssueCollector
from toscaparser.utils.gettextutils import _
try:
@@ -108,7 +108,7 @@
- joined: http://www.githib.com/openstack/heat-translator
"""
if not UrlUtils.validate_url(url):
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValueError(_('"%s" is not a valid URL.') % url))
return urljoin(url, relative_path)
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/utils/ValidateUtils.java b/src/main/java/org/openecomp/sdc/toscaparser/api/utils/ValidateUtils.java
index 9909685..53f5bec 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/utils/ValidateUtils.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/utils/ValidateUtils.java
@@ -1,11 +1,11 @@
package org.openecomp.sdc.toscaparser.api.utils;
+import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
+
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashMap;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
-
public class ValidateUtils {
private static final String RANGE_UNBOUNDED = "UNBOUNDED";
@@ -35,8 +35,8 @@
public static Object validateNumeric(Object value) {
if(value != null) {
if (!(value instanceof Number)) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "ValueError: \"%s\" is not a numeric", value.toString()));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE257", String.format(
+ "ValueError: \"%s\" is not a numeric",value.toString())));
}
}
return value;
@@ -49,8 +49,8 @@
if (value instanceof Boolean) {
return (Boolean) value ? 1 : 0;
}
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "ValueError: \"%s\" is not an integer", value.toString()));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE258", String.format(
+ "ValueError: \"%s\" is not an integer",value.toString())));
}
}
return value;
@@ -59,8 +59,8 @@
public static Object validateFloat(Object value) {
if(value != null) {
if (!(value instanceof Float || value instanceof Double)) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "ValueError: \"%s\" is not a float", value.toString()));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE259", String.format(
+ "ValueError: \"%s\" is not a float",value.toString())));
}
}
return value;
@@ -69,8 +69,8 @@
public static Object validateString(Object value) {
if(value != null) {
if (!(value instanceof String)) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "ValueError: \'%s\' is not a string", value.toString()));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE260", String.format(
+ "ValueError: \'%s\' is not a string",value.toString())));
}
}
return value;
@@ -79,8 +79,8 @@
public static Object validateList(Object value) {
if(value != null) {
if (!(value instanceof ArrayList)) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "ValueError: \"%s\" is not a list", value.toString()));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE261", String.format(
+ "ValueError: \"%s\" is not a list",value.toString())));
}
}
return value;
@@ -93,8 +93,8 @@
validateList(range);
// validate range list has a min and max
if(range instanceof ArrayList && ((ArrayList<Object>)range).size() != 2) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "ValueError: \"%s\" is not a valid range",range.toString()));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE262", String.format(
+ "ValueError: \"%s\" is not a valid range",range.toString())));
// too dangerous to continue...
return range;
}
@@ -106,8 +106,8 @@
if(!(r0 instanceof Integer) && !(r0 instanceof Float) ||
!(r1 instanceof Integer) && !(r1 instanceof Float)) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "ValueError: \"%s\" is not a valid range",range.toString()));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE263", String.format(
+ "ValueError: \"%s\" is not a valid range",range.toString())));
// too dangerous to continue...
return range;
}
@@ -131,8 +131,8 @@
if(!minTest && !maxTest) {
// Note: min == max is allowed
if(min > max) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "ValueError:\"%s\" is not a valid range",range.toString()));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE264", String.format(
+ "ValueError:\"%s\" is not a valid range",range.toString())));
}
}
return range;
@@ -142,8 +142,8 @@
public static Object validateValueInRange(Object value,Object range,String propName) {
// verify all 3 are numeric and convert to Floats
if(!(value instanceof Integer || value instanceof Float)) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "ValueError: validateInRange: \"%s\" is not a number",range.toString()));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE265", String.format(
+ "ValueError: validateInRange: \"%s\" is not a number",range.toString())));
return value;
}
Float fval = value instanceof Integer ? ((Integer)value).floatValue() : (Float)value;
@@ -154,8 +154,8 @@
// better safe than sorry...
// validate that range list has a min and max
if(range instanceof ArrayList && ((ArrayList<Object>)range).size() != 2) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "ValueError: \"%s\" is not a valid range",range.toString()));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE266", String.format(
+ "ValueError: \"%s\" is not a valid range",range.toString())));
// too dangerous to continue...
return value;
}
@@ -167,8 +167,8 @@
if(!(r0 instanceof Integer) && !(r0 instanceof Float) ||
!(r1 instanceof Integer) && !(r1 instanceof Float)) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "ValueError: \"%s\" is not a valid range",range.toString()));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE267", String.format(
+ "ValueError: \"%s\" is not a valid range",range.toString())));
// too dangerous to continue...
return value;
}
@@ -192,8 +192,8 @@
if(!minTest && !maxTest) {
// Note: min == max is allowed
if(min > max) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "ValueError:\"%s\" is not a valid range",range.toString()));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE268", String.format(
+ "ValueError:\"%s\" is not a valid range",range.toString())));
}
}
// finally...
@@ -211,9 +211,9 @@
}
}
if(bError) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE269", String.format(
"RangeValueError: Property \"%s\", \"%s\" not in range [\"%s\" - \"%s\"",
- propName,value.toString(),r0.toString(),r1.toString()));
+ propName,value.toString(),r0.toString(),r1.toString())));
}
return value;
}
@@ -221,8 +221,8 @@
public static Object validateMap(Object ob) {
if(ob != null) {
if (!(ob instanceof LinkedHashMap)) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "ValueError\"%s\" is not a map.", ob.toString()));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE270", String.format(
+ "ValueError\"%s\" is not a map.",ob.toString())));
}
}
return ob;
@@ -239,8 +239,8 @@
return normalized.equals("true");
}
}
- ThreadLocalsHolder.getCollector().appendException(String.format(
- "ValueError: \"%s\" is not a boolean", value.toString()));
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE271", String.format(
+ "ValueError: \"%s\" is not a boolean",value.toString())));
}
return value;
}
@@ -256,7 +256,7 @@
except Exception as e:
original_err_msg = str(e)
log.error(original_err_msg)
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValueError(_('"%(val)s" is not a valid timestamp. "%(msg)s"') %
{'val': value, 'msg': original_err_msg}))
*/
@@ -264,9 +264,9 @@
// timestamps are loaded as Date objects by the YAML parser
if(value != null) {
if (!(value instanceof Date)) {
- ThreadLocalsHolder.getCollector().appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE272", String.format(
"ValueError: \"%s\" is not a valid timestamp",
- value.toString()));
+ value.toString())));
}
}
@@ -278,7 +278,7 @@
/*python
from toscaparser.elements import constraints
-from toscaparser.common.exception import ExceptionCollector
+from toscaparser.common.exception import ValidationIssueCollector
from toscaparser.common.exception import InvalidTOSCAVersionPropertyException
from toscaparser.common.exception import RangeValueError
from toscaparser.utils.gettextutils import _
@@ -301,7 +301,7 @@
def validate_numeric(value):
if not isinstance(value, numbers.Number):
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValueError(_('"%s" is not a numeric.') % value))
return value
@@ -311,28 +311,28 @@
try:
value = int(value)
except Exception:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValueError(_('"%s" is not an integer.') % value))
return value
def validate_float(value):
if not isinstance(value, float):
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValueError(_('"%s" is not a float.') % value))
return value
def validate_string(value):
if not isinstance(value, six.string_types):
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValueError(_('"%s" is not a string.') % value))
return value
def validate_list(value):
if not isinstance(value, list):
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValueError(_('"%s" is not a list.') % value))
return value
@@ -342,7 +342,7 @@
validate_list(range)
# validate range list has a min and max
if len(range) != 2:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValueError(_('"%s" is not a valid range.') % range))
# validate min and max are numerics or the keyword UNBOUNDED
min_test = max_test = False
@@ -358,7 +358,7 @@
if not min_test and not max_test:
# Note: min == max is allowed
if min > max:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValueError(_('"%s" is not a valid range.') % range))
return range
@@ -371,7 +371,7 @@
# Note: value is valid if equal to min
if range[0] != RANGE_UNBOUNDED:
if value < range[0]:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
RangeValueError(pname=prop_name,
pvalue=value,
vmin=range[0],
@@ -379,7 +379,7 @@
# Note: value is valid if equal to max
if range[1] != RANGE_UNBOUNDED:
if value > range[1]:
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
RangeValueError(pname=prop_name,
pvalue=value,
vmin=range[0],
@@ -389,7 +389,7 @@
def validate_map(value):
if not isinstance(value, collections.Mapping):
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValueError(_('"%s" is not a map.') % value))
return value
@@ -403,7 +403,7 @@
if normalised in ['true', 'false']:
return normalised == 'true'
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValueError(_('"%s" is not a boolean.') % value))
@@ -417,7 +417,7 @@
except Exception as e:
original_err_msg = str(e)
log.error(original_err_msg)
- ExceptionCollector.appendException(
+ ValidationIssueCollector.appendException(
ValueError(_('"%(val)s" is not a valid timestamp. "%(msg)s"') %
{'val': value, 'msg': original_err_msg}))
return
diff --git a/src/test/java/org/openecomp/sdc/toscaparser/api/GetValidationIssues.java b/src/test/java/org/openecomp/sdc/toscaparser/api/GetValidationIssues.java
new file mode 100644
index 0000000..7a0eec1
--- /dev/null
+++ b/src/test/java/org/openecomp/sdc/toscaparser/api/GetValidationIssues.java
@@ -0,0 +1,81 @@
+package org.openecomp.sdc.toscaparser.api;
+
+import com.opencsv.CSVWriter;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+import java.util.Scanner;
+//Generate excel file, include all validation issues errors in jtosca
+//the error java code, the line number and file name for each error.
+public class GetValidationIssues {
+
+ public static CSVWriter fileWriter = null;
+ public static List<String[]> data = new ArrayList<>();
+
+ public static void main(String[] args) {
+ System.out.println("GetAllValidationIssues - path to project files Directory is " + Arrays.toString(args));
+ File jtoscaFiles = new File(args[0]+ "\\jtosca\\src\\main\\java\\org\\openecomp\\sdc\\toscaparser\\api");
+
+ try {
+ printFiles(jtoscaFiles);
+ fileWriter = new CSVWriter(new FileWriter(args[1]+"\\JToscaValidationIssues_"+System.currentTimeMillis()+".csv"), '\t');
+ fileWriter.writeNext(new String[] {"Error Message", "Class Name", "Line No."}, false);
+ fileWriter.writeAll(data, false);
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ fileWriter.flush();
+ fileWriter.close();
+ } catch (IOException e) {
+ System.out.println("Error while flushing/closing fileWriter !!!");
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private static void printFiles(File dir) {
+ if (dir != null && dir.exists()) {
+ for (File file : dir.listFiles()) {
+ if (file.isDirectory())
+ printFiles(file);
+ else {
+ Scanner scanner = null;
+ try {
+ scanner = new Scanner(file);
+
+ int lineNum = 0;
+ while (scanner.hasNextLine()) {
+ String line = scanner.nextLine();
+ lineNum++;
+ if (line.startsWith("/*python"))
+ break;
+
+ if (!line.trim().startsWith("//") && !line.trim().startsWith("#") && line.contains("ThreadLocalsHolder.getCollector().appendValidationIssue")) {
+ String errMsg = line.trim();
+ if (!errMsg.contains(";")) {
+ String nextLine = null;
+ while (scanner.hasNextLine() && (nextLine == null || !nextLine.contains(";"))) {
+ nextLine = scanner.nextLine();
+ errMsg += nextLine.trim();
+ }
+ }
+
+ data.add(new String[]{errMsg, file.getName(), String.valueOf(lineNum)});
+ }
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+}
+