Commit 8e7c3d51 authored by Matija Obreza's avatar Matija Obreza

app-blocks: between filter operator deprecated

parent 4c32d804
......@@ -32,6 +32,7 @@ import com.querydsl.core.types.Predicate;
import com.querydsl.core.types.SubQueryExpression;
import com.querydsl.core.types.TemplateExpression;
import com.querydsl.core.types.Visitor;
import com.querydsl.core.types.dsl.NumberPath;
public class ElasticQueryBuilder implements Visitor<Void, Void> {
private static Logger LOG = LoggerFactory.getLogger(ElasticQueryBuilder.class);
......@@ -245,7 +246,11 @@ public class ElasticQueryBuilder implements Visitor<Void, Void> {
}
private void printExpression(String prefix, Expression<?> expr) {
if (expr instanceof Path<?>) {
if (expr instanceof NumberPath<?>) {
NumberPath<?> path = (NumberPath<?>) expr;
LOG.debug("{}: NumberPath {} {}", prefix, path.getRoot(), path.getType());
} else if (expr instanceof Path<?>) {
PathImpl<?> path = (PathImpl<?>) expr;
PathMetadata pmd = path.getMetadata();
if (pmd.getPathType() == PathType.COLLECTION_ANY) {
......@@ -253,12 +258,15 @@ public class ElasticQueryBuilder implements Visitor<Void, Void> {
} else {
LOG.debug("{}: {} {}/{} parent={}", prefix, pmd.getPathType(), pmd.getName(), pmd.getElement(), pmd.getParent());
}
} else if (expr instanceof Constant<?>) {
Constant<?> cons = (Constant<?>) expr;
LOG.debug("{}: Constant {} {}", prefix, cons.getConstant(), cons.getType());
} else if (expr instanceof Predicate) {
Predicate pred = (Predicate) expr;
LOG.debug("{}: should visit Predicate {}", prefix, pred);
} else {
LOG.debug("{}: {} {}", prefix, expr.getClass(), expr.getType());
}
......
......@@ -261,9 +261,9 @@ public class AppliedFiltersConverter {
}
}
private static Number take1Number(AppliedFilter af) {
private static Set<Double> takeNumbers(AppliedFilter af) {
try {
return (Number) ((LiteralValueFilter) af.getValues().iterator().next()).getValue();
return af.getValues().stream().map(fv -> ((LiteralValueFilter)fv).getValue()).map(v -> v == null ? null : ((Number)v).doubleValue()).collect(Collectors.toSet());
} catch (NoSuchElementException e) {
return null;
}
......@@ -305,7 +305,8 @@ public class AppliedFiltersConverter {
} else if (fv instanceof MaxValueFilter) {
f.le = ((Number) ((MaxValueFilter) fv).getTo()).doubleValue();
} else if (fv instanceof ValueRangeFilter) {
f.between = new Double[] { ((Number) ((ValueRangeFilter) fv).getFrom()).doubleValue(), ((Number) ((ValueRangeFilter) fv).getTo()).doubleValue() };
f.ge = ((Number) ((ValueRangeFilter) fv).getFrom()).doubleValue();
f.lt = ((Number) ((ValueRangeFilter) fv).getTo()).doubleValue();
}
}
return f;
......@@ -327,13 +328,15 @@ public class AppliedFiltersConverter {
Calendar date1 = Calendar.getInstance();
date1.setTime(date);
date1.add(Calendar.DAY_OF_MONTH, 1);
df.between = new Date[] { date, date1.getTime() };
df.ge = date;
df.le = date1.getTime();
} else if (fv instanceof MinValueFilter) {
df.ge = parseDate((String) ((MinValueFilter) fv).getFrom());
} else if (fv instanceof MaxValueFilter) {
df.le = parseDate((String) ((MaxValueFilter) fv).getTo());
} else if (fv instanceof ValueRangeFilter) {
df.between = new Date[] { parseDate((String) ((ValueRangeFilter) fv).getFrom()), parseDate((String) ((ValueRangeFilter) fv).getTo()) };
df.ge = parseDate((String) ((ValueRangeFilter) fv).getFrom());
df.le = parseDate((String) ((ValueRangeFilter) fv).getTo());
} else {
throw new RuntimeException("Unhandled date filter type=" + fv.getClass());
}
......@@ -440,9 +443,10 @@ public class AppliedFiltersConverter {
nf.ge = ((Number) min.getFrom()).doubleValue();
} else if (fv instanceof ValueRangeFilter) {
ValueRangeFilter vrf = (ValueRangeFilter) fv;
nf.between = new Double[] { ((Number) vrf.getFrom()).doubleValue(), ((Number) vrf.getTo()).doubleValue() };
nf.ge = ((Number) vrf.getFrom()).doubleValue();
nf.lt = ((Number) vrf.getTo()).doubleValue();
} else if (fv instanceof LiteralValueFilter) {
nf.eq = take1Number(af).doubleValue();
nf.eq = takeNumbers(af);
}
}
return nf;
......
......@@ -220,7 +220,7 @@ public class AccessionFilterTest {
AccessionFilter af = AccessionFilter.convert(filters);
assertThat(af.geo, notNullValue());
assertThat(af.geo.elevation, notNullValue());
assertThat(af.geo.elevation.eq, is(10d));
assertThat(af.geo.elevation.eq, contains(10d));
ElasticQueryBuilder esQb = new ElasticQueryBuilder();
af.buildQuery().accept(esQb, null);
......@@ -253,8 +253,8 @@ public class AccessionFilterTest {
af = AccessionFilter.convert(filters);
assertThat(af.geo, notNullValue());
assertThat(af.geo.elevation, notNullValue());
assertThat(af.geo.elevation.between[0], is(-20d));
assertThat(af.geo.elevation.between[1], is(30d));
assertThat(af.geo.elevation.ge, is(-20d));
assertThat(af.geo.elevation.lt, is(30d));
esQb = new ElasticQueryBuilder();
af.buildQuery().accept(esQb, null);
......@@ -265,8 +265,8 @@ public class AccessionFilterTest {
af = AccessionFilter.convert(filters);
assertThat(af.geo, notNullValue());
assertThat(af.geo.elevation, notNullValue());
assertThat(af.geo.elevation.between[0], is(-10d));
assertThat(af.geo.elevation.between[1], is(40d));
assertThat(af.geo.elevation.ge, is(-10d));
assertThat(af.geo.elevation.lt, is(40d));
esQb = new ElasticQueryBuilder();
af.buildQuery().accept(esQb, null);
......@@ -323,20 +323,20 @@ public class AccessionFilterTest {
AccessionFilter af = AccessionFilter.convert(filters);
assertThat(af.lastModifiedDate, notNullValue());
assertThat(af.lastModifiedDate.between, notNullValue());
assertThat(af.lastModifiedDate.between.length, is(2));
assertThat(af.lastModifiedDate.between[0], is(dateFormat.parse("2018-8-30")));
assertThat(af.lastModifiedDate.between[1], is(dateFormat.parse("2018-8-31")));
assertThat(af.lastModifiedDate.ge, notNullValue());
assertThat(af.lastModifiedDate.le, notNullValue());
assertThat(af.lastModifiedDate.ge, is(dateFormat.parse("2018-8-30")));
assertThat(af.lastModifiedDate.le, is(dateFormat.parse("2018-8-31")));
filters = new ObjectMapper().readValue("{\"lastModifiedDate\":[{\"dateRange\":[\"2017-12-12\",\"2018-02-02\"]}]}", AppliedFilters.class);
LOG.debug("Date filter {}", filters);
af = AccessionFilter.convert(filters);
assertThat(af.lastModifiedDate, notNullValue());
assertThat(af.lastModifiedDate.between, notNullValue());
assertThat(af.lastModifiedDate.between.length, is(2));
assertThat(af.lastModifiedDate.between[0], is(dateFormat.parse("2017-12-12")));
assertThat(af.lastModifiedDate.between[1], is(dateFormat.parse("2018-2-2")));
assertThat(af.lastModifiedDate.ge, notNullValue());
assertThat(af.lastModifiedDate.le, notNullValue());
assertThat(af.lastModifiedDate.ge, is(dateFormat.parse("2017-12-12")));
assertThat(af.lastModifiedDate.le, is(dateFormat.parse("2018-2-2")));
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment