Search in sources :

Example 1 with DatasetEntity

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

the class DeleteObservationHelper method checkForFirstLastReference.

default void checkForFirstLastReference(DataEntity<?> observation, Session session) {
    DatasetEntity dataset = observation.getDataset();
    if (dataset.getFirstObservation() != null && dataset.getFirstObservation().getId() != null && observation.getId() != null && dataset.getFirstObservation().getId().equals(observation.getId())) {
        dataset.setFirstObservation(null);
    }
    if (dataset.getLastObservation() != null && dataset.getLastObservation().getId() != null && observation.getId() != null && dataset.getLastObservation().getId().equals(observation.getId())) {
        dataset.setLastObservation(null);
    }
    session.update(dataset);
    session.flush();
}
Also used : DatasetEntity(org.n52.series.db.beans.DatasetEntity)

Example 2 with DatasetEntity

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

the class DeleteObservationHelper method checkSeriesForFirstLatest.

/**
 * Check if {@link Dataset} should be updated
 *
 * @param serieses
 *            Deleted observation
 * @param session
 *            Hibernate session
 * @throws OwsExceptionReport
 *             If an error occurs
 */
default void checkSeriesForFirstLatest(Collection<Long> serieses, Session session) throws OwsExceptionReport {
    if (!serieses.isEmpty()) {
        AbstractSeriesObservationDAO observationDAO = getDaoFactory().getObservationDAO();
        Map<Long, SeriesTimeExtrema> minMaxTimes = observationDAO.getMinMaxSeriesTimesById(serieses instanceof Set ? (Set<Long>) serieses : new LinkedHashSet<>(serieses), session);
        for (Long id : serieses) {
            DatasetEntity series = session.get(DatasetEntity.class, id);
            boolean update = false;
            if (minMaxTimes.containsKey(series.getId())) {
                SeriesTimeExtrema extrema = minMaxTimes.get(series.getId());
                if (!series.isSetFirstValueAt() || series.isSetFirstValueAt() && !DateTimeHelper.makeDateTime(series.getFirstValueAt()).equals(extrema.getMinPhenomenonTime())) {
                    series.setFirstValueAt(extrema.getMinPhenomenonTime().toDate());
                    DataEntity<?> o = unproxy(observationDAO.getMinObservation(series, extrema.getMinPhenomenonTime(), session), session);
                    series.setFirstObservation(o);
                    if (series.getValueType().equals(ValueType.quantity)) {
                        series.setFirstQuantityValue(((QuantityDataEntity) o).getValue());
                    }
                    update = true;
                }
                if (!series.isSetLastValueAt() || series.isSetLastValueAt() && !DateTimeHelper.makeDateTime(series.getLastValueAt()).equals(extrema.getMaxPhenomenonTime())) {
                    series.setLastValueAt(extrema.getMaxPhenomenonTime().toDate());
                    DataEntity<?> o = unproxy(observationDAO.getMaxObservation(series, extrema.getMaxPhenomenonTime(), session), session);
                    series.setLastObservation(o);
                    if (series.getValueType().equals(ValueType.quantity)) {
                        series.setLastQuantityValue(((QuantityDataEntity) o).getValue());
                    }
                    update = true;
                }
            } else {
                series.setFirstValueAt(null);
                series.setFirstQuantityValue(null);
                series.setFirstObservation(null);
                series.setLastValueAt(null);
                series.setLastQuantityValue(null);
                series.setLastObservation(null);
                update = true;
            }
            if (update) {
                session.saveOrUpdate(series);
                session.flush();
            }
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) DatasetEntity(org.n52.series.db.beans.DatasetEntity) AbstractSeriesObservationDAO(org.n52.sos.ds.hibernate.dao.observation.series.AbstractSeriesObservationDAO) SeriesTimeExtrema(org.n52.sos.ds.hibernate.dao.observation.series.SeriesTimeExtrema)

Example 3 with DatasetEntity

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

the class DeleteDataHelper method getDatasetForOffering.

default List<DatasetEntity> getDatasetForOffering(OfferingEntity offering, Session session) {
    AbstractSeriesDAO seriesDAO = getDaoFactory().getSeriesDAO();
    Criteria c = seriesDAO.getDefaultAllSeriesCriteria(session);
    seriesDAO.addOfferingToCriteria(c, offering);
    return c.list();
}
Also used : Criteria(org.hibernate.Criteria) AbstractSeriesDAO(org.n52.sos.ds.hibernate.dao.observation.series.AbstractSeriesDAO)

Example 4 with DatasetEntity

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

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

the class InsertResultHandler method insertObservationConstellationForProfiles.

private DatasetEntity insertObservationConstellationForProfiles(AbstractSeriesDAO obsConstDao, FormatDAO obsTypeDao, OmObservation o, Session session) throws OwsExceptionReport {
    ProcedureEntity procedure = getDaoFactory().getProcedureDAO().getProcedureForIdentifier(o.getObservationConstellation().getProcedureIdentifier(), session);
    PhenomenonEntity observableProperty = getDaoFactory().getObservablePropertyDAO().getOrInsertObservableProperty(o.getObservationConstellation().getObservableProperty(), session);
    OfferingEntity offering = getDaoFactory().getOfferingDAO().getOfferingForIdentifier(o.getObservationConstellation().getOfferings().iterator().next(), session);
    CategoryEntity category = getDaoFactory().getCategoryDAO().getOrInsertCategory(observableProperty, session);
    DatasetEntity oc = obsConstDao.checkOrInsertSeries(procedure, observableProperty, offering, category, false, session);
    if (o.getObservationConstellation().isSetObservationType()) {
        oc.setOmObservationType(obsTypeDao.getFormatEntityObject(o.getObservationConstellation().getObservationType(), session));
    }
    return oc;
}
Also used : ProcedureEntity(org.n52.series.db.beans.ProcedureEntity) DatasetEntity(org.n52.series.db.beans.DatasetEntity) PhenomenonEntity(org.n52.series.db.beans.PhenomenonEntity) OfferingEntity(org.n52.series.db.beans.OfferingEntity) CategoryEntity(org.n52.series.db.beans.CategoryEntity)

Aggregations

DatasetEntity (org.n52.series.db.beans.DatasetEntity)49 Criteria (org.hibernate.Criteria)21 DataEntity (org.n52.series.db.beans.DataEntity)13 NoApplicableCodeException (org.n52.shetland.ogc.ows.exception.NoApplicableCodeException)13 ProcedureEntity (org.n52.series.db.beans.ProcedureEntity)11 Session (org.hibernate.Session)10 DetachedCriteria (org.hibernate.criterion.DetachedCriteria)10 OfferingEntity (org.n52.series.db.beans.OfferingEntity)9 HashSet (java.util.HashSet)8 OmObservationConstellation (org.n52.shetland.ogc.om.OmObservationConstellation)8 LinkedHashSet (java.util.LinkedHashSet)7 Set (java.util.Set)7 HibernateException (org.hibernate.HibernateException)7 FormatEntity (org.n52.series.db.beans.FormatEntity)7 DatastreamEntity (org.n52.series.db.beans.sta.DatastreamEntity)7 OwsExceptionReport (org.n52.shetland.ogc.ows.exception.OwsExceptionReport)7 Collection (java.util.Collection)6 LinkedList (java.util.LinkedList)6 AbstractFeatureEntity (org.n52.series.db.beans.AbstractFeatureEntity)6 PhenomenonEntity (org.n52.series.db.beans.PhenomenonEntity)6