Search in sources :

Example 1 with FeatureDao

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!");
    }
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) FeatureEntity(org.n52.series.db.beans.FeatureEntity) Coordinate(org.locationtech.jts.geom.Coordinate) SweCoordinate(org.n52.shetland.ogc.swe.SweCoordinate) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) FeatureDao(org.n52.series.db.dao.FeatureDao) SmlPosition(org.n52.shetland.ogc.sensorML.elements.SmlPosition) CodedException(org.n52.shetland.ogc.ows.exception.CodedException) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) HibernateException(org.hibernate.HibernateException) DataAccessException(org.n52.series.db.DataAccessException)

Example 2 with FeatureDao

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!");
// }
}
Also used : AbstractFeatureEntity(org.n52.series.db.beans.AbstractFeatureEntity) GetFeatureOfInterestResponse(org.n52.shetland.ogc.sos.response.GetFeatureOfInterestResponse) Session(org.hibernate.Session) FeatureEntity(org.n52.series.db.beans.FeatureEntity) HashMap(java.util.HashMap) DatasetEntity(org.n52.series.db.beans.DatasetEntity) SosConstants(org.n52.shetland.ogc.sos.SosConstants) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) SamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature) Strings(com.google.common.base.Strings) FeatureCollection(org.n52.shetland.ogc.om.features.FeatureCollection) Lists(com.google.common.collect.Lists) EnvelopeOrGeometry(org.n52.shetland.util.EnvelopeOrGeometry) DbQuery(org.n52.series.db.dao.DbQuery) GetFeatureOfInterestRequest(org.n52.shetland.ogc.sos.request.GetFeatureOfInterestRequest) Map(java.util.Map) FeatureDao(org.n52.series.db.dao.FeatureDao) CodeWithAuthority(org.n52.shetland.ogc.gml.CodeWithAuthority) LinkedHashSet(java.util.LinkedHashSet) HibernateSessionStore(org.n52.series.db.HibernateSessionStore) SpatialOperator(org.n52.shetland.ogc.filter.FilterConstants.SpatialOperator) Collection(java.util.Collection) Set(java.util.Set) SpatialFilter(org.n52.shetland.ogc.filter.SpatialFilter) MissingParameterValueException(org.n52.shetland.ogc.ows.exception.MissingParameterValueException) Collectors(java.util.stream.Collectors) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport) Maps(com.google.common.collect.Maps) GetFeatureOfInterestDao(org.n52.sos.ds.dao.GetFeatureOfInterestDao) DatasetType(org.n52.series.db.beans.dataset.DatasetType) List(java.util.List) GeometryHandler(org.n52.sos.util.GeometryHandler) DatasetDao(org.n52.series.db.dao.DatasetDao) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) InvalidSridException(org.n52.shetland.ogc.om.features.samplingFeatures.InvalidSridException) Sos1Constants(org.n52.shetland.ogc.sos.Sos1Constants) Optional(java.util.Optional) Geometry(org.locationtech.jts.geom.Geometry) CompositeOwsException(org.n52.shetland.ogc.ows.exception.CompositeOwsException) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) HibernateException(org.hibernate.HibernateException) Collections(java.util.Collections) Envelope(org.locationtech.jts.geom.Envelope) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) IoParameters(org.n52.io.request.IoParameters) Joiner(com.google.common.base.Joiner) AbstractFeatureEntity(org.n52.series.db.beans.AbstractFeatureEntity) FeatureEntity(org.n52.series.db.beans.FeatureEntity) DatasetEntity(org.n52.series.db.beans.DatasetEntity) AbstractFeatureEntity(org.n52.series.db.beans.AbstractFeatureEntity) FeatureDao(org.n52.series.db.dao.FeatureDao) DatasetDao(org.n52.series.db.dao.DatasetDao)

Example 3 with FeatureDao

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);
    }
}
Also used : FeatureEntity(org.n52.series.db.beans.FeatureEntity) MissingObservedPropertyParameterException(org.n52.sos.exception.ows.concrete.MissingObservedPropertyParameterException) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) GetObservationResponse(org.n52.shetland.ogc.sos.response.GetObservationResponse) FeatureDao(org.n52.series.db.dao.FeatureDao) DataAccessException(org.n52.series.db.DataAccessException) Session(org.hibernate.Session)

Example 4 with FeatureDao

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());
}
Also used : FeatureEntity(org.n52.series.db.beans.FeatureEntity) DbQuery(org.n52.series.db.dao.DbQuery) HibernateException(org.hibernate.HibernateException) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) DatasetEntity(org.n52.series.db.beans.DatasetEntity) FeatureDao(org.n52.series.db.dao.FeatureDao)

Aggregations

FeatureEntity (org.n52.series.db.beans.FeatureEntity)4 FeatureDao (org.n52.series.db.dao.FeatureDao)4 NoApplicableCodeException (org.n52.shetland.ogc.ows.exception.NoApplicableCodeException)4 HibernateException (org.hibernate.HibernateException)3 Session (org.hibernate.Session)2 Geometry (org.locationtech.jts.geom.Geometry)2 DataAccessException (org.n52.series.db.DataAccessException)2 DatasetEntity (org.n52.series.db.beans.DatasetEntity)2 DbQuery (org.n52.series.db.dao.DbQuery)2 Joiner (com.google.common.base.Joiner)1 Strings (com.google.common.base.Strings)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1