-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Util classes for building and validating schema + leia-common #11
Conversation
leia-client/src/main/java/com/grookage/leia/client/utils/SchemaUtil.java
Outdated
Show resolved
Hide resolved
leia-client/src/main/java/com/grookage/leia/client/utils/SchemaUtil.java
Outdated
Show resolved
Hide resolved
leia-client/src/main/java/com/grookage/leia/client/utils/SchemaUtil.java
Outdated
Show resolved
Hide resolved
leia-client/src/main/java/com/grookage/leia/client/utils/SchemaUtil.java
Outdated
Show resolved
Hide resolved
leia-client/src/main/java/com/grookage/leia/client/utils/SchemaUtil.java
Outdated
Show resolved
Hide resolved
leia-client/src/main/java/com/grookage/leia/client/utils/SchemaUtil.java
Outdated
Show resolved
Hide resolved
leia-client/src/main/java/com/grookage/leia/client/utils/SchemaUtil.java
Outdated
Show resolved
Hide resolved
leia-client/src/main/java/com/grookage/leia/client/utils/SchemaUtil.java
Outdated
Show resolved
Hide resolved
leia-core/src/main/java/com/grookage/leia/core/utils/ValidationUtils.java
Outdated
Show resolved
Hide resolved
leia-models/src/main/java/com/grookage/leia/models/annotations/qualifiers/ShortLived.java
Outdated
Show resolved
Hide resolved
...-schema-validator/src/main/java/com/grookage/leia/validator/utils/SchemaValidationUtils.java
Outdated
Show resolved
Hide resolved
...-schema-validator/src/main/java/com/grookage/leia/validator/utils/SchemaValidationUtils.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a few comments. A couple of high level questions, should we change the SchemaValidatable annotation to look like the following?
`@Target({ElementType.TYPE})
@retention(RetentionPolicy.RUNTIME)
public @interface SchemaDefinition {
SchemaType type() default SchemaType.JSON;
SchemaValidationType validationType() default SchemaValidationType.MATCHING;
SchemaState state() default SchemaState.CREATED;
String schemaName();
String versionId();
String namespace();
String description() default "";
Class<?>[] transformationTargets();
}`
And use the above to build the CreateSchemaRequest itself?
Roughly I'm thinking,
`
@OverRide
public Optional getDetails(Class<?> klass) {
if (null == klass) {
log.debug("No klass definition provided. Can't convert");
return Optional.empty();
}
final var schemaDefinition = klass.getAnnotation(SchemaDefinition.class);
if (null == schemaDefinition) {
log.debug("The klass {} is not annotated with SchemaDefinition. Can't convert", klass.getSimpleName());
return Optional.empty();
}
return Optional.of(CreateSchemaRequest.builder()
.schemaType(schemaDefinition.type())
.validationType(schemaDefinition.validationType())
.description(schemaDefinition.description())
.schemaName(schemaDefinition.schemaName())
.namespace(schemaDefinition.namespace())
.attributes(
FieldUtils.getAllFields(klass)
.stream()
.map(SchemaAttributeUtils::getAttribute)
.collect(Collectors.toSet())
)
.transformationTargets(
SchemaAttributeUtils.getTransformationTargets(
klass,
schemaDefinition.transformationTargets()
)
)
.build());
}
`
Also should we do SchemaUtils (Or SchemaAttributeUtils) as part of the schema-validator itself - also the ValidationUtils must move here? leia-client can use the validator as a dependency then?
leia-common/src/main/java/com/grookage/leia/common/utils/QualifierUtils.java
Outdated
Show resolved
Hide resolved
.findFirst(); | ||
} | ||
|
||
public Set<QualifierInfo> getQualifierInfo(final Type type) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same, rename this to getQualifer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, changed it to getQualifiers
leia-common/src/main/java/com/grookage/leia/common/utils/QualifierUtils.java
Outdated
Show resolved
Hide resolved
leia-common/src/main/java/com/grookage/leia/common/utils/SchemaAttributeUtils.java
Outdated
Show resolved
Hide resolved
leia-common/src/main/java/com/grookage/leia/common/utils/Utils.java
Outdated
Show resolved
Hide resolved
import java.util.Set; | ||
|
||
@UtilityClass | ||
public class TestUtils { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename this to LeiaTestUtils
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a few comments
leia-common
module to host all the common utils classes. Moved theSchemaValidationUtils
andSchemaException
classes fromleia-schema-validator
to this module.PII
,Encrypted
,ShortLived
) that can be added on the members of the Schema class.SchemaBuilder
andSchemaPayloadValidator
-
SchemaBuilder
: For building the schema request against a class annotated withSchemaDefinition
-
SchemaPayloadValidator
: For validating a schema json payload against a specifiedSchemaKey
Object
and Primitive Class types inSchemaValidationUtils
leia-core
andleia-schema-validator
to includeleia-common