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;
}
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);
}
}
Aggregations