From 1e84bf5f854feaf376e6cb39fd372b6ba22ee01b Mon Sep 17 00:00:00 2001 From: Michael Pikielny Date: Mon, 4 Nov 2019 15:19:23 +0200 Subject: [PATCH] filter-fix --- gradle | 2 +- .../src/main/resources/filter-body.java.vm | 25 +++++++++++-------- .../rxrepo/queries/ExpressionsTest.java | 24 ++++++++++++++++++ 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/gradle b/gradle index f10e1dbe..5fd51b04 160000 --- a/gradle +++ b/gradle @@ -1 +1 @@ -Subproject commit f10e1dbef6f213df6e178701919444bedf63bbab +Subproject commit 5fd51b04d8901a5c595dd125ce52b89438f4157e diff --git a/rxrepo-apt/src/main/resources/filter-body.java.vm b/rxrepo-apt/src/main/resources/filter-body.java.vm index b3694c5e..ec84b6de 100644 --- a/rxrepo-apt/src/main/resources/filter-body.java.vm +++ b/rxrepo-apt/src/main/resources/filter-body.java.vm @@ -48,22 +48,25 @@ @$[com.fasterxml.jackson.annotation.JsonCreator] public static #typeParamsDeclaration($sourceClass) Filter#typeParams($sourceClass) create( +#if ($isSearchable) @$[javax.annotation.Nullable] @$[com.fasterxml.jackson.annotation.JsonProperty]("searchText") String searchText,#end #foreach ($p in $filterableProperties) - @$[javax.annotation.Nullable] @$[com.fasterxml.jackson.annotation.JsonProperty]("$p.name()") #filterType($p) ${p.name()}## - #if ($foreach.hasNext || $isSearchable),## - -## - #end## -#end## -#if ($isSearchable) @$[javax.annotation.Nullable] @$[com.fasterxml.jackson.annotation.JsonProperty]("searchText") String searchText#end## - ) { - return Filter.#typeParams($sourceClass)builder() -#foreach ($p in $filterableProperties) - .${p.name()}($p.name()) + @$[javax.annotation.Nullable] @$[com.fasterxml.jackson.annotation.JsonProperty]("$p.name()") #filterType($p) ${p.name()}, #end + @$[javax.annotation.Nullable] @$[com.fasterxml.jackson.annotation.JsonProperty]("equalsTo") $targetClass.simpleName() equalsTo, + @$[javax.annotation.Nullable] @$[com.fasterxml.jackson.annotation.JsonProperty]("notEqualsTo") $targetClass.simpleName() notEqualsTo, + @$[javax.annotation.Nullable] @$[com.fasterxml.jackson.annotation.JsonProperty]("equalsToAny") $[com.google.common.collect.ImmutableList]<$targetClass.simpleName()> equalsToAny, + @$[javax.annotation.Nullable] @$[com.fasterxml.jackson.annotation.JsonProperty]("isNull") Boolean isNull) { + return Filter.#typeParams($sourceClass)builder() #if ($isSearchable) .searchText(searchText) #end +#foreach ($p in $filterableProperties) + .${p.name()}($p.name()) +#end + .equalsTo(equalsTo) + .notEqualsTo(notEqualsTo) + .equalsToAny(equalsToAny) + .isNull(isNull) .build(); } diff --git a/rxrepo-apt/src/test/java/com/slimgears/rxrepo/queries/ExpressionsTest.java b/rxrepo-apt/src/test/java/com/slimgears/rxrepo/queries/ExpressionsTest.java index 450d3d50..200044c6 100644 --- a/rxrepo-apt/src/test/java/com/slimgears/rxrepo/queries/ExpressionsTest.java +++ b/rxrepo-apt/src/test/java/com/slimgears/rxrepo/queries/ExpressionsTest.java @@ -1,13 +1,19 @@ package com.slimgears.rxrepo.queries; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.collect.ImmutableList; import com.slimgears.rxrepo.annotations.Filterable; import com.slimgears.rxrepo.annotations.Indexable; +import com.slimgears.rxrepo.expressions.BooleanExpression; import com.slimgears.rxrepo.expressions.ObjectExpression; +import com.slimgears.rxrepo.filters.ComparableFilter; +import com.slimgears.rxrepo.filters.StringFilter; import com.slimgears.rxrepo.util.Expressions; import com.slimgears.rxrepo.util.PropertyExpressions; import org.junit.Assert; import org.junit.Test; +import java.io.IOException; import java.util.Collections; import java.util.List; import java.util.function.Function; @@ -95,6 +101,24 @@ public void testFilterByValue() { Assert.assertTrue(func.apply(testEntity1)); } + @Test + public void testFilterByValueFromJson() { + TestEntity.Filter filter = TestEntity.Filter + .create( + "", + StringFilter.fromNotEqualsTo(""), + ComparableFilter.fromNotEqualsTo(5), + TestRefEntity.Filter.builder().build(), + testEntity1, + testEntity2, + ImmutableList.of(testEntity1), + false); + Assert.assertEquals(filter.equalsTo(), testEntity1); + Assert.assertEquals(filter.notEqualsTo(), testEntity2); + Assert.assertEquals(filter.equalsToAny(), ImmutableList.of(testEntity1)); + Assert.assertEquals(Boolean.FALSE, filter.isNull()); + } + @Test public void testAnnotationRetrieval() { Assert.assertTrue(TestEntity.metaClass.text.hasAnnotation(Filterable.class));