DATACMNS-1671 - Ignore date auditing property paths if intermediate path is null.

We now ignore failures from setting property paths for date-based auditing properties. With DATACMNS-1461 we introduced a lenient approach for create/modify user properties and this change now consistently introduces lenient error handling for all properties.
This commit is contained in:
Mark Paluch
2020-02-24 15:30:06 +01:00
parent 589d5c2024
commit e49c1a3e6f
2 changed files with 17 additions and 3 deletions

View File

@@ -45,6 +45,7 @@ import org.springframework.util.ConcurrentReferenceHashMap;
*
* @author Oliver Gierke
* @author Christoph Strobl
* @author Mark Paluch
* @since 1.8
*/
public class MappingAuditableBeanWrapperFactory extends DefaultAuditableBeanWrapperFactory {
@@ -262,8 +263,20 @@ public class MappingAuditableBeanWrapperFactory extends DefaultAuditableBeanWrap
private <P extends PersistentProperty<?>> TemporalAccessor setDateProperty(
PersistentPropertyPaths<?, ? extends PersistentProperty<?>> property, TemporalAccessor value) {
property.forEach(it -> this.accessor.setProperty(it,
getDateValueToSet(value, it.getRequiredLeafProperty().getType(), accessor.getBean())));
property.forEach(it -> {
try {
this.accessor.setProperty(it,
getDateValueToSet(value, it.getRequiredLeafProperty().getType(), accessor.getBean()));
} catch (MappingException o_O) {
// Ignore null intermediate errors temporarily
if (!o_O.getMessage().contains("on null intermediate")) {
throw o_O;
}
}
});
return value;
}

View File

@@ -216,13 +216,14 @@ public class MappingAuditableBeanWrapperFactoryUnitTests {
});
}
@Test // DATACMNS-1461
@Test // DATACMNS-1461, DATACMNS-1671
public void skipsNullIntermediatesWhenSettingProperties() {
WithEmbedded withEmbedded = new WithEmbedded();
assertThat(factory.getBeanWrapperFor(withEmbedded)).hasValueSatisfying(it -> {
assertThatCode(() -> it.setCreatedBy("user")).doesNotThrowAnyException();
assertThatCode(() -> it.setLastModifiedDate(Instant.now())).doesNotThrowAnyException();
});
}