summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib')
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/json/JsonUtil.java34
1 files changed, 31 insertions, 3 deletions
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/json/JsonUtil.java b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/json/JsonUtil.java
index 92c590b5df..a975016db2 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/json/JsonUtil.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/json/JsonUtil.java
@@ -36,15 +36,15 @@ import java.util.stream.Collectors;
import org.apache.commons.collections4.CollectionUtils;
import org.everit.json.schema.EnumSchema;
import org.everit.json.schema.Schema;
+import org.everit.json.schema.StringSchema;
import org.everit.json.schema.ValidationException;
import org.everit.json.schema.loader.SchemaLoader;
import org.json.JSONObject;
-import org.onap.sdc.tosca.datatypes.model.RequirementDefinition;
import org.openecomp.core.utilities.CommonMethods;
import org.openecomp.core.utilities.deserializers.RequirementDefinitionDeserializer;
-
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
+import org.onap.sdc.tosca.datatypes.model.RequirementDefinition;
/**
@@ -157,9 +157,14 @@ public class JsonUtil {
}
private static String mapValidationExceptionToMessage(ValidationException exception) {
- if (exception.getViolatedSchema() instanceof EnumSchema) {
+ Object schema = exception.getViolatedSchema();
+
+ if (schema instanceof EnumSchema) {
return mapEnumViolationToMessage(exception);
+ } else if (schema instanceof StringSchema) {
+ return mapStringViolationToMessage(exception);
}
+
return exception.getMessage();
}
@@ -173,6 +178,15 @@ public class JsonUtil {
possibleValues.stream().map(Object::toString).collect(Collectors.toList()))));
}
+ private static String mapStringViolationToMessage(ValidationException validationException) {
+ if (ValidationType.PATTERN.getKeyword().equals(validationException.getKeyword())) {
+ String message = validationException.getMessage();
+ String value = message.substring(message.indexOf("["), message.indexOf("]") + 1);
+ return message.replace("string " + value, value + " is not valid value. It");
+ }
+ return validationException.getMessage();
+ }
+
private static List<ValidationException> validateUsingEverit(String json, String jsonSchema) {
LOGGER.debug(
String.format("validateUsingEverit start, json=%s, jsonSchema=%s", json, jsonSchema));
@@ -189,4 +203,18 @@ public class JsonUtil {
}
return null;
}
+
+ private enum ValidationType {
+ PATTERN("pattern");
+
+ private String keyword;
+
+ private ValidationType(String keyword) {
+ this.keyword = keyword;
+ }
+
+ String getKeyword() {
+ return keyword;
+ }
+ }
}