Search in sources :

Example 1 with DatastreamEntity

use of org.n52.series.db.beans.sta.DatastreamEntity 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 DatastreamEntity

use of org.n52.series.db.beans.sta.DatastreamEntity in project sensorweb-server-sta by 52North.

the class SensorService method updateEntity.

@Override
public ProcedureEntity updateEntity(String id, ProcedureEntity entity, HttpMethod method) throws STACRUDException {
    checkUpdate(entity);
    if (HttpMethod.PATCH.equals(method)) {
        synchronized (getLock(id)) {
            Optional<ProcedureEntity> existing = getRepository().findByStaIdentifier(id, EntityGraphRepository.FetchGraph.FETCHGRAPH_FORMAT, EntityGraphRepository.FetchGraph.FETCHGRAPH_PROCEDUREHISTORY);
            if (existing.isPresent()) {
                ProcedureEntity merged = merge(existing.get(), entity);
                if (entity instanceof SensorEntity) {
                    if (((SensorEntity) entity).hasDatastreams()) {
                        AbstractSensorThingsEntityServiceImpl<?, DatastreamEntity, DatastreamEntity> dsService = getDatastreamService();
                        for (DatastreamEntity datastreamEntity : ((SensorEntity) entity).getDatastreams()) {
                            dsService.createOrUpdate(datastreamEntity);
                        }
                    }
                }
                checkFormat(merged);
                checkProcedureHistory(merged);
                getRepository().save(getAsProcedureEntity(merged));
                return merged;
            }
        }
        throw new STACRUDException("Unable to update. Entity not found.", HTTPStatus.NOT_FOUND);
    } else if (HttpMethod.PUT.equals(method)) {
        throw new STACRUDException("Http PUT is not yet supported!", HTTPStatus.NOT_IMPLEMENTED);
    }
    throw new STACRUDException("Invalid http method for updating entity!", HTTPStatus.BAD_REQUEST);
}
Also used : ProcedureEntity(org.n52.series.db.beans.ProcedureEntity) SensorEntity(org.n52.series.db.beans.sta.SensorEntity) DatastreamEntity(org.n52.series.db.beans.sta.DatastreamEntity) STACRUDException(org.n52.shetland.ogc.sta.exception.STACRUDException)

Example 3 with DatastreamEntity

use of org.n52.series.db.beans.sta.DatastreamEntity 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 4 with DatastreamEntity

use of org.n52.series.db.beans.sta.DatastreamEntity in project sensorweb-server-sta by 52North.

the class ThingService method processDatastreams.

private void processDatastreams(PlatformEntity thing) throws STACRUDException {
    if (thing.hasDatastreams()) {
        Set<DatastreamEntity> datastreams = new LinkedHashSet<>();
        for (DatastreamEntity datastream : thing.getDatastreams()) {
            datastream.setThing(thing);
            DatastreamEntity optionalDatastream = getDatastreamService().createEntity(datastream);
            datastreams.add(optionalDatastream != null ? optionalDatastream : datastream);
        }
        thing.setDatastreams(datastreams);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DatastreamEntity(org.n52.series.db.beans.sta.DatastreamEntity)

Example 5 with DatastreamEntity

use of org.n52.series.db.beans.sta.DatastreamEntity in project sensorweb-server-sta by 52North.

the class ObservationService method createEntity.

@Override
public ObservationEntity<?> createEntity(ObservationEntity<?> entity) throws STACRUDException {
    synchronized (getLock(entity.getStaIdentifier())) {
        ObservationEntity observation = entity;
        if (!observation.isProcessed()) {
            observation.setProcessed(true);
            check(observation);
            DatastreamEntity datastream = getDatastreamService().createEntity(observation.getDatastream());
            observation.setDatastream(datastream);
            // Fetch with all needed associations
            datastream = datastreamRepository.findByStaIdentifier(datastream.getStaIdentifier(), EntityGraphRepository.FetchGraph.FETCHGRAPH_THINGLOCATION, EntityGraphRepository.FetchGraph.FETCHGRAPH_PROCEDURE, EntityGraphRepository.FetchGraph.FETCHGRAPH_UOM, EntityGraphRepository.FetchGraph.FETCHGRAPH_OBS_TYPE, EntityGraphRepository.FetchGraph.FETCHGRAPH_OBSERVABLE_PROP, EntityGraphRepository.FetchGraph.FETCHGRAPH_DATASETS).orElseThrow(() -> new STACRUDException("Unable to find Datastream!"));
            AbstractFeatureEntity<?> feature = checkFeature(observation, datastream);
            // category (obdProp)
            CategoryEntity category = checkCategory();
            // offering (sensor)
            OfferingEntity offering = checkOffering(datastream);
            // dataset
            DatasetEntity dataset = checkDataset(datastream, feature, category, offering);
            // observation
            ObservationEntity<?> data = checkData(observation, dataset);
            if (data != null) {
                updateDataset(dataset, data);
                updateDatastream(datastream, dataset, data);
            }
            return data;
        }
        return observation;
    }
}
Also used : DatasetEntity(org.n52.series.db.beans.DatasetEntity) DatastreamEntity(org.n52.series.db.beans.sta.DatastreamEntity) CategoryObservationEntity(org.n52.series.db.beans.sta.CategoryObservationEntity) QuantityObservationEntity(org.n52.series.db.beans.sta.QuantityObservationEntity) TextObservationEntity(org.n52.series.db.beans.sta.TextObservationEntity) BooleanObservationEntity(org.n52.series.db.beans.sta.BooleanObservationEntity) ObservationEntity(org.n52.series.db.beans.sta.ObservationEntity) CountObservationEntity(org.n52.series.db.beans.sta.CountObservationEntity) OfferingEntity(org.n52.series.db.beans.OfferingEntity) STACRUDException(org.n52.shetland.ogc.sta.exception.STACRUDException) CategoryEntity(org.n52.series.db.beans.CategoryEntity)

Aggregations

DatastreamEntity (org.n52.series.db.beans.sta.DatastreamEntity)18 STACRUDException (org.n52.shetland.ogc.sta.exception.STACRUDException)8 ProcedureEntity (org.n52.series.db.beans.ProcedureEntity)7 FormatEntity (org.n52.series.db.beans.FormatEntity)6 ObservationEntity (org.n52.series.db.beans.sta.ObservationEntity)6 ExpandItem (org.n52.shetland.filter.ExpandItem)6 STAInvalidQueryException (org.n52.shetland.ogc.sta.exception.STAInvalidQueryException)6 DatasetEntity (org.n52.series.db.beans.DatasetEntity)5 LocationEntity (org.n52.series.db.beans.sta.LocationEntity)5 PlatformEntity (org.n52.series.db.beans.PlatformEntity)4 HashSet (java.util.HashSet)3 OfferingEntity (org.n52.series.db.beans.OfferingEntity)3 PhenomenonEntity (org.n52.series.db.beans.PhenomenonEntity)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 HistoricalLocationEntity (org.n52.series.db.beans.sta.HistoricalLocationEntity)3 SensorEntity (org.n52.series.db.beans.sta.SensorEntity)3 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 LinkedHashSet (java.util.LinkedHashSet)2