use of org.n52.shetland.ogc.sta.exception.STACRUDException 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.shetland.ogc.sta.exception.STACRUDException 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.shetland.ogc.sta.exception.STACRUDException 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.shetland.ogc.sta.exception.STACRUDException in project sensorweb-server-sta by 52North.
the class SensorService method checkFormat.
private void checkFormat(ProcedureEntity sensor) throws STACRUDException {
FormatEntity format;
synchronized (getLock(sensor.getFormat().getFormat())) {
if (!formatRepository.existsByFormat(sensor.getFormat().getFormat())) {
format = formatRepository.save(sensor.getFormat());
} else {
format = formatRepository.findByFormat(sensor.getFormat().getFormat());
}
}
sensor.setFormat(format);
if (sensor.hasProcedureHistory()) {
sensor.getProcedureHistory().forEach(pf -> pf.setFormat(format));
}
}
use of org.n52.shetland.ogc.sta.exception.STACRUDException in project sensorweb-server-sta by 52North.
the class ThingService method updateEntity.
@Override
@Transactional
public PlatformEntity updateEntity(String id, PlatformEntity newEntity, HttpMethod method) throws STACRUDException {
// checkUpdate(entity);
if (HttpMethod.PATCH.equals(method)) {
synchronized (getLock(id)) {
Optional<PlatformEntity> existing = getRepository().findByStaIdentifier(id, IdentifierRepository.FetchGraph.FETCHGRAPH_LOCATION, IdentifierRepository.FetchGraph.FETCHGRAPH_HIST_LOCATION);
if (existing.isPresent()) {
PlatformEntity merged = merge(existing.get(), newEntity);
if (newEntity.hasLocationEntities()) {
boolean changedLocations = processLocations(merged, newEntity.getLocations());
merged = getRepository().save(merged);
if (changedLocations) {
generateHistoricalLocation(merged);
}
}
return getRepository().save(merged);
} else {
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);
}
Aggregations