use of org.n52.sos.ds.hibernate.dao.observation.series.SeriesTimeExtrema in project SOS by 52North.
the class DeleteObservationHelper method checkSeriesForFirstLatest.
/**
* Check if {@link Dataset} should be updated
*
* @param serieses
* Deleted observation
* @param session
* Hibernate session
* @throws OwsExceptionReport
* If an error occurs
*/
default void checkSeriesForFirstLatest(Collection<Long> serieses, Session session) throws OwsExceptionReport {
if (!serieses.isEmpty()) {
AbstractSeriesObservationDAO observationDAO = getDaoFactory().getObservationDAO();
Map<Long, SeriesTimeExtrema> minMaxTimes = observationDAO.getMinMaxSeriesTimesById(serieses instanceof Set ? (Set<Long>) serieses : new LinkedHashSet<>(serieses), session);
for (Long id : serieses) {
DatasetEntity series = session.get(DatasetEntity.class, id);
boolean update = false;
if (minMaxTimes.containsKey(series.getId())) {
SeriesTimeExtrema extrema = minMaxTimes.get(series.getId());
if (!series.isSetFirstValueAt() || series.isSetFirstValueAt() && !DateTimeHelper.makeDateTime(series.getFirstValueAt()).equals(extrema.getMinPhenomenonTime())) {
series.setFirstValueAt(extrema.getMinPhenomenonTime().toDate());
DataEntity<?> o = unproxy(observationDAO.getMinObservation(series, extrema.getMinPhenomenonTime(), session), session);
series.setFirstObservation(o);
if (series.getValueType().equals(ValueType.quantity)) {
series.setFirstQuantityValue(((QuantityDataEntity) o).getValue());
}
update = true;
}
if (!series.isSetLastValueAt() || series.isSetLastValueAt() && !DateTimeHelper.makeDateTime(series.getLastValueAt()).equals(extrema.getMaxPhenomenonTime())) {
series.setLastValueAt(extrema.getMaxPhenomenonTime().toDate());
DataEntity<?> o = unproxy(observationDAO.getMaxObservation(series, extrema.getMaxPhenomenonTime(), session), session);
series.setLastObservation(o);
if (series.getValueType().equals(ValueType.quantity)) {
series.setLastQuantityValue(((QuantityDataEntity) o).getValue());
}
update = true;
}
} else {
series.setFirstValueAt(null);
series.setFirstQuantityValue(null);
series.setFirstObservation(null);
series.setLastValueAt(null);
series.setLastQuantityValue(null);
series.setLastObservation(null);
update = true;
}
if (update) {
session.saveOrUpdate(series);
session.flush();
}
}
}
}
Aggregations