Search in sources :

Example 1 with ExpandFilter

use of org.n52.shetland.filter.ExpandFilter in project sensorweb-server-sta by 52North.

the class ObservedPropertyService method fetchExpandEntities.

@Override
protected ObservablePropertyEntity fetchExpandEntities(PhenomenonEntity entity, ExpandFilter expandOption) throws STACRUDException, STAInvalidQueryException {
    for (ExpandItem expandItem : expandOption.getItems()) {
        String expandProperty = expandItem.getPath();
        if (ObservedPropertyEntityDefinition.NAVIGATION_PROPERTIES.contains(expandProperty)) {
            Page<DatastreamEntity> obsP = getDatastreamService().getEntityCollectionByRelatedEntityRaw(entity.getStaIdentifier(), STAEntityDefinition.OBSERVED_PROPERTIES, expandItem.getQueryOptions());
            ObservablePropertyEntity obsProp = new ObservablePropertyEntity(entity);
            return obsProp.setDatastreams(obsP.get().collect(Collectors.toSet()));
        } else {
            throw new STAInvalidQueryException("Invalid expandOption supplied. Cannot find " + expandProperty + " on Entity of type 'ObservableProperty'");
        }
    }
    return new ObservablePropertyEntity(entity);
}
Also used : STAInvalidQueryException(org.n52.shetland.ogc.sta.exception.STAInvalidQueryException) ExpandItem(org.n52.shetland.filter.ExpandItem) DatastreamEntity(org.n52.series.db.beans.sta.DatastreamEntity) ObservablePropertyEntity(org.n52.series.db.beans.sta.ObservablePropertyEntity)

Example 2 with ExpandFilter

use of org.n52.shetland.filter.ExpandFilter in project sensorweb-server-sta by 52North.

the class SensorService method fetchExpandEntities.

@Override
protected SensorEntity fetchExpandEntities(ProcedureEntity entity, ExpandFilter expandOption) throws STACRUDException, STAInvalidQueryException {
    for (ExpandItem expandItem : expandOption.getItems()) {
        String expandProperty = expandItem.getPath();
        if (SensorEntityDefinition.NAVIGATION_PROPERTIES.contains(expandProperty)) {
            Page<DatastreamEntity> observedProps = getDatastreamService().getEntityCollectionByRelatedEntityRaw(entity.getStaIdentifier(), STAEntityDefinition.SENSORS, expandItem.getQueryOptions());
            SensorEntity sensor = new SensorEntity(entity);
            return sensor.setDatastreams(observedProps.get().collect(Collectors.toSet()));
        } else {
            throw new STAInvalidQueryException("Invalid expandOption supplied. Cannot find " + expandProperty + " on Entity of type 'Sensor'");
        }
    }
    return new SensorEntity(entity);
}
Also used : STAInvalidQueryException(org.n52.shetland.ogc.sta.exception.STAInvalidQueryException) ExpandItem(org.n52.shetland.filter.ExpandItem) SensorEntity(org.n52.series.db.beans.sta.SensorEntity) DatastreamEntity(org.n52.series.db.beans.sta.DatastreamEntity)

Example 3 with ExpandFilter

use of org.n52.shetland.filter.ExpandFilter in project sensorweb-server-sta by 52North.

the class HistoricalLocationService method fetchExpandEntities.

@Override
protected HistoricalLocationEntity fetchExpandEntities(HistoricalLocationEntity entity, ExpandFilter expandOption) throws STACRUDException, STAInvalidQueryException {
    for (ExpandItem expandItem : expandOption.getItems()) {
        String expandProperty = expandItem.getPath();
        if (HistoricalLocationEntityDefinition.NAVIGATION_PROPERTIES.contains(expandProperty)) {
            switch(expandProperty) {
                case STAEntityDefinition.LOCATIONS:
                    Page<LocationEntity> locations = getLocationService().getEntityCollectionByRelatedEntityRaw(entity.getStaIdentifier(), STAEntityDefinition.HISTORICAL_LOCATIONS, expandItem.getQueryOptions());
                    entity.setLocations(locations.get().collect(Collectors.toSet()));
                    break;
                case STAEntityDefinition.THING:
                    PlatformEntity things = getThingService().getEntityByRelatedEntityRaw(entity.getStaIdentifier(), STAEntityDefinition.HISTORICAL_LOCATIONS, null, expandItem.getQueryOptions());
                    entity.setThing(things);
                    break;
                default:
                    throw new RuntimeException("This can never happen!");
            }
        } else {
            throw new STAInvalidQueryException("Invalid expandOption supplied. Cannot find " + expandProperty + " on Entity of type 'HistoricalLocation'");
        }
    }
    return entity;
}
Also used : STAInvalidQueryException(org.n52.shetland.ogc.sta.exception.STAInvalidQueryException) PlatformEntity(org.n52.series.db.beans.PlatformEntity) ExpandItem(org.n52.shetland.filter.ExpandItem) HistoricalLocationEntity(org.n52.series.db.beans.sta.HistoricalLocationEntity) LocationEntity(org.n52.series.db.beans.sta.LocationEntity)

Example 4 with ExpandFilter

use of org.n52.shetland.filter.ExpandFilter in project sensorweb-server-sta by 52North.

the class DatastreamService method fetchExpandEntities.

@Override
protected DatastreamEntity fetchExpandEntities(DatastreamEntity entity, ExpandFilter expandOption) throws STACRUDException, STAInvalidQueryException {
    for (ExpandItem expandItem : expandOption.getItems()) {
        String expandProperty = expandItem.getPath();
        if (DatastreamEntityDefinition.NAVIGATION_PROPERTIES.contains(expandProperty)) {
            switch(expandProperty) {
                case STAEntityDefinition.SENSOR:
                    ProcedureEntity sensor = getSensorService().getEntityByRelatedEntityRaw(entity.getStaIdentifier(), STAEntityDefinition.DATASTREAMS, null, expandItem.getQueryOptions());
                    entity.setProcedure(sensor);
                    break;
                case STAEntityDefinition.THING:
                    PlatformEntity thing = getThingService().getEntityByRelatedEntityRaw(entity.getStaIdentifier(), STAEntityDefinition.DATASTREAMS, null, expandItem.getQueryOptions());
                    entity.setThing(thing);
                    break;
                case STAEntityDefinition.OBSERVED_PROPERTY:
                    PhenomenonEntity obsProp = getObservedPropertyService().getEntityByRelatedEntityRaw(entity.getStaIdentifier(), STAEntityDefinition.DATASTREAMS, null, expandItem.getQueryOptions());
                    entity.setObservableProperty(obsProp);
                    break;
                case STAEntityDefinition.OBSERVATIONS:
                    Page<ObservationEntity<?>> observations = getObservationService().getEntityCollectionByRelatedEntityRaw(entity.getStaIdentifier(), STAEntityDefinition.DATASTREAMS, expandItem.getQueryOptions());
                    entity.setObservations(observations.get().collect(Collectors.toSet()));
                    break;
                default:
                    logger.error("Trying to expand unrelated Entity!");
                    throw new RuntimeException("This can never happen!");
            }
        } else {
            throw new STAInvalidQueryException("Invalid expandOption supplied. Cannot find " + expandProperty + " on Entity of type 'Datastream'");
        }
    }
    return entity;
}
Also used : ProcedureEntity(org.n52.series.db.beans.ProcedureEntity) STAInvalidQueryException(org.n52.shetland.ogc.sta.exception.STAInvalidQueryException) PlatformEntity(org.n52.series.db.beans.PlatformEntity) ExpandItem(org.n52.shetland.filter.ExpandItem) PhenomenonEntity(org.n52.series.db.beans.PhenomenonEntity) AbstractObservationEntity(org.n52.series.db.beans.sta.AbstractObservationEntity) ObservationEntity(org.n52.series.db.beans.sta.ObservationEntity)

Example 5 with ExpandFilter

use of org.n52.shetland.filter.ExpandFilter in project arctic-sea by 52North.

the class STAQueryOptionVisitor method handleSlashRewrite.

// Rewrite slash to normal expand systemQueryOption
private ExpandItem handleSlashRewrite(STAQueryOptionsGrammar.ExpandItemContext ctx, QueryOptions baseref) {
    QueryOptions base = baseref;
    if (!ctx.memberExpr().SLASH().isEmpty()) {
        for (int i = ctx.memberExpr().ALPHAPLUS().size() - 1; i >= 1; i--) {
            ExpandItem expandItem = new ExpandItem(ctx.memberExpr().ALPHAPLUS(i).getText(), base);
            ExpandFilter expandFilter = new ExpandFilter(expandItem);
            base = new QueryOptions("", Collections.singleton(expandFilter));
        }
    }
    return new ExpandItem(ctx.memberExpr().ALPHAPLUS(0).getText(), base);
}
Also used : ExpandFilter(org.n52.shetland.filter.ExpandFilter) ExpandItem(org.n52.shetland.filter.ExpandItem) QueryOptions(org.n52.shetland.oasis.odata.query.option.QueryOptions)

Aggregations

ExpandItem (org.n52.shetland.filter.ExpandItem)11 STAInvalidQueryException (org.n52.shetland.ogc.sta.exception.STAInvalidQueryException)7 DatastreamEntity (org.n52.series.db.beans.sta.DatastreamEntity)4 ExpandFilter (org.n52.shetland.filter.ExpandFilter)4 QueryOptions (org.n52.shetland.oasis.odata.query.option.QueryOptions)4 PlatformEntity (org.n52.series.db.beans.PlatformEntity)3 HistoricalLocationEntity (org.n52.series.db.beans.sta.HistoricalLocationEntity)3 Test (org.junit.jupiter.api.Test)2 LocationEntity (org.n52.series.db.beans.sta.LocationEntity)2 FilterFilter (org.n52.shetland.filter.FilterFilter)2 OrderByFilter (org.n52.shetland.filter.OrderByFilter)2 OrderProperty (org.n52.shetland.filter.OrderProperty)2 SelectFilter (org.n52.shetland.filter.SelectFilter)2 SkipTopFilter (org.n52.shetland.filter.SkipTopFilter)2 FilterClause (org.n52.shetland.ogc.filter.FilterClause)2 MemberExpr (org.n52.svalbard.odata.core.expr.MemberExpr)2 ComparisonExpr (org.n52.svalbard.odata.core.expr.bool.ComparisonExpr)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 PhenomenonEntity (org.n52.series.db.beans.PhenomenonEntity)1