use of org.n52.series.db.dao.FeatureDao in project SOS by 52North.
the class AbstractProcedureDescriptionGeneratorSml method createPosition.
/**
* Create SensorML Position from Hibernate procedure entity
*
* @param procedure
* Hibernate procedure entity
*
* @return SensorML Position
* @throws CodedException If an error occurs
*/
protected SmlPosition createPosition(ProcedureEntity procedure, Session session) throws CodedException {
try {
List<FeatureEntity> features = new FeatureDao(session).getAllInstances(createDbQuery(procedure));
SmlPosition position = new SmlPosition();
position.setName(POSITION_NAME);
position.setFixed(true);
int srid = geometryHandler.getDefaultResponseEPSG();
if (features != null && features.size() == 1) {
FeatureEntity feature = features.iterator().next();
if (feature.isSetGeometry() && !feature.getGeometryEntity().isEmpty()) {
Geometry geometry = feature.getGeometryEntity().getGeometry();
// 8.2 set position from geometry
Coordinate c = geometry.getCoordinate();
position.setPosition(createCoordinatesForPosition(c.getY(), c.getX(), c.getZ()));
}
}
position.setReferenceFrame(srsNamePrefix + srid);
return position;
} catch (Exception e) {
throw new NoApplicableCodeException().causedBy(e).withMessage("Error while creating sensor position!");
}
}
use of org.n52.series.db.dao.FeatureDao in project SOS by 52North.
the class GetFeatureOfInterestHandler method queryFeaturesForParameter.
/**
* Get featureOfInterest identifiers for requested parameters
*
* @param req
* GetFeatureOfInterest request
* @param session
* Hibernate session
* @return Resulting FeatureOfInterest identifiers list
* @throws OwsExceptionReport
* If an error occurs during processing
*/
private Collection<AbstractFeatureEntity> queryFeaturesForParameter(GetFeatureOfInterestRequest req, Session session) throws OwsExceptionReport {
// try {
Collection<DatasetEntity> datasets = new DatasetDao(session).get(createDbQuery(req));
Collection<FeatureEntity> allFeatures = req.isSetObservableProperties() || req.isSetProcedures() ? new LinkedHashSet<>() : new FeatureDao(session).get(createFoiDbQuery(req));
if (datasets != null) {
Set<AbstractFeatureEntity> features = datasets.stream().filter(d -> d.isSetFeature() && (d.isPublished() || !d.isPublished() && d.getDatasetType().equals(DatasetType.not_initialized))).map(d -> d.getFeature()).collect(Collectors.toSet());
Set<AbstractFeatureEntity> notVisibleFeatures = datasets.stream().filter(d -> d.isDeleted() || !d.isPublished()).map(d -> d.getFeature()).collect(Collectors.toSet());
features.addAll(allFeatures.stream().filter(o -> !notVisibleFeatures.contains(o)).collect(Collectors.toSet()));
return features;
}
return Collections.emptySet();
// return new FeatureDao(session).getAllInstances(createDbQuery(req));
// } catch (DataAccessException dae) {
// throw new NoApplicableCodeException().causedBy(dae)
// .withMessage("Error while querying data for GetFeatureOfInterest!");
// }
}
use of org.n52.series.db.dao.FeatureDao in project SOS by 52North.
the class GetObservationHandler method getObservation.
@Override
public GetObservationResponse getObservation(GetObservationRequest request) throws OwsExceptionReport {
if (request.getVersion().equals(Sos1Constants.SERVICEVERSION) && request.getObservedProperties().isEmpty()) {
throw new MissingObservedPropertyParameterException();
}
// if (request.isSetResultFilter()) {
// throw new NotYetSupportedException("result filtering");
// }
Session session = sessionStore.getSession();
try {
GetObservationResponse response = new GetObservationResponse();
response.setService(request.getService());
response.setVersion(request.getVersion());
response.setResponseFormat(request.getResponseFormat());
response.setResultModel(request.getResultModel());
List<FeatureEntity> features = new FeatureDao(session).getAllInstances(createDbQuery(request));
if (features == null || features.isEmpty()) {
return response;
}
request.setFeatureIdentifiers(features.stream().map(f -> f.getIdentifier()).collect(Collectors.toList()));
dao.queryObservationData(request, response);
return response;
} catch (DataAccessException e) {
throw new NoApplicableCodeException().causedBy(e).withMessage("Error while querying data for GetObservation!");
} finally {
sessionStore.returnSession(session);
}
}
use of org.n52.series.db.dao.FeatureDao in project SOS by 52North.
the class FeatureOfInterestCacheUpdate method execute.
@Override
public void execute() {
LOGGER.debug("Executing FeatureOfInterestCacheUpdate");
startStopwatch();
try {
Collection<FeatureEntity> features = new FeatureDao(getSession()).get(new DbQuery(IoParameters.createDefaults()));
for (FeatureEntity featureEntity : features) {
String identifier = featureEntity.getIdentifier();
getCache().addFeatureOfInterest(identifier);
Collection<DatasetEntity> datasets = new DatasetDao<>(getSession()).get(createDatasetDbQuery(featureEntity));
if (datasets != null && !datasets.isEmpty()) {
if (datasets.stream().anyMatch(d -> d.isPublished() || d.getDatasetType().equals(DatasetType.not_initialized))) {
getCache().addPublishedFeatureOfInterest(identifier);
}
getCache().setProceduresForFeatureOfInterest(identifier, getProcedures(datasets));
} else {
getCache().addPublishedFeatureOfInterest(identifier);
}
if (featureEntity.isSetName()) {
getCache().addFeatureOfInterestIdentifierHumanReadableName(identifier, featureEntity.getName());
}
if (featureEntity.hasParents()) {
getCache().addParentFeatures(identifier, getParents(featureEntity));
}
}
} catch (HibernateException he) {
getErrors().add(new NoApplicableCodeException().causedBy(he).withMessage("Error while updating featureOfInterest cache!"));
}
LOGGER.debug("Finished executing FeatureOfInterestCacheUpdate ({})", getStopwatchResult());
}
Aggregations