Search in sources :

Example 16 with PlatformEntity

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

the class PlatformDAO method getOrInsertPlatform.

public PlatformEntity getOrInsertPlatform(SweText sweText, Session session) {
    PlatformEntity platform = getPlatformForIdentifier(sweText.getValue(), session);
    if (platform == null) {
        platform = new PlatformEntity();
        addIdentifier(platform, sweText.getValue(), session);
        addName(platform, sweText.getName(), session);
        addDescription(platform, sweText.getDescription());
        session.save(platform);
        session.flush();
        session.refresh(platform);
    }
    return platform;
}
Also used : PlatformEntity(org.n52.series.db.beans.PlatformEntity)

Example 17 with PlatformEntity

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

the class HibernateObservationBuilder method getPlatform.

protected PlatformEntity getPlatform() {
    PlatformEntity platform = (PlatformEntity) session.createCriteria(PlatformEntity.class).add(Restrictions.eq(PlatformEntity.IDENTIFIER, PLATFORM)).uniqueResult();
    if (platform == null) {
        platform = new PlatformEntity();
        platform.setIdentifier(PLATFORM);
        platform.setName(PLATFORM);
        session.save(platform);
        session.flush();
    }
    return platform;
}
Also used : PlatformEntity(org.n52.series.db.beans.PlatformEntity)

Example 18 with PlatformEntity

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

the class HistoricalLocationService method processThing.

private HistoricalLocationEntity processThing(HistoricalLocationEntity historicalLocation) throws STACRUDException {
    PlatformEntity thing = getThingService().createOrUpdate(historicalLocation.getThing());
    historicalLocation.setThing(thing);
    HistoricalLocationEntity created = getRepository().save(historicalLocation);
    created.setProcessed(true);
    getThingService().updateEntity(thing.addHistoricalLocation(created));
    return created.setLocations(historicalLocation.getLocations());
}
Also used : PlatformEntity(org.n52.series.db.beans.PlatformEntity) HistoricalLocationEntity(org.n52.series.db.beans.sta.HistoricalLocationEntity)

Example 19 with PlatformEntity

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

the class LocationService method delete.

@Override
public void delete(String id) throws STACRUDException {
    synchronized (getLock(id)) {
        if (getRepository().existsByStaIdentifier(id)) {
            LocationEntity location = getRepository().findByStaIdentifier(id, EntityGraphRepository.FetchGraph.FETCHGRAPH_HIST_LOCATION, EntityGraphRepository.FetchGraph.FETCHGRAPH_THINGSHISTLOCATION).get();
            for (PlatformEntity thing : location.getThings()) {
                thing.setLocations(null);
                if (location.getHistoricalLocations() != null) {
                    thing.getHistoricalLocations().removeAll(location.getHistoricalLocations());
                }
                getThingService().updateEntity(thing);
            }
            // delete all historical locations
            for (HistoricalLocationEntity historicalLocation : location.getHistoricalLocations()) {
                getHistoricalLocationService().delete(historicalLocation);
            }
            getRepository().deleteByStaIdentifier(id);
        } else {
            throw new STACRUDException(UNABLE_TO_UPDATE_ENTITY_NOT_FOUND, HTTPStatus.NOT_FOUND);
        }
    }
}
Also used : PlatformEntity(org.n52.series.db.beans.PlatformEntity) 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 20 with PlatformEntity

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

the class LocationService method fetchExpandEntities.

@Override
protected LocationEntity fetchExpandEntities(LocationEntity entity, ExpandFilter expandOption) throws STACRUDException, STAInvalidQueryException {
    for (ExpandItem expandItem : expandOption.getItems()) {
        String expandProperty = expandItem.getPath();
        if (LocationEntityDefinition.NAVIGATION_PROPERTIES.contains(expandProperty)) {
            switch(expandProperty) {
                case STAEntityDefinition.HISTORICAL_LOCATIONS:
                    Page<HistoricalLocationEntity> hLocs = getHistoricalLocationService().getEntityCollectionByRelatedEntityRaw(entity.getStaIdentifier(), STAEntityDefinition.LOCATIONS, expandItem.getQueryOptions());
                    entity.setHistoricalLocations(hLocs.get().collect(Collectors.toSet()));
                    break;
                case STAEntityDefinition.THINGS:
                    Page<PlatformEntity> things = getThingService().getEntityCollectionByRelatedEntityRaw(entity.getStaIdentifier(), STAEntityDefinition.LOCATIONS, expandItem.getQueryOptions());
                    entity.setThings(things.get().collect(Collectors.toSet()));
                    break;
                default:
                    throw new RuntimeException("This can never happen!");
            }
        } else {
            throw new STAInvalidQueryException("Invalid expandOption supplied. Cannot find " + expandProperty + " on Entity of type 'Location'");
        }
    }
    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)

Aggregations

PlatformEntity (org.n52.series.db.beans.PlatformEntity)18 HistoricalLocationEntity (org.n52.series.db.beans.sta.HistoricalLocationEntity)13 LocationEntity (org.n52.series.db.beans.sta.LocationEntity)10 DatastreamEntity (org.n52.series.db.beans.sta.DatastreamEntity)6 STACRUDException (org.n52.shetland.ogc.sta.exception.STACRUDException)6 ExpandItem (org.n52.shetland.filter.ExpandItem)5 STAInvalidQueryException (org.n52.shetland.ogc.sta.exception.STAInvalidQueryException)5 HashSet (java.util.HashSet)4 LinkedHashSet (java.util.LinkedHashSet)4 PhenomenonEntity (org.n52.series.db.beans.PhenomenonEntity)4 ProcedureEntity (org.n52.series.db.beans.ProcedureEntity)4 ObservationEntity (org.n52.series.db.beans.sta.ObservationEntity)3 Specification (org.springframework.data.jpa.domain.Specification)3 Optional (java.util.Optional)2 Set (java.util.Set)2 Expression (javax.persistence.criteria.Expression)2 Join (javax.persistence.criteria.Join)2 JoinType (javax.persistence.criteria.JoinType)2 Root (javax.persistence.criteria.Root)2 Subquery (javax.persistence.criteria.Subquery)2