aboutsummaryrefslogtreecommitdiffstats
path: root/jtosca
diff options
context:
space:
mode:
Diffstat (limited to 'jtosca')
-rw-r--r--jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/DataEntity.java15
-rw-r--r--jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/EntityTemplate.java2
-rw-r--r--jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java57
-rw-r--r--jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/common/ExceptionCollector.java64
-rw-r--r--jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/ScalarUnit.java6
-rw-r--r--jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/Schema.java3
6 files changed, 113 insertions, 34 deletions
diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/DataEntity.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/DataEntity.java
index a5d0467..3598d02 100644
--- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/DataEntity.java
+++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/DataEntity.java
@@ -1,7 +1,9 @@
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.elements.*;
@@ -49,8 +51,17 @@ public class DataEntity {
ExceptionCollector.appendException(String.format(
"TypeMismatchError: \"%s\" doesn't match \"%s\"",
value.toString(),dataType.getType()));
- }
- LinkedHashMap<String,Object> valueDict = (LinkedHashMap<String,Object>)value;
+
+ if (value instanceof List)
+ value = ((List) value).get(0);
+
+ if (!(value instanceof LinkedHashMap))
+ return value;
+ }
+
+
+
+ LinkedHashMap<String,Object> valueDict = (LinkedHashMap<String,Object>)value;
ArrayList<String> allowedProps = new ArrayList<>();
ArrayList<String> requiredProps = new ArrayList<>();
LinkedHashMap<String,Object> defaultProps = new LinkedHashMap<>();
diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/EntityTemplate.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/EntityTemplate.java
index 3d9c470..cb765ec 100644
--- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/EntityTemplate.java
+++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/EntityTemplate.java
@@ -351,7 +351,7 @@ public abstract class EntityTemplate {
else {
// Required properties in schema, but not in template
if(!requiredProps.isEmpty()) {
- ExceptionCollector.appendException(String.format(
+ ExceptionCollector.appendWarning(String.format(
"MissingRequiredFieldError2: properties of template \"%s\" are missing field(s): %s",
name,requiredProps.toString()));
}
diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java
index d1b0179..08b66bd 100644
--- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java
+++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java
@@ -1,5 +1,15 @@
package org.openecomp.sdc.toscaparser.api;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
import org.openecomp.sdc.toscaparser.api.common.JToscaException;
import org.openecomp.sdc.toscaparser.api.elements.EntityType;
@@ -12,11 +22,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.Yaml;
-import java.io.*;
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.Map;
-
public class ToscaTemplate extends Object {
private static Logger log = LoggerFactory.getLogger(ToscaTemplate.class.getName());
@@ -501,24 +506,42 @@ public class ToscaTemplate extends Object {
}
private void verifyTemplate() throws JToscaException {
- ArrayList<String> exceptionStrings = ExceptionCollector.getExceptionReport();
- if (exceptionStrings != null && exceptionStrings.size() > 0) {
- int nexc = ExceptionCollector.errorsCaught();
- log.error("ToscaTemplate - verifyTemplate - {} Parsing Exception{} occurred...", nexc, (nexc > 1 ? "s" : ""));
- for (String s : exceptionStrings) {
+ //Warnings
+ List<String> warningsStrings = ExceptionCollector.getWarningsReport();
+ if (warningsStrings != null && warningsStrings.size() > 0) {
+ int nexcw = ExceptionCollector.warningsCaught();
+ log.warn("####################################################################################################");
+ log.warn("ToscaTemplate - verifyTemplate - {} Parsing Warning{} occurred...", nexcw, (nexcw > 1 ? "s" : ""));
+ for (String s : warningsStrings) {
if (s != null) {
log.debug("ToscaTemplate - verifyTemplate - {}", s);
}
}
- if(bAbortOnParsingErrors) {
- throw new JToscaException("Aborting because of parsing errors");
+ log.warn("####################################################################################################");
+
+
+ List<String> exceptionStrings = ExceptionCollector.getCriticalsReport();
+ if (exceptionStrings != null && exceptionStrings.size() > 0) {
+ int nexc = ExceptionCollector.errorsCaught();
+ log.error("####################################################################################################");
+ log.error("ToscaTemplate - verifyTemplate - {} Parsing Critical{} occurred...", nexc, (nexc > 1 ? "s" : ""));
+ for (String s : exceptionStrings) {
+ if (s != null) {
+ log.debug("ToscaTemplate - verifyTemplate - {}", s);
+ }
+ }
+ log.error("####################################################################################################");
+ if(bAbortOnParsingErrors) {
+ throw new JToscaException("Aborting because of parsing errors");
+ }
+ }
+ else {
+ if (inputPath != null) {
+ log.debug("ToscaTemplate - verifyTemplate - The input {} passed validation", inputPath);
+ }
}
+
}
- else {
- if (inputPath != null) {
- log.debug("ToscaTemplate - verifyTemplate - The input {} passed validation", inputPath);
- }
- }
}
public String getPath() {
diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/common/ExceptionCollector.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/common/ExceptionCollector.java
index 07dabf8..b810e87 100644
--- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/common/ExceptionCollector.java
+++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/common/ExceptionCollector.java
@@ -1,6 +1,7 @@
package org.openecomp.sdc.toscaparser.api.common;
import java.util.ArrayList;
+import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -13,13 +14,15 @@ public class ExceptionCollector {
//private static boolean isCollecting = false;
private static ArrayList<String> exceptionStrings = new ArrayList<>();
- private static ArrayList<String> traceStrings = new ArrayList<>();
+ private static ArrayList<String> exceptionTraceStrings = new ArrayList<>();
+ private static ArrayList<String> warningStrings = new ArrayList<>();
+ private static ArrayList<String> warningTraceStrings = new ArrayList<>();
private static boolean bWantTrace = true;
/*public static void start() {
if(exceptionStrings == null) {
exceptionStrings = new ArrayList<String>();
- traceStrings = new ArrayList<String>();
+ exceptionTraceStrings = new ArrayList<String>();
}
isCollecting = true;
}*/
@@ -30,7 +33,9 @@ public class ExceptionCollector {
public static void clear() {
exceptionStrings = new ArrayList<>();
- traceStrings = new ArrayList<>();
+ exceptionTraceStrings = new ArrayList<>();
+ warningStrings = new ArrayList<>();
+ warningTraceStrings = new ArrayList<>();
}
public static void appendException(String strExc) { // throws Exception {
@@ -50,28 +55,67 @@ public class ExceptionCollector {
sb.append(String.format(" %s(%s:%d)%s",ste[i].getClassName(),ste[i].getFileName(),
ste[i].getLineNumber(),i==ste.length-1?" ":"\n"));
}
- traceStrings.add(sb.toString());
+ exceptionTraceStrings.add(sb.toString());
}
}
+
+ public static void appendWarning(String strExc) { // throws Exception {
- public static ArrayList<String> getExceptionReport() {
+ /*if(!isCollecting) {
+ // throw new Exception("Can't append exception " + strExc);
+ log.error("ExceptionCollector - appendException - Can't append exception {}", strExc);
+ }*/
+
+ if(!warningStrings.contains(strExc)) {
+ warningStrings.add(strExc);
+ // 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"));
+ }
+ warningTraceStrings.add(sb.toString());
+ }
+ }
+
+ public static List<String> getCriticalsReport() {
+
+ List<String> res = new ArrayList<>();
if(exceptionStrings.size() > 0) {
- ArrayList<String> report = new ArrayList<>();
for(int i=0; i<exceptionStrings.size(); i++) {
- report.add(exceptionStrings.get(i));
+ res.add(exceptionStrings.get(i));
+ if(bWantTrace) {
+ res.add(exceptionTraceStrings.get(i));
+ }
+ }
+ }
+ return res;
+ }
+
+ public static List<String> getWarningsReport() {
+
+ List<String> res = new ArrayList<>();
+ if(warningStrings.size() > 0) {
+ for(int i=0; i<warningStrings.size(); i++) {
+ res.add(warningStrings.get(i));
if(bWantTrace) {
- report.add(traceStrings.get(i));
+ res.add(warningTraceStrings.get(i));
}
}
- return report;
}
- return new ArrayList<>();
+ return res;
}
public static int errorsCaught() {
return exceptionStrings.size();
}
+ public static int warningsCaught() {
+ return warningStrings.size();
+ }
+
public static void setWantTrace(boolean b) {
bWantTrace = b;
}
diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/ScalarUnit.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/ScalarUnit.java
index 1150e19..5b17b9a 100644
--- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/ScalarUnit.java
+++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/ScalarUnit.java
@@ -86,9 +86,9 @@ public abstract class ScalarUnit {
ValidateUtils.strToNum(matcher.group(1));
String scalarUnit = _checkUnitInScalarStandardUnits(matcher.group(2));
value = matcher.group(1) + " " + scalarUnit;
- Object on1 = ValidateUtils.strToNum(matcher.group(1));
- Object on2 = SCALAR_UNIT_DICT.get(matcher.group(2));
- Object on3 = SCALAR_UNIT_DICT.get(unit);
+ Object on1 = ValidateUtils.strToNum(matcher.group(1)) != null ? ValidateUtils.strToNum(matcher.group(1)) : 0;
+ Object on2 = SCALAR_UNIT_DICT.get(matcher.group(2)) != null ? SCALAR_UNIT_DICT.get(matcher.group(2)) : 0;
+ Object on3 = SCALAR_UNIT_DICT.get(unit) != null ? SCALAR_UNIT_DICT.get(unit) : 0;
Double n1 = new Double(on1.toString());
Double n2 = new Double(on2.toString());
diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/Schema.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/Schema.java
index c21bd7b..5fa7547 100644
--- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/Schema.java
+++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/Schema.java
@@ -35,11 +35,12 @@ public class Schema {
public static final String VERSION = "version";
public static final String PORTDEF = "PortDef";
public static final String PORTSPEC = "PortSpec"; //??? PortSpec.SHORTNAME
+ public static final String JSON = "json";
public static final String PROPERTY_TYPES[] = {
INTEGER, STRING, BOOLEAN, FLOAT, RANGE,NUMBER, TIMESTAMP, LIST, MAP,
SCALAR_UNIT_SIZE, SCALAR_UNIT_FREQUENCY, SCALAR_UNIT_TIME,
- VERSION, PORTDEF, PORTSPEC};
+ VERSION, PORTDEF, PORTSPEC, JSON};
@SuppressWarnings("unused")
private static final String SCALAR_UNIT_SIZE_DEFAULT = "B";