use of org.n52.sos.ds.FeatureQueryHandlerQueryObject in project SOS by 52North.
the class HibernateFeatureQueryHandlerTest method shouldCreateValidModelDomainFeature.
@Test
public void shouldCreateValidModelDomainFeature() throws OwsExceptionReport {
Session session = getSession();
try {
final String id = "id";
final String type = SfConstants.SAMPLING_FEAT_TYPE_SF_SAMPLING_POINT;
FeatureEntity feature = create(1, id, null, "name", "url", createFeatureOfInterestType(1L, type));
String version = Sos2Constants.SERVICEVERSION;
AbstractFeature result = featureQueryHandler.createSosAbstractFeature(feature, new FeatureQueryHandlerQueryObject(session).setVersion(version));
final AbstractFeature expectedResult = SamplingFeatureBuilder.aSamplingFeature().setFeatureType(type).setIdentifier(id).build();
assertThat(expectedResult, is(result));
} catch (HibernateException he) {
throw new NoApplicableCodeException().causedBy(he);
} finally {
returnSession(session);
}
}
use of org.n52.sos.ds.FeatureQueryHandlerQueryObject in project SOS by 52North.
the class HibernateFeatureQueryHandler method createSosFeatures.
/**
* Creates a map with FOI identifier and SOS feature
*
* @param features FeatureOfInterest objects
* @param queryObject SOS version
* @param session the session
* @return Map with FOI identifier and SOS feature
* @throws OwsExceptionReport * If feature type is not supported
*/
protected Map<String, AbstractFeature> createSosFeatures(final List<AbstractFeatureEntity> features, final FeatureQueryHandlerQueryObject queryObject, Session session) throws OwsExceptionReport {
final Map<String, AbstractFeature> sosAbstractFois = new HashMap<>(features.size());
for (final AbstractFeatureEntity feature : features) {
final AbstractFeature sosFeature = createSosAbstractFeature(feature, queryObject, session);
sosAbstractFois.put(feature.getIdentifier(), sosFeature);
}
// TODO if sampledFeatures are also in sosAbstractFois, reference them.
return sosAbstractFois;
}
use of org.n52.sos.ds.FeatureQueryHandlerQueryObject in project SOS by 52North.
the class HibernateFeatureQueryHandler method getFeaturesForNonSpatialDatasource.
protected Map<String, AbstractFeature> getFeaturesForNonSpatialDatasource(FeatureQueryHandlerQueryObject queryObject) throws OwsExceptionReport {
final Session session = HibernateSessionHolder.getSession(queryObject.getConnection());
final Map<String, AbstractFeature> featureMap = new HashMap<>(0);
List<org.locationtech.jts.geom.Geometry> envelopes = null;
boolean hasSpatialFilter = false;
if (queryObject.isSetSpatialFilters()) {
hasSpatialFilter = true;
envelopes = new ArrayList<>(queryObject.getSpatialFilters().size());
for (final SpatialFilter filter : queryObject.getSpatialFilters()) {
envelopes.add(getGeometryHandler().getFilterForNonSpatialDatasource(filter));
}
}
final List<AbstractFeatureEntity> featuresOfInterest = daoFactory.getFeatureDAO().getFeatureOfInterestObjects(queryObject.getFeatures(), session);
for (final AbstractFeatureEntity feature : featuresOfInterest) {
final AbstractSamplingFeature sosAbstractFeature = (AbstractSamplingFeature) createSosAbstractFeature(feature, queryObject, session);
if (!hasSpatialFilter) {
featureMap.put(sosAbstractFeature.getIdentifierCodeWithAuthority().getValue(), sosAbstractFeature);
} else if (getGeometryHandler().featureIsInFilter(sosAbstractFeature.getGeometry(), envelopes)) {
featureMap.put(sosAbstractFeature.getIdentifierCodeWithAuthority().getValue(), sosAbstractFeature);
}
}
return featureMap;
}
use of org.n52.sos.ds.FeatureQueryHandlerQueryObject in project SOS by 52North.
the class QueryHelper method getFeatureIdentifier.
public static Set<String> getFeatureIdentifier(FeatureQueryHandler featureQueryHandler, SpatialFilter spatialFilter, List<String> featureIdentifier, Session session) throws OwsExceptionReport {
Set<String> foiIDs = null;
// spatial filter
if (spatialFilter != null) {
String valueReference = spatialFilter.getValueReference();
if (!valueReference.contains(OM_FEATURE_OF_INTEREST) || !valueReference.contains(SAMS_SHAPE)) {
throw new NoApplicableCodeException().withMessage("The requested valueReference for spatial filters is not supported by this server!");
}
FeatureQueryHandlerQueryObject query = new FeatureQueryHandlerQueryObject(session).addSpatialFilter(spatialFilter);
foiIDs = new HashSet<>(featureQueryHandler.getFeatureIDs(query));
}
// feature of interest
if (CollectionHelper.isNotEmpty(featureIdentifier)) {
return (foiIDs == null) ? new HashSet<>(featureIdentifier) : featureIdentifier.stream().filter(foiIDs::contains).collect(Collectors.toSet());
}
return foiIDs;
}
use of org.n52.sos.ds.FeatureQueryHandlerQueryObject in project SOS by 52North.
the class AbstractOmObservationCreator method createFeatureOfInterest.
/**
* Get featureOfInterest object from series
*
* @param featureOfInterest the feature
* @return FeatureOfInerest object
* @throws OwsExceptionReport
* If an error occurs
*/
protected AbstractFeature createFeatureOfInterest(String featureOfInterest) throws OwsExceptionReport {
FeatureQueryHandlerQueryObject queryObject = new FeatureQueryHandlerQueryObject(getSession());
queryObject.setFeatureObject(featureOfInterest).setVersion(getVersion());
if (getRequest().isSetRequestedLanguage()) {
queryObject.setI18N(getRequestedLanguage());
}
final AbstractFeature feature = getFeatureQueryHandler().getFeatureByID(queryObject);
return feature;
}
Aggregations