Search in sources :

Example 1 with FeatureQueryHandlerQueryObject

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);
    }
}
Also used : FeatureEntity(org.n52.series.db.beans.FeatureEntity) HibernateException(org.hibernate.HibernateException) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) Session(org.hibernate.Session) FeatureQueryHandlerQueryObject(org.n52.sos.ds.FeatureQueryHandlerQueryObject) Test(org.junit.Test)

Example 2 with FeatureQueryHandlerQueryObject

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;
}
Also used : HashMap(java.util.HashMap) AbstractFeatureEntity(org.n52.series.db.beans.AbstractFeatureEntity) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature)

Example 3 with FeatureQueryHandlerQueryObject

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;
}
Also used : AbstractSamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature) HashMap(java.util.HashMap) AbstractFeatureEntity(org.n52.series.db.beans.AbstractFeatureEntity) SpatialFilter(org.n52.shetland.ogc.filter.SpatialFilter) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) Geometry(org.locationtech.jts.geom.Geometry) Session(org.hibernate.Session)

Example 4 with FeatureQueryHandlerQueryObject

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;
}
Also used : NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) FeatureQueryHandlerQueryObject(org.n52.sos.ds.FeatureQueryHandlerQueryObject)

Example 5 with FeatureQueryHandlerQueryObject

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;
}
Also used : AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) FeatureQueryHandlerQueryObject(org.n52.sos.ds.FeatureQueryHandlerQueryObject)

Aggregations

Session (org.hibernate.Session)7 AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)7 NoApplicableCodeException (org.n52.shetland.ogc.ows.exception.NoApplicableCodeException)6 FeatureQueryHandlerQueryObject (org.n52.sos.ds.FeatureQueryHandlerQueryObject)6 HibernateException (org.hibernate.HibernateException)5 Geometry (org.locationtech.jts.geom.Geometry)5 AbstractFeatureEntity (org.n52.series.db.beans.AbstractFeatureEntity)5 FeatureEntity (org.n52.series.db.beans.FeatureEntity)4 Test (org.junit.Test)3 SpatialFilter (org.n52.shetland.ogc.filter.SpatialFilter)3 HashMap (java.util.HashMap)2 Criteria (org.hibernate.Criteria)2 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)2 AbstractSamplingFeature (org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature)2 SamplingFeature (org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature)2 FeatureVisitorContext (org.n52.sos.ds.hibernate.create.FeatureVisitorContext)2 HibernateGeometryVisitor (org.n52.sos.ds.hibernate.create.HibernateGeometryVisitor)2 LinkedList (java.util.LinkedList)1 Dialect (org.hibernate.dialect.Dialect)1 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)1