@Override
@SuppressWarnings("unchecked")
public Collection<? extends DomainConfigurationProblem> validateFieldMetadata(PersistentFieldMetadata fieldMetadata, Class<?> domainType, DomainConfigurationValidationContext validationContext) {
MappingContext mappingContext = validationContext.getMappingContext();
final LightAdminConfiguration lightAdminConfiguration = validationContext.getLightAdminConfiguration();
final PersistentEntity persistentEntity = mappingContext.getPersistentEntity(domainType);
PersistentProperty persistentProperty = persistentEntity.getPersistentProperty(fieldMetadata.getField());
if (persistentProperty == null) {
return newArrayList(validationContext.notPersistableFieldProblem(fieldMetadata.getName()));
}
if (!isSupportedAttributeType(PersistentPropertyType.forPersistentProperty(persistentProperty))) {
return newArrayList(validationContext.notSupportedTypeFieldProblem(fieldMetadata.getName()));
}
if (!isOfFileReferenceType(persistentProperty)) {
return emptyList();
}
Annotation annotation = persistentProperty.findAnnotation(FileReference.class);
FileReference fileReference = (FileReference) annotation;
if (isEmpty(fileReference.baseDirectory())) {
if (lightAdminConfiguration.getFileStorageDirectory() != null) {
return emptyList();
}
return newArrayList(validationContext.missingBaseDirectoryInFileReferenceProblem(fieldMetadata.getName()));
}