/**
  * GetDataAvailability processing is series mapping is supported.
  *
  * @param request GetDataAvailability request
  * @param session Hibernate session
  * @return List of valid data availability information
  * @throws OwsExceptionReport If an error occurs
  */
 private List<?> querySeriesDataAvailabilities(GetDataAvailabilityRequest request, Session session)
     throws OwsExceptionReport {
   List<DataAvailability> dataAvailabilityValues = Lists.newLinkedList();
   Map<String, ReferenceType> procedures = new HashMap<String, ReferenceType>();
   Map<String, ReferenceType> observableProperties = new HashMap<String, ReferenceType>();
   Map<String, ReferenceType> featuresOfInterest = new HashMap<String, ReferenceType>();
   AbstractSeriesObservationDAO seriesObservationDAO = getSeriesObservationDAO();
   SeriesMinMaxTransformer seriesMinMaxTransformer = new SeriesMinMaxTransformer();
   boolean supportsNamedQuery =
       HibernateHelper.isNamedQuerySupported(SQL_QUERY_GET_DATA_AVAILABILITY_FOR_SERIES, session);
   for (final Series series :
       DaoFactory.getInstance()
           .getSeriesDAO()
           .getSeries(
               request.getProcedures(),
               request.getObservedProperties(),
               request.getFeaturesOfInterest(),
               session)) {
     TimePeriod timePeriod = null;
     if (!request.isSetOfferings()) {
       // get time information from series object
       if (series.isSetFirstLastTime()) {
         timePeriod = new TimePeriod(series.getFirstTimeStamp(), series.getLastTimeStamp());
       }
       // get time information from a named query
       else if (timePeriod == null && supportsNamedQuery) {
         timePeriod =
             getTimePeriodFromNamedQuery(series.getSeriesId(), seriesMinMaxTransformer, session);
       }
     }
     // get time information from SeriesGetDataAvailability mapping if
     // supported
     if (timePeriod == null) {
       SeriesObservationTimeDAO seriesObservationTimeDAO =
           (SeriesObservationTimeDAO) DaoFactory.getInstance().getObservationTimeDAO();
       timePeriod =
           getTimePeriodFromSeriesGetDataAvailability(
               seriesObservationTimeDAO, series, request, seriesMinMaxTransformer, session);
     }
     // create DataAvailabilities
     if (timePeriod != null && !timePeriod.isEmpty()) {
       DataAvailability dataAvailability =
           new DataAvailability(
               getProcedureReference(series, procedures),
               getObservedPropertyReference(series, observableProperties),
               getFeatureOfInterestReference(series, featuresOfInterest, session),
               timePeriod);
       if (isShowCount(request)) {
         dataAvailability.setCount(getCountFor(series, request, session));
       }
       if (isIncludeResultTime(request)) {
         dataAvailability.setResultTimes(
             getResultTimesFromSeriesObservation(seriesObservationDAO, series, request, session));
       }
       dataAvailabilityValues.add(dataAvailability);
     }
   }
   return dataAvailabilityValues;
 }
 /**
  * constructor
  *
  * @param request {@link GetObservationRequest}
  * @param series Datasource series id
  * @throws CodedException
  */
 public HibernateSeriesStreamingValue(GetObservationRequest request, long series)
     throws CodedException {
   super(request);
   this.series = series;
   this.seriesValueDAO = (AbstractSeriesValueDAO) DaoFactory.getInstance().getValueDAO();
   this.seriesValueTimeDAO =
       (AbstractSeriesValueTimeDAO) DaoFactory.getInstance().getValueTimeDAO();
 }
 protected AbstractSeriesObservationDAO getSeriesObservationDAO() throws OwsExceptionReport {
   AbstractObservationDAO observationDAO = DaoFactory.getInstance().getObservationDAO();
   if (observationDAO instanceof AbstractSeriesObservationDAO) {
     return (AbstractSeriesObservationDAO) observationDAO;
   } else {
     throw new NoApplicableCodeException()
         .withMessage(
             "The required '%s' implementation is no supported!",
             AbstractObservationDAO.class.getName());
   }
 }
 /**
  * Query observations for observation identifiers
  *
  * @param request GetObservationById request
  * @param session Hibernate session
  * @return Resulting observations
  * @throws CodedException If an error occurs during querying the database
  */
 @SuppressWarnings("unchecked")
 private List<AbstractObservation> queryObservation(
     GetObservationByIdRequest request, Session session) throws CodedException {
   Criteria c =
       DaoFactory.getInstance()
           .getObservationDAO(session)
           .getObservationClassCriteriaForResultModel(request.getResultModel(), session);
   c.add(Restrictions.in(AbstractObservation.IDENTIFIER, request.getObservationIdentifier()));
   LOGGER.debug("QUERY queryObservation(request): {}", HibernateHelper.getSqlString(c));
   return c.list();
 }
 /**
  * Get the next results from database
  *
  * @throws OwsExceptionReport If an error occurs when querying the next results
  */
 private void getNextResults() throws OwsExceptionReport {
   if (session == null) {
     session = sessionHolder.getSession();
   }
   try {
     // query with temporal filter
     Collection<AbstractValue> valuesResult = null;
     if (temporalFilterCriterion != null) {
       valuesResult =
           valueDAO.getStreamingValuesFor(
               request,
               procedure,
               observableProperty,
               featureOfInterest,
               temporalFilterCriterion,
               chunkSize,
               currentRow,
               session);
     }
     // query without temporal or indeterminate filters
     else {
       valuesResult =
           valueDAO.getStreamingValuesFor(
               request,
               procedure,
               observableProperty,
               featureOfInterest,
               chunkSize,
               currentRow,
               session);
     }
     currentRow += chunkSize;
     // get SpatialFilteringProfile values
     AbstractSpatialFilteringProfileDAO<?> spatialFilteringProfileDAO =
         DaoFactory.getInstance().getSpatialFilteringProfileDAO(session);
     if (spatialFilteringProfileDAO != null) {
       setSpatialFilteringProfileAdder(
           new SpatialFilteringProfileAdder(
               spatialFilteringProfileDAO.getSpatialFilertingProfiles(
                   getObservationIds(valuesResult), session)));
     }
     setObservationValuesResult(valuesResult);
   } catch (final HibernateException he) {
     sessionHolder.returnSession(session);
     throw new NoApplicableCodeException()
         .causedBy(he)
         .withMessage("Error while querying observation data!")
         .setStatus(HTTPStatus.INTERNAL_SERVER_ERROR);
   }
 }
  @Override
  public GetObservationByIdResponse getObservationById(GetObservationByIdRequest request)
      throws OwsExceptionReport {
    Session session = null;
    try {
      session = sessionHolder.getSession();
      List<AbstractObservation> observations = queryObservation(request, session);
      GetObservationByIdResponse response = new GetObservationByIdResponse();
      response.setService(request.getService());
      response.setVersion(request.getVersion());
      response.setResponseFormat(request.getResponseFormat());
      Map<Long, AbstractSpatialFilteringProfile> spatialFilteringProfile = Maps.newHashMap();
      AbstractSpatialFilteringProfileDAO<?> spatialFilteringProfileDAO =
          DaoFactory.getInstance().getSpatialFilteringProfileDAO(session);
      if (spatialFilteringProfileDAO != null) {
        spatialFilteringProfile =
            spatialFilteringProfileDAO.getSpatialFilertingProfiles(
                HibernateObservationUtilities.getObservationIds(observations), session);
      }
      response.setObservationCollection(
          HibernateObservationUtilities.createSosObservationsFromObservations(
              observations,
              spatialFilteringProfile,
              request.getVersion(),
              request.getResultModel(),
              session));
      return response;

    } catch (HibernateException he) {
      throw new NoApplicableCodeException()
          .causedBy(he)
          .withMessage("Error while querying observation data!");
    } catch (ConverterException ce) {
      throw new NoApplicableCodeException()
          .causedBy(ce)
          .withMessage("Error while processing observation data!");
    } finally {
      sessionHolder.returnSession(session);
    }
  }