aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/BooleanValidator.java40
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/DataTypeValidatorConverter.java772
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/FloatValidator.java48
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/HeatBooleanValidator.java50
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/HeatCommaDelimitedListValidator.java40
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/HeatNumberValidator.java50
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/HeatStringValidator.java40
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/IntegerValidator.java92
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/JsonValidator.java64
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/KeyValidator.java48
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/ListValidator.java255
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/MapValidator.java254
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/PropertyTypeValidator.java34
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/StringValidator.java109
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/ToscaBooleanValidator.java40
15 files changed, 961 insertions, 975 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/BooleanValidator.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/BooleanValidator.java
index def0e7c391..443334db52 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/BooleanValidator.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/BooleanValidator.java
@@ -20,36 +20,36 @@
package org.openecomp.sdc.be.model.tosca.validators;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+
import java.util.Arrays;
import java.util.Map;
-import org.openecomp.sdc.be.model.DataTypeDefinition;
-
public class BooleanValidator implements PropertyTypeValidator {
- private static BooleanValidator booleanValidator = new BooleanValidator();
- private static String[] validValues = { "true", "t", "on", "yes", "y", "1", "false", "f", "off", "no", "n", "0" };
+ private static BooleanValidator booleanValidator = new BooleanValidator();
+ private static String[] validValues = { "true", "t", "on", "yes", "y", "1", "false", "f", "off", "no", "n", "0" };
- public static BooleanValidator getInstance() {
- return booleanValidator;
- }
+ public static BooleanValidator getInstance() {
+ return booleanValidator;
+ }
- private BooleanValidator() {
+ private BooleanValidator() {
- }
+ }
- @Override
- public boolean isValid(String value, String innerType, Map<String, DataTypeDefinition> allDataTypes) {
+ @Override
+ public boolean isValid(String value, String innerType, Map<String, DataTypeDefinition> allDataTypes) {
- if (value == null || true == value.isEmpty()) {
- return true;
- }
+ if (value == null || value.isEmpty()) {
+ return true;
+ }
- return (Arrays.stream(validValues).filter(str -> str.equalsIgnoreCase(value)).toArray().length == 1);
- }
+ return (Arrays.stream(validValues).filter(str -> str.equalsIgnoreCase(value)).toArray().length == 1);
+ }
- @Override
- public boolean isValid(String value, String innerType) {
- return isValid(value, null, null);
- }
+ @Override
+ public boolean isValid(String value, String innerType) {
+ return isValid(value, null, null);
+ }
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/DataTypeValidatorConverter.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/DataTypeValidatorConverter.java
index ed58bc221b..c64e47a14a 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/DataTypeValidatorConverter.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/DataTypeValidatorConverter.java
@@ -20,420 +20,414 @@
package org.openecomp.sdc.be.model.tosca.validators;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
+import com.google.gson.*;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
import org.openecomp.sdc.be.model.tosca.converters.PropertyValueConverter;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.openecomp.sdc.common.log.wrappers.Logger;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
-import com.google.gson.JsonPrimitive;
-import com.google.gson.JsonSyntaxException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
public class DataTypeValidatorConverter {
- private static DataTypeValidatorConverter dataTypeValidatorConverter = new DataTypeValidatorConverter();
+ private static DataTypeValidatorConverter dataTypeValidatorConverter = new DataTypeValidatorConverter();
- public static DataTypeValidatorConverter getInstance() {
- return dataTypeValidatorConverter;
- }
+ public static DataTypeValidatorConverter getInstance() {
+ return dataTypeValidatorConverter;
+ }
- private DataTypeValidatorConverter() {
+ private DataTypeValidatorConverter() {
- }
+ }
- private static Logger log = LoggerFactory.getLogger(DataTypeValidatorConverter.class.getName());
+ private static final Logger log = Logger.getLogger(DataTypeValidatorConverter.class.getName());
- JsonParser jsonParser = new JsonParser();
+ JsonParser jsonParser = new JsonParser();
- ImmutablePair<JsonElement, Boolean> falseResult = new ImmutablePair<JsonElement, Boolean>(null, false);
- ImmutablePair<JsonElement, Boolean> trueEmptyResult = new ImmutablePair<JsonElement, Boolean>(null, true);
+ ImmutablePair<JsonElement, Boolean> falseResult = new ImmutablePair<>(null, false);
+ ImmutablePair<JsonElement, Boolean> trueEmptyResult = new ImmutablePair<>(null, true);
- ImmutablePair<String, Boolean> trueStringEmptyResult = new ImmutablePair<String, Boolean>(null, true);
- ImmutablePair<String, Boolean> falseStringEmptyResult = new ImmutablePair<String, Boolean>(null, true);
+ ImmutablePair<String, Boolean> trueStringEmptyResult = new ImmutablePair<>(null, true);
+ ImmutablePair<String, Boolean> falseStringEmptyResult = new ImmutablePair<>(null, true);
- private ToscaPropertyType isDataTypeDerviedFromScalarType(DataTypeDefinition dataTypeDef) {
+ private ToscaPropertyType isDataTypeDerviedFromScalarType(DataTypeDefinition dataTypeDef) {
- ToscaPropertyType result = null;
+ ToscaPropertyType result = null;
- DataTypeDefinition dataType = dataTypeDef;
+ DataTypeDefinition dataType = dataTypeDef;
- while (dataType != null) {
+ while (dataType != null) {
- String name = dataType.getName();
- ToscaPropertyType typeIfScalar = ToscaPropertyType.getTypeIfScalar(name);
- if (typeIfScalar != null) {
- result = typeIfScalar;
- break;
- }
+ String name = dataType.getName();
+ ToscaPropertyType typeIfScalar = ToscaPropertyType.getTypeIfScalar(name);
+ if (typeIfScalar != null) {
+ result = typeIfScalar;
+ break;
+ }
- dataType = dataType.getDerivedFrom();
- }
+ dataType = dataType.getDerivedFrom();
+ }
- return result;
- }
+ return result;
+ }
- private ImmutablePair<JsonElement, Boolean> validateAndUpdate(JsonElement jsonElement, DataTypeDefinition dataTypeDefinition, Map<String, DataTypeDefinition> allDataTypes) {
-
- Map<String, PropertyDefinition> allProperties = getAllProperties(dataTypeDefinition);
-
- ToscaPropertyType toscaPropertyType = null;
- if ((toscaPropertyType = isDataTypeDerviedFromScalarType(dataTypeDefinition)) != null) {
-
- PropertyTypeValidator validator = toscaPropertyType.getValidator();
- PropertyValueConverter converter = toscaPropertyType.getConverter();
- if (jsonElement == null || true == jsonElement.isJsonNull()) {
- boolean valid = validator.isValid(null, null, allDataTypes);
- if (!valid) {
- log.trace("Failed in validation of property {} from type {}", dataTypeDefinition.getName(), dataTypeDefinition.getName());
- return falseResult;
- }
- return new ImmutablePair<JsonElement, Boolean>(jsonElement, true);
-
- } else {
- if (jsonElement.isJsonPrimitive()) {
- String value = null;
- if (jsonElement != null) {
- if (jsonElement.toString().isEmpty()) {
- value = "";
- } else {
- value = jsonElement.toString();
- }
- }
- boolean valid = validator.isValid(value, null, null);
- if (!valid) {
- log.trace("Failed in validation of property {} from type {}. Json primitive value is {}", dataTypeDefinition.getName(), dataTypeDefinition.getName(), value);
- return falseResult;
- }
-
- String convertedValue = converter.convert(value, null, allDataTypes);
- JsonElement element = null;
- try {
- element = jsonParser.parse(convertedValue);
- } catch (JsonSyntaxException e) {
- log.debug("Failed to parse value {} of property {} {}", convertedValue, dataTypeDefinition.getName(), e);
- return falseResult;
- }
-
- return new ImmutablePair<JsonElement, Boolean>(element, true);
-
- } else {
- // MAP, LIST, OTHER types cannot be applied data type
- // definition scalar type. We currently cannot derived from
- // map/list. (cannot add the entry schema to it)
- log.debug("We cannot derive from list/map. Thus, the value cannot be not primitive since the data type {} is scalar one", dataTypeDefinition.getName());
-
- return falseResult;
- }
- }
- } else {
-
- if (jsonElement == null || jsonElement.isJsonNull()) {
-
- return new ImmutablePair<JsonElement, Boolean>(jsonElement, true);
-
- } else {
-
- if (jsonElement.isJsonObject()) {
-
- JsonObject buildJsonObject = new JsonObject();
-
- JsonObject asJsonObject = jsonElement.getAsJsonObject();
- Set<Entry<String, JsonElement>> entrySet = asJsonObject.entrySet();
-
- for (Entry<String, JsonElement> entry : entrySet) {
- String propName = entry.getKey();
-
- JsonElement elementValue = entry.getValue();
-
- PropertyDefinition propertyDefinition = allProperties.get(propName);
- if (propertyDefinition == null) {
- log.debug("The property {} was not found under data type {}" ,propName, dataTypeDefinition.getName());
- return falseResult;
- }
- String type = propertyDefinition.getType();
- boolean isScalarType = ToscaPropertyType.isScalarType(type);
-
- if (isScalarType) {
- ToscaPropertyType propertyType = ToscaPropertyType.isValidType(type);
- if (propertyType == null) {
- log.debug("cannot find the {} under default tosca property types", type);
- return falseResult;
- }
- PropertyTypeValidator validator = propertyType.getValidator();
- String innerType = null;
- if (propertyType == ToscaPropertyType.LIST || propertyType == ToscaPropertyType.MAP) {
- if (propertyDefinition.getSchema() != null && propertyDefinition.getSchema().getProperty() != null) {
- innerType = propertyDefinition.getSchema().getProperty().getType();
- if (innerType == null) {
- log.debug("Property type {} must have inner type in its declaration.", propertyType);
- return falseResult;
- }
- }
- }
-
- String value = null;
- if (elementValue != null) {
- if (elementValue.isJsonPrimitive() && elementValue.getAsString().isEmpty()) {
- value = "";
- } else {
- value = elementValue.toString();
- }
- }
-
- boolean isValid = validator.isValid(value, innerType, allDataTypes);
- if (false == isValid) {
- log.debug("Failed to validate the value {} from type {}", value, propertyType);
- return falseResult;
- }
-
- PropertyValueConverter converter = propertyType.getConverter();
- String convertedValue = converter.convert(value, innerType, allDataTypes);
-
- JsonElement element = null;
- if (convertedValue != null) {
- if (convertedValue.isEmpty()) {
- element = new JsonPrimitive("");
- } else {
- try {
- element = jsonParser.parse(convertedValue);
- } catch (JsonSyntaxException e) {
- log.debug("Failed to parse value {} of type {}", convertedValue, propertyType, e);
- return falseResult;
- }
- }
- }
- buildJsonObject.add(propName, element);
-
- } else {
-
- DataTypeDefinition typeDefinition = allDataTypes.get(type);
- if (typeDefinition == null) {
- log.debug("The data type {} cannot be found in the given data type list.", type);
- return falseResult;
- }
+ private ImmutablePair<JsonElement, Boolean> validateAndUpdate(JsonElement jsonElement, DataTypeDefinition dataTypeDefinition, Map<String, DataTypeDefinition> allDataTypes) {
+
+ Map<String, PropertyDefinition> allProperties = getAllProperties(dataTypeDefinition);
+
+ ToscaPropertyType toscaPropertyType = null;
+ if ((toscaPropertyType = isDataTypeDerviedFromScalarType(dataTypeDefinition)) != null) {
+
+ PropertyTypeValidator validator = toscaPropertyType.getValidator();
+ PropertyValueConverter converter = toscaPropertyType.getConverter();
+ if (jsonElement == null || jsonElement.isJsonNull()) {
+ boolean valid = validator.isValid(null, null, allDataTypes);
+ if (!valid) {
+ log.trace("Failed in validation of property {} from type {}", dataTypeDefinition.getName(), dataTypeDefinition.getName());
+ return falseResult;
+ }
+ return new ImmutablePair<>(jsonElement, true);
+
+ } else {
+ if (jsonElement.isJsonPrimitive()) {
+ String value = null;
+ if (jsonElement != null) {
+ if (jsonElement.toString().isEmpty()) {
+ value = "";
+ } else {
+ value = jsonElement.toString();
+ }
+ }
+ boolean valid = validator.isValid(value, null, null);
+ if (!valid) {
+ log.trace("Failed in validation of property {} from type {}. Json primitive value is {}", dataTypeDefinition.getName(), dataTypeDefinition.getName(), value);
+ return falseResult;
+ }
+
+ String convertedValue = converter.convert(value, null, allDataTypes);
+ JsonElement element = null;
+ try {
+ element = jsonParser.parse(convertedValue);
+ } catch (JsonSyntaxException e) {
+ log.debug("Failed to parse value {} of property {} {}", convertedValue, dataTypeDefinition.getName(), e);
+ return falseResult;
+ }
+
+ return new ImmutablePair<>(element, true);
+
+ } else {
+ // MAP, LIST, OTHER types cannot be applied data type
+ // definition scalar type. We currently cannot derived from
+ // map/list. (cannot add the entry schema to it)
+ log.debug("We cannot derive from list/map. Thus, the value cannot be not primitive since the data type {} is scalar one", dataTypeDefinition.getName());
+
+ return falseResult;
+ }
+ }
+ } else {
+
+ if (jsonElement == null || jsonElement.isJsonNull()) {
+
+ return new ImmutablePair<>(jsonElement, true);
+
+ } else {
+
+ if (jsonElement.isJsonObject()) {
+
+ JsonObject buildJsonObject = new JsonObject();
+
+ JsonObject asJsonObject = jsonElement.getAsJsonObject();
+ Set<Entry<String, JsonElement>> entrySet = asJsonObject.entrySet();
+
+ for (Entry<String, JsonElement> entry : entrySet) {
+ String propName = entry.getKey();
+
+ JsonElement elementValue = entry.getValue();
+
+ PropertyDefinition propertyDefinition = allProperties.get(propName);
+ if (propertyDefinition == null) {
+ log.debug("The property {} was not found under data type {}" ,propName, dataTypeDefinition.getName());
+ return falseResult;
+ }
+ String type = propertyDefinition.getType();
+ boolean isScalarType = ToscaPropertyType.isScalarType(type);
+
+ if (isScalarType) {
+ ToscaPropertyType propertyType = ToscaPropertyType.isValidType(type);
+ if (propertyType == null) {
+ log.debug("cannot find the {} under default tosca property types", type);
+ return falseResult;
+ }
+ PropertyTypeValidator validator = propertyType.getValidator();
+ String innerType = null;
+ if (propertyType == ToscaPropertyType.LIST || propertyType == ToscaPropertyType.MAP) {
+ if (propertyDefinition.getSchema() != null && propertyDefinition.getSchema().getProperty() != null) {
+ innerType = propertyDefinition.getSchema().getProperty().getType();
+ if (innerType == null) {
+ log.debug("Property type {} must have inner type in its declaration.", propertyType);
+ return falseResult;
+ }
+ }
+ }
+
+ String value = null;
+ if (elementValue != null) {
+ if (elementValue.isJsonPrimitive() && elementValue.getAsString().isEmpty()) {
+ value = "";
+ } else {
+ value = elementValue.toString();
+ }
+ }
+
+ boolean isValid = validator.isValid(value, innerType, allDataTypes);
+ if (!isValid) {
+ log.debug("Failed to validate the value {} from type {}", value, propertyType);
+ return falseResult;
+ }
+
+ PropertyValueConverter converter = propertyType.getConverter();
+ String convertedValue = converter.convert(value, innerType, allDataTypes);
+
+ JsonElement element = null;
+ if (convertedValue != null) {
+ if (convertedValue.isEmpty()) {
+ element = new JsonPrimitive("");
+ } else {
+ try {
+ element = jsonParser.parse(convertedValue);
+ } catch (JsonSyntaxException e) {
+ log.debug("Failed to parse value {} of type {}", convertedValue, propertyType, e);
+ return falseResult;
+ }
+ }
+ }
+ buildJsonObject.add(propName, element);
+
+ } else {
+
+ DataTypeDefinition typeDefinition = allDataTypes.get(type);
+ if (typeDefinition == null) {
+ log.debug("The data type {} cannot be found in the given data type list.", type);
+ return falseResult;
+ }
- ImmutablePair<JsonElement, Boolean> isValid = validateAndUpdate(elementValue, typeDefinition, allDataTypes);
+ ImmutablePair<JsonElement, Boolean> isValid = validateAndUpdate(elementValue, typeDefinition, allDataTypes);
- if (!isValid.getRight().booleanValue()) {
- log.debug("Failed in validation of value {} from type {}", (elementValue != null ? elementValue.toString() : null), typeDefinition.getName());
- return falseResult;
- }
-
- buildJsonObject.add(propName, isValid.getLeft());
- }
-
- }
-
- return new ImmutablePair<JsonElement, Boolean>(buildJsonObject, true);
- } else {
- log.debug("The value {} of type {} should be json object", (jsonElement != null ? jsonElement.toString() : null), dataTypeDefinition.getName());
- return falseResult;
- }
-
- }
- }
-
- }
-
- public ImmutablePair<JsonElement, Boolean> validateAndUpdate(String value, DataTypeDefinition dataTypeDefinition, Map<String, DataTypeDefinition> allDataTypes) {
-
- ImmutablePair<JsonElement, Boolean> result = falseResult;
-
- if (value == null || value.isEmpty()) {
- return trueEmptyResult;
- }
-
- JsonElement jsonElement = null;
- try {
- jsonElement = jsonParser.parse(value);
- } catch (JsonSyntaxException e) {
- return falseResult;
- }
-
- result = validateAndUpdate(jsonElement, dataTypeDefinition, allDataTypes);
-
- return result;
- }
-
- private Map<String, PropertyDefinition> getAllProperties(DataTypeDefinition dataTypeDefinition) {
-
- Map<String, PropertyDefinition> allParentsProps = new HashMap<String, PropertyDefinition>();
-
- while (dataTypeDefinition != null) {
-
- List<PropertyDefinition> currentParentsProps = dataTypeDefinition.getProperties();
- if (currentParentsProps != null) {
- currentParentsProps.stream().forEach(p -> allParentsProps.put(p.getName(), p));
- }
-
- dataTypeDefinition = dataTypeDefinition.getDerivedFrom();
- }
-
- return allParentsProps;
- }
-
- public boolean isValid(String value, DataTypeDefinition dataTypeDefinition, Map<String, DataTypeDefinition> allDataTypes) {
-
- boolean result = false;
-
- if (value == null || value.isEmpty()) {
- return true;
- }
-
- JsonElement jsonElement = null;
- try {
- jsonElement = jsonParser.parse(value);
- } catch (JsonSyntaxException e) {
- log.debug("Failed to parse the value {} from type {}", value, dataTypeDefinition, e);
- return false;
- }
-
- result = isValid(jsonElement, dataTypeDefinition, allDataTypes);
-
- return result;
- }
-
- private boolean isValid(JsonElement jsonElement, DataTypeDefinition dataTypeDefinition, Map<String, DataTypeDefinition> allDataTypes) {
-
- Map<String, PropertyDefinition> allProperties = getAllProperties(dataTypeDefinition);
-
- ToscaPropertyType toscaPropertyType = null;
- if ((toscaPropertyType = isDataTypeDerviedFromScalarType(dataTypeDefinition)) != null) {
-
- PropertyTypeValidator validator = toscaPropertyType.getValidator();
- if (jsonElement == null || true == jsonElement.isJsonNull()) {
- boolean valid = validator.isValid(null, null, allDataTypes);
- if (false == valid) {
- log.trace("Failed in validation of property {} from type {}", dataTypeDefinition.getName(), dataTypeDefinition.getName());
- return false;
- }
-
- return true;
-
- } else {
- if (true == jsonElement.isJsonPrimitive()) {
- String value = null;
- if (jsonElement != null) {
- if (jsonElement.toString().isEmpty()) {
- value = "";
- } else {
- value = jsonElement.toString();
- }
- }
- boolean valid = validator.isValid(value, null, allDataTypes);
- if (false == valid) {
- log.trace("Failed in validation of property {} from type {}. Json primitive value is {}", dataTypeDefinition.getName(), dataTypeDefinition.getName(), value);
- return false;
- }
-
- return true;
+ if (!isValid.getRight().booleanValue()) {
+ log.debug("Failed in validation of value {} from type {}", (elementValue != null ? elementValue.toString() : null), typeDefinition.getName());
+ return falseResult;
+ }
+
+ buildJsonObject.add(propName, isValid.getLeft());
+ }
+
+ }
+
+ return new ImmutablePair<>(buildJsonObject, true);
+ } else {
+ log.debug("The value {} of type {} should be json object", (jsonElement != null ? jsonElement.toString() : null), dataTypeDefinition.getName());
+ return falseResult;
+ }
+
+ }
+ }
+
+ }
+
+ public ImmutablePair<JsonElement, Boolean> validateAndUpdate(String value, DataTypeDefinition dataTypeDefinition, Map<String, DataTypeDefinition> allDataTypes) {
+
+ ImmutablePair<JsonElement, Boolean> result = falseResult;
+
+ if (value == null || value.isEmpty()) {
+ return trueEmptyResult;
+ }
+
+ JsonElement jsonElement = null;
+ try {
+ jsonElement = jsonParser.parse(value);
+ } catch (JsonSyntaxException e) {
+ return falseResult;
+ }
+
+ result = validateAndUpdate(jsonElement, dataTypeDefinition, allDataTypes);
+
+ return result;
+ }
+
+ private Map<String, PropertyDefinition> getAllProperties(DataTypeDefinition dataTypeDefinition) {
+
+ Map<String, PropertyDefinition> allParentsProps = new HashMap<>();
+
+ while (dataTypeDefinition != null) {
+
+ List<PropertyDefinition> currentParentsProps = dataTypeDefinition.getProperties();
+ if (currentParentsProps != null) {
+ currentParentsProps.stream().forEach(p -> allParentsProps.put(p.getName(), p));
+ }
+
+ dataTypeDefinition = dataTypeDefinition.getDerivedFrom();
+ }
+
+ return allParentsProps;
+ }
+
+ public boolean isValid(String value, DataTypeDefinition dataTypeDefinition, Map<String, DataTypeDefinition> allDataTypes) {
+
+ boolean result = false;
+
+ if (value == null || value.isEmpty()) {
+ return true;
+ }
+
+ JsonElement jsonElement = null;
+ try {
+ jsonElement = jsonParser.parse(value);
+ } catch (JsonSyntaxException e) {
+ log.debug("Failed to parse the value {} from type {}", value, dataTypeDefinition, e);
+ return false;
+ }
+
+ result = isValid(jsonElement, dataTypeDefinition, allDataTypes);
+
+ return result;
+ }
+
+ private boolean isValid(JsonElement jsonElement, DataTypeDefinition dataTypeDefinition, Map<String, DataTypeDefinition> allDataTypes) {
+
+ Map<String, PropertyDefinition> allProperties = getAllProperties(dataTypeDefinition);
+
+ ToscaPropertyType toscaPropertyType = null;
+ if ((toscaPropertyType = isDataTypeDerviedFromScalarType(dataTypeDefinition)) != null) {
+
+ PropertyTypeValidator validator = toscaPropertyType.getValidator();
+ if (jsonElement == null || jsonElement.isJsonNull()) {
+ boolean valid = validator.isValid(null, null, allDataTypes);
+ if (!valid) {
+ log.trace("Failed in validation of property {} from type {}", dataTypeDefinition.getName(), dataTypeDefinition.getName());
+ return false;
+ }
+
+ return true;
+
+ } else {
+ if (jsonElement.isJsonPrimitive()) {
+ String value = null;
+ if (jsonElement != null) {
+ if (jsonElement.toString().isEmpty()) {
+ value = "";
+ } else {
+ value = jsonElement.toString();
+ }
+ }
+ boolean valid = validator.isValid(value, null, allDataTypes);
+ if (!valid) {
+ log.trace("Failed in validation of property {} from type {}. Json primitive value is {}", dataTypeDefinition.getName(), dataTypeDefinition.getName(), value);
+ return false;
+ }
+
+ return true;
- } else {
- // MAP, LIST, OTHER types cannot be applied data type
- // definition scalar type. We currently cannot derived from
- // map/list. (cannot add the entry schema to it)
- log.debug("We cannot derive from list/map. Thus, the value cannot be not primitive since the data type {} is scalar one", dataTypeDefinition.getName());
-
- return false;
- }
- }
- } else {
-
- if (jsonElement == null || jsonElement.isJsonNull()) {
-
- return true;
-
- } else {
-
- if (jsonElement.isJsonObject()) {
-
- JsonObject asJsonObject = jsonElement.getAsJsonObject();
- Set<Entry<String, JsonElement>> entrySet = asJsonObject.entrySet();
-
- for (Entry<String, JsonElement> entry : entrySet) {
- String propName = entry.getKey();
-
- JsonElement elementValue = entry.getValue();
-
- PropertyDefinition propertyDefinition = allProperties.get(propName);
- if (propertyDefinition == null) {
- log.debug("The property {} was not found under data type {}", propName, dataTypeDefinition.getName());
- return false;
- }
- String type = propertyDefinition.getType();
- boolean isScalarType = ToscaPropertyType.isScalarType(type);
-
- if (true == isScalarType) {
- ToscaPropertyType propertyType = ToscaPropertyType.isValidType(type);
- if (propertyType == null) {
- log.debug("cannot find the {} under default tosca property types", type);
- return false;
- }
- PropertyTypeValidator validator = propertyType.getValidator();
- String innerType = null;
- if (propertyType == ToscaPropertyType.LIST || propertyType == ToscaPropertyType.MAP) {
- if (propertyDefinition.getSchema() != null && propertyDefinition.getSchema().getProperty() != null) {
- innerType = propertyDefinition.getSchema().getProperty().getType();
- if (innerType == null) {
- log.debug("Property type {} must have inner type in its declaration.", propertyType);
- return false;
- }
- }
- }
-
- String value = null;
- if (elementValue != null) {
- if (elementValue.isJsonPrimitive() && elementValue.getAsString().isEmpty()) {
- value = "";
- } else {
- value = elementValue.toString();
- }
- }
-
- boolean isValid = validator.isValid(value, innerType, allDataTypes);
- if (false == isValid) {
- log.debug("Failed to validate the value {} from type {}", value, propertyType);
- return false;
- }
-
- } else {
-
- DataTypeDefinition typeDefinition = allDataTypes.get(type);
- if (typeDefinition == null) {
- log.debug("The data type {} cannot be found in the given data type list.", type);
- return false;
- }
-
- boolean isValid = isValid(elementValue, typeDefinition, allDataTypes);
-
- if (false == isValid) {
- log.debug("Failed in validation of value {} from type {}", (elementValue != null ? elementValue.toString() : null), typeDefinition.getName());
- return false;
- }
-
- }
-
- }
-
- return true;
- } else {
- log.debug("The value {} of type {} should be json object", (jsonElement != null ? jsonElement.toString() : null), dataTypeDefinition.getName());
- return false;
- }
-
- }
- }
-
- }
+ } else {
+ // MAP, LIST, OTHER types cannot be applied data type
+ // definition scalar type. We currently cannot derived from
+ // map/list. (cannot add the entry schema to it)
+ log.debug("We cannot derive from list/map. Thus, the value cannot be not primitive since the data type {} is scalar one", dataTypeDefinition.getName());
+
+ return false;
+ }
+ }
+ } else {
+
+ if (jsonElement == null || jsonElement.isJsonNull()) {
+
+ return true;
+
+ } else {
+
+ if (jsonElement.isJsonObject()) {
+
+ JsonObject asJsonObject = jsonElement.getAsJsonObject();
+ Set<Entry<String, JsonElement>> entrySet = asJsonObject.entrySet();
+
+ for (Entry<String, JsonElement> entry : entrySet) {
+ String propName = entry.getKey();
+
+ JsonElement elementValue = entry.getValue();
+
+ PropertyDefinition propertyDefinition = allProperties.get(propName);
+ if (propertyDefinition == null) {
+ log.debug("The property {} was not found under data type {}", propName, dataTypeDefinition.getName());
+ return false;
+ }
+ String type = propertyDefinition.getType();
+ boolean isScalarType = ToscaPropertyType.isScalarType(type);
+
+ if (isScalarType) {
+ ToscaPropertyType propertyType = ToscaPropertyType.isValidType(type);
+ if (propertyType == null) {
+ log.debug("cannot find the {} under default tosca property types", type);
+ return false;
+ }
+ PropertyTypeValidator validator = propertyType.getValidator();
+ String innerType = null;
+ if (propertyType == ToscaPropertyType.LIST || propertyType == ToscaPropertyType.MAP) {
+ if (propertyDefinition.getSchema() != null && propertyDefinition.getSchema().getProperty() != null) {
+ innerType = propertyDefinition.getSchema().getProperty().getType();
+ if (innerType == null) {
+ log.debug("Property type {} must have inner type in its declaration.", propertyType);
+ return false;
+ }
+ }
+ }
+
+ String value = null;
+ if (elementValue != null) {
+ if (elementValue.isJsonPrimitive() && elementValue.getAsString().isEmpty()) {
+ value = "";
+ } else {
+ value = elementValue.toString();
+ }
+ }
+
+ boolean isValid = validator.isValid(value, innerType, allDataTypes);
+ if (!isValid) {
+ log.debug("Failed to validate the value {} from type {}", value, propertyType);
+ return false;
+ }
+
+ } else {
+
+ DataTypeDefinition typeDefinition = allDataTypes.get(type);
+ if (typeDefinition == null) {
+ log.debug("The data type {} cannot be found in the given data type list.", type);
+ return false;
+ }
+
+ boolean isValid = isValid(elementValue, typeDefinition, allDataTypes);
+
+ if (!isValid) {
+ log.debug("Failed in validation of value {} from type {}", (elementValue != null ? elementValue.toString() : null), typeDefinition.getName());
+ return false;
+ }
+
+ }
+
+ }
+
+ return true;
+ } else {
+ log.debug("The value {} of type {} should be json object", (jsonElement != null ? jsonElement.toString() : null), dataTypeDefinition.getName());
+ return false;
+ }
+
+ }
+ }
+
+ }
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/FloatValidator.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/FloatValidator.java
index 2518eaa51e..f9121d17ca 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/FloatValidator.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/FloatValidator.java
@@ -20,41 +20,41 @@
package org.openecomp.sdc.be.model.tosca.validators;
-import java.util.Map;
-
import org.openecomp.sdc.be.model.DataTypeDefinition;
+import java.util.Map;
+
public class FloatValidator implements PropertyTypeValidator {
- private static FloatValidator FloatValidator = new FloatValidator();
+ private static FloatValidator FloatValidator = new FloatValidator();
- public static FloatValidator getInstance() {
- return FloatValidator;
- }
+ public static FloatValidator getInstance() {
+ return FloatValidator;
+ }
- private FloatValidator() {
+ private FloatValidator() {
- }
+ }
- @Override
- public boolean isValid(String value, String innerType, Map<String, DataTypeDefinition> allDataTypes) {
+ @Override
+ public boolean isValid(String value, String innerType, Map<String, DataTypeDefinition> allDataTypes) {
- if (value == null || true == value.isEmpty()) {
- return true;
- }
+ if (value == null || value.isEmpty()) {
+ return true;
+ }
- try {
- Float.parseFloat(value);
- } catch (IllegalArgumentException e) {
- return false;
- }
+ try {
+ Float.parseFloat(value);
+ } catch (IllegalArgumentException e) {
+ return false;
+ }
- return true;
- }
+ return true;
+ }
- @Override
- public boolean isValid(String value, String innerType) {
- return isValid(value, innerType, null);
- }
+ @Override
+ public boolean isValid(String value, String innerType) {
+ return isValid(value, innerType, null);
+ }
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/HeatBooleanValidator.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/HeatBooleanValidator.java
index ec4051e65c..f527206270 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/HeatBooleanValidator.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/HeatBooleanValidator.java
@@ -20,42 +20,42 @@
package org.openecomp.sdc.be.model.tosca.validators;
-import java.util.Map;
-
import org.openecomp.sdc.be.model.DataTypeDefinition;
+import java.util.Map;
+
public class HeatBooleanValidator implements PropertyTypeValidator {
- private static HeatBooleanValidator booleanValidator = new HeatBooleanValidator();
+ private static HeatBooleanValidator booleanValidator = new HeatBooleanValidator();
- public static HeatBooleanValidator getInstance() {
- return booleanValidator;
- }
+ public static HeatBooleanValidator getInstance() {
+ return booleanValidator;
+ }
- private HeatBooleanValidator() {
+ private HeatBooleanValidator() {
- }
+ }
- @Override
- public boolean isValid(String value, String innerType, Map<String, DataTypeDefinition> allDataTypes) {
+ @Override
+ public boolean isValid(String value, String innerType, Map<String, DataTypeDefinition> allDataTypes) {
- if (value == null || true == value.isEmpty()) {
- return true;
- }
+ if (value == null || value.isEmpty()) {
+ return true;
+ }
- if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false") || value.equalsIgnoreCase("t")
- || value.equalsIgnoreCase("f") || value.equalsIgnoreCase("on") || value.equalsIgnoreCase("off")
- || value.equalsIgnoreCase("yes") || value.equalsIgnoreCase("no") || value.equalsIgnoreCase("y")
- || value.equalsIgnoreCase("n") || value.equalsIgnoreCase("1") || value.equalsIgnoreCase("0")) {
- return true;
- }
+ if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false") || value.equalsIgnoreCase("t")
+ || value.equalsIgnoreCase("f") || value.equalsIgnoreCase("on") || value.equalsIgnoreCase("off")
+ || value.equalsIgnoreCase("yes") || value.equalsIgnoreCase("no") || value.equalsIgnoreCase("y")
+ || value.equalsIgnoreCase("n") || value.equalsIgnoreCase("1") || value.equalsIgnoreCase("0")) {
+ return true;
+ }
- return false;
- }
+ return false;
+ }
- @Override
- public boolean isValid(String value, String innerType) {
- return isValid(value, innerType, null);
- }
+ @Override
+ public boolean isValid(String value, String innerType) {
+ return isValid(value, innerType, null);
+ }
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/HeatCommaDelimitedListValidator.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/HeatCommaDelimitedListValidator.java
index 464dbf0975..6a2a13402b 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/HeatCommaDelimitedListValidator.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/HeatCommaDelimitedListValidator.java
@@ -20,36 +20,36 @@
package org.openecomp.sdc.be.model.tosca.validators;
-import java.util.Map;
-
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.common.util.ValidationUtils;
+import java.util.Map;
+
public class HeatCommaDelimitedListValidator implements PropertyTypeValidator {
- private static HeatCommaDelimitedListValidator stringValidator = new HeatCommaDelimitedListValidator();
+ private static HeatCommaDelimitedListValidator stringValidator = new HeatCommaDelimitedListValidator();
- public static HeatCommaDelimitedListValidator getInstance() {
- return stringValidator;
- }
+ public static HeatCommaDelimitedListValidator getInstance() {
+ return stringValidator;
+ }
- private HeatCommaDelimitedListValidator() {
+ private HeatCommaDelimitedListValidator() {
- }
+ }
- @Override
- public boolean isValid(String value, String innerType, Map<String, DataTypeDefinition> allDataTypes) {
+ @Override
+ public boolean isValid(String value, String innerType, Map<String, DataTypeDefinition> allDataTypes) {
- if (value == null || true == value.isEmpty()) {
- return true;
- }
+ if (value == null || value.isEmpty()) {
+ return true;
+ }
- String coverted = ValidationUtils.removeNoneUtf8Chars(value);
- return ValidationUtils.validateIsEnglish(coverted);
- }
+ String coverted = ValidationUtils.removeNoneUtf8Chars(value);
+ return ValidationUtils.validateIsEnglish(coverted);
+ }
- @Override
- public boolean isValid(String value, String innerType) {
- return isValid(value, innerType, null);
- }
+ @Override
+ public boolean isValid(String value, String innerType) {
+ return isValid(value, innerType, null);
+ }
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/HeatNumberValidator.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/HeatNumberValidator.java
index 37c4a46829..0ae3f74c85 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/HeatNumberValidator.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/HeatNumberValidator.java
@@ -20,42 +20,42 @@
package org.openecomp.sdc.be.model.tosca.validators;
-import java.util.Map;
-
import org.openecomp.sdc.be.model.DataTypeDefinition;
+import java.util.Map;
+
public class HeatNumberValidator implements PropertyTypeValidator {
- private static HeatNumberValidator numberValidator = new HeatNumberValidator();
+ private static HeatNumberValidator numberValidator = new HeatNumberValidator();
- private static FloatValidator floatValidator = FloatValidator.getInstance();
- private static IntegerValidator integerValidator = IntegerValidator.getInstance();
+ private static FloatValidator floatValidator = FloatValidator.getInstance();
+ private static IntegerValidator integerValidator = IntegerValidator.getInstance();
- public static HeatNumberValidator getInstance() {
- return numberValidator;
- }
+ public static HeatNumberValidator getInstance() {
+ return numberValidator;
+ }
- private HeatNumberValidator() {
+ private HeatNumberValidator() {
- }
+ }
- @Override
- public boolean isValid(String value, String innerType, Map<String, DataTypeDefinition> allDataTypes) {
+ @Override
+ public boolean isValid(String value, String innerType, Map<String, DataTypeDefinition> allDataTypes) {
- if (value == null || true == value.isEmpty()) {
- return true;
- }
- boolean valid = integerValidator.isValid(value, null, allDataTypes);
+ if (value == null || value.isEmpty()) {
+ return true;
+ }
+ boolean valid = integerValidator.isValid(value, null, allDataTypes);
- if (!valid) {
- valid = floatValidator.isValid(value, null, allDataTypes);
- }
+ if (!valid) {
+ valid = floatValidator.isValid(value, null, allDataTypes);
+ }
- return valid;
- }
+ return valid;
+ }
- @Override
- public boolean isValid(String value, String innerType) {
- return isValid(value, innerType, null);
- }
+ @Override
+ public boolean isValid(String value, String innerType) {
+ return isValid(value, innerType, null);
+ }
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/HeatStringValidator.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/HeatStringValidator.java
index 8c63090e03..fd71647b8d 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/HeatStringValidator.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/HeatStringValidator.java
@@ -20,36 +20,36 @@
package org.openecomp.sdc.be.model.tosca.validators;
-import java.util.Map;
-
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.common.util.ValidationUtils;
+import java.util.Map;
+
public class HeatStringValidator implements PropertyTypeValidator {
- private static HeatStringValidator stringValidator = new HeatStringValidator();
+ private static HeatStringValidator stringValidator = new HeatStringValidator();
- public static HeatStringValidator getInstance() {
- return stringValidator;
- }
+ public static HeatStringValidator getInstance() {
+ return stringValidator;
+ }
- private HeatStringValidator() {
+ private HeatStringValidator() {
- }
+ }
- @Override
- public boolean isValid(String value, String innerType, Map<String, DataTypeDefinition> allDataTypes) {
+ @Override
+ public boolean isValid(String value, String innerType, Map<String, DataTypeDefinition> allDataTypes) {
- if (value == null || true == value.isEmpty()) {
- return true;
- }
+ if (value == null || value.isEmpty()) {
+ return true;
+ }
- String converted = ValidationUtils.removeNoneUtf8Chars(value);
- return ValidationUtils.validateIsEnglish(converted);
- }
+ String converted = ValidationUtils.removeNoneUtf8Chars(value);
+ return ValidationUtils.validateIsEnglish(converted);
+ }
- @Override
- public boolean isValid(String value, String innerType) {
- return isValid(value, innerType, null);
- }
+ @Override
+ public boolean isValid(String value, String innerType) {
+ return isValid(value, innerType, null);
+ }
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/IntegerValidator.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/IntegerValidator.java
index 61d321c45e..484f88e37a 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/IntegerValidator.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/IntegerValidator.java
@@ -20,66 +20,66 @@
package org.openecomp.sdc.be.model.tosca.validators;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.openecomp.sdc.be.model.DataTypeDefinition;
-
public class IntegerValidator implements PropertyTypeValidator {
- private static IntegerValidator integerValidator = new IntegerValidator();
+ private static IntegerValidator integerValidator = new IntegerValidator();
- private IntegerValidator() {
- }
+ private IntegerValidator() {
+ }
- public static IntegerValidator getInstance() {
- return integerValidator;
- }
+ public static IntegerValidator getInstance() {
+ return integerValidator;
+ }
- private class PatternBase {
- public PatternBase(Pattern pattern, Integer base) {
- this.pattern = pattern;
- this.base = base;
- }
+ private class PatternBase {
+ public PatternBase(Pattern pattern, Integer base) {
+ this.pattern = pattern;
+ this.base = base;
+ }
- Pattern pattern;
- Integer base;
- }
+ Pattern pattern;
+ Integer base;
+ }
- private PatternBase base8Pattern = new PatternBase(Pattern.compile("([-+])?0o([0-7]+)"), 8);
- private PatternBase base10Pattern = new PatternBase(Pattern.compile("([-+])?(0|[1-9][0-9]*)"), 10);
- private PatternBase base16Pattern = new PatternBase(Pattern.compile("([-+])?0x([0-9a-fA-F]+)"), 16);
+ private PatternBase base8Pattern = new PatternBase(Pattern.compile("([-+])?0o([0-7]+)"), 8);
+ private PatternBase base10Pattern = new PatternBase(Pattern.compile("([-+])?(0|[1-9][0-9]*)"), 10);
+ private PatternBase base16Pattern = new PatternBase(Pattern.compile("([-+])?0x([0-9a-fA-F]+)"), 16);
- private PatternBase[] patterns = { base10Pattern, base8Pattern, base16Pattern };
+ private PatternBase[] patterns = { base10Pattern, base8Pattern, base16Pattern };
- @Override
- public boolean isValid(String value, String innerType, Map<String, DataTypeDefinition> allDataTypes) {
+ @Override
+ public boolean isValid(String value, String innerType, Map<String, DataTypeDefinition> allDataTypes) {
- if (value == null || true == value.isEmpty()) {
- return true;
- }
+ if (value == null || value.isEmpty()) {
+ return true;
+ }
- for (PatternBase patternBase : patterns) {
- Matcher matcher = patternBase.pattern.matcher(value);
- Long parsed = null;
- if (matcher.matches()) {
- try {
- parsed = Long.parseLong(matcher.group(2), patternBase.base);
- if (matcher.group(1) != null && matcher.group(1).compareTo("-") == 0) {
- parsed *= -1;
- }
- return (Integer.MIN_VALUE <= parsed && parsed <= (Integer.MAX_VALUE)) ? true : false;
- } catch (NumberFormatException e) {
- return false;
- }
- }
- }
- return false;
- }
+ for (PatternBase patternBase : patterns) {
+ Matcher matcher = patternBase.pattern.matcher(value);
+ Long parsed = null;
+ if (matcher.matches()) {
+ try {
+ parsed = Long.parseLong(matcher.group(2), patternBase.base);
+ if (matcher.group(1) != null && matcher.group(1).compareTo("-") == 0) {
+ parsed *= -1;
+ }
+ return (Integer.MIN_VALUE <= parsed && parsed <= (Integer.MAX_VALUE)) ? true : false;
+ } catch (NumberFormatException e) {
+ return false;
+ }
+ }
+ }
+ return false;
+ }
- @Override
- public boolean isValid(String value, String innerType) {
- return isValid(value, innerType, null);
- }
+ @Override
+ public boolean isValid(String value, String innerType) {
+ return isValid(value, innerType, null);
+ }
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/JsonValidator.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/JsonValidator.java
index 6a1aff558f..77fcf5214a 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/JsonValidator.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/JsonValidator.java
@@ -20,50 +20,48 @@
package org.openecomp.sdc.be.model.tosca.validators;
-import java.io.StringReader;
-import java.util.Map;
-
-import org.openecomp.sdc.be.model.DataTypeDefinition;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException;
import com.google.gson.stream.JsonReader;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+
+import java.io.StringReader;
+import java.util.Map;
public class JsonValidator implements PropertyTypeValidator {
- private static JsonValidator jsonValidator = new JsonValidator();
+ private static JsonValidator jsonValidator = new JsonValidator();
- private static Logger log = LoggerFactory.getLogger(JsonValidator.class.getName());
+ private static final Logger log = Logger.getLogger(JsonValidator.class.getName());
- private static JsonParser jsonParser = new JsonParser();
+ private static JsonParser jsonParser = new JsonParser();
- public static JsonValidator getInstance() {
- return jsonValidator;
- }
+ public static JsonValidator getInstance() {
+ return jsonValidator;
+ }
- @Override
- public boolean isValid(String value, String innerType, Map<String, DataTypeDefinition> allDataTypes) {
+ @Override
+ public boolean isValid(String value, String innerType, Map<String, DataTypeDefinition> allDataTypes) {
- if (value == null || value.isEmpty()) {
- return true;
- }
- try {
- StringReader reader = new StringReader(value);
- JsonReader jsonReader = new JsonReader(reader);
- jsonReader.setLenient(true);
- jsonParser.parse(jsonReader);
- } catch (JsonSyntaxException e) {
- log.debug("Error parsing JSON property", e);
- return false;
- }
- return true;
+ if (value == null || value.isEmpty()) {
+ return true;
+ }
+ try {
+ StringReader reader = new StringReader(value);
+ JsonReader jsonReader = new JsonReader(reader);
+ jsonReader.setLenient(true);
+ jsonParser.parse(jsonReader);
+ } catch (JsonSyntaxException e) {
+ log.debug("Error parsing JSON property", e);
+ return false;
+ }
+ return true;
- }
+ }
- @Override
- public boolean isValid(String value, String innerType) {
- return isValid(value, innerType, null);
- }
+ @Override
+ public boolean isValid(String value, String innerType) {
+ return isValid(value, innerType, null);
+ }
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/KeyValidator.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/KeyValidator.java
index 73b5e939ef..07e123376a 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/KeyValidator.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/KeyValidator.java
@@ -20,42 +20,42 @@
package org.openecomp.sdc.be.model.tosca.validators;
-import java.util.Map;
-
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.common.util.ValidationUtils;
+import java.util.Map;
+
public class KeyValidator implements PropertyTypeValidator {
- public static final int STRING_MAXIMUM_LENGTH = 100;
+ public static final int STRING_MAXIMUM_LENGTH = 100;
- private static KeyValidator keyValidator = new KeyValidator();
+ private static KeyValidator keyValidator = new KeyValidator();
- public static KeyValidator getInstance() {
- return keyValidator;
- }
+ public static KeyValidator getInstance() {
+ return keyValidator;
+ }
- private KeyValidator() {
+ private KeyValidator() {
- }
+ }
- @Override
- public boolean isValid(String value, String innerType, Map<String, DataTypeDefinition> allDataTypes) {
+ @Override
+ public boolean isValid(String value, String innerType, Map<String, DataTypeDefinition> allDataTypes) {
- if (value == null || true == value.isEmpty()) {
- return false;
- }
+ if (value == null || value.isEmpty()) {
+ return false;
+ }
- if (value.length() > STRING_MAXIMUM_LENGTH) {
- return false;
- }
- String converted = ValidationUtils.removeNoneUtf8Chars(value);
- return ValidationUtils.validateIsEnglish(converted);
- }
+ if (value.length() > STRING_MAXIMUM_LENGTH) {
+ return false;
+ }
+ String converted = ValidationUtils.removeNoneUtf8Chars(value);
+ return ValidationUtils.validateIsEnglish(converted);
+ }
- @Override
- public boolean isValid(String value, String innerType) {
- return isValid(value, innerType, null);
- }
+ @Override
+ public boolean isValid(String value, String innerType) {
+ return isValid(value, innerType, null);
+ }
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/ListValidator.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/ListValidator.java
index 8eb784029b..ed40964614 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/ListValidator.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/ListValidator.java
@@ -20,141 +20,138 @@
package org.openecomp.sdc.be.model.tosca.validators;
-import java.util.Map;
-
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonParser;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
+import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.common.util.JsonUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import com.google.gson.JsonArray;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonParser;
-import com.google.gson.JsonSyntaxException;
+import java.util.Map;
public class ListValidator implements PropertyTypeValidator {
- private static ListValidator listValidator = new ListValidator();
-
- private static Logger log = LoggerFactory.getLogger(ListValidator.class.getName());
-
- private static JsonParser jsonParser = new JsonParser();
-
- private static DataTypeValidatorConverter dataTypeValidatorConverter = DataTypeValidatorConverter.getInstance();
-
- public static ListValidator getInstance() {
- return listValidator;
- }
-
- @Override
- public boolean isValid(String value, String innerType, Map<String, DataTypeDefinition> allDataTypes) {
-
- log.debug("Going to validate value {} with inner type {}", value, innerType);
-
- if (value == null || value == "") {
- return true;
- }
- if (innerType == null) {
- return false;
- }
-
- PropertyTypeValidator innerValidator;
-
- ToscaPropertyType innerToscaType = ToscaPropertyType.isValidType(innerType);
-
- if (innerToscaType != null) {
- switch (innerToscaType) {
- case STRING:
- innerValidator = ToscaPropertyType.STRING.getValidator();
- break;
- case INTEGER:
- innerValidator = ToscaPropertyType.INTEGER.getValidator();
- break;
- case FLOAT:
- innerValidator = ToscaPropertyType.FLOAT.getValidator();
- break;
- case BOOLEAN:
- innerValidator = ToscaPropertyType.BOOLEAN.getValidator();
- break;
- case JSON:
- innerValidator = ToscaPropertyType.JSON.getValidator();
- break;
- default:
- log.debug("inner Tosca Type is unknown. {}", innerToscaType);
- return false;
- }
-
- } else {
- log.debug("inner Tosca Type is: {}", innerType);
-
- boolean isValid = validateComplexInnerType(value, innerType, allDataTypes);
- log.debug("Finish to validate value {} of list with inner type {}. result is {}",value,innerType,isValid);
- return isValid;
- }
-
- try {
- JsonArray jo = (JsonArray) jsonParser.parse(value);
- if(ToscaPropertyType.JSON == innerToscaType)
- return true;
- int size = jo.size();
- for (int i = 0; i < size; i++) {
- JsonElement currentValue = jo.get(i);
- String element = JsonUtils.toString(currentValue);
- if (!innerValidator.isValid(element, null, allDataTypes)) {
- log.debug("validation of element : {} failed", element);
- return false;
- }
-
- }
- return true;
-
- } catch (JsonSyntaxException e) {
- log.debug("Failed to parse json : {}", value, e);
- BeEcompErrorManager.getInstance().logBeInvalidJsonInput("List Validator");
- }
-
- return false;
-
- }
-
- @Override
- public boolean isValid(String value, String innerType) {
- return isValid(value, innerType, null);
- }
-
- private boolean validateComplexInnerType(String value, String innerType,
- Map<String, DataTypeDefinition> allDataTypes) {
-
- DataTypeDefinition innerDataTypeDefinition = allDataTypes.get(innerType);
- if (innerDataTypeDefinition == null) {
- log.debug("Data type {} cannot be found in our data types.", innerType);
- return false;
- }
-
- try {
-
- JsonArray jo = (JsonArray) jsonParser.parse(value);
- int size = jo.size();
- for (int i = 0; i < size; i++) {
- JsonElement currentValue = jo.get(i);
- if (currentValue != null) {
- String element = JsonUtils.toString(currentValue);
- boolean isValid = dataTypeValidatorConverter.isValid(element, innerDataTypeDefinition,
- allDataTypes);
- if (isValid == false) {
- log.debug("Cannot parse value {} from type {} in list parameter",currentValue,innerType);
- return false;
- }
- }
- }
-
- } catch (Exception e) {
- log.debug("Error when parsing JSON of object of type ", e);
- return false;
- }
-
- return true;
- }
+ private static ListValidator listValidator = new ListValidator();
+
+ private static final Logger log = Logger.getLogger(ListValidator.class.getName());
+
+ private static JsonParser jsonParser = new JsonParser();
+
+ private static DataTypeValidatorConverter dataTypeValidatorConverter = DataTypeValidatorConverter.getInstance();
+
+ public static ListValidator getInstance() {
+ return listValidator;
+ }
+
+ @Override
+ public boolean isValid(String value, String innerType, Map<String, DataTypeDefinition> allDataTypes) {
+
+ log.debug("Going to validate value {} with inner type {}", value, innerType);
+
+ if (value == null || value == "") {
+ return true;
+ }
+ if (innerType == null) {
+ return false;
+ }
+
+ PropertyTypeValidator innerValidator;
+
+ ToscaPropertyType innerToscaType = ToscaPropertyType.isValidType(innerType);
+
+ if (innerToscaType != null) {
+ switch (innerToscaType) {
+ case STRING:
+ innerValidator = ToscaPropertyType.STRING.getValidator();
+ break;
+ case INTEGER:
+ innerValidator = ToscaPropertyType.INTEGER.getValidator();
+ break;
+ case FLOAT:
+ innerValidator = ToscaPropertyType.FLOAT.getValidator();
+ break;
+ case BOOLEAN:
+ innerValidator = ToscaPropertyType.BOOLEAN.getValidator();
+ break;
+ case JSON:
+ innerValidator = ToscaPropertyType.JSON.getValidator();
+ break;
+ default:
+ log.debug("inner Tosca Type is unknown. {}", innerToscaType);
+ return false;
+ }
+
+ } else {
+ log.debug("inner Tosca Type is: {}", innerType);
+
+ boolean isValid = validateComplexInnerType(value, innerType, allDataTypes);
+ log.debug("Finish to validate value {} of list with inner type {}. result is {}",value,innerType,isValid);
+ return isValid;
+ }
+
+ try {
+ JsonArray jo = (JsonArray) jsonParser.parse(value);
+ if(ToscaPropertyType.JSON == innerToscaType)
+ return true;
+ int size = jo.size();
+ for (int i = 0; i < size; i++) {
+ JsonElement currentValue = jo.get(i);
+ String element = JsonUtils.toString(currentValue);
+ if (!innerValidator.isValid(element, null, allDataTypes)) {
+ log.debug("validation of element : {} failed", element);
+ return false;
+ }
+
+ }
+ return true;
+
+ } catch (Exception e) {
+ log.debug("Failed to parse json : {}", value, e);
+ BeEcompErrorManager.getInstance().logBeInvalidJsonInput("List Validator");
+ }
+
+ return false;
+
+ }
+
+ @Override
+ public boolean isValid(String value, String innerType) {
+ return isValid(value, innerType, null);
+ }
+
+ private boolean validateComplexInnerType(String value, String innerType,
+ Map<String, DataTypeDefinition> allDataTypes) {
+
+ DataTypeDefinition innerDataTypeDefinition = allDataTypes.get(innerType);
+ if (innerDataTypeDefinition == null) {
+ log.debug("Data type {} cannot be found in our data types.", innerType);
+ return false;
+ }
+
+ try {
+
+ JsonArray jo = (JsonArray) jsonParser.parse(value);
+ int size = jo.size();
+ for (int i = 0; i < size; i++) {
+ JsonElement currentValue = jo.get(i);
+ if (currentValue != null) {
+ String element = JsonUtils.toString(currentValue);
+ boolean isValid = dataTypeValidatorConverter.isValid(element, innerDataTypeDefinition,
+ allDataTypes);
+ if (!isValid) {
+ log.debug("Cannot parse value {} from type {} in list parameter",currentValue,innerType);
+ return false;
+ }
+ }
+ }
+
+ } catch (Exception e) {
+ log.debug("Error when parsing JSON of object of type ", e);
+ return false;
+ }
+
+ return true;
+ }
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/MapValidator.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/MapValidator.java
index 862766b6fa..996e24ee06 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/MapValidator.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/MapValidator.java
@@ -20,22 +20,20 @@
package org.openecomp.sdc.be.model.tosca.validators;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import com.google.gson.JsonSyntaxException;
import org.apache.commons.lang.StringUtils;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
+import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.common.util.JsonUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
-import com.google.gson.JsonSyntaxException;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
/*
* Property Type Map correct usage:
@@ -47,90 +45,90 @@ validators and converters works the same as before
Types:
when written line by line :
- key1 : val1
- key2 : val2
+ key1 : val1
+ key2 : val2
key1 and val does not need " " , even if val1 is a string.
when written as one line : {"key1":val1 , "key2":val2}
Keys always need " " around them.
*/
public class MapValidator implements PropertyTypeValidator {
- private static MapValidator mapValidator = new MapValidator();
-
- private static final Logger LOGGER = LoggerFactory.getLogger(MapValidator.class.getName());
-
- private static DataTypeValidatorConverter dataTypeValidatorConverter = DataTypeValidatorConverter.getInstance();
-
- private static JsonParser jsonParser = new JsonParser();
-
- public static MapValidator getInstance() {
- return mapValidator;
- }
-
- @Override
- public boolean isValid(String value, String innerType, Map<String, DataTypeDefinition> allDataTypes) {
-
- if (StringUtils.isEmpty(value)) {
- return true;
- }
- if (innerType == null) {
- return false;
- }
-
- PropertyTypeValidator innerValidator;
- PropertyTypeValidator keyValidator = ToscaPropertyType.KEY.getValidator();
- ToscaPropertyType innerToscaType = ToscaPropertyType.isValidType(innerType);
-
- if (innerToscaType != null) {
- switch (innerToscaType) {
- case STRING:
- innerValidator = ToscaPropertyType.STRING.getValidator();
- break;
- case INTEGER:
- innerValidator = ToscaPropertyType.INTEGER.getValidator();
- break;
- case FLOAT:
- innerValidator = ToscaPropertyType.FLOAT.getValidator();
- break;
- case BOOLEAN:
- innerValidator = ToscaPropertyType.BOOLEAN.getValidator();
- break;
- case JSON:
- innerValidator = ToscaPropertyType.JSON.getValidator();
- break;
- default:
- LOGGER.debug("inner Tosca Type is unknown. {}", innerToscaType);
- return false;
- }
-
- } else {
- LOGGER.debug("inner Tosca Type is: {}", innerType);
-
- boolean isValid = validateComplexInnerType(value, innerType, allDataTypes);
- LOGGER.debug("Finish to validate value {} of map with inner type {}. result is {}",value,innerType,isValid);
- return isValid;
-
- }
-
- try {
- JsonElement jsonObject = jsonParser.parse(value);
- if (!jsonObject.isJsonObject()) {
- return false;
+ private static MapValidator mapValidator = new MapValidator();
+
+ private static final Logger log = Logger.getLogger(MapValidator.class.getName());
+
+ private static DataTypeValidatorConverter dataTypeValidatorConverter = DataTypeValidatorConverter.getInstance();
+
+ private static JsonParser jsonParser = new JsonParser();
+
+ public static MapValidator getInstance() {
+ return mapValidator;
+ }
+
+ @Override
+ public boolean isValid(String value, String innerType, Map<String, DataTypeDefinition> allDataTypes) {
+
+ if (StringUtils.isEmpty(value)) {
+ return true;
+ }
+ if (innerType == null) {
+ return false;
+ }
+
+ PropertyTypeValidator innerValidator;
+ PropertyTypeValidator keyValidator = ToscaPropertyType.KEY.getValidator();
+ ToscaPropertyType innerToscaType = ToscaPropertyType.isValidType(innerType);
+
+ if (innerToscaType != null) {
+ switch (innerToscaType) {
+ case STRING:
+ innerValidator = ToscaPropertyType.STRING.getValidator();
+ break;
+ case INTEGER:
+ innerValidator = ToscaPropertyType.INTEGER.getValidator();
+ break;
+ case FLOAT:
+ innerValidator = ToscaPropertyType.FLOAT.getValidator();
+ break;
+ case BOOLEAN:
+ innerValidator = ToscaPropertyType.BOOLEAN.getValidator();
+ break;
+ case JSON:
+ innerValidator = ToscaPropertyType.JSON.getValidator();
+ break;
+ default:
+ log.debug("inner Tosca Type is unknown. {}", innerToscaType);
+ return false;
}
- JsonObject valueAsJson = jsonObject.getAsJsonObject();
- return validateJsonObject(allDataTypes, innerValidator, keyValidator, valueAsJson);
- } catch (JsonSyntaxException e) {
- LOGGER.debug("Failed to parse json : {}", value, e);
- BeEcompErrorManager.getInstance().logBeInvalidJsonInput("Map Validator");
- }
- return false;
+ } else {
+ log.debug("inner Tosca Type is: {}", innerType);
+
+ boolean isValid = validateComplexInnerType(value, innerType, allDataTypes);
+ log.debug("Finish to validate value {} of map with inner type {}. result is {}",value,innerType,isValid);
+ return isValid;
+
+ }
+
+ try {
+ JsonElement jsonObject = jsonParser.parse(value);
+ if (!jsonObject.isJsonObject()) {
+ return false;
+ }
+ JsonObject valueAsJson = jsonObject.getAsJsonObject();
+ return validateJsonObject(allDataTypes, innerValidator, keyValidator, valueAsJson);
+ } catch (JsonSyntaxException e) {
+ log.debug("Failed to parse json : {}", value, e);
+ BeEcompErrorManager.getInstance().logBeInvalidJsonInput("Map Validator");
+ }
- }
+ return false;
- private boolean validateJsonObject(Map<String, DataTypeDefinition> allDataTypes, PropertyTypeValidator innerValidator, PropertyTypeValidator keyValidator, JsonObject asJsonObject) {
- Set<Entry<String, JsonElement>> entrySet = asJsonObject.entrySet();
- for (Entry<String, JsonElement> entry : entrySet) {
+ }
+
+ private boolean validateJsonObject(Map<String, DataTypeDefinition> allDataTypes, PropertyTypeValidator innerValidator, PropertyTypeValidator keyValidator, JsonObject asJsonObject) {
+ Set<Entry<String, JsonElement>> entrySet = asJsonObject.entrySet();
+ for (Entry<String, JsonElement> entry : entrySet) {
String currentKey = entry.getKey();
JsonElement jsonValue = entry.getValue();
@@ -138,52 +136,52 @@ public class MapValidator implements PropertyTypeValidator {
if (!innerValidator.isValid(element, null, allDataTypes)
|| !keyValidator.isValid(entry.getKey(), null, allDataTypes)) {
- LOGGER.debug("validation of key : {}, element : {} failed", currentKey, entry.getValue());
+ log.debug("validation of key : {}, element : {} failed", currentKey, entry.getValue());
return false;
}
}
- return true;
- }
-
- private boolean validateComplexInnerType(String value, String innerType,
- Map<String, DataTypeDefinition> allDataTypes) {
-
- DataTypeDefinition innerDataTypeDefinition = allDataTypes.get(innerType);
- if (innerDataTypeDefinition == null) {
- LOGGER.debug("Data type {} cannot be found in our data types.", innerType);
- return false;
- }
-
- try {
- JsonElement jsonObject = jsonParser.parse(value);
- JsonObject asJsonObject = jsonObject.getAsJsonObject();
- Set<Entry<String, JsonElement>> entrySet = asJsonObject.entrySet();
- for (Entry<String, JsonElement> entry : entrySet) {
- String currentKey = entry.getKey();
- JsonElement currentValue = entry.getValue();
-
- if (currentValue != null) {
- String element = JsonUtils.toString(currentValue);
- boolean isValid = dataTypeValidatorConverter.isValid(element, innerDataTypeDefinition,
- allDataTypes);
- if (!isValid) {
- LOGGER.debug("Cannot parse value {} from type {} of key {}",currentValue,innerType,currentKey);
- return false;
- }
- }
- }
-
- } catch (Exception e) {
- LOGGER.debug("Cannot parse value {} of map from inner type {}", value, innerType, e);
- return false;
- }
-
- return true;
- }
-
- @Override
- public boolean isValid(String value, String innerType) {
- return isValid(value, innerType, null);
- }
+ return true;
+ }
+
+ private boolean validateComplexInnerType(String value, String innerType,
+ Map<String, DataTypeDefinition> allDataTypes) {
+
+ DataTypeDefinition innerDataTypeDefinition = allDataTypes.get(innerType);
+ if (innerDataTypeDefinition == null) {
+ log.debug("Data type {} cannot be found in our data types.", innerType);
+ return false;
+ }
+
+ try {
+ JsonElement jsonObject = jsonParser.parse(value);
+ JsonObject asJsonObject = jsonObject.getAsJsonObject();
+ Set<Entry<String, JsonElement>> entrySet = asJsonObject.entrySet();
+ for (Entry<String, JsonElement> entry : entrySet) {
+ String currentKey = entry.getKey();
+ JsonElement currentValue = entry.getValue();
+
+ if (currentValue != null) {
+ String element = JsonUtils.toString(currentValue);
+ boolean isValid = dataTypeValidatorConverter.isValid(element, innerDataTypeDefinition,
+ allDataTypes);
+ if (!isValid) {
+ log.debug("Cannot parse value {} from type {} of key {}",currentValue,innerType,currentKey);
+ return false;
+ }
+ }
+ }
+
+ } catch (Exception e) {
+ log.debug("Cannot parse value {} of map from inner type {}", value, innerType, e);
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public boolean isValid(String value, String innerType) {
+ return isValid(value, innerType, null);
+ }
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/PropertyTypeValidator.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/PropertyTypeValidator.java
index f0cf225c0a..587107a93a 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/PropertyTypeValidator.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/PropertyTypeValidator.java
@@ -20,27 +20,27 @@
package org.openecomp.sdc.be.model.tosca.validators;
-import java.util.Map;
-
import org.openecomp.sdc.be.model.DataTypeDefinition;
+import java.util.Map;
+
public interface PropertyTypeValidator {
- boolean isValid(String value, String innerType, Map<String, DataTypeDefinition> allDataTypes);
+ boolean isValid(String value, String innerType, Map<String, DataTypeDefinition> allDataTypes);
- boolean isValid(String value, String innerType);
- /*
- * The value format should be validated according to the "Property Type" :
- * "integer" - valid tag:yaml.org,2002:int , the number base 8,10,18 should
- * be handled ( hint : to validate by calling parseInt(
- * s,10)/parseInt(s,16)/parseInt(s,8) or just regexp [-+]?[0-9]+ for Base 10
- * , [-+]?0[0-7]+ for Base 8 , [-+]?0x[0-9a-fA-F]+ for Base 16
- *
- * "float" - valid tag:yaml.org,2002:float , parseFloat() "boolean" - valid
- * tag:yaml.org,2002:bool : can be only "true" or "false" ( upper case
- * characters should be converted to lower case : TRUE ->true, True->true
- * "string" - valid tag:yaml.org,2002:str and limited to 100 chars.
- *
- */
+ boolean isValid(String value, String innerType);
+ /*
+ * The value format should be validated according to the "Property Type" :
+ * "integer" - valid tag:yaml.org,2002:int , the number base 8,10,18 should
+ * be handled ( hint : to validate by calling parseInt(
+ * s,10)/parseInt(s,16)/parseInt(s,8) or just regexp [-+]?[0-9]+ for Base 10
+ * , [-+]?0[0-7]+ for Base 8 , [-+]?0x[0-9a-fA-F]+ for Base 16
+ *
+ * "float" - valid tag:yaml.org,2002:float , parseFloat() "boolean" - valid
+ * tag:yaml.org,2002:bool : can be only "true" or "false" ( upper case
+ * characters should be converted to lower case : TRUE ->true, True->true
+ * "string" - valid tag:yaml.org,2002:str and limited to 100 chars.
+ *
+ */
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/StringValidator.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/StringValidator.java
index dad3461c91..cd8d9272f2 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/StringValidator.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/StringValidator.java
@@ -20,66 +20,65 @@
package org.openecomp.sdc.be.model.tosca.validators;
-import java.util.Map;
-
import org.openecomp.sdc.be.config.Configuration.ToscaValidatorsConfig;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.common.util.ValidationUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+
+import java.util.Map;
public class StringValidator implements PropertyTypeValidator {
- public static final int DEFAULT_STRING_MAXIMUM_LENGTH = 2500;
-
- private static int STRING_MAXIMUM_LENGTH = DEFAULT_STRING_MAXIMUM_LENGTH;
-
- private static Logger log = LoggerFactory.getLogger(StringValidator.class.getName());
-
- private static StringValidator stringValidator = new StringValidator();
-
- private StringValidator() {
- if (ConfigurationManager.getConfigurationManager() != null) {
- ToscaValidatorsConfig toscaValidators = ConfigurationManager.getConfigurationManager().getConfiguration()
- .getToscaValidators();
- log.debug("toscaValidators= {}", toscaValidators);
- if (toscaValidators != null) {
- Integer stringMaxLength = toscaValidators.getStringMaxLength();
- if (stringMaxLength != null) {
- STRING_MAXIMUM_LENGTH = stringMaxLength;
- }
- }
- }
- }
-
- public static StringValidator getInstance() {
- return stringValidator;
- }
-
- @Override
- public boolean isValid(String value, String innerType, Map<String, DataTypeDefinition> allDataTypes) {
-
- if (value == null || true == value.isEmpty()) {
- return true;
- }
-
- if (value.length() > STRING_MAXIMUM_LENGTH) {
- log.debug("parameter String length {} is higher than configured({})", value.length(), STRING_MAXIMUM_LENGTH);
- return false;
- }
- String converted = ValidationUtils.removeNoneUtf8Chars(value);
- boolean isValid = ValidationUtils.validateIsAscii(converted);
-
- if (false == isValid && log.isDebugEnabled()) {
- log.debug("parameter String value {} is not an ascii string.", value.substring(0, Math.min(value.length(), 20)));
- }
-
- return isValid;
- }
-
- @Override
- public boolean isValid(String value, String innerType) {
- return isValid(value, innerType, null);
- }
+ public static final int DEFAULT_STRING_MAXIMUM_LENGTH = 2500;
+
+ private static int STRING_MAXIMUM_LENGTH = DEFAULT_STRING_MAXIMUM_LENGTH;
+
+ private static final Logger log = Logger.getLogger(StringValidator.class.getName());
+
+ private static StringValidator stringValidator = new StringValidator();
+
+ private StringValidator() {
+ if (ConfigurationManager.getConfigurationManager() != null) {
+ ToscaValidatorsConfig toscaValidators = ConfigurationManager.getConfigurationManager().getConfiguration()
+ .getToscaValidators();
+ log.debug("toscaValidators= {}", toscaValidators);
+ if (toscaValidators != null) {
+ Integer stringMaxLength = toscaValidators.getStringMaxLength();
+ if (stringMaxLength != null) {
+ STRING_MAXIMUM_LENGTH = stringMaxLength;
+ }
+ }
+ }
+ }
+
+ public static StringValidator getInstance() {
+ return stringValidator;
+ }
+
+ @Override
+ public boolean isValid(String value, String innerType, Map<String, DataTypeDefinition> allDataTypes) {
+
+ if (value == null || value.isEmpty()) {
+ return true;
+ }
+
+ if (value.length() > STRING_MAXIMUM_LENGTH) {
+ log.debug("parameter String length {} is higher than configured({})", value.length(), STRING_MAXIMUM_LENGTH);
+ return false;
+ }
+ String converted = ValidationUtils.removeNoneUtf8Chars(value);
+ boolean isValid = ValidationUtils.validateIsAscii(converted);
+
+ if (!isValid && log.isDebugEnabled()) {
+ log.debug("parameter String value {} is not an ascii string.", value.substring(0, Math.min(value.length(), 20)));
+ }
+
+ return isValid;
+ }
+
+ @Override
+ public boolean isValid(String value, String innerType) {
+ return isValid(value, innerType, null);
+ }
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/ToscaBooleanValidator.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/ToscaBooleanValidator.java
index 7f8dff42d0..fbec8e8d46 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/ToscaBooleanValidator.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/ToscaBooleanValidator.java
@@ -20,37 +20,37 @@
package org.openecomp.sdc.be.model.tosca.validators;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+
import java.util.Arrays;
import java.util.Map;
-import org.openecomp.sdc.be.model.DataTypeDefinition;
-
public class ToscaBooleanValidator implements PropertyTypeValidator {
- private static ToscaBooleanValidator booleanValidator = new ToscaBooleanValidator();
+ private static ToscaBooleanValidator booleanValidator = new ToscaBooleanValidator();
- private static String[] validValues = { "true", "on", "yes", "y", "false", "off", "no", "n" };
+ private static String[] validValues = { "true", "on", "yes", "y", "false", "off", "no", "n" };
- public static ToscaBooleanValidator getInstance() {
- return booleanValidator;
- }
+ public static ToscaBooleanValidator getInstance() {
+ return booleanValidator;
+ }
- private ToscaBooleanValidator() {
+ private ToscaBooleanValidator() {
- }
+ }
- @Override
- public boolean isValid(String value, String innerType, Map<String, DataTypeDefinition> dataTypes) {
+ @Override
+ public boolean isValid(String value, String innerType, Map<String, DataTypeDefinition> dataTypes) {
- if (value == null || true == value.isEmpty()) {
- return true;
- }
+ if (value == null || value.isEmpty()) {
+ return true;
+ }
- return (Arrays.stream(validValues).filter(str -> str.equalsIgnoreCase(value)).toArray().length == 1);
- }
+ return (Arrays.stream(validValues).filter(str -> str.equalsIgnoreCase(value)).toArray().length == 1);
+ }
- @Override
- public boolean isValid(String value, String innerType) {
- return isValid(value, innerType, null);
- }
+ @Override
+ public boolean isValid(String value, String innerType) {
+ return isValid(value, innerType, null);
+ }
}