Search in sources :

Example 1 with AbstractSeriesDAO

use of org.n52.sos.ds.hibernate.dao.observation.series.AbstractSeriesDAO in project SOS by 52North.

the class ProcedureDAO method getProcedureTimeExtrema.

@SuppressWarnings("unchecked")
public Map<String, TimeExtrema> getProcedureTimeExtrema(Session session) throws OwsExceptionReport {
    List<ProcedureTimeExtrema> results = null;
    if (isAllProcedureTimeExtremaNamedQuerySupported(session)) {
        Query namedQuery = session.getNamedQuery(SQL_QUERY_GET_ALL_PROCEDURE_TIME_EXTREMA);
        LOGGER.trace("QUERY getProcedureTimeExtrema() with NamedQuery '{}': {}", SQL_QUERY_GET_ALL_PROCEDURE_TIME_EXTREMA, namedQuery.getQueryString());
        namedQuery.setResultTransformer(transformer);
        results = namedQuery.list();
    } else {
        AbstractSeriesDAO seriesDAO = getDaoFactory().getSeriesDAO();
        if (seriesDAO != null) {
            Criteria c = seriesDAO.getDefaultSeriesCriteria(session);
            c.createAlias(DatasetEntity.PROPERTY_PROCEDURE, "p");
            c.setProjection(Projections.projectionList().add(Projections.groupProperty(P_PREFIX + ProcedureEntity.IDENTIFIER)).add(Projections.min(DatasetEntity.PROPERTY_FIRST_VALUE_AT)).add(Projections.max(DatasetEntity.PROPERTY_LAST_VALUE_AT)));
            LOGGER.trace(QUERY_TIME_EXTREMA_LOG_TEMPLATE, HibernateHelper.getSqlString(c));
            c.setResultTransformer(transformer);
            results = c.list();
        }
        if (checkHasNoProcedureTimeResult(results)) {
            AbstractObservationDAO observationDAO = getDaoFactory().getObservationDAO();
            Criteria criteria = observationDAO.getDefaultObservationTimeCriteria(session);
            String alias = observationDAO.addProcedureAlias(criteria);
            criteria.setProjection(Projections.projectionList().add(Projections.groupProperty(alias + ProcedureEntity.IDENTIFIER)).add(Projections.min(DataEntity.PROPERTY_SAMPLING_TIME_START)).add(Projections.max(DataEntity.PROPERTY_SAMPLING_TIME_START)).add(Projections.max(DataEntity.PROPERTY_SAMPLING_TIME_START)));
            LOGGER.trace(QUERY_TIME_EXTREMA_LOG_TEMPLATE, HibernateHelper.getSqlString(criteria));
            criteria.setResultTransformer(transformer);
            results = criteria.list();
        }
    }
    Map<String, TimeExtrema> procedureTimeExtrema = Maps.newHashMap();
    if (results != null && !results.isEmpty()) {
        for (ProcedureTimeExtrema pte : results) {
            if (pte != null && pte.isSetProcedure()) {
                procedureTimeExtrema.put(pte.getProcedure(), pte);
            }
        }
    }
    return procedureTimeExtrema;
}
Also used : Query(org.hibernate.query.Query) ProcedureTimeExtrema(org.n52.sos.ds.hibernate.util.ProcedureTimeExtrema) TimeExtrema(org.n52.sos.ds.hibernate.util.TimeExtrema) ProcedureTimeExtrema(org.n52.sos.ds.hibernate.util.ProcedureTimeExtrema) Criteria(org.hibernate.Criteria) DetachedCriteria(org.hibernate.criterion.DetachedCriteria) AbstractObservationDAO(org.n52.sos.ds.hibernate.dao.observation.AbstractObservationDAO) AbstractSeriesDAO(org.n52.sos.ds.hibernate.dao.observation.series.AbstractSeriesDAO)

Example 2 with AbstractSeriesDAO

use of org.n52.sos.ds.hibernate.dao.observation.series.AbstractSeriesDAO 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 3 with AbstractSeriesDAO

use of org.n52.sos.ds.hibernate.dao.observation.series.AbstractSeriesDAO 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)

Example 4 with AbstractSeriesDAO

use of org.n52.sos.ds.hibernate.dao.observation.series.AbstractSeriesDAO in project SOS by 52North.

the class DeleteDataHelper method getDatasetForProcedure.

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

Example 5 with AbstractSeriesDAO

use of org.n52.sos.ds.hibernate.dao.observation.series.AbstractSeriesDAO in project SOS by 52North.

the class FeatureOfInterestDAO method getIdentifiersForOffering.

/**
 * Get featureOfInterest identifiers for an offering identifier
 *
 * @param offering
 *            Offering identifier
 * @param session
 *            Hibernate session Hibernate session
 * @return FeatureOfInterest identifiers for offering
 * @throws CodedException If an error occurs
 */
@SuppressWarnings({ "unchecked" })
public List<String> getIdentifiersForOffering(String offering, Session session) throws OwsExceptionReport {
    if (HibernateHelper.isNamedQuerySupported(SQL_QUERY_GET_FEATURE_OF_INTEREST_IDENTIFIER_FOR_OFFERING, session)) {
        Query namedQuery = session.getNamedQuery(SQL_QUERY_GET_FEATURE_OF_INTEREST_IDENTIFIER_FOR_OFFERING);
        namedQuery.setParameter(OFFERING, offering);
        LOGGER.trace("QUERY getFeatureOfInterestIdentifiersForOffering(offeringIdentifiers) with NamedQuery: {}", SQL_QUERY_GET_FEATURE_OF_INTEREST_IDENTIFIER_FOR_OFFERING);
        return namedQuery.list();
    } else {
        AbstractSeriesDAO datasetDAO = getDaoFactory().getSeriesDAO();
        Criteria c = datasetDAO.getDefaultSeriesCriteria(session).createCriteria(DatasetEntity.PROPERTY_FEATURE).setProjection(Projections.distinct(Projections.property(AbstractFeatureEntity.IDENTIFIER)));
        getDaoFactory().getOfferingDAO().addOfferingRestricionForObservation(c, offering);
        LOGGER.trace("QUERY getFeatureOfInterestIdentifiersForOffering(offeringIdentifiers): {}", HibernateHelper.getSqlString(c));
        return c.list();
    }
}
Also used : Query(org.hibernate.query.Query) Criteria(org.hibernate.Criteria) DetachedCriteria(org.hibernate.criterion.DetachedCriteria) AbstractSeriesDAO(org.n52.sos.ds.hibernate.dao.observation.series.AbstractSeriesDAO)

Aggregations

AbstractSeriesDAO (org.n52.sos.ds.hibernate.dao.observation.series.AbstractSeriesDAO)7 DatasetEntity (org.n52.series.db.beans.DatasetEntity)6 Criteria (org.hibernate.Criteria)4 LinkedList (java.util.LinkedList)3 FormatEntity (org.n52.series.db.beans.FormatEntity)3 OfferingEntity (org.n52.series.db.beans.OfferingEntity)3 ProcedureEntity (org.n52.series.db.beans.ProcedureEntity)3 UnitEntity (org.n52.series.db.beans.UnitEntity)3 OmObservation (org.n52.shetland.ogc.om.OmObservation)3 NoApplicableCodeException (org.n52.shetland.ogc.ows.exception.NoApplicableCodeException)3 HibernateException (org.hibernate.HibernateException)2 Session (org.hibernate.Session)2 Transaction (org.hibernate.Transaction)2 DetachedCriteria (org.hibernate.criterion.DetachedCriteria)2 Query (org.hibernate.query.Query)2 DateTime (org.joda.time.DateTime)2 CategoryEntity (org.n52.series.db.beans.CategoryEntity)2 CodespaceEntity (org.n52.series.db.beans.CodespaceEntity)2 DataEntity (org.n52.series.db.beans.DataEntity)2 PhenomenonEntity (org.n52.series.db.beans.PhenomenonEntity)2