use of org.n52.series.db.beans.sta.HistoricalLocationEntity 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.HistoricalLocationEntity 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.HistoricalLocationEntity 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.HistoricalLocationEntity 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);
}
}
use of org.n52.series.db.beans.sta.HistoricalLocationEntity in project sensorweb-server-sta by 52North.
the class MessageBusRepository method getRelatedCollections.
private <S extends T> Map<String, Set<String>> getRelatedCollections(S rawObject) {
Map<String, Set<String>> collections = new HashMap<>();
if (rawObject instanceof ProcedureEntity) {
if (rawObject instanceof SensorEntity) {
SensorEntity entity = (SensorEntity) rawObject;
if (entity.hasDatastreams()) {
collections.put(STAEntityDefinition.DATASTREAMS, entity.getDatastreams().stream().map(DatastreamEntity::getStaIdentifier).collect(Collectors.toSet()));
}
} else {
ProcedureEntity entity = (ProcedureEntity) rawObject;
collections.put(STAEntityDefinition.DATASTREAM, datastreamRepository.findAll(dQs.withSensorStaIdentifier(entity.getStaIdentifier())).stream().map(DatastreamEntity::getStaIdentifier).collect(Collectors.toSet()));
}
} else if (rawObject instanceof LocationEntity) {
LocationEntity entity = (LocationEntity) rawObject;
if (entity.hasHistoricalLocations()) {
collections.put(STAEntityDefinition.HISTORICAL_LOCATIONS, entity.getHistoricalLocations().stream().map(HistoricalLocationEntity::getStaIdentifier).collect(Collectors.toSet()));
}
if (entity.hasThings()) {
collections.put(STAEntityDefinition.THINGS, entity.getThings().stream().map(PlatformEntity::getStaIdentifier).collect(Collectors.toSet()));
}
} else if (rawObject instanceof PlatformEntity) {
PlatformEntity entity = (PlatformEntity) rawObject;
if (entity.hasLocationEntities()) {
collections.put(STAEntityDefinition.LOCATIONS, entity.getLocations().stream().map(LocationEntity::getStaIdentifier).collect(Collectors.toSet()));
}
if (entity.hasHistoricalLocations()) {
collections.put(STAEntityDefinition.HISTORICAL_LOCATIONS, entity.getHistoricalLocations().stream().map(HistoricalLocationEntity::getStaIdentifier).collect(Collectors.toSet()));
}
if (entity.hasDatastreams()) {
collections.put(STAEntityDefinition.DATASTREAMS, entity.getDatastreams().stream().map(DatastreamEntity::getStaIdentifier).collect(Collectors.toSet()));
}
} else if (rawObject instanceof DatastreamEntity) {
DatastreamEntity entity = (DatastreamEntity) rawObject;
if (entity.hasThing()) {
collections.put(STAEntityDefinition.THINGS, Collections.singleton(entity.getThing().getStaIdentifier()));
}
if (entity.hasProcedure()) {
collections.put(STAEntityDefinition.SENSORS, Collections.singleton(entity.getProcedure().getStaIdentifier()));
}
if (entity.hasObservableProperty()) {
collections.put(STAEntityDefinition.OBSERVED_PROPERTIES, Collections.singleton(entity.getObservableProperty().getStaIdentifier()));
}
} else if (rawObject instanceof HistoricalLocationEntity) {
HistoricalLocationEntity entity = (HistoricalLocationEntity) rawObject;
if (entity.hasThing()) {
collections.put(STAEntityDefinition.THINGS, Collections.singleton(entity.getThing().getStaIdentifier()));
}
if (entity.hasLocationEntities()) {
collections.put(STAEntityDefinition.LOCATIONS, entity.getLocations().stream().map(LocationEntity::getStaIdentifier).collect(Collectors.toSet()));
}
} else if (rawObject instanceof ObservationEntity<?>) {
ObservationEntity<?> entity = (ObservationEntity<?>) rawObject;
if (entity.getDataset() != null && entity.getDataset().getFeature() != null) {
collections.put(STAEntityDefinition.FEATURES_OF_INTEREST, Collections.singleton(entity.getDataset().getFeature().getStaIdentifier()));
}
Optional<DatastreamEntity> datastreamEntity = datastreamRepository.findOne(dQs.withObservationStaIdentifier(entity.getStaIdentifier()));
if (datastreamEntity.isPresent()) {
collections.put(STAEntityDefinition.DATASTREAMS, Collections.singleton(datastreamEntity.get().getStaIdentifier()));
} else {
LOGGER.debug("No Datastream associated with this Entity {}", entity.getStaIdentifier());
}
} else if (rawObject instanceof AbstractFeatureEntity) {
return collections;
} else if (rawObject instanceof PhenomenonEntity) {
PhenomenonEntity entity = (PhenomenonEntity) rawObject;
List<DatastreamEntity> observations = datastreamRepository.findAll(dQs.withObservedPropertyStaIdentifier(entity.getStaIdentifier()));
collections.put(STAEntityDefinition.DATASTREAMS, observations.stream().map(DatastreamEntity::getStaIdentifier).collect(Collectors.toSet()));
} else {
LOGGER.error("Error while computing related Collections: Could not identify Entity Type");
}
return collections;
}
Aggregations