Search in sources :

Example 1 with FeatureEntity

use of org.n52.series.db.beans.FeatureEntity in project SOS by 52North.

the class FeatureOfInterestDAO method getOrInsert.

/**
 * Insert and/or get featureOfInterest object for identifier
 *
 * @param identifier
 *            FeatureOfInterest identifier
 * @param url
 *            FeatureOfInterest URL, if defined as link
 * @param session
 *            Hibernate session
 * @return FeatureOfInterest object
 */
public AbstractFeatureEntity getOrInsert(String identifier, String url, Session session) {
    AbstractFeatureEntity feature = get(identifier, session);
    if (feature == null) {
        feature = new FeatureEntity();
        feature.setIdentifier(identifier, getDaoFactory().isStaSupportsUrls());
        if (url != null && !url.isEmpty()) {
            feature.setUrl(url);
        }
        FormatEntity type = new FormatDAO().getOrInsertFormatEntity(OGCConstants.UNKNOWN, session);
        feature.setFeatureType(type);
        session.save(feature);
    } else if (feature.getUrl() != null && !feature.getUrl().isEmpty() && url != null && !url.isEmpty()) {
        feature.setUrl(url);
        session.saveOrUpdate(feature);
    }
    // don't flush here because we may be batching
    return feature;
}
Also used : AbstractFeatureEntity(org.n52.series.db.beans.AbstractFeatureEntity) FeatureEntity(org.n52.series.db.beans.FeatureEntity) FormatEntity(org.n52.series.db.beans.FormatEntity) AbstractFeatureEntity(org.n52.series.db.beans.AbstractFeatureEntity)

Example 2 with FeatureEntity

use of org.n52.series.db.beans.FeatureEntity in project SOS by 52North.

the class FeatureOfInterestDAO method getFeatureOfInterestObject.

/**
 * Get featureOfInterest objects for featureOfInterest identifiers
 *
 * @param identifiers
 *            FeatureOfInterest identifiers
 * @param session
 *            Hibernate session
 * @return FeatureOfInterest objects
 */
@SuppressWarnings("unchecked")
public List<FeatureEntity> getFeatureOfInterestObject(Collection<String> identifiers, Session session) {
    if (identifiers == null || identifiers.isEmpty()) {
        return Collections.emptyList();
    }
    Criteria criteria = session.createCriteria(FeatureEntity.class).add(QueryHelper.getCriterionForObjects(AbstractFeatureEntity.IDENTIFIER, identifiers));
    LOGGER.trace("QUERY getFeatureOfInterestObject(identifiers): {}", HibernateHelper.getSqlString(criteria));
    return criteria.list();
}
Also used : AbstractFeatureEntity(org.n52.series.db.beans.AbstractFeatureEntity) FeatureEntity(org.n52.series.db.beans.FeatureEntity) Criteria(org.hibernate.Criteria) DetachedCriteria(org.hibernate.criterion.DetachedCriteria)

Example 3 with FeatureEntity

use of org.n52.series.db.beans.FeatureEntity 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 4 with FeatureEntity

use of org.n52.series.db.beans.FeatureEntity in project SOS by 52North.

the class FeatureOfInterestEnrichment method createFeatures.

private Map<String, AbstractFeature> createFeatures(Set<FeatureEntity> featureEntities) throws InvalidSridException, OwsExceptionReport {
    final Map<String, AbstractFeature> map = new HashMap<>(featureEntities.size());
    for (final FeatureEntity feature : featureEntities) {
        final AbstractFeature abstractFeature = createFeature(feature);
        map.put(abstractFeature.getIdentifier(), abstractFeature);
    }
    return map;
}
Also used : FeatureEntity(org.n52.series.db.beans.FeatureEntity) HashMap(java.util.HashMap) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature)

Example 5 with FeatureEntity

use of org.n52.series.db.beans.FeatureEntity in project SOS by 52North.

the class AbstractFeatureOfInerestCreator method createFeature.

public AbstractFeature createFeature(FeatureEntity f) throws OwsExceptionReport {
    final CodeWithAuthority identifier = getIdentifier(f);
    if (!SosHelper.checkFeatureOfInterestIdentifierForSosV2(f.getIdentifier(), getContext().getVersion())) {
        identifier.setValue(null);
    }
    final AbstractFeature absFeat = createFeature(identifier);
    addNameAndDescription(f, absFeat, getContext().getRequestedLanguage(), getContext().getDefaultLanguage(), getContext().isShowAllLanguages());
    if (absFeat instanceof AbstractSamplingFeature) {
        AbstractSamplingFeature absSampFeat = (AbstractSamplingFeature) absFeat;
        absSampFeat.setGeometry(createGeometryFrom(f));
        absSampFeat.setFeatureType(getFeatureTypes(f));
        absSampFeat.setUrl(f.getUrl());
        if (f.isSetXml()) {
            absSampFeat.setXml(f.getXml());
        }
        addParameter(absSampFeat, f);
        final Set<FeatureEntity> parentFeatures = f.getParents();
        if (parentFeatures != null && !parentFeatures.isEmpty()) {
            final List<AbstractFeature> sampledFeatures = new ArrayList<AbstractFeature>(parentFeatures.size());
            for (final AbstractFeatureEntity parentFeature : parentFeatures) {
                sampledFeatures.add(new HibernateFeatureVisitor(getContext()).visit(parentFeature));
            }
            absSampFeat.setSampledFeatures(sampledFeatures);
        }
    }
    return absFeat;
}
Also used : AbstractSamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature) AbstractFeatureEntity(org.n52.series.db.beans.AbstractFeatureEntity) FeatureEntity(org.n52.series.db.beans.FeatureEntity) AbstractFeatureEntity(org.n52.series.db.beans.AbstractFeatureEntity) ArrayList(java.util.ArrayList) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) CodeWithAuthority(org.n52.shetland.ogc.gml.CodeWithAuthority)

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