use of org.n52.shetland.filter.SelectFilter in project sensorweb-server-sta by 52North.
the class STACollectionRequestHandler method readCollectionRefDirect.
/**
* Matches all requests on Collections referenced directly and addressing an association link
* e.g. /Datastreams/$ref
*
* @param collectionName name of the collection. Automatically set by Spring via @PathVariable
* @param request Full request
* @return CollectionWrapper Requested collection
*/
@GetMapping(value = "/{collectionName:" + BASE_COLLECTION_REGEX + "}" + SLASHREF, produces = "application/json")
public CollectionWrapper readCollectionRefDirect(@PathVariable String collectionName, HttpServletRequest request) throws STACRUDException {
HashSet<FilterClause> filters = new HashSet<>();
String queryString = request.getQueryString();
if (queryString != null) {
// Parse QueryString normally and extract relevant Filters
QueryOptions options = decodeQueryString(request);
filters.add(options.getSkipFilter());
filters.add(options.getTopFilter());
filters.add(options.getCountFilter());
filters.add(options.getFilterFilter());
}
// Overwrite select filter with filter only returning id
filters.add(new SelectFilter(ID));
return serviceRepository.getEntityService(collectionName).getEntityCollection(QUERY_OPTIONS_FACTORY.createQueryOptions(filters)).setRequestURL(rootUrl + collectionName);
}
use of org.n52.shetland.filter.SelectFilter in project sensorweb-server-sta by 52North.
the class STAEntityRequestHandler method readEntityRefDirect.
/**
* Matches all requests on Entities referenced directly via id and addressing an association link
* e.g. /Datastreams(52)/$ref
*
* @param entity name of entity. Automatically set by Spring via @PathVariable
* @param id id of entity. Automatically set by Spring via @PathVariable
* @param request full request
*/
@GetMapping(value = MAPPING_PREFIX + ENTITY_IDENTIFIED_DIRECTLY + SLASHREF, produces = "application/json")
public ElementWithQueryOptions<?> readEntityRefDirect(@PathVariable String entity, @PathVariable String id, HttpServletRequest request) throws Exception {
String requestURI = request.getRequestURI();
validateResource(requestURI.substring(request.getContextPath().length(), requestURI.length() - 5), serviceRepository);
String entityId = id.substring(1, id.length() - 1);
HashSet<FilterClause> filters = new HashSet<>();
// Overwrite select filter with filter only returning id
filters.add(new SelectFilter(ID));
return serviceRepository.getEntityService(entity).getEntity(entityId, QUERY_OPTIONS_FACTORY.createQueryOptions(filters));
}
use of org.n52.shetland.filter.SelectFilter in project sensorweb-server-sta by 52North.
the class STAPropertyRequestHandler method readEntityPropertyDirect.
private ElementWithQueryOptions<?> readEntityPropertyDirect(String entity, String id, String property, String url) throws Exception {
validateResource(url.substring(0, url.length() - property.length() - 1), serviceRepository);
validateProperty(entity, property);
String entityId = id.substring(1, id.length() - 1);
HashSet<FilterClause> filters = new HashSet<>();
// Add select filter with filter only returning property
filters.add(new SelectFilter(property));
return serviceRepository.getEntityService(entity).getEntity(entityId, QUERY_OPTIONS_FACTORY.createQueryOptions(filters));
}
use of org.n52.shetland.filter.SelectFilter in project sensorweb-server-sta by 52North.
the class STAPropertyRequestHandler method readRelatedEntityProperty.
private ElementWithQueryOptions readRelatedEntityProperty(String entity, String target, String property, String url) throws Exception {
validateResource(url.substring(0, url.length() - property.length() - 1), serviceRepository);
String sourceType = entity.substring(0, entity.indexOf("("));
String sourceId = entity.substring(sourceType.length() + 1, entity.length() - 1);
validateProperty(sourceType, property);
HashSet<FilterClause> filters = new HashSet<>();
// Add select filter with filter only returning property
filters.add(new SelectFilter(property));
return serviceRepository.getEntityService(target).getEntityByRelatedEntity(sourceId, sourceType, null, QUERY_OPTIONS_FACTORY.createQueryOptions(filters));
}
use of org.n52.shetland.filter.SelectFilter 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