Search in sources :

Example 11 with FeatureEntity

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!");
// }
}
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 12 with FeatureEntity

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);
    }
}
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 13 with FeatureEntity

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;
}
Also used : FeatureEntity(org.n52.series.db.beans.FeatureEntity) ArrayList(java.util.ArrayList) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) SamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature) CodeWithAuthority(org.n52.shetland.ogc.gml.CodeWithAuthority)

Example 14 with FeatureEntity

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;
}
Also used : FeatureEntity(org.n52.series.db.beans.FeatureEntity)

Example 15 with FeatureEntity

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());
}
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)19 AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)8 AbstractFeatureEntity (org.n52.series.db.beans.AbstractFeatureEntity)7 NoApplicableCodeException (org.n52.shetland.ogc.ows.exception.NoApplicableCodeException)7 HibernateException (org.hibernate.HibernateException)6 Session (org.hibernate.Session)6 ArrayList (java.util.ArrayList)5 SamplingFeature (org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature)5 Test (org.junit.Test)4 Geometry (org.locationtech.jts.geom.Geometry)4 FeatureDao (org.n52.series.db.dao.FeatureDao)4 CodeWithAuthority (org.n52.shetland.ogc.gml.CodeWithAuthority)4 DatasetEntity (org.n52.series.db.beans.DatasetEntity)3 FeatureQueryHandlerQueryObject (org.n52.sos.ds.FeatureQueryHandlerQueryObject)3 HashMap (java.util.HashMap)2 Set (java.util.Set)2 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)2 DataAccessException (org.n52.series.db.DataAccessException)2 FormatEntity (org.n52.series.db.beans.FormatEntity)2 DbQuery (org.n52.series.db.dao.DbQuery)2