summaryrefslogtreecommitdiffstats
path: root/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/utils
diff options
context:
space:
mode:
Diffstat (limited to 'jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/utils')
-rw-r--r--jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/utils/JToscaErrorCodes.java32
-rw-r--r--jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/utils/TOSCAVersionProperty.java6
-rw-r--r--jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/utils/ThreadLocalsHolder.java24
-rw-r--r--jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/utils/UrlUtils.java4
-rw-r--r--jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/utils/ValidateUtils.java32
5 files changed, 77 insertions, 21 deletions
diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/utils/JToscaErrorCodes.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/utils/JToscaErrorCodes.java
new file mode 100644
index 0000000..354fef0
--- /dev/null
+++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/utils/JToscaErrorCodes.java
@@ -0,0 +1,32 @@
+package org.openecomp.sdc.toscaparser.api.utils;
+
+
+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");
+
+ private String value;
+
+ private JToscaErrorCodes(String value) {
+ this.value = value;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public static JToscaErrorCodes getByCode(String code) {
+ for(JToscaErrorCodes v : values()){
+ if( v.getValue().equals(code)){
+ return v;
+ }
+ }
+ return null;
+ }
+} \ No newline at end of file
diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/utils/TOSCAVersionProperty.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/utils/TOSCAVersionProperty.java
index 7c6b62f..6b3c1ce 100644
--- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/utils/TOSCAVersionProperty.java
+++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/utils/TOSCAVersionProperty.java
@@ -35,7 +35,7 @@ public class TOSCAVersionProperty {// test with functions/test_concat.yaml
Pattern pattern = Pattern.compile(versionRe);
Matcher matcher = pattern.matcher(version);
if(!matcher.find()) {
- ExceptionCollector.appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendException(String.format(
"InvalidTOSCAVersionPropertyException: " +
"Value of TOSCA version property \"%s\" is invalid",
version));
@@ -77,7 +77,7 @@ public class TOSCAVersionProperty {// test with functions/test_concat.yaml
if((fixVersion == null && value != null) ||
(minorVersion.equals("0") && majorVersion.equals("0") &&
fixVersion.equals("0") && value != null)) {
- ExceptionCollector.appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendException(String.format(
"InvalidTOSCAVersionPropertyException: " +
"Value of TOSCA version property \"%s\" is invalid",
version));
@@ -92,7 +92,7 @@ public class TOSCAVersionProperty {// test with functions/test_concat.yaml
// Eg: version = 18.0.0-1 is invalid.
if(qualifier == null && value != null) {
- ExceptionCollector.appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendException(String.format(
"InvalidTOSCAVersionPropertyException: " +
"Value of TOSCA version property \"%s\" is invalid",
version));
diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/utils/ThreadLocalsHolder.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/utils/ThreadLocalsHolder.java
new file mode 100644
index 0000000..47ba972
--- /dev/null
+++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/utils/ThreadLocalsHolder.java
@@ -0,0 +1,24 @@
+package org.openecomp.sdc.toscaparser.api.utils;
+
+import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
+
+public class ThreadLocalsHolder {
+
+ private static final ThreadLocal<ExceptionCollector> exceptionCollectorThreadLocal = new ThreadLocal<>();
+
+ private ThreadLocalsHolder(){}
+
+ public static ExceptionCollector getCollector() {
+ return exceptionCollectorThreadLocal.get();
+ }
+
+ public static void setCollector(ExceptionCollector exceptionCollector) {
+ cleanup();
+ exceptionCollectorThreadLocal.set(exceptionCollector);
+ }
+
+ public static void cleanup(){
+ exceptionCollectorThreadLocal.remove();
+ }
+
+}
diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/utils/UrlUtils.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/utils/UrlUtils.java
index 0aadcfe..092f827 100644
--- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/utils/UrlUtils.java
+++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/utils/UrlUtils.java
@@ -34,7 +34,7 @@ public class UrlUtils {
// relative_path: heat-translator
// - joined: http://www.githib.com/openstack/heat-translator
if(!validateUrl(sUrl)) {
- ExceptionCollector.appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendException(String.format(
"ValueError: The URL \"%s\" is malformed",sUrl));
}
try {
@@ -42,7 +42,7 @@ public class UrlUtils {
return (new URL(base,relativePath)).toString();
}
catch(MalformedURLException e) {
- ExceptionCollector.appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendException(String.format(
"ValueError: Joining URL \"%s\" and relative path \"%s\" caused an exception",sUrl,relativePath));
return sUrl;
}
diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/utils/ValidateUtils.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/utils/ValidateUtils.java
index 675ab16..291316f 100644
--- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/utils/ValidateUtils.java
+++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/utils/ValidateUtils.java
@@ -34,7 +34,7 @@ public class ValidateUtils {
public static Object validateNumeric(Object value) {
if(!(value instanceof Number)) {
- ExceptionCollector.appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendException(String.format(
"ValueError: \"%s\" is not a numeric",value.toString()));
}
return value;
@@ -46,7 +46,7 @@ public class ValidateUtils {
if(value instanceof Boolean) {
return (Boolean)value ? 1 : 0;
}
- ExceptionCollector.appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendException(String.format(
"ValueError: \"%s\" is not an integer",value.toString()));
}
return value;
@@ -54,7 +54,7 @@ public class ValidateUtils {
public static Object validateFloat(Object value) {
if(!(value instanceof Float || value instanceof Double)) {
- ExceptionCollector.appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendException(String.format(
"ValueError: \"%s\" is not a float",value.toString()));
}
return value;
@@ -62,7 +62,7 @@ public class ValidateUtils {
public static Object validateString(Object value) {
if(!(value instanceof String)) {
- ExceptionCollector.appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendException(String.format(
"ValueError: \'%s\' is not a string",value.toString()));
}
return value;
@@ -70,7 +70,7 @@ public class ValidateUtils {
public static Object validateList(Object value) {
if(!(value instanceof ArrayList)) {
- ExceptionCollector.appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendException(String.format(
"ValueError: \"%s\" is not a list",value.toString()));
}
return value;
@@ -83,7 +83,7 @@ public class ValidateUtils {
validateList(range);
// validate range list has a min and max
if(range instanceof ArrayList && ((ArrayList<Object>)range).size() != 2) {
- ExceptionCollector.appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendException(String.format(
"ValueError: \"%s\" is not a valid range",range.toString()));
// too dangerous to continue...
return range;
@@ -96,7 +96,7 @@ public class ValidateUtils {
if(!(r0 instanceof Integer) && !(r0 instanceof Float) ||
!(r1 instanceof Integer) && !(r1 instanceof Float)) {
- ExceptionCollector.appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendException(String.format(
"ValueError: \"%s\" is not a valid range",range.toString()));
// too dangerous to continue...
return range;
@@ -121,7 +121,7 @@ public class ValidateUtils {
if(!minTest && !maxTest) {
// Note: min == max is allowed
if(min > max) {
- ExceptionCollector.appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendException(String.format(
"ValueError:\"%s\" is not a valid range",range.toString()));
}
}
@@ -132,7 +132,7 @@ public class ValidateUtils {
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)) {
- ExceptionCollector.appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendException(String.format(
"ValueError: validateInRange: \"%s\" is not a number",range.toString()));
return value;
}
@@ -144,7 +144,7 @@ public class ValidateUtils {
// better safe than sorry...
// validate that range list has a min and max
if(range instanceof ArrayList && ((ArrayList<Object>)range).size() != 2) {
- ExceptionCollector.appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendException(String.format(
"ValueError: \"%s\" is not a valid range",range.toString()));
// too dangerous to continue...
return value;
@@ -157,7 +157,7 @@ public class ValidateUtils {
if(!(r0 instanceof Integer) && !(r0 instanceof Float) ||
!(r1 instanceof Integer) && !(r1 instanceof Float)) {
- ExceptionCollector.appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendException(String.format(
"ValueError: \"%s\" is not a valid range",range.toString()));
// too dangerous to continue...
return value;
@@ -182,7 +182,7 @@ public class ValidateUtils {
if(!minTest && !maxTest) {
// Note: min == max is allowed
if(min > max) {
- ExceptionCollector.appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendException(String.format(
"ValueError:\"%s\" is not a valid range",range.toString()));
}
}
@@ -201,7 +201,7 @@ public class ValidateUtils {
}
}
if(bError) {
- ExceptionCollector.appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendException(String.format(
"RangeValueError: Property \"%s\", \"%s\" not in range [\"%s\" - \"%s\"",
propName,value.toString(),r0.toString(),r1.toString()));
}
@@ -210,7 +210,7 @@ public class ValidateUtils {
public static Object validateMap(Object ob) {
if(!(ob instanceof LinkedHashMap)) {
- ExceptionCollector.appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendException(String.format(
"ValueError\"%s\" is not a map.",ob.toString()));
}
return ob;
@@ -226,7 +226,7 @@ public class ValidateUtils {
return normalized.equals("true");
}
}
- ExceptionCollector.appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendException(String.format(
"ValueError: \"%s\" is not a boolean",value.toString()));
return value;
}
@@ -249,7 +249,7 @@ public class ValidateUtils {
// timestamps are loaded as Date objects by the YAML parser
if(!(value instanceof Date)) {
- ExceptionCollector.appendException(String.format(
+ ThreadLocalsHolder.getCollector().appendException(String.format(
"ValueError: \"%s\" is not a valid timestamp",
value.toString()));