spring-data-rest: remove Guava from EntityAssociationsExtractor
*/
package springfox.documentation.spring.data.rest;
-import com.google.common.base.Function;
-import com.google.common.collect.FluentIterable;
-import org.springframework.data.mapping.Association;
-import org.springframework.data.mapping.PersistentEntity;
-import org.springframework.data.mapping.PersistentProperty;
import org.springframework.data.mapping.SimpleAssociationHandler;
import org.springframework.data.rest.webmvc.mapping.Associations;
import springfox.documentation.RequestHandler;
import java.util.List;
-import static com.google.common.collect.Lists.*;
-import java.util.Optional;
+import java.util.ArrayList;
+import java.util.stream.Collectors;
public class EntityAssociationsExtractor implements EntityOperationsExtractor {
-
@Override
public List<RequestHandler> extract(final EntityContext context) {
- final List<RequestHandler> handlers = newArrayList();
- final Optional<PersistentEntity<?, ?>> potentialEntity = context.entity();
- if(!potentialEntity.isPresent()){
- return handlers;
- }
- final PersistentEntity<?, ?> entity = potentialEntity.get();
+
+ final List<RequestHandler> handlers = new ArrayList<>();
final Associations associations = context.getAssociations();
- entity.doWithAssociations(new SimpleAssociationHandler() {
+ context.entity()
+ .ifPresent(entity -> entity.doWithAssociations((SimpleAssociationHandler) association -> {
- @Override
- public void doWithAssociation(Association<? extends PersistentProperty<?>> association) {
- PersistentProperty<?> property = association.getInverse();
- if (!associations.isLinkableAssociation(property)) {
- return;
- }
+ if (associations.isLinkableAssociation(association)) {
final EntityAssociationContext associationContext = new EntityAssociationContext(context, association);
- handlers.addAll(FluentIterable.from(context.getAssociationExtractors())
- .transformAndConcat(extractHandlers(associationContext))
- .toList());
- }
- });
- return handlers;
- }
- private Function<EntityAssociationOperationsExtractor, Iterable<RequestHandler>> extractHandlers(
- final EntityAssociationContext associationContext) {
- return new Function<EntityAssociationOperationsExtractor, Iterable<RequestHandler>>() {
- @Override
- public Iterable<RequestHandler> apply(EntityAssociationOperationsExtractor input) {
- return input.extract(associationContext);
+ handlers.addAll(context.getAssociationExtractors().stream()
+ .flatMap(extractor -> extractor.extract(associationContext).stream())
+ .collect(Collectors.toList()));
}
- };
+ }));
+
+ return handlers;
}
}
