Search in sources :

Example 1 with ProcedureDAO

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

the class DescribeSensorDaoImpl method getProcedureDescriptions.

/**
 * @param request
 *            DescribeSensorRequest request
 * @param session
 *            Hibernate session
 * @return Matching procedure descriptions
 * @throws OwsExceptionReport
 *             If an error occurs
 */
private List<SosProcedureDescription<?>> getProcedureDescriptions(DescribeSensorRequest request, Session session) throws OwsExceptionReport {
    Set<String> possibleProcedureDescriptionFormats = getPossibleProcedureDescriptionFormats(request.getProcedureDescriptionFormat());
    final ProcedureEntity procedure = new ProcedureDAO(daoFactory).getProcedureForIdentifier(request.getProcedure(), possibleProcedureDescriptionFormats, request.getValidTime(), session);
    List<SosProcedureDescription<?>> list = Lists.newLinkedList();
    if (procedure != null) {
        if (procedure.hasProcedureHistory()) {
            for (ProcedureHistoryEntity validProcedureTime : daoFactory.getProcedureHistoryDAO().get(procedure, possibleProcedureDescriptionFormats, request.getValidTime(), session)) {
                SosProcedureDescription<?> sosProcedureDescription = procedureConverter.createSosProcedureDescriptionFromValidProcedureTime(procedure, request.getProcedureDescriptionFormat(), validProcedureTime, request.getVersion(), getRequestedLocale(request), session);
                list.add(convertProcedureDescription(sosProcedureDescription, request));
            }
        }
    } else {
        SosProcedureDescription<?> procedureDescription = getProcedureDescription(request, session);
        if (procedureDescription != null) {
            list.add(procedureDescription);
        } else {
            if (!request.isSetValidTime()) {
                throw new NoApplicableCodeException().causedBy(new IllegalArgumentException(LOG_PARAMETER_PROCEDURE_NOT_NULL)).setStatus(HTTPStatus.INTERNAL_SERVER_ERROR);
            }
        }
    }
    return list;
}
Also used : ProcedureEntity(org.n52.series.db.beans.ProcedureEntity) ProcedureHistoryEntity(org.n52.series.db.beans.ProcedureHistoryEntity) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) SosProcedureDescription(org.n52.shetland.ogc.sos.SosProcedureDescription)

Example 2 with ProcedureDAO

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

the class GetCapabilitiesHandler method getProceduresForOfferingEntity.

private Collection<ProcedureEntity> getProceduresForOfferingEntity(OfferingEntity offering, Session session) throws OwsExceptionReport, DataAccessException {
    Map<String, String> map = new HashMap<>(1);
    map.put(IoParameters.OFFERINGS, Long.toString(offering.getId()));
    return new ProcedureDao(session).get(new DbQuery(IoParameters.createFromSingleValueMap(map)));
}
Also used : ProcedureDao(org.n52.series.db.dao.ProcedureDao) DbQuery(org.n52.series.db.dao.DbQuery) HashMap(java.util.HashMap)

Example 3 with ProcedureDAO

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

the class ProcedureHistoryDAO method setEndTime.

/**
 * Set valid end time to valid procedure time object for procedure
 * identifier
 *
 * @param procedureIdentifier
 *            Procedure identifier
 * @param session
 *            Hibernate session
 * @throws UnsupportedOperatorException If an error occurs
 * @throws UnsupportedValueReferenceException If an error occurs
 * @throws UnsupportedTimeException If an error occurs
 */
public void setEndTime(String procedureIdentifier, String procedureDescriptionFormat, Session session) throws UnsupportedTimeException, UnsupportedValueReferenceException, UnsupportedOperatorException {
    ProcedureEntity procedure = new ProcedureDAO(daoFactory).getProcedureForIdentifier(procedureIdentifier, procedureDescriptionFormat, null, session);
    Set<ProcedureHistoryEntity> validProcedureTimes = procedure.getProcedureHistory();
    for (ProcedureHistoryEntity validProcedureTime : validProcedureTimes) {
        if (validProcedureTime.getEndTime() == null) {
            validProcedureTime.setEndTime(new DateTime(DateTimeZone.UTC).toDate());
        }
    }
}
Also used : ProcedureEntity(org.n52.series.db.beans.ProcedureEntity) ProcedureHistoryEntity(org.n52.series.db.beans.ProcedureHistoryEntity) DateTime(org.joda.time.DateTime)

Example 4 with ProcedureDAO

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

the class AbstractHibernateProcedureDescriptionGenerator method addNameAndDescription.

protected void addNameAndDescription(ProcedureEntity procedure, AbstractFeature feature, Session session) throws OwsExceptionReport {
    HibernateI18NDAO<I18NProcedureMetadata> i18nDAO = (HibernateI18NDAO<I18NProcedureMetadata>) i18NDAORepository.getDAO(I18NProcedureMetadata.class);
    Locale requestedLocale = getLocale();
    if (i18nDAO == null) {
        // no locale support
        ProcedureDAO dao = daoFactory.getProcedureDAO();
        feature.addName(dao.getName(procedure));
        feature.setDescription(dao.getDescription(procedure));
    } else {
        if (requestedLocale != null) {
            // specific locale was requested
            I18NProcedureMetadata i18n = i18nDAO.getMetadata(procedure.getIdentifier(), requestedLocale, session);
            Optional<LocalizedString> name = i18n.getName().getLocalization(requestedLocale);
            if (name.isPresent()) {
                feature.addName(new CodeType(name.get()));
            }
            Optional<LocalizedString> description = i18n.getDescription().getLocalization(requestedLocale);
            if (description.isPresent()) {
                feature.setDescription(description.get().getText());
            }
        } else {
            final I18NProcedureMetadata i18n;
            if (this.showAllLanguages) {
                // load all names
                i18n = i18nDAO.getMetadata(procedure.getIdentifier(), session);
            } else {
                // load only name in default locale
                i18n = i18nDAO.getMetadata(procedure.getIdentifier(), defaultLanguage, session);
            }
            for (LocalizedString name : i18n.getName()) {
                // either all or default only
                feature.addName(new CodeType(name));
            }
            // choose always the description in the default locale
            Optional<LocalizedString> description = i18n.getDescription().getLocalization(defaultLanguage);
            if (description.isPresent()) {
                feature.setDescription(description.get().getText());
            }
        }
    }
}
Also used : Locale(java.util.Locale) ProcedureDAO(org.n52.sos.ds.hibernate.dao.ProcedureDAO) CodeType(org.n52.shetland.ogc.gml.CodeType) HibernateI18NDAO(org.n52.sos.ds.hibernate.dao.i18n.HibernateI18NDAO) LocalizedString(org.n52.janmayen.i18n.LocalizedString) I18NProcedureMetadata(org.n52.iceland.i18n.metadata.I18NProcedureMetadata)

Example 5 with ProcedureDAO

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

the class DescribeSensorHandler method getSensorDescription.

@Override
public DescribeSensorResponse getSensorDescription(final DescribeSensorRequest request) throws OwsExceptionReport {
    Session session = null;
    try {
        session = sessionStore.getSession();
        final DescribeSensorResponse response = new DescribeSensorResponse();
        response.setService(request.getService());
        response.setVersion(request.getVersion());
        response.setOutputFormat(request.getProcedureDescriptionFormat());
        Collection<ProcedureEntity> entities = new ProcedureDao(session).get(createDbQuery(request));
        if (entities == null || entities.isEmpty()) {
            throw new NoApplicableCodeException().causedBy(new IllegalArgumentException("Parameter 'procedure' should not be null!")).setStatus(HTTPStatus.INTERNAL_SERVER_ERROR);
        }
        if (dao != null) {
            response.setSensorDescriptions(dao.querySensorDescriptions(request, session));
        } else {
            response.addSensorDescription(createSensorDescription(entities.iterator().next(), request, session));
        }
        return response;
    } catch (final HibernateException e) {
        throw new NoApplicableCodeException().causedBy(e).withMessage("Error while querying data for DescribeSensor document!");
    } finally {
        sessionStore.returnSession(session);
    }
}
Also used : ProcedureEntity(org.n52.series.db.beans.ProcedureEntity) ProcedureDao(org.n52.series.db.dao.ProcedureDao) HibernateException(org.hibernate.HibernateException) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) DescribeSensorResponse(org.n52.shetland.ogc.sos.response.DescribeSensorResponse) Session(org.hibernate.Session)

Aggregations

ProcedureEntity (org.n52.series.db.beans.ProcedureEntity)4 NoApplicableCodeException (org.n52.shetland.ogc.ows.exception.NoApplicableCodeException)3 HibernateException (org.hibernate.HibernateException)2 Session (org.hibernate.Session)2 DateTime (org.joda.time.DateTime)2 ProcedureHistoryEntity (org.n52.series.db.beans.ProcedureHistoryEntity)2 ProcedureDao (org.n52.series.db.dao.ProcedureDao)2 ProcedureDAO (org.n52.sos.ds.hibernate.dao.ProcedureDAO)2 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Locale (java.util.Locale)1 Transaction (org.hibernate.Transaction)1 I18NProcedureMetadata (org.n52.iceland.i18n.metadata.I18NProcedureMetadata)1 LocalizedString (org.n52.janmayen.i18n.LocalizedString)1 CategoryEntity (org.n52.series.db.beans.CategoryEntity)1 FormatEntity (org.n52.series.db.beans.FormatEntity)1 OfferingEntity (org.n52.series.db.beans.OfferingEntity)1 PhenomenonEntity (org.n52.series.db.beans.PhenomenonEntity)1 RelatedFeatureEntity (org.n52.series.db.beans.RelatedFeatureEntity)1 UnitEntity (org.n52.series.db.beans.UnitEntity)1