DATACMNS-1609, DATACMNS-1438 - Skip collection path segments for auditing properties.
We now skip PersistentPropertyPath instances pointing to auditing properties for which the path contains a collection or map path segment as the PersistentPropertyAccessor currently cannot handle those. A more extensive fix for that will be put in place for Moore but requires more extensive API changes which we don't want to ship in a Lovelace maintenance release. Related tickets: DATACMNS-1461.
This commit is contained in:
committed by
Christoph Strobl
parent
e28a78ee8e
commit
ced3dde2a4
@@ -99,6 +99,9 @@ public class MappingAuditableBeanWrapperFactory extends DefaultAuditableBeanWrap
|
||||
*/
|
||||
static class MappingAuditingMetadata {
|
||||
|
||||
private static final Predicate<? super PersistentProperty<?>> HAS_COLLECTION_PROPERTY = it -> it.isCollectionLike()
|
||||
|| it.isMap();
|
||||
|
||||
private final PersistentPropertyPaths<?, ? extends PersistentProperty<?>> createdByPaths, createdDatePaths,
|
||||
lastModifiedByPaths, lastModifiedDatePaths;
|
||||
|
||||
@@ -113,10 +116,10 @@ public class MappingAuditableBeanWrapperFactory extends DefaultAuditableBeanWrap
|
||||
|
||||
Assert.notNull(type, "Type must not be null!");
|
||||
|
||||
this.createdByPaths = context.findPersistentPropertyPaths(type, withAnnotation(CreatedBy.class));
|
||||
this.createdDatePaths = context.findPersistentPropertyPaths(type, withAnnotation(CreatedDate.class));
|
||||
this.lastModifiedByPaths = context.findPersistentPropertyPaths(type, withAnnotation(LastModifiedBy.class));
|
||||
this.lastModifiedDatePaths = context.findPersistentPropertyPaths(type, withAnnotation(LastModifiedDate.class));
|
||||
this.createdByPaths = findPropertyPaths(type, CreatedBy.class, context);
|
||||
this.createdDatePaths = findPropertyPaths(type, CreatedDate.class, context);
|
||||
this.lastModifiedByPaths = findPropertyPaths(type, LastModifiedBy.class, context);
|
||||
this.lastModifiedDatePaths = findPropertyPaths(type, LastModifiedDate.class, context);
|
||||
|
||||
this.isAuditable = Lazy.of( //
|
||||
() -> Arrays.asList(createdByPaths, createdDatePaths, lastModifiedByPaths, lastModifiedDatePaths) //
|
||||
@@ -125,10 +128,6 @@ public class MappingAuditableBeanWrapperFactory extends DefaultAuditableBeanWrap
|
||||
);
|
||||
}
|
||||
|
||||
private static Predicate<PersistentProperty<?>> withAnnotation(Class<? extends Annotation> type) {
|
||||
return t -> t.findAnnotation(type) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the {@link PersistentEntity} is auditable at all (read: any of the auditing annotations is
|
||||
* present).
|
||||
@@ -138,6 +137,18 @@ public class MappingAuditableBeanWrapperFactory extends DefaultAuditableBeanWrap
|
||||
public boolean isAuditable() {
|
||||
return isAuditable.get();
|
||||
}
|
||||
|
||||
private PersistentPropertyPaths<?, ? extends PersistentProperty<?>> findPropertyPaths(Class<?> type,
|
||||
Class<? extends Annotation> annotation, MappingContext<?, ? extends PersistentProperty<?>> context) {
|
||||
|
||||
return context //
|
||||
.findPersistentPropertyPaths(type, withAnnotation(annotation)) //
|
||||
.dropPathIfSegmentMatches(HAS_COLLECTION_PROPERTY);
|
||||
}
|
||||
|
||||
private static Predicate<PersistentProperty<?>> withAnnotation(Class<? extends Annotation> type) {
|
||||
return t -> t.findAnnotation(type) != null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user