use of org.n52.series.db.beans.sta.DatastreamEntity in project sensorweb-server-sta by 52North.
the class ObservedPropertyService method fetchExpandEntities.
@Override
protected ObservablePropertyEntity fetchExpandEntities(PhenomenonEntity entity, ExpandFilter expandOption) throws STACRUDException, STAInvalidQueryException {
for (ExpandItem expandItem : expandOption.getItems()) {
String expandProperty = expandItem.getPath();
if (ObservedPropertyEntityDefinition.NAVIGATION_PROPERTIES.contains(expandProperty)) {
Page<DatastreamEntity> obsP = getDatastreamService().getEntityCollectionByRelatedEntityRaw(entity.getStaIdentifier(), STAEntityDefinition.OBSERVED_PROPERTIES, expandItem.getQueryOptions());
ObservablePropertyEntity obsProp = new ObservablePropertyEntity(entity);
return obsProp.setDatastreams(obsP.get().collect(Collectors.toSet()));
} else {
throw new STAInvalidQueryException("Invalid expandOption supplied. Cannot find " + expandProperty + " on Entity of type 'ObservableProperty'");
}
}
return new ObservablePropertyEntity(entity);
}
use of org.n52.series.db.beans.sta.DatastreamEntity in project sensorweb-server-sta by 52North.
the class SensorService method updateEntity.
@Override
public ProcedureEntity updateEntity(String id, ProcedureEntity entity, HttpMethod method) throws STACRUDException {
checkUpdate(entity);
if (HttpMethod.PATCH.equals(method)) {
synchronized (getLock(id)) {
Optional<ProcedureEntity> existing = getRepository().findByStaIdentifier(id, EntityGraphRepository.FetchGraph.FETCHGRAPH_FORMAT, EntityGraphRepository.FetchGraph.FETCHGRAPH_PROCEDUREHISTORY);
if (existing.isPresent()) {
ProcedureEntity merged = merge(existing.get(), entity);
if (entity instanceof SensorEntity) {
if (((SensorEntity) entity).hasDatastreams()) {
AbstractSensorThingsEntityServiceImpl<?, DatastreamEntity, DatastreamEntity> dsService = getDatastreamService();
for (DatastreamEntity datastreamEntity : ((SensorEntity) entity).getDatastreams()) {
dsService.createOrUpdate(datastreamEntity);
}
}
}
checkFormat(merged);
checkProcedureHistory(merged);
getRepository().save(getAsProcedureEntity(merged));
return merged;
}
}
throw new STACRUDException("Unable to update. Entity not found.", HTTPStatus.NOT_FOUND);
} else if (HttpMethod.PUT.equals(method)) {
throw new STACRUDException("Http PUT is not yet supported!", HTTPStatus.NOT_IMPLEMENTED);
}
throw new STACRUDException("Invalid http method for updating entity!", HTTPStatus.BAD_REQUEST);
}
use of org.n52.series.db.beans.sta.DatastreamEntity in project sensorweb-server-sta by 52North.
the class SensorService method fetchExpandEntities.
@Override
protected SensorEntity fetchExpandEntities(ProcedureEntity entity, ExpandFilter expandOption) throws STACRUDException, STAInvalidQueryException {
for (ExpandItem expandItem : expandOption.getItems()) {
String expandProperty = expandItem.getPath();
if (SensorEntityDefinition.NAVIGATION_PROPERTIES.contains(expandProperty)) {
Page<DatastreamEntity> observedProps = getDatastreamService().getEntityCollectionByRelatedEntityRaw(entity.getStaIdentifier(), STAEntityDefinition.SENSORS, expandItem.getQueryOptions());
SensorEntity sensor = new SensorEntity(entity);
return sensor.setDatastreams(observedProps.get().collect(Collectors.toSet()));
} else {
throw new STAInvalidQueryException("Invalid expandOption supplied. Cannot find " + expandProperty + " on Entity of type 'Sensor'");
}
}
return new SensorEntity(entity);
}
use of org.n52.series.db.beans.sta.DatastreamEntity in project sensorweb-server-sta by 52North.
the class ThingService method processDatastreams.
private void processDatastreams(PlatformEntity thing) throws STACRUDException {
if (thing.hasDatastreams()) {
Set<DatastreamEntity> datastreams = new LinkedHashSet<>();
for (DatastreamEntity datastream : thing.getDatastreams()) {
datastream.setThing(thing);
DatastreamEntity optionalDatastream = getDatastreamService().createEntity(datastream);
datastreams.add(optionalDatastream != null ? optionalDatastream : datastream);
}
thing.setDatastreams(datastreams);
}
}
use of org.n52.series.db.beans.sta.DatastreamEntity 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;
}
}
Aggregations