use of org.n52.shetland.filter.SkipTopFilter in project sensorweb-server-sta by 52North.
the class CollectionSer method serialize.
@Override
public void serialize(CollectionWrapper value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeStartObject();
gen.writeNumberField("@iot.count", value.getTotalEntityCount());
// We have multiple pages
if (value.hasNextPage() && !value.getEntities().isEmpty()) {
QueryOptions queryOptions = value.getEntities().get(0).getQueryOptions();
long oldTop = queryOptions.getTopFilter().getValue();
long oldSkip = queryOptions.hasSkipFilter() ? queryOptions.getSkipFilter().getValue() : 0L;
// Replace old skip Filter with new one
Set<FilterClause> allFilters = queryOptions.getAllFilters();
allFilters.remove(queryOptions.getSkipFilter());
allFilters.add(new SkipTopFilter(FilterConstants.SkipTopOperator.Skip, oldSkip + oldTop));
gen.writeStringField("@iot.nextLink", value.getRequestURL() + "?" + new QueryOptions("", allFilters).toString());
}
gen.writeArrayFieldStart("value");
for (ElementWithQueryOptions element : value.getEntities()) {
provider.defaultSerializeValue(element, gen);
}
gen.writeEndArray();
gen.writeEndObject();
}
use of org.n52.shetland.filter.SkipTopFilter in project arctic-sea by 52North.
the class SkipQueryOptionTest method testValidSkipOption.
@Test
public void testValidSkipOption() {
int val = 1;
SkipTopFilter filter;
init(ODataConstants.QueryOptions.SKIP + EQ + val);
filter = ((QueryOptions) parser.queryOptions().accept(new STAQueryOptionVisitor())).getSkipFilter();
Assertions.assertEquals(filter.getOperator(), FilterConstants.SkipTopOperator.Skip);
Assertions.assertEquals(filter.getValue(), val);
val = 0;
init(ODataConstants.QueryOptions.SKIP + EQ + val);
filter = ((QueryOptions) parser.queryOptions().accept(new STAQueryOptionVisitor())).getSkipFilter();
Assertions.assertEquals(filter.getOperator(), FilterConstants.SkipTopOperator.Skip);
Assertions.assertEquals(filter.getValue(), val);
val = 100000;
init(ODataConstants.QueryOptions.SKIP + EQ + val);
filter = ((QueryOptions) parser.queryOptions().accept(new STAQueryOptionVisitor())).getSkipFilter();
Assertions.assertEquals(filter.getOperator(), FilterConstants.SkipTopOperator.Skip);
Assertions.assertEquals(filter.getValue(), val);
long longval = Long.MAX_VALUE;
init(ODataConstants.QueryOptions.SKIP + EQ + longval);
filter = ((QueryOptions) parser.queryOptions().accept(new STAQueryOptionVisitor())).getSkipFilter();
Assertions.assertEquals(filter.getOperator(), FilterConstants.SkipTopOperator.Skip);
Assertions.assertEquals(filter.getValue(), longval);
}
use of org.n52.shetland.filter.SkipTopFilter in project arctic-sea by 52North.
the class TopQueryOptionTest method testValidTopOption.
@Test
public void testValidTopOption() {
int val = 1;
SkipTopFilter filter;
init(ODataConstants.QueryOptions.TOP + EQ + val);
filter = ((QueryOptions) parser.queryOptions().accept(new STAQueryOptionVisitor())).getTopFilter();
Assertions.assertEquals(filter.getOperator(), FilterConstants.SkipTopOperator.Top);
Assertions.assertEquals(filter.getValue(), val);
val = 0;
init(ODataConstants.QueryOptions.TOP + EQ + val);
filter = ((QueryOptions) parser.queryOptions().accept(new STAQueryOptionVisitor())).getTopFilter();
Assertions.assertEquals(filter.getOperator(), FilterConstants.SkipTopOperator.Top);
Assertions.assertEquals(filter.getValue(), val);
val = 100000;
init(ODataConstants.QueryOptions.TOP + EQ + val);
filter = ((QueryOptions) parser.queryOptions().accept(new STAQueryOptionVisitor())).getTopFilter();
Assertions.assertEquals(filter.getOperator(), FilterConstants.SkipTopOperator.Top);
Assertions.assertEquals(filter.getValue(), val);
long longval = Long.MAX_VALUE;
init(ODataConstants.QueryOptions.TOP + EQ + longval);
filter = ((QueryOptions) parser.queryOptions().accept(new STAQueryOptionVisitor())).getTopFilter();
Assertions.assertEquals(filter.getOperator(), FilterConstants.SkipTopOperator.Top);
Assertions.assertEquals(filter.getValue(), longval);
}
use of org.n52.shetland.filter.SkipTopFilter 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!");
}
}
}
use of org.n52.shetland.filter.SkipTopFilter in project arctic-sea by 52North.
the class ExpandQueryOptionTest method testValidExpandOption.
@Test
public void testValidExpandOption() {
String val, nested;
ExpandFilter actual, reference;
QueryOptions defaultQO = new QueryOptions("", null);
Set<FilterClause> nestedFilters;
// Simple
val = "test";
init(ODataConstants.QueryOptions.EXPAND + EQ + val);
actual = ((QueryOptions) parser.queryOptions().accept(new STAQueryOptionVisitor())).getExpandFilter();
reference = new ExpandFilter(new ExpandItem(val, defaultQO));
Assertions.assertEquals(reference, actual);
// Resolve nested Expand
val = "test";
nested = "nested";
init(ODataConstants.QueryOptions.EXPAND + EQ + val + "/" + nested);
actual = ((QueryOptions) parser.queryOptions().accept(new STAQueryOptionVisitor())).getExpandFilter();
nestedFilters = new HashSet<>();
nestedFilters.add(new ExpandFilter(new ExpandItem(nested, defaultQO)));
reference = new ExpandFilter(new ExpandItem(val, new QueryOptions("", nestedFilters)));
Assertions.assertEquals(reference, actual);
// Expand with queryOptions
val = "test";
String queryOption = "($filter=id eq '2')";
init(ODataConstants.QueryOptions.EXPAND + EQ + val + queryOption);
actual = ((QueryOptions) parser.queryOptions().accept(new STAQueryOptionVisitor())).getExpandFilter();
nestedFilters = new HashSet<>();
nestedFilters.add(new FilterFilter(new ComparisonExpr(FilterConstants.ComparisonOperator.PropertyIsEqualTo, new MemberExpr("id"), new StringValueExpr("2"))));
reference = new ExpandFilter(new ExpandItem(val, new QueryOptions("", nestedFilters)));
Assertions.assertEquals(reference, actual);
// Expand with queryOptions
val = "test";
queryOption = "($top=52)";
init(ODataConstants.QueryOptions.EXPAND + EQ + val + queryOption);
actual = ((QueryOptions) parser.queryOptions().accept(new STAQueryOptionVisitor())).getExpandFilter();
nestedFilters = new HashSet<>();
nestedFilters.add(new SkipTopFilter(FilterConstants.SkipTopOperator.Top, 52L));
reference = new ExpandFilter(new ExpandItem(val, new QueryOptions("", nestedFilters)));
Assertions.assertEquals(reference, actual);
// Expand with queryOptions
val = "test";
queryOption = "($skip=52)";
init(ODataConstants.QueryOptions.EXPAND + EQ + val + queryOption);
actual = ((QueryOptions) parser.queryOptions().accept(new STAQueryOptionVisitor())).getExpandFilter();
nestedFilters = new HashSet<>();
nestedFilters.add(new SkipTopFilter(FilterConstants.SkipTopOperator.Skip, 52L));
reference = new ExpandFilter(new ExpandItem(val, new QueryOptions("", nestedFilters)));
Assertions.assertEquals(reference, actual);
// Expand with queryOptions
val = "test";
queryOption = "($select=id)";
init(ODataConstants.QueryOptions.EXPAND + EQ + val + queryOption);
actual = ((QueryOptions) parser.queryOptions().accept(new STAQueryOptionVisitor())).getExpandFilter();
nestedFilters = new HashSet<>();
nestedFilters.add(new SelectFilter("id"));
reference = new ExpandFilter(new ExpandItem(val, new QueryOptions("", nestedFilters)));
Assertions.assertEquals(reference, actual);
// Expand with queryOptions
val = "test";
queryOption = "($expand=nested)";
init(ODataConstants.QueryOptions.EXPAND + EQ + val + queryOption);
actual = ((QueryOptions) parser.queryOptions().accept(new STAQueryOptionVisitor())).getExpandFilter();
nestedFilters = new HashSet<>();
nestedFilters.add(new ExpandFilter(new ExpandItem(nested, defaultQO)));
reference = new ExpandFilter(new ExpandItem(val, new QueryOptions("", nestedFilters)));
Assertions.assertEquals(reference, actual);
// Expand with queryOptions
val = "test";
queryOption = "($orderby=id asc)";
init(ODataConstants.QueryOptions.EXPAND + EQ + val + queryOption);
actual = ((QueryOptions) parser.queryOptions().accept(new STAQueryOptionVisitor())).getExpandFilter();
nestedFilters = new HashSet<>();
nestedFilters.add(new OrderByFilter(new OrderProperty("id", FilterConstants.SortOrder.ASC)));
reference = new ExpandFilter(new ExpandItem(val, new QueryOptions("", nestedFilters)));
Assertions.assertEquals(reference, actual);
}
Aggregations