use of org.n52.series.db.beans.FeatureEntity 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.beans.FeatureEntity 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.beans.FeatureEntity in project SOS by 52North.
the class FeatureOfInterestEnrichment method createFeature.
private AbstractFeature createFeature(FeatureEntity feature) throws InvalidSridException, OwsExceptionReport {
final SamplingFeature sampFeat = new SamplingFeature(new CodeWithAuthority(feature.getIdentifier()));
addNameAndDescription(feature, sampFeat, getLocale(), null, false);
if (feature.isSetGeometry() && !feature.getGeometryEntity().isEmpty()) {
if (getProcedureCreationContext().getGeometryHandler() != null) {
sampFeat.setGeometry(getProcedureCreationContext().getGeometryHandler().switchCoordinateAxisFromToDatasourceIfNeeded(feature.getGeometryEntity().getGeometry()));
} else {
sampFeat.setGeometry(feature.getGeometryEntity().getGeometry());
}
}
final Set<FeatureEntity> parentFeatures = feature.getParents();
if (parentFeatures != null && !parentFeatures.isEmpty()) {
final List<AbstractFeature> sampledFeatures = new ArrayList<>(parentFeatures.size());
for (final FeatureEntity parentFeature : parentFeatures) {
sampledFeatures.add(createFeature(parentFeature));
}
sampFeat.setSampledFeatures(sampledFeatures);
}
return sampFeat;
}
use of org.n52.series.db.beans.FeatureEntity in project SOS by 52North.
the class FeatureOfInterestCacheUpdate method getParents.
private Collection<String> getParents(FeatureEntity featureEntity) {
Set<String> parentFeatures = Sets.newTreeSet();
if (featureEntity.hasParents()) {
for (FeatureEntity parentEntity : featureEntity.getParents()) {
parentFeatures.add(parentEntity.getIdentifier());
parentFeatures.addAll(getParents(parentEntity));
}
}
return parentFeatures;
}
use of org.n52.series.db.beans.FeatureEntity 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