Search in sources :

Example 1 with STACRUDException

use of org.n52.shetland.ogc.sta.exception.STACRUDException 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 STACRUDException

use of org.n52.shetland.ogc.sta.exception.STACRUDException 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 STACRUDException

use of org.n52.shetland.ogc.sta.exception.STACRUDException 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 STACRUDException

use of org.n52.shetland.ogc.sta.exception.STACRUDException in project sensorweb-server-sta by 52North.

the class SensorService method checkFormat.

private void checkFormat(ProcedureEntity sensor) throws STACRUDException {
    FormatEntity format;
    synchronized (getLock(sensor.getFormat().getFormat())) {
        if (!formatRepository.existsByFormat(sensor.getFormat().getFormat())) {
            format = formatRepository.save(sensor.getFormat());
        } else {
            format = formatRepository.findByFormat(sensor.getFormat().getFormat());
        }
    }
    sensor.setFormat(format);
    if (sensor.hasProcedureHistory()) {
        sensor.getProcedureHistory().forEach(pf -> pf.setFormat(format));
    }
}
Also used : FormatEntity(org.n52.series.db.beans.FormatEntity)

Example 5 with STACRUDException

use of org.n52.shetland.ogc.sta.exception.STACRUDException in project sensorweb-server-sta by 52North.

the class ThingService method updateEntity.

@Override
@Transactional
public PlatformEntity updateEntity(String id, PlatformEntity newEntity, HttpMethod method) throws STACRUDException {
    // checkUpdate(entity);
    if (HttpMethod.PATCH.equals(method)) {
        synchronized (getLock(id)) {
            Optional<PlatformEntity> existing = getRepository().findByStaIdentifier(id, IdentifierRepository.FetchGraph.FETCHGRAPH_LOCATION, IdentifierRepository.FetchGraph.FETCHGRAPH_HIST_LOCATION);
            if (existing.isPresent()) {
                PlatformEntity merged = merge(existing.get(), newEntity);
                if (newEntity.hasLocationEntities()) {
                    boolean changedLocations = processLocations(merged, newEntity.getLocations());
                    merged = getRepository().save(merged);
                    if (changedLocations) {
                        generateHistoricalLocation(merged);
                    }
                }
                return getRepository().save(merged);
            } else {
                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 : PlatformEntity(org.n52.series.db.beans.PlatformEntity) STACRUDException(org.n52.shetland.ogc.sta.exception.STACRUDException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

STACRUDException (org.n52.shetland.ogc.sta.exception.STACRUDException)21 HistoricalLocationEntity (org.n52.series.db.beans.sta.HistoricalLocationEntity)15 DatastreamEntity (org.n52.series.db.beans.sta.DatastreamEntity)13 LocationEntity (org.n52.series.db.beans.sta.LocationEntity)12 PlatformEntity (org.n52.series.db.beans.PlatformEntity)9 ExpandItem (org.n52.shetland.filter.ExpandItem)8 STAInvalidQueryException (org.n52.shetland.ogc.sta.exception.STAInvalidQueryException)8 LinkedHashSet (java.util.LinkedHashSet)6 HashSet (java.util.HashSet)5 BooleanObservationEntity (org.n52.series.db.beans.sta.BooleanObservationEntity)5 CategoryObservationEntity (org.n52.series.db.beans.sta.CategoryObservationEntity)5 CountObservationEntity (org.n52.series.db.beans.sta.CountObservationEntity)5 ObservationEntity (org.n52.series.db.beans.sta.ObservationEntity)5 QuantityObservationEntity (org.n52.series.db.beans.sta.QuantityObservationEntity)5 FormatEntity (org.n52.series.db.beans.FormatEntity)4 ProcedureEntity (org.n52.series.db.beans.ProcedureEntity)4 TextObservationEntity (org.n52.series.db.beans.sta.TextObservationEntity)4 DatasetEntity (org.n52.series.db.beans.DatasetEntity)3 SensorEntity (org.n52.series.db.beans.sta.SensorEntity)3 LineString (org.locationtech.jts.geom.LineString)2