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