Search in sources :

Example 1 with ProcedureEntity

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

the class ProcedureDAO method getProcedureForIdentifier.

// 
// private ProcedureEntity
// getProcedureWithLatestValidProcedureDescription(String
// identifier, Session session) {
// Criteria criteria = getDefaultCriteria(session);
// criteria.add(Restrictions.eq(ProcedureEntity.IDENTIFIER, identifier));
// criteria.createCriteria(TProcedureEntity.VALID_PROCEDURE_TIME).add(
// Restrictions.isNull(ValidProcedureTime.END_TIME));
// LOGGER.trace(QUERY_IDENTIFIER_LOG_TEMPLATE,
// HibernateHelper.getSqlString(criteria));
// return (ProcedureEntity) criteria.uniqueResult();
// }
/**
 * Get ProcedureEntity object for procedure identifier
 *
 * @param identifier
 *            ProcedureEntity identifier
 * @param session
 *            Hibernate session
 * @return ProcedureEntity object
 */
public ProcedureEntity getProcedureForIdentifier(final String identifier, Time time, final Session session) {
    Criteria criteria = getDefaultCriteria(session).add(Restrictions.eq(ProcedureEntity.IDENTIFIER, identifier));
    LOGGER.trace(QUERY_IDENTIFIER_LOG_TEMPLATE, HibernateHelper.getSqlString(criteria));
    return (ProcedureEntity) criteria.uniqueResult();
}
Also used : ProcedureEntity(org.n52.series.db.beans.ProcedureEntity) Criteria(org.hibernate.Criteria) DetachedCriteria(org.hibernate.criterion.DetachedCriteria)

Example 2 with ProcedureEntity

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

the class ProcedureDAO method getProcedureForIdentifier.

/**
 * Get procedure for identifier, possible procedureDescriptionFormats and
 * valid time
 *
 * @param identifier
 *            Identifier of the procedure
 * @param possibleProcedureDescriptionFormats
 *            Possible procedureDescriptionFormats
 * @param validTime
 *            Valid time of the procedure
 * @param session
 *            Hibernate Session
 * @return ProcedureEntity entity that match the parameters
 * @throws UnsupportedTimeException
 *             If the time is not supported
 * @throws UnsupportedValueReferenceException
 *             If the valueReference is not supported
 * @throws UnsupportedOperatorException
 *             If the temporal operator is not supported
 */
public ProcedureEntity getProcedureForIdentifier(String identifier, Set<String> possibleProcedureDescriptionFormats, Time validTime, Session session) throws UnsupportedTimeException, UnsupportedValueReferenceException, UnsupportedOperatorException {
    Criteria criteria = getDefaultCriteria(session).add(Restrictions.eq(ProcedureEntity.IDENTIFIER, identifier));
    Criteria createValidProcedureTime = criteria.createCriteria(ProcedureEntity.PROPERTY_VALID_PROCEDURE_TIME);
    Criterion validTimeCriterion = QueryHelper.getValidTimeCriterion(validTime);
    if (validTime == null || validTimeCriterion == null) {
        createValidProcedureTime.add(Restrictions.isNull(ProcedureHistoryEntity.END_TIME));
    } else {
        createValidProcedureTime.add(validTimeCriterion);
    }
    createValidProcedureTime.createCriteria(ProcedureHistoryEntity.PROCEDURE_DESCRIPTION_FORMAT).add(Restrictions.in(FormatEntity.FORMAT, possibleProcedureDescriptionFormats));
    LOGGER.trace("QUERY getProcedureForIdentifier(identifier, possibleProcedureDescriptionFormats, validTime): {}", HibernateHelper.getSqlString(criteria));
    return (ProcedureEntity) criteria.uniqueResult();
}
Also used : ProcedureEntity(org.n52.series.db.beans.ProcedureEntity) Criterion(org.hibernate.criterion.Criterion) Criteria(org.hibernate.Criteria) DetachedCriteria(org.hibernate.criterion.DetachedCriteria)

Example 3 with ProcedureEntity

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

the class ProcedureDAO method updateProcedure.

public ProcedureEntity updateProcedure(ProcedureEntity procedure, SosProcedureDescription procedureDescription, Session session) {
    AbstractFeature af = procedureDescription.getProcedureDescription();
    if (af.isSetName()) {
        if (!procedure.isSetName() || procedure.isSetName() && !checkForName(af.getName(), procedure.getName())) {
            procedure.setName(af.getFirstName().getValue());
        }
        if (af.isSetDescription() && !af.getDescription().equals(procedure.getDescription())) {
            procedure.setDescription(af.getDescription());
        }
    }
    session.saveOrUpdate(procedure);
    session.flush();
    session.refresh(procedure);
    return procedure;
}
Also used : AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature)

Example 4 with ProcedureEntity

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

the class ProcedureDAO method getMaxDate4Procedure.

/**
 * Get max time from observations for procedure
 *
 * @param procedure
 *            ProcedureEntity identifier
 * @param session
 *            Hibernate session
 * @return max time for procedure
 * @throws CodedException
 *             If an error occurs
 */
public DateTime getMaxDate4Procedure(final String procedure, final Session session) throws OwsExceptionReport {
    Object maxStart = null;
    Object maxEnd = null;
    if (HibernateHelper.isNamedQuerySupported(SQL_QUERY_GET_MAX_DATE_FOR_PROCEDURE, session)) {
        Query namedQuery = session.getNamedQuery(SQL_QUERY_GET_MAX_DATE_FOR_PROCEDURE);
        namedQuery.setParameter(PROCEDURE, procedure);
        LOGGER.trace("QUERY getMaxDate4Procedure(procedure) with NamedQuery: {}", SQL_QUERY_GET_MAX_DATE_FOR_PROCEDURE);
        maxStart = namedQuery.uniqueResult();
        maxEnd = maxStart;
    } else {
        AbstractObservationDAO observationDAO = getDaoFactory().getObservationDAO();
        Criteria cstart = observationDAO.getDefaultObservationInfoCriteria(session);
        Criteria cend = observationDAO.getDefaultObservationInfoCriteria(session);
        if (observationDAO instanceof SeriesObservationDAO) {
            addProcedureRestrictionForSeries(cstart, procedure);
            addProcedureRestrictionForSeries(cend, procedure);
        } else {
            addProcedureRestrictionForObservation(cstart, procedure);
            addProcedureRestrictionForObservation(cend, procedure);
        }
        addMinMaxProjection(cstart, MinMax.MAX, DataEntity.PROPERTY_SAMPLING_TIME_START);
        addMinMaxProjection(cend, MinMax.MAX, DataEntity.PROPERTY_SAMPLING_TIME_END);
        LOGGER.trace("QUERY getMaxDate4Procedure(procedure) start: {}", HibernateHelper.getSqlString(cstart));
        LOGGER.trace("QUERY getMaxDate4Procedure(procedure) end: {}", HibernateHelper.getSqlString(cend));
        if (HibernateHelper.getSqlString(cstart).endsWith(HibernateHelper.getSqlString(cend))) {
            maxStart = cstart.uniqueResult();
            maxEnd = maxStart;
            LOGGER.trace("Max time start and end query are identically, only one query is executed!");
        } else {
            maxStart = cstart.uniqueResult();
            maxEnd = cend.uniqueResult();
        }
    }
    if (maxStart == null && maxEnd == null) {
        return null;
    } else {
        final DateTime start = new DateTime(maxStart, DateTimeZone.UTC);
        if (maxEnd != null) {
            final DateTime end = new DateTime(maxEnd, DateTimeZone.UTC);
            if (end.isAfter(start)) {
                return end;
            }
        }
        return start;
    }
}
Also used : Query(org.hibernate.query.Query) Criteria(org.hibernate.Criteria) DetachedCriteria(org.hibernate.criterion.DetachedCriteria) AbstractObservationDAO(org.n52.sos.ds.hibernate.dao.observation.AbstractObservationDAO) SeriesObservationDAO(org.n52.sos.ds.hibernate.dao.observation.series.SeriesObservationDAO) DateTime(org.joda.time.DateTime)

Example 5 with ProcedureEntity

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

the class ProcedureDAO method getProcedureForIdentifierIncludeDeleted.

/**
 * Get ProcedureEntity object for procedure identifier inclusive deleted
 * procedure
 *
 * @param identifier
 *            ProcedureEntity identifier
 * @param session
 *            Hibernate session
 * @return ProcedureEntity object
 */
public ProcedureEntity getProcedureForIdentifierIncludeDeleted(final String identifier, final Session session) {
    Criteria criteria = session.createCriteria(ProcedureEntity.class).add(Restrictions.eq(ProcedureEntity.IDENTIFIER, identifier));
    LOGGER.trace("QUERY getProcedureForIdentifierIncludeDeleted(identifier): {}", HibernateHelper.getSqlString(criteria));
    return (ProcedureEntity) criteria.uniqueResult();
}
Also used : ProcedureEntity(org.n52.series.db.beans.ProcedureEntity) Criteria(org.hibernate.Criteria) DetachedCriteria(org.hibernate.criterion.DetachedCriteria)

Aggregations

ProcedureEntity (org.n52.series.db.beans.ProcedureEntity)32 NoApplicableCodeException (org.n52.shetland.ogc.ows.exception.NoApplicableCodeException)14 HibernateException (org.hibernate.HibernateException)11 DatasetEntity (org.n52.series.db.beans.DatasetEntity)10 PhenomenonEntity (org.n52.series.db.beans.PhenomenonEntity)10 Criteria (org.hibernate.Criteria)9 Session (org.hibernate.Session)9 OfferingEntity (org.n52.series.db.beans.OfferingEntity)9 SosProcedureDescription (org.n52.shetland.ogc.sos.SosProcedureDescription)9 HashSet (java.util.HashSet)8 FormatEntity (org.n52.series.db.beans.FormatEntity)7 DetachedCriteria (org.hibernate.criterion.DetachedCriteria)6 DateTime (org.joda.time.DateTime)6 ArrayList (java.util.ArrayList)5 Collection (java.util.Collection)5 HashMap (java.util.HashMap)5 Transaction (org.hibernate.Transaction)5 ProcedureHistoryEntity (org.n52.series.db.beans.ProcedureHistoryEntity)5 Set (java.util.Set)4 Collectors.toCollection (java.util.stream.Collectors.toCollection)4