Skip to content

Commit

Permalink
Replace EntityEncoderFilter with per-entity object read filter #501
Browse files Browse the repository at this point in the history
cleanup, refactoring
  • Loading branch information
andrus committed Nov 28, 2021
1 parent 255fe1c commit 824cdfb
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ protected AgEntity<T> buildEntity() {
rootDataResolver != null ? rootDataResolver : ThrowingRootDataResolver.getInstance(),

// TODO: support Exp filters via annotations?
ObjectFilter.trueFilter());
ObjectFilter.allowsAllFilter());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public DataResponse<E4> getWithRequestEncoder(@Context UriInfo uriInfo, @PathPar

return Ag.service(config)
.select(E4.class)
.objectFilter(E4.class, e4 -> cVarchar.equals(e4.getCVarchar()))
.filter(E4.class, e4 -> cVarchar.equals(e4.getCVarchar()))
.uri(uriInfo)
.get();
}
Expand Down
7 changes: 5 additions & 2 deletions agrest-engine/src/main/java/io/agrest/SelectBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public interface SelectBuilder<T> {
* @return this builder instance
* @see AgBuilder#entityEncoderFilter(EntityEncoderFilter)
* @since 3.4
* @deprecated since 4.8 in favor of {@link #objectFilter(Class, ObjectFilter)}.
* @deprecated since 4.8 in favor of {@link #filter(Class, ObjectFilter)}.
*/
@Deprecated
SelectBuilder<T> entityEncoderFilter(EntityEncoderFilter filter);
Expand Down Expand Up @@ -111,10 +111,13 @@ default <A> SelectBuilder<T> propFilter(Class<A> entityType, PropertyFilter filt
}

/**
* Installs an in-memory filter for a given entity type that will exclude objects from response that do not match
* the filter. This filter is combined with any runtime-level filters for the same entity.
*
* @return this builder instance
* @since 4.8
*/
default <A> SelectBuilder<T> objectFilter(Class<A> entityType, ObjectFilter<A> filter) {
default <A> SelectBuilder<T> filter(Class<A> entityType, ObjectFilter<A> filter) {
return entityOverlay(AgEntity.overlay(entityType).selectFilter(filter));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ protected AgEntity<T> buildEntity() {
rootDataResolver != null ? rootDataResolver : ThrowingRootDataResolver.getInstance(),

// TODO: support Exp filters via annotations?
ObjectFilter.trueFilter());
ObjectFilter.allowsAllFilter());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@FunctionalInterface
public interface ObjectFilter<T> {

static <T> ObjectFilter<T> trueFilter() {
static <T> ObjectFilter<T> allowsAllFilter() {
return AllowAllObjectFilter.instance;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public AgEntityOverlay(Class<T> type) {
this.type = type;
this.attributes = new HashMap<>();
this.relationships = new HashMap<>();
this.selectFilter = ObjectFilter.trueFilter();
this.selectFilter = ObjectFilter.allowsAllFilter();
}

private static PropertyReader fromFunction(Function<?, ?> f) {
Expand Down

0 comments on commit 824cdfb

Please sign in to comment.