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;
}
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;
}
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());
}
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);
}
}
}
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;
}
Aggregations