use of org.n52.svalbard.odata.core.expr.arithmetic.NumericValueExpr in project arctic-sea by 52North.
the class STAQueryOptionVisitor method visitArithmeticExpr.
@Override
public ArithmeticExpr visitArithmeticExpr(STAQueryOptionsGrammar.ArithmeticExprContext ctx) {
// arithmeticExpr
// : (OP (SP)*)? (numericLiteral | memberExpr | negateExpr | arithmeticMethodCallExpr) (addExpr | subExpr |
// mulExpr | divExpr | modExpr)? (OP (SP)*)?
// ;
ArithmeticExpr left;
if (ctx.numericLiteral() != null) {
left = new NumericValueExpr(ctx.numericLiteral().getText());
} else if (ctx.memberExpr() != null) {
left = new MemberExpr(ctx.memberExpr().getText());
} else if (ctx.negateExpr() != null) {
// TODO: check if this can be done nicer than subtracting from 0
left = new SimpleArithmeticExpr(FilterConstants.SimpleArithmeticOperator.Sub, new NumericValueExpr(0), this.visitArithmeticExpr(ctx.negateExpr().arithmeticExpr()));
} else {
left = this.visitArithmeticMethodCallExpr(ctx.arithmeticMethodCallExpr());
}
ArithmeticExpr right;
if (ctx.addExpr() != null) {
right = visitAddExpr(ctx.addExpr());
return new SimpleArithmeticExpr(FilterConstants.SimpleArithmeticOperator.Add, left, right);
} else if (ctx.subExpr() != null) {
right = visitSubExpr(ctx.subExpr());
return new SimpleArithmeticExpr(FilterConstants.SimpleArithmeticOperator.Sub, left, right);
} else if (ctx.mulExpr() != null) {
right = visitMulExpr(ctx.mulExpr());
return new SimpleArithmeticExpr(FilterConstants.SimpleArithmeticOperator.Mul, left, right);
} else if (ctx.divExpr() != null) {
right = visitDivExpr(ctx.divExpr());
return new SimpleArithmeticExpr(FilterConstants.SimpleArithmeticOperator.Div, left, right);
} else if (ctx.modExpr() != null) {
right = visitModExpr(ctx.modExpr());
return new SimpleArithmeticExpr(FilterConstants.SimpleArithmeticOperator.Mod, left, right);
} else {
// There is no right Expr. return left only
return left;
}
}
use of org.n52.svalbard.odata.core.expr.arithmetic.NumericValueExpr in project arctic-sea by 52North.
the class ExpandQueryOptionTest method complexExpandOption.
@Test
public void complexExpandOption() {
init(ODataConstants.QueryOptions.EXPAND + EQ + "Observations($filter=result eq 1;$expand=FeatureOfInterest;$select=id;$orderby=id;" + "$skip=5;$top=10;$count=true),ObservedProperty");
QueryOptions options = (QueryOptions) parser.queryOptions().accept(new STAQueryOptionVisitor());
Assertions.assertTrue(options.hasExpandFilter());
Assertions.assertTrue(options.getExpandFilter() instanceof ExpandFilter);
Set<ExpandItem> items = (options.getExpandFilter().getItems());
Assertions.assertNotNull(items);
Assertions.assertEquals(2, items.size());
for (ExpandItem obs : items) {
if (obs.getPath().equals("Observations")) {
Assertions.assertEquals("Observations", obs.getPath());
Assertions.assertTrue(obs.getQueryOptions().hasExpandFilter());
Assertions.assertTrue(obs.getQueryOptions().hasFilterFilter());
Assertions.assertTrue(obs.getQueryOptions().hasSelectFilter());
Assertions.assertTrue(obs.getQueryOptions().hasOrderByFilter());
Assertions.assertTrue(obs.getQueryOptions().hasSkipFilter());
Assertions.assertTrue(obs.getQueryOptions().hasTopFilter());
Assertions.assertTrue(obs.getQueryOptions().hasCountFilter());
Set<FilterClause> filters = new HashSet<>();
filters.add(new FilterFilter(new ComparisonExpr(FilterConstants.ComparisonOperator.PropertyIsEqualTo, new MemberExpr("result"), new NumericValueExpr("1"))));
filters.add(new ExpandFilter(new ExpandItem("FeatureOfInterest", new QueryOptions("", null))));
filters.add(new SelectFilter("id"));
filters.add(new OrderByFilter(new OrderProperty("id")));
filters.add(new SkipTopFilter(FilterConstants.SkipTopOperator.Skip, 5L));
filters.add(new SkipTopFilter(FilterConstants.SkipTopOperator.Top, 10L));
filters.add(new CountFilter(true));
Assertions.assertEquals(new QueryOptions("", filters), obs.getQueryOptions());
} else if (obs.getPath().equals("ObservedProperty")) {
Assertions.assertEquals("ObservedProperty", obs.getPath());
Assertions.assertNotNull(obs.getQueryOptions());
Assertions.assertTrue(obs.getQueryOptions().hasTopFilter());
Assertions.assertFalse(obs.getQueryOptions().hasExpandFilter());
Assertions.assertFalse(obs.getQueryOptions().hasFilterFilter());
Assertions.assertFalse(obs.getQueryOptions().hasSelectFilter());
Assertions.assertFalse(obs.getQueryOptions().hasOrderByFilter());
Assertions.assertFalse(obs.getQueryOptions().hasSkipFilter());
Assertions.assertFalse(obs.getQueryOptions().hasCountFilter());
} else {
Assertions.fail("Did not find expected expandItem!");
}
}
}
Aggregations