DATAREST-1261 - Fixed invalid fallback to default delegate in UnwrappingRepositoryInvoker.invokeFindById(…).
Previously we fell back to the default by-id lookup even if a custom entity lookup was defined but returned an empty result.
This commit is contained in:
@@ -22,7 +22,6 @@ import java.io.Serializable;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
@@ -30,7 +29,6 @@ import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.repository.support.RepositoryInvoker;
|
||||
import org.springframework.data.repository.support.RepositoryInvokerFactory;
|
||||
import org.springframework.data.rest.core.util.Java8PluginRegistry;
|
||||
import org.springframework.data.util.Optionals;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
@@ -91,10 +89,9 @@ public class UnwrappingRepositoryInvokerFactory implements RepositoryInvokerFact
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> Optional<T> invokeFindById(Object id) {
|
||||
|
||||
Supplier<Optional<T>> viaLookup = () -> (Optional<T>) lookup.flatMap(it -> it.lookupEntity(id));
|
||||
Supplier<Optional<T>> fallback = () -> delegate.invokeFindById(id);
|
||||
|
||||
return Optionals.firstNonEmpty(viaLookup, fallback);
|
||||
return lookup.isPresent() //
|
||||
? (Optional<T>) lookup.flatMap(it -> it.lookupEntity(id)) //
|
||||
: delegate.invokeFindById(id);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -76,7 +76,7 @@ public class UnwrappingRepositoryInvokerFactoryUnitTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test // DATAREST-724
|
||||
@Test // DATAREST-724, DATAREST-1261
|
||||
@SuppressWarnings("unchecked")
|
||||
public void usesRegisteredEntityLookup() {
|
||||
|
||||
@@ -89,6 +89,7 @@ public class UnwrappingRepositoryInvokerFactoryUnitTests {
|
||||
factory.getInvokerFor(Profile.class).invokeFindById(1L);
|
||||
|
||||
verify(lookup, times(1)).lookupEntity(eq(1L));
|
||||
verify(invoker, never()).invokeFindById(eq(1L)); // DATAREST-1261
|
||||
}
|
||||
|
||||
private static Consumer<AbstractOptionalAssert<?, Object>> $(Consumer<AbstractOptionalAssert<?, Object>> consumer) {
|
||||
|
||||
Reference in New Issue
Block a user