DATACMNS-1609, DATACMNS-1461 - Handle null intermediates in setting auditing property paths.

We now catch the MappingException produced by trying to set auditing property paths containing null intermediate segments and ignore those. A less expensive (non-Exception-based) approach is going to be introduced for Moore as it requires API changes to the property path setting APIs.

Related tickets: DATACMNS-1438.
This commit is contained in:
Oliver Drotbohm
2019-01-09 21:38:21 +01:00
committed by Christoph Strobl
parent f7398f490e
commit 71a42664c2
2 changed files with 26 additions and 5 deletions

View File

@@ -27,6 +27,7 @@ import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.domain.Auditable;
import org.springframework.data.mapping.MappingException;
import org.springframework.data.mapping.PersistentEntity;
import org.springframework.data.mapping.PersistentProperty;
import org.springframework.data.mapping.PersistentPropertyAccessor;
@@ -174,10 +175,7 @@ public class MappingAuditableBeanWrapperFactory extends DefaultAuditableBeanWrap
*/
@Override
public Object setCreatedBy(Object value) {
metadata.createdByPaths.forEach(it -> this.accessor.setProperty(it, value));
return value;
return setProperty(metadata.createdByPaths, value);
}
/*
@@ -232,7 +230,20 @@ public class MappingAuditableBeanWrapperFactory extends DefaultAuditableBeanWrap
private <S, P extends PersistentProperty<?>> S setProperty(
PersistentPropertyPaths<?, ? extends PersistentProperty<?>> paths, S value) {
paths.forEach(it -> this.accessor.setProperty(it, value));
paths.forEach(it -> {
try {
this.accessor.setProperty(it, value);
} catch (MappingException o_O) {
// Ignore null intermediate errors temporarily
if (!o_O.getMessage().contains("on null intermediate")) {
throw o_O;
}
}
});
return value;
}