Skip to content

Commit

Permalink
filter-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Pikielny authored and Michael Pikielny committed Nov 4, 2019
1 parent 65ea856 commit 1e84bf5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
2 changes: 1 addition & 1 deletion gradle
25 changes: 14 additions & 11 deletions rxrepo-apt/src/main/resources/filter-body.java.vm
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 1e84bf5

Please sign in to comment.