Search in sources :

Example 1 with LocationEntity

use of org.n52.series.db.beans.sta.LocationEntity in project SOS by 52North.

the class PlatformDAO method getOrInsertHistoricalLocation.

private HistoricalLocationEntity getOrInsertHistoricalLocation(PlatformEntity platform, LocationEntity location, Session session) {
    HistoricalLocationEntity historicalLocation = new HistoricalLocationEntity();
    historicalLocation.setIdentifier(UUID.randomUUID().toString(), getDaoFactory().isStaSupportsUrls());
    historicalLocation.setThing(platform);
    historicalLocation.setTime(DateTime.now().toDate());
    session.save(historicalLocation);
    session.flush();
    session.refresh(historicalLocation);
    location.addHistoricalLocation(historicalLocation);
    session.saveOrUpdate(location);
    session.flush();
    return historicalLocation;
}
Also used : HistoricalLocationEntity(org.n52.series.db.beans.sta.HistoricalLocationEntity)

Example 2 with LocationEntity

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

the class ServiceUtils method createFeatureOfInterest.

static AbstractFeatureEntity<?> createFeatureOfInterest(LocationEntity location) {
    FeatureEntity featureOfInterest = new FeatureEntity();
    featureOfInterest.setIdentifier(location.getIdentifier());
    featureOfInterest.setStaIdentifier(location.getStaIdentifier());
    // Used to distinguish in FeatureOfInterestService
    featureOfInterest.setXml("autogenerated");
    featureOfInterest.setName(location.getName());
    featureOfInterest.setDescription(location.getDescription());
    featureOfInterest.setGeometryEntity(location.getGeometryEntity());
    featureOfInterest.setFeatureType(createFeatureType(location.getGeometry()));
    return featureOfInterest;
}
Also used : AbstractFeatureEntity(org.n52.series.db.beans.AbstractFeatureEntity) FeatureEntity(org.n52.series.db.beans.FeatureEntity)

Example 3 with LocationEntity

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

the class ThingService method generateHistoricalLocation.

private void generateHistoricalLocation(PlatformEntity thing) throws STACRUDException {
    if (thing == null) {
        throw new STACRUDException("Error processing HistoricalLocations. Thing does not exist!");
    }
    // Persist nested HistoricalLocations
    if (thing.hasHistoricalLocations()) {
        Set<HistoricalLocationEntity> historicalLocations = thing.getHistoricalLocations();
        thing.setHistoricalLocations(null);
        for (HistoricalLocationEntity historicalLocation : historicalLocations) {
            // Check if historicalLocation is not already persisted
            if (historicalLocation.getId() == null) {
                getHistoricalLocationService().createOrUpdate(historicalLocation);
            }
        }
    }
    // Create new HistoricalLocation based on current location
    if (thing.hasLocationEntities()) {
        Set<HistoricalLocationEntity> historicalLocations = thing.hasHistoricalLocations() ? new LinkedHashSet<>(thing.getHistoricalLocations()) : new LinkedHashSet<>();
        HistoricalLocationEntity historicalLocation = new HistoricalLocationEntity();
        historicalLocation.setIdentifier(UUID.randomUUID().toString());
        historicalLocation.setThing(thing);
        historicalLocation.setTime(DateTime.now().toDate());
        historicalLocation.setProcessed(true);
        HistoricalLocationEntity createdHistoricalLocation = getHistoricalLocationService().createOrUpdate(historicalLocation);
        if (createdHistoricalLocation != null) {
            historicalLocations.add(createdHistoricalLocation);
        }
        for (LocationEntity location : thing.getLocations()) {
            location.setHistoricalLocations(Collections.singleton(createdHistoricalLocation));
            getLocationService().createOrUpdate(location);
        }
        thing.setHistoricalLocations(historicalLocations);
    }
}
Also used : HistoricalLocationEntity(org.n52.series.db.beans.sta.HistoricalLocationEntity) LocationEntity(org.n52.series.db.beans.sta.LocationEntity) HistoricalLocationEntity(org.n52.series.db.beans.sta.HistoricalLocationEntity) STACRUDException(org.n52.shetland.ogc.sta.exception.STACRUDException)

Example 4 with LocationEntity

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

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

the class HistoricalLocationService method updateLocations.

private void updateLocations(HistoricalLocationEntity historicalLocation) throws STACRUDException {
    for (LocationEntity location : historicalLocation.getLocations()) {
        location.getHistoricalLocations().remove(historicalLocation);
        getLocationService().updateEntity(location);
    }
}
Also used : HistoricalLocationEntity(org.n52.series.db.beans.sta.HistoricalLocationEntity) LocationEntity(org.n52.series.db.beans.sta.LocationEntity)

Aggregations

HistoricalLocationEntity (org.n52.series.db.beans.sta.HistoricalLocationEntity)17 LocationEntity (org.n52.series.db.beans.sta.LocationEntity)16 PlatformEntity (org.n52.series.db.beans.PlatformEntity)6 STACRUDException (org.n52.shetland.ogc.sta.exception.STACRUDException)6 HashSet (java.util.HashSet)3 LinkedHashSet (java.util.LinkedHashSet)3 DatastreamEntity (org.n52.series.db.beans.sta.DatastreamEntity)3 ExpandItem (org.n52.shetland.filter.ExpandItem)3 STAInvalidQueryException (org.n52.shetland.ogc.sta.exception.STAInvalidQueryException)3 AbstractFeatureEntity (org.n52.series.db.beans.AbstractFeatureEntity)2 FormatEntity (org.n52.series.db.beans.FormatEntity)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Matcher (java.util.regex.Matcher)1 Expression (javax.persistence.criteria.Expression)1 Join (javax.persistence.criteria.Join)1 JoinType (javax.persistence.criteria.JoinType)1 Root (javax.persistence.criteria.Root)1