aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib
diff options
context:
space:
mode:
authorshrikantawachar <shrikant.awachar@amdocs.com>2018-05-15 15:32:18 +0530
committershrikantawachar <shrikant.awachar@amdocs.com>2018-05-29 16:25:29 +0530
commite9966c94065f6a74d07578b8cee055c37594a0f7 (patch)
treeb793a40dabb934c5354b2d5ff72ad31a0985da86 /openecomp-be/lib
parente1e4f69030a34ebdbe65e72f8ff5fa25ea8e82bc (diff)
Refactoring validation
Refactoring validation from Code to FTL Change-Id: Ic33a3719a021bb4c82565653fd8d95de38b7929e Issue-ID: SDC-1334 Signed-off-by: shrikantawachar <shrikant.awachar@amdocs.com>
Diffstat (limited to 'openecomp-be/lib')
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/json/JsonUtil.java34
-rw-r--r--openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/schemagenerator/ImageCompositionSchemaInput.java13
2 files changed, 43 insertions, 4 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;
+ }
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/schemagenerator/ImageCompositionSchemaInput.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/schemagenerator/ImageCompositionSchemaInput.java
index add08a7020..9db298c86c 100644
--- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/schemagenerator/ImageCompositionSchemaInput.java
+++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/schemagenerator/ImageCompositionSchemaInput.java
@@ -4,6 +4,17 @@ import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Image;
public class ImageCompositionSchemaInput implements SchemaTemplateInput {
+ private boolean manual;
+ private Image image;
+
+ public boolean isManual() {
+ return manual;
+ }
+
+ public void setManual(boolean manual) {
+ this.manual = manual;
+ }
+
public Image getImage() {
return image;
}
@@ -12,7 +23,7 @@ public class ImageCompositionSchemaInput implements SchemaTemplateInput {
this.image = image;
}
- private Image image;
+
}