use of org.n52.series.db.beans.DatasetEntity in project sensorweb-server-sta by 52North.
the class ObservationService method createEntity.
@Override
public ObservationEntity<?> createEntity(ObservationEntity<?> entity) throws STACRUDException {
synchronized (getLock(entity.getStaIdentifier())) {
ObservationEntity observation = entity;
if (!observation.isProcessed()) {
observation.setProcessed(true);
check(observation);
DatastreamEntity datastream = getDatastreamService().createEntity(observation.getDatastream());
observation.setDatastream(datastream);
// Fetch with all needed associations
datastream = datastreamRepository.findByStaIdentifier(datastream.getStaIdentifier(), EntityGraphRepository.FetchGraph.FETCHGRAPH_THINGLOCATION, EntityGraphRepository.FetchGraph.FETCHGRAPH_PROCEDURE, EntityGraphRepository.FetchGraph.FETCHGRAPH_UOM, EntityGraphRepository.FetchGraph.FETCHGRAPH_OBS_TYPE, EntityGraphRepository.FetchGraph.FETCHGRAPH_OBSERVABLE_PROP, EntityGraphRepository.FetchGraph.FETCHGRAPH_DATASETS).orElseThrow(() -> new STACRUDException("Unable to find Datastream!"));
AbstractFeatureEntity<?> feature = checkFeature(observation, datastream);
// category (obdProp)
CategoryEntity category = checkCategory();
// offering (sensor)
OfferingEntity offering = checkOffering(datastream);
// dataset
DatasetEntity dataset = checkDataset(datastream, feature, category, offering);
// observation
ObservationEntity<?> data = checkData(observation, dataset);
if (data != null) {
updateDataset(dataset, data);
updateDatastream(datastream, dataset, data);
}
return data;
}
return observation;
}
}
use of org.n52.series.db.beans.DatasetEntity in project sensorweb-server-sta by 52North.
the class DatastreamService method processObservation.
private DatastreamEntity processObservation(DatastreamEntity datastream, Set<AbstractObservationEntity> observations) throws STACRUDException {
if (observations != null && !observations.isEmpty()) {
Set<DatasetEntity> datasets = new LinkedHashSet<>();
if (datastream.getDatasets() != null) {
datasets.addAll(datastream.getDatasets());
}
for (AbstractObservationEntity observation : observations) {
AbstractObservationEntity<?> data = getObservationService().createEntity(observation);
if (data != null) {
datasets.add(data.getDataset());
}
}
datastream.setDatasets(datasets);
}
return datastream;
}
use of org.n52.series.db.beans.DatasetEntity in project sensorweb-server-sta by 52North.
the class DatastreamQuerySpecifications method handleRelatedPropertyFilter.
/**
* Handles filtering of properties in related Entities.
*
* @param propertyName Name of property
* @param propertyValue Supposed value of Property
* @return BooleanExpression evaluating to true if Entity is not filtered out
*/
@Override
protected Specification<DatastreamEntity> handleRelatedPropertyFilter(String propertyName, Specification<?> propertyValue) {
return (root, query, builder) -> {
try {
switch(propertyName) {
case SENSOR:
{
Subquery<DatastreamEntity> sq = query.subquery(DatastreamEntity.class);
Root<ProcedureEntity> sensor = sq.from(ProcedureEntity.class);
sq.select(sensor.get(DescribableEntity.PROPERTY_ID)).where(((Specification<ProcedureEntity>) propertyValue).toPredicate(sensor, query, builder));
return builder.in(root.get(DatastreamEntity.PROPERTY_SENSOR)).value(sq);
}
case OBSERVED_PROPERTY:
{
Subquery<DatastreamEntity> sq = query.subquery(DatastreamEntity.class);
Root<PhenomenonEntity> observedProperty = sq.from(PhenomenonEntity.class);
sq.select(observedProperty.get(DescribableEntity.PROPERTY_ID)).where(((Specification<PhenomenonEntity>) propertyValue).toPredicate(observedProperty, query, builder));
return builder.in(root.get(DatastreamEntity.PROPERTY_OBSERVABLE_PROPERTY)).value(sq);
}
case THING:
{
Subquery<DatastreamEntity> sq = query.subquery(DatastreamEntity.class);
Root<PlatformEntity> thing = sq.from(PlatformEntity.class);
sq.select(thing.get(DescribableEntity.PROPERTY_ID)).where(((Specification<PlatformEntity>) propertyValue).toPredicate(thing, query, builder));
return builder.in(root.get(DatastreamEntity.PROPERTY_THING)).value(sq);
}
case OBSERVATIONS:
{
Subquery<DatasetEntity> sq = query.subquery(DatasetEntity.class);
Join<DatastreamEntity, DatasetEntity> join = root.join(DatastreamEntity.PROPERTY_DATASETS);
Root<ObservationEntity> data = sq.from(ObservationEntity.class);
sq.select(data.get(ObservationEntity.PROPERTY_DATASET)).where(((Specification<ObservationEntity>) propertyValue).toPredicate(data, query, builder));
return builder.in(join.get(DatasetEntity.PROPERTY_ID)).value(sq);
}
default:
throw new STAInvalidFilterExpressionException("Could not find related property: " + propertyName);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
};
}
use of org.n52.series.db.beans.DatasetEntity in project SOS by 52North.
the class ObservationOmObservationCreator method createObservationConstellation.
private OmObservationConstellation createObservationConstellation(DataEntity<?> hObservation, String procedureId, String phenomenonId, String featureId, Set<String> offerings) throws OwsExceptionReport {
long start = System.currentTimeMillis();
LOGGER.trace("Creating ObservationConstellation...");
OmObservationConstellation obsConst = new OmObservationConstellation(getProcedure(procedureId), getObservedProperty(phenomenonId), getFeature(featureId), offerings);
if (observationConstellations.containsKey(obsConst.hashCode())) {
obsConst = observationConstellations.get(obsConst.hashCode());
}
int hashCode = obsConst.hashCode();
if (!Strings.isNullOrEmpty(getResultModel())) {
obsConst.setObservationType(getResultModel());
}
if (hObservation.getDataset().isSetOmObservationType()) {
obsConst.setObservationType(hObservation.getDataset().getOmObservationType().getFormat());
}
observationConstellations.put(hashCode, obsConst);
DatasetEntity series = hObservation.getDataset();
if (series.isSetIdentifier()) {
addIdentifier(obsConst, series);
}
obsConst.setObservationType(getResultModel());
if (request.isSetRequestedLanguage()) {
addNameAndDescription(series, obsConst, getRequestedLanguage(), getI18N(), false);
if (obsConst.isSetName()) {
obsConst.setHumanReadableIdentifier(obsConst.getFirstName().getValue());
}
} else {
if (series.isSetName()) {
addName(obsConst, series);
}
if (series.isSetDescription()) {
obsConst.setDescription(series.getDescription());
}
}
LOGGER.trace("Creating ObservationConstellation done in {} ms.", System.currentTimeMillis() - start);
return obsConst;
}
use of org.n52.series.db.beans.DatasetEntity in project SOS by 52North.
the class ObservationOmObservationCreator method addParameter.
private void addParameter(OmObservation observation, DataEntity<?> hObservation) throws OwsExceptionReport {
long start = System.currentTimeMillis();
LOGGER.trace("Creating Parameter...");
DatasetEntity series = ((DataEntity<?>) hObservation).getDataset();
if (!seriesParameter.containsKey(series.getId()) && series.hasParameters()) {
seriesParameter.put(series.getId(), series.getParameters());
}
if (seriesParameter.get(series.getId()) != null && !seriesParameter.get(series.getId()).isEmpty()) {
new DatasetParameterAdder(observation, seriesParameter.get(series.getId())).add();
}
new ParameterAdder(observation, hObservation).add();
LOGGER.trace("Creating Parameter done in {} ms.", System.currentTimeMillis() - start);
}
Aggregations