Search in sources :

Example 1 with ObservablePropertyDAO

use of org.n52.sos.ds.hibernate.dao.ObservablePropertyDAO in project SOS by 52North.

the class ObservablePropertyDAOTest method save.

protected Map<String, PhenomenonEntity> save(List<AbstractPhenomenon> abstractPhenomenons, Session session) {
    I18NDAORepository i18NDAORepository = new I18NDAORepository();
    DaoFactory daoFactory = new DaoFactory();
    daoFactory.setI18NDAORepository(i18NDAORepository);
    ObservablePropertyDAO dao = daoFactory.getObservablePropertyDAO();
    Collection<PhenomenonEntity> savedObservableProperties = dao.getOrInsertObservableProperty(abstractPhenomenons, session);
    return asMap(savedObservableProperties);
}
Also used : ObservablePropertyDAO(org.n52.sos.ds.hibernate.dao.ObservablePropertyDAO) PhenomenonEntity(org.n52.series.db.beans.PhenomenonEntity) I18NDAORepository(org.n52.iceland.i18n.I18NDAORepository) DaoFactory(org.n52.sos.ds.hibernate.dao.DaoFactory)

Example 2 with ObservablePropertyDAO

use of org.n52.sos.ds.hibernate.dao.ObservablePropertyDAO in project SOS by 52North.

the class AbstractSeriesDAO method checkSeries.

/**
 * Check and Update and/or get observation constellation objects
 *
 * @param sosOC
 *            SOS observation constellation
 * @param offering
 *            Offering identifier
 * @param session
 *            Hibernate session
 * @param parameterName
 *            Parameter name for exception
 * @return Observation constellation object
 * @throws OwsExceptionReport
 *             If the requested observation type is invalid
 */
public DatasetEntity checkSeries(OmObservationConstellation sosOC, String offering, Session session, String parameterName) throws OwsExceptionReport {
    // TODO: check for Unit if available!!!
    AbstractPhenomenon observableProperty = sosOC.getObservableProperty();
    String observablePropertyIdentifier = observableProperty.getIdentifier();
    Criteria c = session.createCriteria(getSeriesClass()).setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    c.createCriteria(DatasetEntity.PROPERTY_OFFERING).add(Restrictions.eq(OfferingEntity.IDENTIFIER, offering));
    c.createCriteria(DatasetEntity.PROPERTY_PHENOMENON).add(Restrictions.eq(PhenomenonEntity.IDENTIFIER, observablePropertyIdentifier));
    if (sosOC.isSetProcedure()) {
        c.createCriteria(DatasetEntity.PROPERTY_PROCEDURE).add(Restrictions.eq(ProcedureEntity.IDENTIFIER, sosOC.getProcedureIdentifier()));
    }
    LOGGER.trace("QUERY checkObservationConstellation(sosObservationConstellation, offering): {}", HibernateHelper.getSqlString(c));
    List<DatasetEntity> hocs = c.list();
    if (hocs == null || hocs.isEmpty()) {
        throw new InvalidParameterValueException().at(Sos2Constants.InsertObservationParams.observation).withMessage("The requested observation constellation (procedure=%s, " + "observedProperty=%s and offering=%s) is invalid!", sosOC.getProcedureIdentifier(), observablePropertyIdentifier, sosOC.getOfferings());
    }
    String observationType = sosOC.getObservationType();
    DatasetEntity hObsConst = null;
    for (DatasetEntity hoc : hocs) {
        if (!checkObservationType(hoc, observationType, session)) {
            throw new InvalidParameterValueException().at(parameterName).withMessage("The requested observationType (%s) is invalid for procedure = %s, " + "observedProperty = %s and offering = %s! The valid observationType is '%s'!", observationType, sosOC.getProcedureIdentifier(), observablePropertyIdentifier, sosOC.getOfferings(), hoc.getOmObservationType().getFormat());
        }
        if (hObsConst == null) {
            if (sosOC.isSetProcedure()) {
                if (hoc.getProcedure().getIdentifier().equals(sosOC.getProcedureIdentifier())) {
                    hObsConst = hoc;
                }
            } else {
                hObsConst = hoc;
            }
        }
    // add parent/childs
    // if (observableProperty instanceof OmCompositePhenomenon) {
    // OmCompositePhenomenon omCompositePhenomenon =
    // (OmCompositePhenomenon) observableProperty;
    // ObservablePropertyDAO dao = new
    // ObservablePropertyDAO(getDaoFactory());
    // Map<String, PhenomenonEntity> obsprop =
    // dao.getOrInsertObservablePropertyAsMap(Arrays.asList(observableProperty),
    // false, session);
    // for (OmObservableProperty child : omCompositePhenomenon) {
    // checkOrInsertSeries(hoc.getProcedure(),
    // obsprop.get(child.getIdentifier()),
    // hoc.getOffering(), true, session);
    // }
    // }
    }
    return hObsConst;
}
Also used : InvalidParameterValueException(org.n52.shetland.ogc.ows.exception.InvalidParameterValueException) AbstractPhenomenon(org.n52.shetland.ogc.om.AbstractPhenomenon) DatasetEntity(org.n52.series.db.beans.DatasetEntity) Criteria(org.hibernate.Criteria) DetachedCriteria(org.hibernate.criterion.DetachedCriteria)

Aggregations

Criteria (org.hibernate.Criteria)1 DetachedCriteria (org.hibernate.criterion.DetachedCriteria)1 I18NDAORepository (org.n52.iceland.i18n.I18NDAORepository)1 DatasetEntity (org.n52.series.db.beans.DatasetEntity)1 PhenomenonEntity (org.n52.series.db.beans.PhenomenonEntity)1 AbstractPhenomenon (org.n52.shetland.ogc.om.AbstractPhenomenon)1 InvalidParameterValueException (org.n52.shetland.ogc.ows.exception.InvalidParameterValueException)1 DaoFactory (org.n52.sos.ds.hibernate.dao.DaoFactory)1 ObservablePropertyDAO (org.n52.sos.ds.hibernate.dao.ObservablePropertyDAO)1