Search in sources :

Example 1 with FilterClause

use of org.n52.shetland.ogc.filter.FilterClause 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();
}
Also used : SkipTopFilter(org.n52.shetland.filter.SkipTopFilter) FilterClause(org.n52.shetland.ogc.filter.FilterClause) ElementWithQueryOptions(org.n52.sta.serdes.util.ElementWithQueryOptions) ElementWithQueryOptions(org.n52.sta.serdes.util.ElementWithQueryOptions) QueryOptions(org.n52.shetland.oasis.odata.query.option.QueryOptions)

Example 2 with FilterClause

use of org.n52.shetland.ogc.filter.FilterClause 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);
}
Also used : FilterClause(org.n52.shetland.ogc.filter.FilterClause) SelectFilter(org.n52.shetland.filter.SelectFilter) QueryOptions(org.n52.shetland.oasis.odata.query.option.QueryOptions) HashSet(java.util.HashSet) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 3 with FilterClause

use of org.n52.shetland.ogc.filter.FilterClause 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));
}
Also used : FilterClause(org.n52.shetland.ogc.filter.FilterClause) SelectFilter(org.n52.shetland.filter.SelectFilter) HashSet(java.util.HashSet) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 4 with FilterClause

use of org.n52.shetland.ogc.filter.FilterClause 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));
}
Also used : FilterClause(org.n52.shetland.ogc.filter.FilterClause) SelectFilter(org.n52.shetland.filter.SelectFilter) HashSet(java.util.HashSet)

Example 5 with FilterClause

use of org.n52.shetland.ogc.filter.FilterClause 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));
}
Also used : FilterClause(org.n52.shetland.ogc.filter.FilterClause) SelectFilter(org.n52.shetland.filter.SelectFilter) HashSet(java.util.HashSet)

Aggregations

FilterClause (org.n52.shetland.ogc.filter.FilterClause)9 SelectFilter (org.n52.shetland.filter.SelectFilter)8 HashSet (java.util.HashSet)7 QueryOptions (org.n52.shetland.oasis.odata.query.option.QueryOptions)5 GetMapping (org.springframework.web.bind.annotation.GetMapping)4 SkipTopFilter (org.n52.shetland.filter.SkipTopFilter)3 Test (org.junit.jupiter.api.Test)2 ExpandFilter (org.n52.shetland.filter.ExpandFilter)2 ExpandItem (org.n52.shetland.filter.ExpandItem)2 FilterFilter (org.n52.shetland.filter.FilterFilter)2 OrderByFilter (org.n52.shetland.filter.OrderByFilter)2 OrderProperty (org.n52.shetland.filter.OrderProperty)2 MemberExpr (org.n52.svalbard.odata.core.expr.MemberExpr)2 ComparisonExpr (org.n52.svalbard.odata.core.expr.bool.ComparisonExpr)2 CountFilter (org.n52.shetland.filter.CountFilter)1 ElementWithQueryOptions (org.n52.sta.serdes.util.ElementWithQueryOptions)1 StringValueExpr (org.n52.svalbard.odata.core.expr.StringValueExpr)1 NumericValueExpr (org.n52.svalbard.odata.core.expr.arithmetic.NumericValueExpr)1