use of org.alfresco.event.sdk.model.v1.model.schema.Required in project alfresco-java-sdk by Alfresco.
the class JsonSchemaGeneratorTest method getConfigBuilder.
private SchemaGeneratorConfigBuilder getConfigBuilder(final EventEntry entry) {
final JacksonModule module = new JacksonModule(JacksonOption.RESPECT_JSONPROPERTY_ORDER);
final SchemaGeneratorConfigBuilder configBuilder = new SchemaGeneratorConfigBuilder(SchemaVersion.DRAFT_2019_09, OptionPreset.PLAIN_JSON).with(module);
configBuilder.forTypesInGeneral().withSubtypeResolver((declaredType, generationContext) -> {
if (declaredType.getErasedType() == Resource.class) {
final TypeContext typeContext = generationContext.getTypeContext();
switch(entry) {
case NODE_ENTRY:
return List.of(typeContext.resolveSubtype(declaredType, NodeResource.class));
case CHILD_ASSOC_ENTRY:
return List.of(typeContext.resolveSubtype(declaredType, ChildAssociationResource.class));
case PEER_ASSOC_ENTRY:
return List.of(typeContext.resolveSubtype(declaredType, PeerAssociationResource.class));
}
}
if (declaredType.getErasedType() == DataAttributes.class) {
final TypeContext typeContext = generationContext.getTypeContext();
if (entry == EventEntry.NODE_UPDATED_ENTRY) {
return List.of(typeContext.resolveSubtype(declaredType, EventDataWithResourceBefore.class));
} else {
return List.of(typeContext.resolveSubtype(declaredType, EventDataWithoutResourceBefore.class));
}
}
return null;
});
configBuilder.forFields().withTargetTypeOverridesResolver(field -> {
if (field.getDeclaredType().getErasedType() == URI.class) {
return Stream.of(String.class).map(specificSubtype -> field.getContext().resolve(String.class)).collect(Collectors.toList());
}
return null;
});
configBuilder.forFields().withRequiredCheck(field -> {
final Required annotation = field.getAnnotation(Required.class);
return (annotation != null);
});
return configBuilder;
}
Aggregations