Search in sources :

Example 11 with DaoFactory

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

the class GetObservationDaoImpl method querySeriesObservationForStreaming.

/**
 * Query the series observations for streaming datasource
 *
 * @param request
 *            The GetObservation request
 * @param session
 *            Hibernate Session
 * @return List of internal observations
 * @throws OwsExceptionReport
 *             If an error occurs.
 * @throws ConverterException
 *             If an error occurs during sensor description creation.
 */
private List<OmObservation> querySeriesObservationForStreaming(GetObservationRequest request, GetObservationResponse response, Session session) throws OwsExceptionReport, ConverterException {
    final long start = System.currentTimeMillis();
    final List<OmObservation> result = new LinkedList<OmObservation>();
    List<String> features = request.getFeatureIdentifiers();
    Criterion temporalFilterCriterion = getTemporalFilterCriterion(request);
    List<DatasetEntity> serieses = daoFactory.getSeriesDAO().getSeries(request, features, session);
    checkMaxNumberOfReturnedSeriesSize(serieses.size());
    int maxNumberOfValuesPerSeries = getMaxNumberOfValuesPerSeries(serieses.size());
    for (DatasetEntity series : serieses) {
        ObservationStream createSosObservationFromSeries = HibernateObservationUtilities.createSosObservationFromSeries(series, request, getRequestedLocale(request), getProcedureDescriptionFormat(request.getResponseFormat()), observationCreatorContext, session);
        OmObservation observationTemplate = createSosObservationFromSeries.next();
        HibernateSeriesStreamingValue streamingValue = new HibernateChunkSeriesStreamingValue(sessionHolder.getConnectionProvider(), daoFactory, request, series.getId(), observationCreatorContext.getBindingRepository(), getChunkSize());
        streamingValue.setResponseFormat(request.getResponseFormat());
        streamingValue.setTemporalFilterCriterion(temporalFilterCriterion);
        streamingValue.setObservationTemplate(observationTemplate);
        streamingValue.setMaxNumberOfValues(maxNumberOfValuesPerSeries);
        observationTemplate.setValue(streamingValue);
        result.add(observationTemplate);
    }
    ObservationTimeExtrema timeExtrema = daoFactory.getValueTimeDAO().getTimeExtremaForSeries(serieses, temporalFilterCriterion, session);
    if (timeExtrema.isSetPhenomenonTimes()) {
        response.setGlobalObservationValues(new GlobalObservationResponseValues().setPhenomenonTime(timeExtrema.getPhenomenonTime()));
    }
    LOGGER.debug(LOG_TIME_TO_QUERY, System.currentTimeMillis() - start);
    return result;
}
Also used : DatasetEntity(org.n52.series.db.beans.DatasetEntity) OmObservation(org.n52.shetland.ogc.om.OmObservation) LinkedList(java.util.LinkedList) HibernateChunkSeriesStreamingValue(org.n52.sos.ds.hibernate.values.series.HibernateChunkSeriesStreamingValue) ObservationTimeExtrema(org.n52.sos.ds.hibernate.util.ObservationTimeExtrema) Criterion(org.hibernate.criterion.Criterion) ObservationStream(org.n52.shetland.ogc.om.ObservationStream) HibernateSeriesStreamingValue(org.n52.sos.ds.hibernate.values.series.HibernateSeriesStreamingValue) GlobalObservationResponseValues(org.n52.shetland.ogc.sos.response.GlobalObservationResponseValues)

Example 12 with DaoFactory

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

the class UpdateSensorDescriptionHandler method updateSensorDescription.

@Override
public synchronized UpdateSensorResponse updateSensorDescription(UpdateSensorRequest request) throws OwsExceptionReport {
    Session session = null;
    Transaction transaction = null;
    try {
        session = sessionHolder.getSession();
        transaction = session.beginTransaction();
        UpdateSensorResponse response = new UpdateSensorResponse();
        response.setService(request.getService());
        response.setVersion(request.getVersion());
        for (SosProcedureDescription<?> procedureDescription : request.getProcedureDescriptions()) {
            DateTime currentTime = new DateTime(DateTimeZone.UTC);
            // TODO: check for all validTimes of descriptions for this
            // identifier
            // ITime validTime =
            // getValidTimeForProcedure(procedureDescription);
            ProcedureEntity procedure = daoFactory.getProcedureDAO().getProcedureForIdentifier(request.getProcedureIdentifier(), session);
            FormatEntity procedureDescriptionFormat = new DaoFactory().getProcedureDescriptionFormatDAO().getFormatEntityObject(request.getProcedureDescriptionFormat(), session);
            Set<ProcedureHistoryEntity> procedureHistories = procedure.getProcedureHistory();
            ProcedureHistoryDAO procedureHistroyDAO = daoFactory.getProcedureHistoryDAO();
            for (ProcedureHistoryEntity procedureHistroy : procedureHistories) {
                if (procedureHistroy.getFormat().getFormat().equals(procedureDescriptionFormat.getFormat()) && procedureHistroy.getEndTime() == null) {
                    procedureHistroy.setEndTime(currentTime.toDate());
                    procedureHistroyDAO.update(procedureHistroy, session);
                }
            }
            procedureHistroyDAO.insert(procedure, procedureDescriptionFormat, getSensorDescriptionFromProcedureDescription(procedureDescription), currentTime, session);
        }
        session.flush();
        transaction.commit();
        response.setUpdatedProcedure(request.getProcedureIdentifier());
        return response;
    } catch (HibernateException he) {
        if (transaction != null) {
            transaction.rollback();
        }
        throw new NoApplicableCodeException().causedBy(he).withMessage("Error while processing data for UpdateSensorDescription document!");
    } finally {
        sessionHolder.returnSession(session);
    }
}
Also used : ProcedureHistoryEntity(org.n52.series.db.beans.ProcedureHistoryEntity) HibernateException(org.hibernate.HibernateException) FormatEntity(org.n52.series.db.beans.FormatEntity) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) DateTime(org.joda.time.DateTime) DaoFactory(org.n52.sos.ds.hibernate.dao.DaoFactory) ProcedureEntity(org.n52.series.db.beans.ProcedureEntity) Transaction(org.hibernate.Transaction) UpdateSensorResponse(org.n52.shetland.ogc.sos.response.UpdateSensorResponse) ProcedureHistoryDAO(org.n52.sos.ds.hibernate.dao.ProcedureHistoryDAO) Session(org.hibernate.Session)

Aggregations

DaoFactory (org.n52.sos.ds.hibernate.dao.DaoFactory)6 Session (org.hibernate.Session)5 I18NDAORepository (org.n52.iceland.i18n.I18NDAORepository)5 Transaction (org.hibernate.Transaction)4 DateTime (org.joda.time.DateTime)4 ProcedureEntity (org.n52.series.db.beans.ProcedureEntity)4 HibernateException (org.hibernate.HibernateException)3 DatasetEntity (org.n52.series.db.beans.DatasetEntity)3 ProcedureHistoryEntity (org.n52.series.db.beans.ProcedureHistoryEntity)3 ObservationStream (org.n52.shetland.ogc.om.ObservationStream)3 LinkedList (java.util.LinkedList)2 FormatEntity (org.n52.series.db.beans.FormatEntity)2 PhenomenonEntity (org.n52.series.db.beans.PhenomenonEntity)2 OmObservation (org.n52.shetland.ogc.om.OmObservation)2 NoApplicableCodeException (org.n52.shetland.ogc.ows.exception.NoApplicableCodeException)2 OmObservationCreatorContext (org.n52.sos.ds.hibernate.util.observation.OmObservationCreatorContext)2 SosHelper (org.n52.sos.util.SosHelper)2 ArrayList (java.util.ArrayList)1 Criterion (org.hibernate.criterion.Criterion)1 Before (org.junit.Before)1