Search in sources :

Example 1 with AbstractFeatureEntity

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

the class FeatureOfInterestDAO method checkOrInsert.

/**
 * Insert featureOfInterest if it is supported
 *
 * @param featureOfInterest
 *            SOS featureOfInterest to insert
 * @param session
 *            Hibernate session
 * @return FeatureOfInterest object
 * @throws NoApplicableCodeException
 *             If SOS feature type is not supported (with status
 *             {@link HTTPStatus}.BAD_REQUEST
 */
public AbstractFeatureEntity checkOrInsert(AbstractFeature featureOfInterest, Session session) throws OwsExceptionReport {
    if (featureOfInterest == null) {
        throw new NoApplicableCodeException().withMessage("The feature to check or insert is null.");
    }
    AbstractFeatureEntity<?> feature = getFeature(featureOfInterest.getIdentifier(), session);
    if (feature != null) {
        return feature;
    }
    if (featureOfInterest instanceof AbstractSamplingFeature) {
        AbstractSamplingFeature sf = (AbstractSamplingFeature) featureOfInterest;
        String featureIdentifier = getFeatureQueryHandler().insertFeature(sf, session);
        return getFeature(featureIdentifier, session);
    } else {
        throw new NoApplicableCodeException().withMessage("The used feature type '%s' is not supported.", featureOfInterest.getClass().getName()).setStatus(HTTPStatus.BAD_REQUEST);
    }
}
Also used : AbstractSamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) LineString(org.locationtech.jts.geom.LineString)

Example 2 with AbstractFeatureEntity

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

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

the class FeatureOfInterestDAO method updateFeatureOfInterestGeometry.

public void updateFeatureOfInterestGeometry(AbstractFeatureEntity featureOfInterest, Geometry geom, Session session) {
    if (featureOfInterest != null) {
        if (featureOfInterest.isSetGeometry()) {
            if (geom instanceof Point) {
                List<Coordinate> coords = Lists.newArrayList();
                Geometry convert = featureOfInterest.getGeometry();
                if (convert instanceof Point) {
                    coords.add(convert.getCoordinate());
                } else if (convert instanceof LineString) {
                    coords.addAll(Lists.newArrayList(convert.getCoordinates()));
                }
                if (!coords.isEmpty()) {
                    coords.add(geom.getCoordinate());
                    Geometry newGeometry = new GeometryFactory().createLineString(coords.toArray(new Coordinate[coords.size()]));
                    newGeometry.setSRID(featureOfInterest.getGeometry().getSRID());
                    featureOfInterest.setGeometry(newGeometry);
                }
            }
        } else {
            featureOfInterest.setGeometry(geom);
        }
        session.merge(featureOfInterest);
    }
}
Also used : FeatureWithGeometry(org.n52.shetland.ogc.gml.FeatureWith.FeatureWithGeometry) Geometry(org.locationtech.jts.geom.Geometry) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Coordinate(org.locationtech.jts.geom.Coordinate) LineString(org.locationtech.jts.geom.LineString) WmlMonitoringPoint(org.n52.shetland.ogc.om.series.wml.WmlMonitoringPoint) Point(org.locationtech.jts.geom.Point)

Example 4 with AbstractFeatureEntity

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

the class InsertObservationHandler method insertObservation.

private void insertObservation(OmObservation sosObservation, InsertObservationCache cache, CompositeOwsException exceptions, Session session) throws OwsExceptionReport, CodedException {
    checkSpatialFilteringProfile(sosObservation);
    OmObservationConstellation sosObsConst = sosObservation.getObservationConstellation();
    cache.addOfferings(sosObsConst.getOfferings());
    AbstractFeatureEntity hFeature = null;
    // if (sosObsConst.getOfferings().size() > 1) {
    // 
    // }
    String offeringID = sosObsConst.getOfferings().iterator().next();
    DatasetEntity hDataset = cache.get(sosObsConst, offeringID);
    if (hDataset == null) {
        if (!cache.isChecked(sosObsConst, offeringID)) {
            try {
                hDataset = getDaoFactory().getSeriesDAO().checkSeries(sosObsConst, offeringID, session, Sos2Constants.InsertObservationParams.observationType.name());
                // add to cache table
                cache.putConstellation(sosObsConst, offeringID, hDataset);
            } catch (OwsExceptionReport owse) {
                exceptions.add(owse);
            }
            // mark as checked
            cache.checkConstellation(sosObsConst, offeringID);
        }
    }
    if (hDataset != null) {
        // getFeature feature from local cache or create if necessary
        hFeature = getFeature(sosObsConst.getFeatureOfInterest(), cache, session);
        // AbstractFeature/offering combo
        if (!cache.isChecked(sosObsConst.getFeatureOfInterest(), offeringID)) {
            getDaoFactory().getFeatureOfInterestDAO().checkOrInsertRelatedFeatureRelation(hFeature, hDataset.getOffering(), session);
            cache.checkFeature(sosObsConst.getFeatureOfInterest(), offeringID);
        }
        AbstractObservationDAO observationDAO = getDaoFactory().getObservationDAO();
        DatasetEntity dataset = null;
        if (sosObservation.getValue() instanceof SingleObservationValue) {
            dataset = observationDAO.insertObservationSingleValue(hDataset, hFeature, sosObservation, cache.getCodespaceCache(), cache.getUnitCache(), cache.getFormatCache(), session);
        } else if (sosObservation.getValue() instanceof MultiObservationValues) {
            dataset = observationDAO.insertObservationMultiValue(hDataset, hFeature, sosObservation, cache.getCodespaceCache(), cache.getUnitCache(), cache.getFormatCache(), session);
        }
        if (dataset != null && !cache.get(sosObsConst, offeringID).equals(dataset)) {
            cache.putConstellation(sosObsConst, offeringID, dataset);
        }
    }
}
Also used : SingleObservationValue(org.n52.shetland.ogc.om.SingleObservationValue) AbstractFeatureEntity(org.n52.series.db.beans.AbstractFeatureEntity) DatasetEntity(org.n52.series.db.beans.DatasetEntity) OmObservationConstellation(org.n52.shetland.ogc.om.OmObservationConstellation) AbstractObservationDAO(org.n52.sos.ds.hibernate.dao.observation.AbstractObservationDAO) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport) MultiObservationValues(org.n52.shetland.ogc.om.MultiObservationValues)

Example 5 with AbstractFeatureEntity

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

AbstractFeatureEntity (org.n52.series.db.beans.AbstractFeatureEntity)23 AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)8 NoApplicableCodeException (org.n52.shetland.ogc.ows.exception.NoApplicableCodeException)8 ArrayList (java.util.ArrayList)7 Criteria (org.hibernate.Criteria)7 Session (org.hibernate.Session)7 DatasetEntity (org.n52.series.db.beans.DatasetEntity)7 HashMap (java.util.HashMap)6 Geometry (org.locationtech.jts.geom.Geometry)6 FeatureEntity (org.n52.series.db.beans.FeatureEntity)6 HibernateException (org.hibernate.HibernateException)5 LineString (org.locationtech.jts.geom.LineString)4 LocationEntity (org.n52.series.db.beans.sta.LocationEntity)4 OmObservationConstellation (org.n52.shetland.ogc.om.OmObservationConstellation)4 OwsExceptionReport (org.n52.shetland.ogc.ows.exception.OwsExceptionReport)4 FormatEntity (org.n52.series.db.beans.FormatEntity)3 ResultTemplateEntity (org.n52.series.db.beans.ResultTemplateEntity)3 HistoricalLocationEntity (org.n52.series.db.beans.sta.HistoricalLocationEntity)3 SpatialFilter (org.n52.shetland.ogc.filter.SpatialFilter)3 AbstractSamplingFeature (org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature)3