From 5da6e951279b97c826f8b821d179fe89a63dc8a6 Mon Sep 17 00:00:00 2001 From: Gunda Abhishek Date: Fri, 29 Nov 2024 17:44:51 +0530 Subject: [PATCH] adds leia-common module and moved all validation utils --- README.md | 16 ++-- leia-bom/pom.xml | 5 + leia-client/pom.xml | 6 -- leia-common/pom.xml | 92 ++++++++++++++++++ .../leia/common/builder/SchemaBuilder.java | 96 ++++--------------- .../exception/SchemaValidationException.java | 2 +- .../exception/ValidationErrorCode.java | 2 +- .../leia/common/utils/QualifierUtils.java | 55 +++++++++++ .../com/grookage/leia/common/utils/Utils.java | 56 +++++++++++ .../validation}/SchemaValidationUtils.java | 38 ++------ .../common/builder/SchemaBuilderTest.java | 81 ++++++++-------- .../SchemaValidationUtilsTest.java | 38 ++++---- .../src/test/resources/validNestedSchema.json | 24 +++-- .../src/test/resources/validSchema.json | 16 ++-- .../leia/core/utils/ValidationUtilsTest.java | 48 ++++++++++ .../annotations/qualifiers/Standard.java | 11 --- .../leia/models/attributes/AttributeTest.java | 17 ++++ .../attributeWithMultipleQualifiers.json | 14 +++ .../attributes/attributeWithQualifier.json | 8 +- .../resources/attributes/enumAttribute.json | 8 +- .../resources/schema/createSchemaRequest.json | 8 +- .../test/resources/schema/schemaDetails.json | 19 ++-- .../resources/schema/updateSchemaRequest.json | 16 ++-- leia-schema-validator/pom.xml | 4 + .../leia/validator/StaticSchemaValidator.java | 6 +- pom.xml | 1 + 26 files changed, 454 insertions(+), 233 deletions(-) create mode 100644 leia-common/pom.xml rename leia-client/src/main/java/com/grookage/leia/client/utils/SchemaUtil.java => leia-common/src/main/java/com/grookage/leia/common/builder/SchemaBuilder.java (67%) rename {leia-schema-validator/src/main/java/com/grookage/leia/validator => leia-common/src/main/java/com/grookage/leia/common}/exception/SchemaValidationException.java (98%) rename {leia-schema-validator/src/main/java/com/grookage/leia/validator => leia-common/src/main/java/com/grookage/leia/common}/exception/ValidationErrorCode.java (94%) create mode 100644 leia-common/src/main/java/com/grookage/leia/common/utils/QualifierUtils.java create mode 100644 leia-common/src/main/java/com/grookage/leia/common/utils/Utils.java rename {leia-schema-validator/src/main/java/com/grookage/leia/validator/utils => leia-common/src/main/java/com/grookage/leia/common/validation}/SchemaValidationUtils.java (85%) rename leia-client/src/test/java/com/grookage/leia/client/utils/SchemaUtilTest.java => leia-common/src/test/java/com/grookage/leia/common/builder/SchemaBuilderTest.java (78%) rename {leia-schema-validator/src/test/java/com/grookage/leia/validator => leia-common/src/test/java/com/grookage/leia/common/validation}/SchemaValidationUtilsTest.java (91%) rename {leia-schema-validator => leia-common}/src/test/resources/validNestedSchema.json (70%) rename {leia-schema-validator => leia-common}/src/test/resources/validSchema.json (78%) delete mode 100644 leia-models/src/main/java/com/grookage/leia/models/annotations/qualifiers/Standard.java create mode 100644 leia-models/src/test/resources/attributes/attributeWithMultipleQualifiers.json diff --git a/README.md b/README.md index 522edf3..0975d14 100644 --- a/README.md +++ b/README.md @@ -92,9 +92,11 @@ A sample schema looks like the following "type": "ARRAY", "name": "testAttribute", "optional": true, - "qualifierInfo": { - "type": "PII" - } + "qualifiers": [ + { + "type": "PII" + } + ] }, { "type": "ENUM", @@ -103,9 +105,11 @@ A sample schema looks like the following "values": [ "TEST_ENUM" ], - "qualifierInfo": { - "type": "PII" - } + "qualifiers": [ + { + "type": "PII" + } + ] } ], "transformationTargets": [ diff --git a/leia-bom/pom.xml b/leia-bom/pom.xml index b9f39cb..5897097 100644 --- a/leia-bom/pom.xml +++ b/leia-bom/pom.xml @@ -39,6 +39,11 @@ leia-models ${project.version} + + com.grookage.leia + leia-common + ${project.version} + com.grookage.leia leia-core diff --git a/leia-client/pom.xml b/leia-client/pom.xml index f2da970..cfbb232 100644 --- a/leia-client/pom.xml +++ b/leia-client/pom.xml @@ -54,12 +54,6 @@ org.projectlombok - - org.apache.commons - commons-lang3 - ${lang3.version} - - junit-jupiter org.junit.jupiter diff --git a/leia-common/pom.xml b/leia-common/pom.xml new file mode 100644 index 0000000..e88605f --- /dev/null +++ b/leia-common/pom.xml @@ -0,0 +1,92 @@ + + + + + + 4.0.0 + + com.grookage.leia + leia-parent + 0.0.1-RC7 + ../leia-parent + + + leia-common + + + 3.11 + false + + + + + lombok + org.projectlombok + + + + org.apache.commons + commons-lang3 + ${lang3.version} + + + + junit-jupiter + org.junit.jupiter + + + + com.grookage.leia + leia-models + + + + mockito-core + org.mockito + test + + + + mockito-junit-jupiter + org.mockito + test + + + + mockito-inline + org.mockito + test + + + + com.grookage.leia + leia-models + test-jar + + + * + * + + + + + + + + \ No newline at end of file diff --git a/leia-client/src/main/java/com/grookage/leia/client/utils/SchemaUtil.java b/leia-common/src/main/java/com/grookage/leia/common/builder/SchemaBuilder.java similarity index 67% rename from leia-client/src/main/java/com/grookage/leia/client/utils/SchemaUtil.java rename to leia-common/src/main/java/com/grookage/leia/common/builder/SchemaBuilder.java index 068a683..2eae070 100644 --- a/leia-client/src/main/java/com/grookage/leia/client/utils/SchemaUtil.java +++ b/leia-common/src/main/java/com/grookage/leia/common/builder/SchemaBuilder.java @@ -1,10 +1,8 @@ -package com.grookage.leia.client.utils; +package com.grookage.leia.common.builder; +import com.grookage.leia.common.utils.QualifierUtils; +import com.grookage.leia.common.utils.Utils; import com.grookage.leia.models.annotations.Optional; -import com.grookage.leia.models.annotations.qualifiers.Encrypted; -import com.grookage.leia.models.annotations.qualifiers.PII; -import com.grookage.leia.models.annotations.qualifiers.ShortLived; -import com.grookage.leia.models.annotations.qualifiers.Standard; import com.grookage.leia.models.attributes.ArrayAttribute; import com.grookage.leia.models.attributes.BooleanAttribute; import com.grookage.leia.models.attributes.DoubleAttribute; @@ -16,11 +14,7 @@ import com.grookage.leia.models.attributes.ObjectAttribute; import com.grookage.leia.models.attributes.SchemaAttribute; import com.grookage.leia.models.attributes.StringAttribute; -import com.grookage.leia.models.qualifiers.EncryptedQualifier; -import com.grookage.leia.models.qualifiers.PIIQualifier; import com.grookage.leia.models.qualifiers.QualifierInfo; -import com.grookage.leia.models.qualifiers.ShortLivedQualifier; -import com.grookage.leia.models.qualifiers.StandardQualifier; import lombok.experimental.UtilityClass; import org.apache.commons.lang3.ClassUtils; @@ -28,20 +22,16 @@ import java.lang.reflect.GenericArrayType; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; -import java.util.HashSet; -import java.util.List; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; @UtilityClass -public class SchemaUtil { +public class SchemaBuilder { public Set buildSchemaAttributes(final Class klass) { - return getAllFields(klass) - .stream().map(SchemaUtil::schemaAttribute) + return Utils.getAllFields(klass) + .stream().map(SchemaBuilder::schemaAttribute) .collect(Collectors.toSet()); } @@ -49,7 +39,7 @@ private SchemaAttribute schemaAttribute(final Field field) { return schemaAttribute( field.getGenericType(), field.getName(), - getQualifierInfo(field), + QualifierUtils.getQualifierInfo(field), isOptional(field) ); } @@ -103,8 +93,8 @@ private SchemaAttribute handleMap(ParameterizedType parameterizedType, name, optional, qualifiers, - schemaAttribute(keyType, "key", getQualifierInfo(keyType), isOptional(keyType)), - schemaAttribute(valueType, "value", getQualifierInfo(valueType), isOptional(valueType)) + schemaAttribute(keyType, "key", QualifierUtils.getQualifierInfo(keyType), isOptional(keyType)), + schemaAttribute(valueType, "value", QualifierUtils.getQualifierInfo(valueType), isOptional(valueType)) ); } @@ -116,7 +106,8 @@ private SchemaAttribute handleCollection(ParameterizedType parameterizedType, name, optional, qualifiers, - schemaAttribute(elementType, "element", getQualifierInfo(elementType), isOptional(elementType)) + schemaAttribute(elementType, "element", QualifierUtils.getQualifierInfo(elementType), + isOptional(elementType)) ); } @@ -129,7 +120,8 @@ private SchemaAttribute schemaAttribute(final GenericArrayType genericArrayType, name, optional, qualifiers, - schemaAttribute(componentType, "element", getQualifierInfo(componentType), isOptional(componentType)) + schemaAttribute(componentType, "element", QualifierUtils.getQualifierInfo(componentType), + isOptional(componentType)) ); } @@ -143,7 +135,7 @@ private SchemaAttribute schemaAttribute(final Class klass, } if (klass.isEnum()) { - return new EnumAttribute(name, optional, qualifiers, getEnumValues(klass)); + return new EnumAttribute(name, optional, qualifiers, Utils.getEnumValues(klass)); } if (klass.isPrimitive()) { @@ -157,7 +149,8 @@ private SchemaAttribute schemaAttribute(final Class klass, name, optional, qualifiers, - schemaAttribute(componentType, "element", getQualifierInfo(componentType), isOptional(componentType)) + schemaAttribute(componentType, "element", QualifierUtils.getQualifierInfo(componentType), + isOptional(componentType)) ); } @@ -190,63 +183,6 @@ private SchemaAttribute handlePrimitive(final Class klass, } - private List getAllFields(Class type) { - List fields = new ArrayList<>(); - for (Class c = type; c != null; c = c.getSuperclass()) { - fields.addAll(Arrays.asList(c.getDeclaredFields())); - } - return fields; - } - - private Set getEnumValues(Class klass) { - return Arrays.stream(klass.getEnumConstants()) - .map(enumConstant -> ((Enum) enumConstant).name()) - .collect(Collectors.toSet()); - } - - private Set getQualifierInfo(Field field) { - Set qualifierInfos = new HashSet<>(); - if (field.isAnnotationPresent(Encrypted.class)) { - qualifierInfos.add(new EncryptedQualifier()); - } - if (field.isAnnotationPresent(Standard.class)) { - qualifierInfos.add(new StandardQualifier()); - } - if (field.isAnnotationPresent(PII.class)) { - qualifierInfos.add(new PIIQualifier()); - } - if (field.isAnnotationPresent(ShortLived.class)) { - final var shortLived = field.getAnnotation(ShortLived.class); - qualifierInfos.add(new ShortLivedQualifier(shortLived.ttlSeconds())); - } - return qualifierInfos; - } - - private Set getQualifierInfo(Type type) { - if (type instanceof Class klass) { - return getQualifierInfo(klass); - } - return new HashSet<>(); - } - - private Set getQualifierInfo(Class klass) { - Set qualifierInfos = new HashSet<>(); - if (klass.isAnnotationPresent(Encrypted.class)) { - qualifierInfos.add(new EncryptedQualifier()); - } - if (klass.isAnnotationPresent(Standard.class)) { - qualifierInfos.add(new StandardQualifier()); - } - if (klass.isAnnotationPresent(PII.class)) { - qualifierInfos.add(new PIIQualifier()); - } - if (klass.isAnnotationPresent(ShortLived.class)) { - final var shortLived = klass.getAnnotation(ShortLived.class); - qualifierInfos.add(new ShortLivedQualifier(shortLived.ttlSeconds())); - } - return qualifierInfos; - } - private boolean isOptional(Type type) { if (type instanceof Class klass) { return isOptional(klass); diff --git a/leia-schema-validator/src/main/java/com/grookage/leia/validator/exception/SchemaValidationException.java b/leia-common/src/main/java/com/grookage/leia/common/exception/SchemaValidationException.java similarity index 98% rename from leia-schema-validator/src/main/java/com/grookage/leia/validator/exception/SchemaValidationException.java rename to leia-common/src/main/java/com/grookage/leia/common/exception/SchemaValidationException.java index 99667f3..20b8aca 100644 --- a/leia-schema-validator/src/main/java/com/grookage/leia/validator/exception/SchemaValidationException.java +++ b/leia-common/src/main/java/com/grookage/leia/common/exception/SchemaValidationException.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.grookage.leia.validator.exception; +package com.grookage.leia.common.exception; import lombok.Builder; import lombok.Getter; diff --git a/leia-schema-validator/src/main/java/com/grookage/leia/validator/exception/ValidationErrorCode.java b/leia-common/src/main/java/com/grookage/leia/common/exception/ValidationErrorCode.java similarity index 94% rename from leia-schema-validator/src/main/java/com/grookage/leia/validator/exception/ValidationErrorCode.java rename to leia-common/src/main/java/com/grookage/leia/common/exception/ValidationErrorCode.java index 03284aa..fff4e56 100644 --- a/leia-schema-validator/src/main/java/com/grookage/leia/validator/exception/ValidationErrorCode.java +++ b/leia-common/src/main/java/com/grookage/leia/common/exception/ValidationErrorCode.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.grookage.leia.validator.exception; +package com.grookage.leia.common.exception; import lombok.Getter; diff --git a/leia-common/src/main/java/com/grookage/leia/common/utils/QualifierUtils.java b/leia-common/src/main/java/com/grookage/leia/common/utils/QualifierUtils.java new file mode 100644 index 0000000..8fea6c4 --- /dev/null +++ b/leia-common/src/main/java/com/grookage/leia/common/utils/QualifierUtils.java @@ -0,0 +1,55 @@ +package com.grookage.leia.common.utils; + +import com.grookage.leia.models.annotations.qualifiers.Encrypted; +import com.grookage.leia.models.annotations.qualifiers.PII; +import com.grookage.leia.models.annotations.qualifiers.ShortLived; +import com.grookage.leia.models.qualifiers.EncryptedQualifier; +import com.grookage.leia.models.qualifiers.PIIQualifier; +import com.grookage.leia.models.qualifiers.QualifierInfo; +import com.grookage.leia.models.qualifiers.ShortLivedQualifier; +import lombok.experimental.UtilityClass; + +import java.lang.reflect.Field; +import java.lang.reflect.Type; +import java.util.HashSet; +import java.util.Set; + +@UtilityClass +public class QualifierUtils { + public Set getQualifierInfo(Type type) { + if (type instanceof Class klass) { + return getQualifierInfo(klass); + } + return new HashSet<>(); + } + + public Set getQualifierInfo(Field field) { + Set qualifierInfos = new HashSet<>(); + if (field.isAnnotationPresent(Encrypted.class)) { + qualifierInfos.add(new EncryptedQualifier()); + } + if (field.isAnnotationPresent(PII.class)) { + qualifierInfos.add(new PIIQualifier()); + } + if (field.isAnnotationPresent(ShortLived.class)) { + final var shortLived = field.getAnnotation(ShortLived.class); + qualifierInfos.add(new ShortLivedQualifier(shortLived.ttlSeconds())); + } + return qualifierInfos; + } + + public Set getQualifierInfo(Class klass) { + Set qualifierInfos = new HashSet<>(); + if (klass.isAnnotationPresent(Encrypted.class)) { + qualifierInfos.add(new EncryptedQualifier()); + } + if (klass.isAnnotationPresent(PII.class)) { + qualifierInfos.add(new PIIQualifier()); + } + if (klass.isAnnotationPresent(ShortLived.class)) { + final var shortLived = klass.getAnnotation(ShortLived.class); + qualifierInfos.add(new ShortLivedQualifier(shortLived.ttlSeconds())); + } + return qualifierInfos; + } +} diff --git a/leia-common/src/main/java/com/grookage/leia/common/utils/Utils.java b/leia-common/src/main/java/com/grookage/leia/common/utils/Utils.java new file mode 100644 index 0000000..1ed75e6 --- /dev/null +++ b/leia-common/src/main/java/com/grookage/leia/common/utils/Utils.java @@ -0,0 +1,56 @@ +package com.grookage.leia.common.utils; + +import com.grookage.leia.common.exception.SchemaValidationException; +import com.grookage.leia.common.exception.ValidationErrorCode; +import com.grookage.leia.models.annotations.Optional; +import lombok.experimental.UtilityClass; + +import java.lang.reflect.Field; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +@UtilityClass +public class Utils { + public List getAllFields(Class type) { + List fields = new ArrayList<>(); + for (Class c = type; c != null; c = c.getSuperclass()) { + fields.addAll(Arrays.asList(c.getDeclaredFields())); + } + return fields; + } + + public Type[] getTypeArguments(ParameterizedType parameterizedType) { + Type[] typeArguments = parameterizedType.getActualTypeArguments(); + if (typeArguments.length == 0) { + throw SchemaValidationException.error(ValidationErrorCode.INVALID_SCHEMAS, + String.format("No type arguments found for %s", parameterizedType)); + } + return typeArguments; + } + + public Set getEnumValues(Class klass) { + return Arrays.stream(klass.getEnumConstants()) + .map(enumConstant -> ((Enum) enumConstant).name()) + .collect(Collectors.toSet()); + } + + private boolean isOptional(Type type) { + if (type instanceof Class klass) { + return isOptional(klass); + } + return false; + } + + private boolean isOptional(Class klass) { + return klass.isAnnotationPresent(Optional.class); + } + + private boolean isOptional(Field field) { + return field.isAnnotationPresent(Optional.class); + } +} diff --git a/leia-schema-validator/src/main/java/com/grookage/leia/validator/utils/SchemaValidationUtils.java b/leia-common/src/main/java/com/grookage/leia/common/validation/SchemaValidationUtils.java similarity index 85% rename from leia-schema-validator/src/main/java/com/grookage/leia/validator/utils/SchemaValidationUtils.java rename to leia-common/src/main/java/com/grookage/leia/common/validation/SchemaValidationUtils.java index 5366505..3c54c8c 100644 --- a/leia-schema-validator/src/main/java/com/grookage/leia/validator/utils/SchemaValidationUtils.java +++ b/leia-common/src/main/java/com/grookage/leia/common/validation/SchemaValidationUtils.java @@ -14,9 +14,12 @@ * limitations under the License. */ -package com.grookage.leia.validator.utils; +package com.grookage.leia.common.validation; import com.google.common.collect.Sets; +import com.grookage.leia.common.exception.SchemaValidationException; +import com.grookage.leia.common.exception.ValidationErrorCode; +import com.grookage.leia.common.utils.Utils; import com.grookage.leia.models.attributes.ArrayAttribute; import com.grookage.leia.models.attributes.MapAttribute; import com.grookage.leia.models.attributes.ObjectAttribute; @@ -25,8 +28,6 @@ import com.grookage.leia.models.schema.SchemaDetails; import com.grookage.leia.models.schema.SchemaValidationType; import com.grookage.leia.models.schema.SchemaValidationVisitor; -import com.grookage.leia.validator.exception.SchemaValidationException; -import com.grookage.leia.validator.exception.ValidationErrorCode; import lombok.experimental.UtilityClass; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ClassUtils; @@ -35,8 +36,6 @@ import java.lang.reflect.GenericArrayType; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Map; @@ -64,7 +63,7 @@ public boolean valid(final SchemaDetails schemaDetails, public boolean valid(final SchemaValidationType validationType, Set attributes, final Class klass) { - final var fields = getAllFields(klass); + final var fields = Utils.getAllFields(klass); if (!validSchema(validationType, attributes, fields)) { return false; } @@ -108,14 +107,6 @@ public Boolean matching() { }); } - private List getAllFields(Class type) { - List fields = new ArrayList<>(); - for (Class c = type; c != null; c = c.getSuperclass()) { - fields.addAll(Arrays.asList(c.getDeclaredFields())); - } - return fields; - } - private boolean validAttribute(final SchemaAttribute attribute, List fields, SchemaValidationType validationType) { final var field = fields.stream() @@ -149,12 +140,12 @@ public Boolean accept(ArrayAttribute attribute) { } return valid(validationType, attribute.getElementAttribute(), klass.getComponentType()); } - return Collection.class.isAssignableFrom(klass) && attribute.getElementAttribute() == null; + return ClassUtils.isAssignable(klass, Collection.class) && attribute.getElementAttribute() == null; } @Override public Boolean accept(MapAttribute attribute) { - return Map.class.isAssignableFrom(klass) && attribute.getKeyAttribute() == null; + return ClassUtils.isAssignable(klass, Map.class) && attribute.getKeyAttribute() == null; } @Override @@ -173,10 +164,10 @@ public Boolean accept(ArrayAttribute attribute) { return true; } final var rawType = (Class) parameterizedType.getRawType(); - if (!attribute.getType().getAssignableClass().isAssignableFrom(rawType)) { + if (!ClassUtils.isAssignable(rawType, attribute.getType().getAssignableClass())) { return false; } - final var typeArguments = getTypeArguments(parameterizedType); + final var typeArguments = Utils.getTypeArguments(parameterizedType); return valid(validationType, attribute.getElementAttribute(), typeArguments[0]); } @@ -189,7 +180,7 @@ public Boolean accept(MapAttribute attribute) { if (!attribute.getType().getAssignableClass().isAssignableFrom(rawType)) { return false; } - final var typeArguments = getTypeArguments(parameterizedType); + final var typeArguments = Utils.getTypeArguments(parameterizedType); return valid(validationType, attribute.getKeyAttribute(), typeArguments[0]) && valid(validationType, attribute.getValueAttribute(), typeArguments[1]); } @@ -206,15 +197,6 @@ public Boolean accept(final ArrayAttribute attribute) { }); } - private Type[] getTypeArguments(ParameterizedType parameterizedType) { - Type[] typeArguments = parameterizedType.getActualTypeArguments(); - if (typeArguments.length == 0) { - throw SchemaValidationException.error(ValidationErrorCode.INVALID_SCHEMAS, - String.format("No type arguments found for %s", parameterizedType)); - } - return typeArguments; - } - public boolean valid(Class klass, SchemaAttribute schemaAttribute) { return schemaAttribute.accept(new SchemaAttributeHandler<>(assignableCheckFunction.apply(klass)) { }); diff --git a/leia-client/src/test/java/com/grookage/leia/client/utils/SchemaUtilTest.java b/leia-common/src/test/java/com/grookage/leia/common/builder/SchemaBuilderTest.java similarity index 78% rename from leia-client/src/test/java/com/grookage/leia/client/utils/SchemaUtilTest.java rename to leia-common/src/test/java/com/grookage/leia/common/builder/SchemaBuilderTest.java index 1e558b5..9c0a567 100644 --- a/leia-client/src/test/java/com/grookage/leia/client/utils/SchemaUtilTest.java +++ b/leia-common/src/test/java/com/grookage/leia/common/builder/SchemaBuilderTest.java @@ -1,4 +1,4 @@ -package com.grookage.leia.client.utils; +package com.grookage.leia.common.builder; import com.grookage.leia.models.annotations.Optional; import com.grookage.leia.models.annotations.qualifiers.Encrypted; @@ -16,6 +16,8 @@ import com.grookage.leia.models.attributes.SchemaAttribute; import com.grookage.leia.models.attributes.SchemaAttributeAcceptor; import com.grookage.leia.models.attributes.StringAttribute; +import com.grookage.leia.models.qualifiers.EncryptedQualifier; +import com.grookage.leia.models.qualifiers.PIIQualifier; import com.grookage.leia.models.qualifiers.QualifierInfo; import com.grookage.leia.models.qualifiers.QualifierType; import com.grookage.leia.models.qualifiers.ShortLivedQualifier; @@ -29,89 +31,89 @@ import java.util.Objects; import java.util.Set; -class SchemaUtilTest { +class SchemaBuilderTest { @Test void testSchemaAttributes_WithPrimitiveClass() { - final var schemaAttributeSet = SchemaUtil.buildSchemaAttributes(TestWithPrimitive.class); + final var schemaAttributeSet = SchemaBuilder.buildSchemaAttributes(TestWithPrimitive.class); Assertions.assertNotNull(schemaAttributeSet); Assertions.assertEquals(2, schemaAttributeSet.size()); final var nameAttribute = new StringAttribute("name", true, new HashSet<>()); - equals(nameAttribute, filter(schemaAttributeSet, "name").orElse(null)); + assertEquals(nameAttribute, filter(schemaAttributeSet, "name").orElse(null)); final var idAttribute = new IntegerAttribute("id", false, new HashSet<>()); - equals(idAttribute, filter(schemaAttributeSet, "id").orElse(null)); + assertEquals(idAttribute, filter(schemaAttributeSet, "id").orElse(null)); } @Test void testSchemaAttributes_WithRecordClass() { - final var schemaAttributeSet = SchemaUtil.buildSchemaAttributes(TestRecord.class); + final var schemaAttributeSet = SchemaBuilder.buildSchemaAttributes(TestRecord.class); Assertions.assertNotNull(schemaAttributeSet); Assertions.assertEquals(2, schemaAttributeSet.size()); - final var nameAttribute = new StringAttribute("name", false, Set.of(new com.grookage.leia.models.qualifiers.PIIQualifier())); - equals(nameAttribute, filter(schemaAttributeSet, "name").orElse(null)); + final var nameAttribute = new StringAttribute("name", false, Set.of(new PIIQualifier())); + assertEquals(nameAttribute, filter(schemaAttributeSet, "name").orElse(null)); final var idAttribute = new IntegerAttribute("id", true, new HashSet<>()); - equals(idAttribute, filter(schemaAttributeSet, "id").orElse(null)); + assertEquals(idAttribute, filter(schemaAttributeSet, "id").orElse(null)); } @Test void testSchemaAttributes_WithNestedObject() { - final var schemaAttributes = SchemaUtil.buildSchemaAttributes(TestWithNested.class); + final var schemaAttributes = SchemaBuilder.buildSchemaAttributes(TestWithNested.class); Assertions.assertFalse(schemaAttributes.isEmpty()); Assertions.assertEquals(6, schemaAttributes.size()); final var nameAttribute = new StringAttribute("name", false, new HashSet<>()); - equals(nameAttribute, filter(schemaAttributes, "name").orElse(null)); + assertEquals(nameAttribute, filter(schemaAttributes, "name").orElse(null)); final var idAttribute = new IntegerAttribute("id", false, new HashSet<>()); - equals(idAttribute, filter(schemaAttributes, "id").orElse(null)); + assertEquals(idAttribute, filter(schemaAttributes, "id").orElse(null)); final var testPIIDataAttributes = new HashSet(); final var piiNameAttribute = new StringAttribute("name", false, new HashSet<>()); - final var accountNumberAttribute = new StringAttribute("accountNumber", false, Set.of(new com.grookage.leia.models.qualifiers.EncryptedQualifier())); + final var accountNumberAttribute = new StringAttribute("accountNumber", false, Set.of(new EncryptedQualifier())); testPIIDataAttributes.add(piiNameAttribute); testPIIDataAttributes.add(accountNumberAttribute); - final var piiDataAttribute = new ObjectAttribute("piiData", false, Set.of(new com.grookage.leia.models.qualifiers.PIIQualifier()), testPIIDataAttributes); - equals(piiDataAttribute, filter(schemaAttributes, "piiData").orElse(null)); + final var piiDataAttribute = new ObjectAttribute("piiData", false, Set.of(new PIIQualifier(), new EncryptedQualifier()), testPIIDataAttributes); + assertEquals(piiDataAttribute, filter(schemaAttributes, "piiData").orElse(null)); final var testRecordAttributes = new HashSet(); - final var recordNameAttribute = new StringAttribute("name", false, Set.of(new com.grookage.leia.models.qualifiers.PIIQualifier())); + final var recordNameAttribute = new StringAttribute("name", false, Set.of(new PIIQualifier())); final var recordIdAttribute = new IntegerAttribute("id", true, new HashSet<>()); testRecordAttributes.add(recordNameAttribute); testRecordAttributes.add(recordIdAttribute); - final var testRecordAttribute = new ObjectAttribute("testRecord", false, Set.of(new com.grookage.leia.models.qualifiers.EncryptedQualifier()), + final var testRecordAttribute = new ObjectAttribute("testRecord", false, Set.of(new EncryptedQualifier()), testRecordAttributes); - equals(testRecordAttribute, filter(schemaAttributes, "testRecord").orElse(null)); + assertEquals(testRecordAttribute, filter(schemaAttributes, "testRecord").orElse(null)); final var enumClassAttribute = new EnumAttribute("enumClass", false, new HashSet<>(), Set.of(EnumClass.ONE.name(), EnumClass.TWO.name())); - equals(enumClassAttribute, filter(schemaAttributes, "enumClass").orElse(null)); + assertEquals(enumClassAttribute, filter(schemaAttributes, "enumClass").orElse(null)); - final var phoneNoAttribute = new StringAttribute("phoneNumber", false, Set.of(new com.grookage.leia.models.qualifiers.PIIQualifier())); - equals(phoneNoAttribute, filter(schemaAttributes, "phoneNumber").orElse(null)); + final var phoneNoAttribute = new StringAttribute("phoneNumber", false, Set.of(new PIIQualifier())); + assertEquals(phoneNoAttribute, filter(schemaAttributes, "phoneNumber").orElse(null)); } @Test void testSchemaAttributes_WithParameterizedType() { - final var schemaAttributes = SchemaUtil.buildSchemaAttributes(TestWithParameterized.class); + final var schemaAttributes = SchemaBuilder.buildSchemaAttributes(TestWithParameterized.class); Assertions.assertNotNull(schemaAttributes); Assertions.assertEquals(3, schemaAttributes.size()); final var valuesAttributes = new ArrayAttribute("values", false, new HashSet<>(), new StringAttribute("element", false, new HashSet<>())); - equals(valuesAttributes, filter(schemaAttributes, "values").orElse(null)); + assertEquals(valuesAttributes, filter(schemaAttributes, "values").orElse(null)); final var testPIIDataAttributes = new HashSet(); final var piiNameAttribute = new StringAttribute("name", false, new HashSet<>()); - final var accountNumberAttribute = new StringAttribute("accountNumber", false, Set.of(new com.grookage.leia.models.qualifiers.EncryptedQualifier())); + final var accountNumberAttribute = new StringAttribute("accountNumber", false, Set.of(new EncryptedQualifier())); testPIIDataAttributes.add(piiNameAttribute); testPIIDataAttributes.add(accountNumberAttribute); - final var piiDataListAttribute = new ArrayAttribute("piiDataList", false, Set.of(new com.grookage.leia.models.qualifiers.PIIQualifier()), - new ObjectAttribute("element", false, Set.of(new com.grookage.leia.models.qualifiers.PIIQualifier()), testPIIDataAttributes)); - equals(piiDataListAttribute, filter(schemaAttributes, "piiDataList").orElse(null)); + final var piiDataListAttribute = new ArrayAttribute("piiDataList", false, Set.of(new PIIQualifier()), + new ObjectAttribute("element", false, Set.of(new PIIQualifier()), testPIIDataAttributes)); + assertEquals(piiDataListAttribute, filter(schemaAttributes, "piiDataList").orElse(null)); - final var mapAttribute = new MapAttribute("map", false, Set.of(new com.grookage.leia.models.qualifiers.EncryptedQualifier()), + final var mapAttribute = new MapAttribute("map", false, Set.of(new EncryptedQualifier()), new EnumAttribute("key", false, new HashSet<>(), Set.of(EnumClass.ONE.name(), EnumClass.TWO.name())), new StringAttribute("value", false, new HashSet<>())); - equals(mapAttribute, filter(schemaAttributes, "map").orElse(null)); + assertEquals(mapAttribute, filter(schemaAttributes, "map").orElse(null)); } enum EnumClass { @@ -127,7 +129,7 @@ static class TestPIIData { } record TestRecord(@PII String name, - @Optional int id) { + @Optional int id) { } @@ -141,6 +143,7 @@ static class TestWithNested { String name; int id; @PII + @Encrypted TestPIIData piiData; @Encrypted TestRecord testRecord; @@ -164,8 +167,8 @@ private java.util.Optional filter(Set schemaAt .findFirst(); } - private void equals(SchemaAttribute expected, - SchemaAttribute original) { + private void assertEquals(SchemaAttribute expected, + SchemaAttribute original) { if (Objects.isNull(expected) && Objects.isNull(original)) { return; } @@ -174,7 +177,7 @@ private void equals(SchemaAttribute expected, Assertions.assertEquals(expected.isOptional(), original.isOptional(), "Optionality mismatch"); // Compare QualifierInfo - equals(expected.getQualifiers(), original.getQualifiers()); + assertEquals(expected.getQualifiers(), original.getQualifiers()); // Accept the expected attribute type and perform specific validations expected.accept(new SchemaAttributeAcceptor() { @@ -232,7 +235,7 @@ public Void accept(StringAttribute attribute) { public Void accept(ArrayAttribute attribute) { Assertions.assertInstanceOf(ArrayAttribute.class, original, "Original is not ArrayAttribute"); ArrayAttribute originalArray = (ArrayAttribute) original; - SchemaUtilTest.this.equals(attribute.getElementAttribute(), originalArray.getElementAttribute()); // Recursive comparison for elementAttribute + SchemaBuilderTest.this.assertEquals(attribute.getElementAttribute(), originalArray.getElementAttribute()); // Recursive comparison for elementAttribute return null; } @@ -240,8 +243,8 @@ public Void accept(ArrayAttribute attribute) { public Void accept(MapAttribute attribute) { Assertions.assertInstanceOf(MapAttribute.class, original, "Original is not MapAttribute"); MapAttribute originalMap = (MapAttribute) original; - SchemaUtilTest.this.equals(attribute.getKeyAttribute(), originalMap.getKeyAttribute()); // Recursive comparison for key - SchemaUtilTest.this.equals(attribute.getValueAttribute(), originalMap.getValueAttribute()); // Recursive comparison for value + SchemaBuilderTest.this.assertEquals(attribute.getKeyAttribute(), originalMap.getKeyAttribute()); // Recursive comparison for key + SchemaBuilderTest.this.assertEquals(attribute.getValueAttribute(), originalMap.getValueAttribute()); // Recursive comparison for value return null; } @@ -257,15 +260,15 @@ public Void accept(ObjectAttribute attribute) { Iterator originalIterator = originalObject.getNestedAttributes().iterator(); while (expectedIterator.hasNext() && originalIterator.hasNext()) { - SchemaUtilTest.this.equals(expectedIterator.next(), originalIterator.next()); + SchemaBuilderTest.this.assertEquals(expectedIterator.next(), originalIterator.next()); } return null; } }); } - private void equals(Set expected, - Set original) { + private void assertEquals(Set expected, + Set original) { Assertions.assertNotNull(expected, "Expected qualifiers should not be null"); Assertions.assertNotNull(original, "Actual qualifiers should not be null"); Assertions.assertEquals(expected.size(), original.size(), "Qualifier sets size mismatch"); diff --git a/leia-schema-validator/src/test/java/com/grookage/leia/validator/SchemaValidationUtilsTest.java b/leia-common/src/test/java/com/grookage/leia/common/validation/SchemaValidationUtilsTest.java similarity index 91% rename from leia-schema-validator/src/test/java/com/grookage/leia/validator/SchemaValidationUtilsTest.java rename to leia-common/src/test/java/com/grookage/leia/common/validation/SchemaValidationUtilsTest.java index 82fe03a..8784eb8 100644 --- a/leia-schema-validator/src/test/java/com/grookage/leia/validator/SchemaValidationUtilsTest.java +++ b/leia-common/src/test/java/com/grookage/leia/common/validation/SchemaValidationUtilsTest.java @@ -1,27 +1,21 @@ -/* - * Copyright (c) 2024. Koushik R . - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.grookage.leia.validator; +package com.grookage.leia.common.validation; +import com.grookage.leia.common.exception.ValidationErrorCode; import com.grookage.leia.models.ResourceHelper; -import com.grookage.leia.models.attributes.*; +import com.grookage.leia.models.attributes.ArrayAttribute; +import com.grookage.leia.models.attributes.BooleanAttribute; +import com.grookage.leia.models.attributes.ByteAttribute; +import com.grookage.leia.models.attributes.DataType; +import com.grookage.leia.models.attributes.DoubleAttribute; +import com.grookage.leia.models.attributes.EnumAttribute; +import com.grookage.leia.models.attributes.FloatAttribute; +import com.grookage.leia.models.attributes.IntegerAttribute; +import com.grookage.leia.models.attributes.LongAttribute; +import com.grookage.leia.models.attributes.MapAttribute; +import com.grookage.leia.models.attributes.ObjectAttribute; +import com.grookage.leia.models.attributes.StringAttribute; import com.grookage.leia.models.schema.SchemaDetails; import com.grookage.leia.models.schema.SchemaValidationType; -import com.grookage.leia.validator.exception.ValidationErrorCode; -import com.grookage.leia.validator.utils.SchemaValidationUtils; import lombok.SneakyThrows; import org.apache.commons.lang3.ClassUtils; import org.junit.jupiter.api.Assertions; @@ -33,7 +27,6 @@ import java.util.concurrent.ConcurrentHashMap; class SchemaValidationUtilsTest { - @Test @SneakyThrows void testSchemaValidator() { @@ -237,4 +230,5 @@ void testIsAssignableFrom() { Assertions.assertTrue(primitive.isPrimitive()); Assertions.assertTrue(ClassUtils.isAssignable(primitive, dataType.getAssignableClass())); } -} + +} \ No newline at end of file diff --git a/leia-schema-validator/src/test/resources/validNestedSchema.json b/leia-common/src/test/resources/validNestedSchema.json similarity index 70% rename from leia-schema-validator/src/test/resources/validNestedSchema.json rename to leia-common/src/test/resources/validNestedSchema.json index a424eeb..db00ff5 100644 --- a/leia-schema-validator/src/test/resources/validNestedSchema.json +++ b/leia-common/src/test/resources/validNestedSchema.json @@ -14,25 +14,31 @@ "type": "STRING", "name": "stringAttribute", "optional": true, - "qualifierInfo": { - "type": "PII" - } + "qualifiers": [ + { + "type": "PII" + } + ] }, { "type": "OBJECT", "name": "nestedObjectAttribute", "optional": true, - "qualifierInfo": { - "type": "PII" - }, + "qualifiers": [ + { + "type": "PII" + } + ], "nestedAttributes": [ { "type": "INTEGER", "name": "integerAttribute", "optional": true, - "qualifierInfo": { - "type": "PII" - } + "qualifiers": [ + { + "type": "PII" + } + ] } ] } diff --git a/leia-schema-validator/src/test/resources/validSchema.json b/leia-common/src/test/resources/validSchema.json similarity index 78% rename from leia-schema-validator/src/test/resources/validSchema.json rename to leia-common/src/test/resources/validSchema.json index 9c06511..a86fbf1 100644 --- a/leia-schema-validator/src/test/resources/validSchema.json +++ b/leia-common/src/test/resources/validSchema.json @@ -17,9 +17,11 @@ "elementAttribute": { "type": "STRING" }, - "qualifierInfo": { - "type": "PII" - } + "qualifiers": [ + { + "type": "PII" + } + ] }, { "type": "ENUM", @@ -28,9 +30,11 @@ "values": [ "TEST_ENUM" ], - "qualifierInfo": { - "type": "PII" - } + "qualifiers": [ + { + "type": "PII" + } + ] } ] } \ No newline at end of file diff --git a/leia-core/src/test/java/com/grookage/leia/core/utils/ValidationUtilsTest.java b/leia-core/src/test/java/com/grookage/leia/core/utils/ValidationUtilsTest.java index 061af8e..3177b2b 100644 --- a/leia-core/src/test/java/com/grookage/leia/core/utils/ValidationUtilsTest.java +++ b/leia-core/src/test/java/com/grookage/leia/core/utils/ValidationUtilsTest.java @@ -9,8 +9,12 @@ import com.grookage.leia.models.attributes.SchemaAttribute; import com.grookage.leia.models.attributes.StringAttribute; import com.grookage.leia.models.schema.SchemaValidationType; +import lombok.Builder; +import lombok.Data; import org.junit.jupiter.api.Test; +import java.util.List; +import java.util.Map; import java.util.Set; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -197,4 +201,48 @@ void testInvalidMapValueType() throws Exception { assertFalse(errors.isEmpty()); assertEquals(1, errors.size()); } + + @Test + void testValidateNested() { + final var testRecord = TestRecord.builder() + .id(100) + .name("name") + .nestedObjectsList(List.of(NestedObject.builder() + .key("key") + .version(5l) + .enumclass(Enumclass.ONE) + .build(), NestedObject.builder() + .key("key") + .version(6l) + .enumclass(Enumclass.TWO) + .build())) + .nestedObjectMap(Map.of(Enumclass.ONE, NestedObject.builder() + .key("key") + .version(7l) + .enumclass(Enumclass.ONE) + .build())) + .build(); + final var jsonNode = ResourceHelper.getObjectMapper().valueToTree(testRecord); + } + + static enum Enumclass { + ONE, + TWO + } + @Data + @Builder + static class NestedObject{ + String key; + long version; + Enumclass enumclass; + } + + @Data + @Builder + static class TestRecord { + String name; + int id; + List nestedObjectsList; + Map nestedObjectMap; + } } \ No newline at end of file diff --git a/leia-models/src/main/java/com/grookage/leia/models/annotations/qualifiers/Standard.java b/leia-models/src/main/java/com/grookage/leia/models/annotations/qualifiers/Standard.java deleted file mode 100644 index 7322ca1..0000000 --- a/leia-models/src/main/java/com/grookage/leia/models/annotations/qualifiers/Standard.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.grookage.leia.models.annotations.qualifiers; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Target({ElementType.TYPE, ElementType.FIELD}) -@Retention(RetentionPolicy.RUNTIME) -public @interface Standard { -} diff --git a/leia-models/src/test/java/com/grookage/leia/models/attributes/AttributeTest.java b/leia-models/src/test/java/com/grookage/leia/models/attributes/AttributeTest.java index 1a64f46..b85d714 100644 --- a/leia-models/src/test/java/com/grookage/leia/models/attributes/AttributeTest.java +++ b/leia-models/src/test/java/com/grookage/leia/models/attributes/AttributeTest.java @@ -17,7 +17,9 @@ package com.grookage.leia.models.attributes; import com.grookage.leia.models.ResourceHelper; +import com.grookage.leia.models.qualifiers.EncryptedQualifier; import com.grookage.leia.models.qualifiers.QualifierType; +import com.grookage.leia.models.qualifiers.ShortLivedQualifier; import lombok.SneakyThrows; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -42,6 +44,21 @@ void testAttributeStructures() { Assertions.assertSame(DataType.ARRAY, attribute.getType()); Assertions.assertEquals(1, attribute.getQualifiers().size()); Assertions.assertEquals(QualifierType.PII, attribute.getQualifiers().stream().findFirst().get().getType()); + attribute = ResourceHelper.getResource("attributes/attributeWithMultipleQualifiers.json", SchemaAttribute.class); + Assertions.assertNotNull(attribute); + Assertions.assertEquals("testAttribute", attribute.getName()); + Assertions.assertSame(DataType.ARRAY, attribute.getType()); + Assertions.assertEquals(2, attribute.getQualifiers().size()); + final var shortLivedQualifier = (ShortLivedQualifier) attribute.getQualifiers().stream() + .filter(qualifierInfo -> qualifierInfo.getType().equals(QualifierType.SHORT_LIVED)) + .findFirst().orElse(null); + Assertions.assertNotNull(shortLivedQualifier); + Assertions.assertEquals(100, shortLivedQualifier.getTtlSeconds()); + final var encryptedQualifier = (EncryptedQualifier) attribute.getQualifiers().stream() + .filter(qualifierInfo -> qualifierInfo.getType().equals(QualifierType.ENCRYPTED)) + .findFirst() + .orElse(null); + Assertions.assertNotNull(encryptedQualifier); } } diff --git a/leia-models/src/test/resources/attributes/attributeWithMultipleQualifiers.json b/leia-models/src/test/resources/attributes/attributeWithMultipleQualifiers.json new file mode 100644 index 0000000..4bb9cb7 --- /dev/null +++ b/leia-models/src/test/resources/attributes/attributeWithMultipleQualifiers.json @@ -0,0 +1,14 @@ +{ + "type": "ARRAY", + "name": "testAttribute", + "optional": true, + "qualifiers": [ + { + "type": "ENCRYPTED" + }, + { + "type": "SHORT_LIVED", + "ttlSeconds": 100 + } + ] +} \ No newline at end of file diff --git a/leia-models/src/test/resources/attributes/attributeWithQualifier.json b/leia-models/src/test/resources/attributes/attributeWithQualifier.json index 02f792c..e6bbaba 100644 --- a/leia-models/src/test/resources/attributes/attributeWithQualifier.json +++ b/leia-models/src/test/resources/attributes/attributeWithQualifier.json @@ -2,7 +2,9 @@ "type": "ARRAY", "name": "testAttribute", "optional": true, - "qualifierInfo": { - "type": "PII" - } + "qualifiers": [ + { + "type": "PII" + } + ] } \ No newline at end of file diff --git a/leia-models/src/test/resources/attributes/enumAttribute.json b/leia-models/src/test/resources/attributes/enumAttribute.json index 2b9e6ce..14cac5b 100644 --- a/leia-models/src/test/resources/attributes/enumAttribute.json +++ b/leia-models/src/test/resources/attributes/enumAttribute.json @@ -5,7 +5,9 @@ "values": [ "TEST_ENUM" ], - "qualifierInfo": { - "type": "PII" - } + "qualifiers": [ + { + "type": "PII" + } + ] } \ No newline at end of file diff --git a/leia-models/src/test/resources/schema/createSchemaRequest.json b/leia-models/src/test/resources/schema/createSchemaRequest.json index 9b473a1..64bfa43 100644 --- a/leia-models/src/test/resources/schema/createSchemaRequest.json +++ b/leia-models/src/test/resources/schema/createSchemaRequest.json @@ -7,9 +7,11 @@ "type": "ARRAY", "name": "testAttribute", "optional": true, - "qualifierInfo": { - "type": "PII" - } + "qualifiers": [ + { + "type": "PII" + } + ] } ] } \ No newline at end of file diff --git a/leia-models/src/test/resources/schema/schemaDetails.json b/leia-models/src/test/resources/schema/schemaDetails.json index 096fb47..af05efd 100644 --- a/leia-models/src/test/resources/schema/schemaDetails.json +++ b/leia-models/src/test/resources/schema/schemaDetails.json @@ -14,9 +14,11 @@ "type": "ARRAY", "name": "testAttribute", "optional": true, - "qualifierInfo": { - "type": "PII" - } + "qualifiers": [ + { + "type": "PII" + } + ] }, { "type": "ENUM", @@ -25,9 +27,14 @@ "values": [ "TEST_ENUM" ], - "qualifierInfo": { - "type": "PII" - } + "qualifiers": [ + { + "type": "PII" + }, + { + "type": "ENCRYPTED" + } + ] } ], "transformationTargets": [ diff --git a/leia-models/src/test/resources/schema/updateSchemaRequest.json b/leia-models/src/test/resources/schema/updateSchemaRequest.json index 570bdd4..d0fd2cf 100644 --- a/leia-models/src/test/resources/schema/updateSchemaRequest.json +++ b/leia-models/src/test/resources/schema/updateSchemaRequest.json @@ -9,9 +9,11 @@ "type": "ARRAY", "name": "testAttribute", "optional": true, - "qualifierInfo": { - "type": "PII" - } + "qualifiers": [ + { + "type": "PII" + } + ] }, { "type": "ENUM", @@ -20,9 +22,11 @@ "values": [ "TEST_ENUM" ], - "qualifierInfo": { - "type": "PII" - } + "qualifiers": [ + { + "type": "PII" + } + ] } ] } \ No newline at end of file diff --git a/leia-schema-validator/pom.xml b/leia-schema-validator/pom.xml index 9a0a9d5..5ce41cd 100644 --- a/leia-schema-validator/pom.xml +++ b/leia-schema-validator/pom.xml @@ -41,6 +41,10 @@ com.grookage.leia leia-models + + com.grookage.leia + leia-common + reflections diff --git a/leia-schema-validator/src/main/java/com/grookage/leia/validator/StaticSchemaValidator.java b/leia-schema-validator/src/main/java/com/grookage/leia/validator/StaticSchemaValidator.java index fe2dce8..20b96c6 100644 --- a/leia-schema-validator/src/main/java/com/grookage/leia/validator/StaticSchemaValidator.java +++ b/leia-schema-validator/src/main/java/com/grookage/leia/validator/StaticSchemaValidator.java @@ -16,12 +16,12 @@ package com.grookage.leia.validator; +import com.grookage.leia.common.exception.SchemaValidationException; +import com.grookage.leia.common.exception.ValidationErrorCode; +import com.grookage.leia.common.validation.SchemaValidationUtils; import com.grookage.leia.models.schema.SchemaDetails; import com.grookage.leia.models.schema.SchemaKey; import com.grookage.leia.validator.annotations.SchemaValidatable; -import com.grookage.leia.validator.exception.SchemaValidationException; -import com.grookage.leia.validator.exception.ValidationErrorCode; -import com.grookage.leia.validator.utils.SchemaValidationUtils; import lombok.Builder; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; diff --git a/pom.xml b/pom.xml index 462922c..52fc0b0 100644 --- a/pom.xml +++ b/pom.xml @@ -31,6 +31,7 @@ leia-parent leia-core leia-models + leia-common leia-dropwizard leia-repository leia-elastic