Search in sources :

Example 1 with QueryOptions

use of org.n52.shetland.oasis.odata.query.option.QueryOptions 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 QueryOptions

use of org.n52.shetland.oasis.odata.query.option.QueryOptions 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 QueryOptions

use of org.n52.shetland.oasis.odata.query.option.QueryOptions in project sensorweb-server-sta by 52North.

the class STACollectionRequestHandler method readCollectionRelated.

/**
 * Matches all requests on Entities not referenced directly via id but via related entity.
 * e.g. /Datastreams(52)/Thing
 *
 * @param entity  requested entity. Automatically set by Spring via @PathVariable
 * @param target  related entity. Automatically set by Spring via @PathVariable
 * @param request full request
 * @return CollectionWrapper Requested collection
 */
@GetMapping(value = { MAPPING_PREFIX + COLLECTION_IDENTIFIED_BY_THING_PATH_VARIABLE, MAPPING_PREFIX + COLLECTION_IDENTIFIED_BY_LOCATION_PATH_VARIABLE, MAPPING_PREFIX + COLLECTION_IDENTIFIED_BY_OBSERVED_PROPERTY_PATH_VARIABLE, MAPPING_PREFIX + COLLECTION_IDENTIFIED_BY_FEATURE_OF_INTEREST_PATH_VARIABLE, MAPPING_PREFIX + COLLECTION_IDENTIFIED_BY_SENSOR_PATH_VARIABLE, MAPPING_PREFIX + COLLECTION_IDENTIFIED_BY_DATASTREAM_PATH_VARIABLE, MAPPING_PREFIX + COLLECTION_IDENTIFIED_BY_HIST_LOCATION_PATH_VARIABLE }, produces = "application/json")
public CollectionWrapper readCollectionRelated(@PathVariable String entity, @PathVariable String target, HttpServletRequest request) throws Exception {
    validateResource(request.getRequestURI().substring(request.getContextPath().length()), serviceRepository);
    String[] split = splitId(entity);
    String sourceType = split[0];
    String sourceId = split[1].replace(")", "");
    QueryOptions options = decodeQueryString(request);
    return serviceRepository.getEntityService(target).getEntityCollectionByRelatedEntity(sourceId, sourceType, options).setRequestURL(rootUrl + entity + "/" + target);
}
Also used : QueryOptions(org.n52.shetland.oasis.odata.query.option.QueryOptions) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 4 with QueryOptions

use of org.n52.shetland.oasis.odata.query.option.QueryOptions in project sensorweb-server-sta by 52North.

the class STAEntityRequestHandler method readEntityDirect.

/**
 * Matches all requests on Entities referenced directly via id
 * e.g. /Datastreams(52)
 *
 * @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, produces = "application/json")
public ElementWithQueryOptions<?> readEntityDirect(@PathVariable String entity, @PathVariable String id, HttpServletRequest request) throws Exception {
    validateResource(request.getRequestURI().substring(request.getContextPath().length()), serviceRepository);
    String entityId = id.substring(1, id.length() - 1);
    QueryOptions options = decodeQueryString(request);
    return serviceRepository.getEntityService(entity).getEntity(entityId, options);
}
Also used : ElementWithQueryOptions(org.n52.sta.serdes.util.ElementWithQueryOptions) QueryOptions(org.n52.shetland.oasis.odata.query.option.QueryOptions) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 5 with QueryOptions

use of org.n52.shetland.oasis.odata.query.option.QueryOptions in project sensorweb-server-sta by 52North.

the class STAEntityRequestHandler method readRelatedEntity.

/**
 * Matches all requests on Entities not referenced directly via id but via referenced entity
 * e.g. /Datastreams(52)/Thing
 *
 * @param entity  composite of entity and referenced entity. Automatically set by Spring via @PathVariable
 * @param request full request
 * @return JSON String representing Entity
 */
@GetMapping(value = { MAPPING_PREFIX + ENTITY_IDENTIFIED_BY_DATASTREAM_PATH_VARIABLE, MAPPING_PREFIX + ENTITY_IDENTIFIED_BY_OBSERVATION_PATH_VARIABLE, MAPPING_PREFIX + ENTITY_IDENTIFIED_BY_HISTORICAL_LOCATION_PATH_VARIABLE }, produces = "application/json")
public ElementWithQueryOptions<?> readRelatedEntity(@PathVariable String entity, @PathVariable String target, HttpServletRequest request) throws Exception {
    validateResource(request.getRequestURI().substring(request.getContextPath().length()), serviceRepository);
    String sourceType = entity.substring(0, entity.indexOf("("));
    String sourceId = entity.substring(sourceType.length() + 1, entity.length() - 1);
    QueryOptions options = decodeQueryString(request);
    return serviceRepository.getEntityService(target).getEntityByRelatedEntity(sourceId, sourceType, null, options);
}
Also used : ElementWithQueryOptions(org.n52.sta.serdes.util.ElementWithQueryOptions) QueryOptions(org.n52.shetland.oasis.odata.query.option.QueryOptions) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

QueryOptions (org.n52.shetland.oasis.odata.query.option.QueryOptions)14 Test (org.junit.jupiter.api.Test)7 ExpandItem (org.n52.shetland.filter.ExpandItem)5 SkipTopFilter (org.n52.shetland.filter.SkipTopFilter)5 FilterClause (org.n52.shetland.ogc.filter.FilterClause)5 GetMapping (org.springframework.web.bind.annotation.GetMapping)5 ExpandFilter (org.n52.shetland.filter.ExpandFilter)4 SelectFilter (org.n52.shetland.filter.SelectFilter)4 OffsetLimitBasedPageRequest (org.n52.sta.data.OffsetLimitBasedPageRequest)4 ElementWithQueryOptions (org.n52.sta.serdes.util.ElementWithQueryOptions)4 HashSet (java.util.HashSet)3 BooleanObservationEntity (org.n52.series.db.beans.sta.BooleanObservationEntity)3 CategoryObservationEntity (org.n52.series.db.beans.sta.CategoryObservationEntity)3 CountObservationEntity (org.n52.series.db.beans.sta.CountObservationEntity)3 ObservationEntity (org.n52.series.db.beans.sta.ObservationEntity)3 QuantityObservationEntity (org.n52.series.db.beans.sta.QuantityObservationEntity)3 TextObservationEntity (org.n52.series.db.beans.sta.TextObservationEntity)3 OrderByFilter (org.n52.shetland.filter.OrderByFilter)3 OrderProperty (org.n52.shetland.filter.OrderProperty)3 CollectionWrapper (org.n52.sta.data.service.util.CollectionWrapper)3