use of org.n52.sos.ds.hibernate.dao.observation.series.AbstractSeriesObservationDAO 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();
}
}
}
}
use of org.n52.sos.ds.hibernate.dao.observation.series.AbstractSeriesObservationDAO in project SOS by 52North.
the class SeriesOmObservationCreator method getObservationConstellation.
/**
* Get {@link OmObservationConstellation} from series information
*
* @param procedure
* Procedure object
* @param obsProp
* ObservableProperty object
* @param feature
* FeatureOfInterest object
* @return Observation constellation
* @throws OwsExceptionReport If an error occurs
*/
protected OmObservationConstellation getObservationConstellation(SosProcedureDescription<?> procedure, OmObservableProperty obsProp, AbstractFeature feature) throws OwsExceptionReport {
OmObservationConstellation obsConst = new OmObservationConstellation(procedure, obsProp, null, feature, null);
/* get the offerings to find the templates */
if (obsConst.getOfferings() == null) {
if (getSeries().isSetOffering()) {
obsConst.setOfferings(Sets.newHashSet(getSeries().getOffering().getIdentifier()));
} else {
AbstractSeriesObservationDAO observationDAO = (AbstractSeriesObservationDAO) getDaoFactory().getObservationDAO();
obsConst.setOfferings(observationDAO.getOfferingsForSeries(dataset, getSession()));
// } else {
// obsConst.setOfferings(Sets.newHashSet(getCache().getOfferingsForProcedure(
// obsConst.getProcedure().getIdentifier())));
}
}
if (!Strings.isNullOrEmpty(getResultModel())) {
obsConst.setObservationType(getResultModel());
}
if (getSeries().isSetIdentifier()) {
addIdentifier(obsConst, getSeries());
}
if (getRequest().isSetRequestedLanguage()) {
addNameAndDescription(getSeries(), obsConst, getRequestedLanguage(), getI18N(), false);
if (obsConst.isSetName()) {
obsConst.setHumanReadableIdentifier(obsConst.getFirstName().getValue());
}
} else {
if (getSeries().isSetName()) {
addName(obsConst, getSeries());
}
if (getSeries().isSetDescription()) {
obsConst.setDescription(getSeries().getDescription());
}
}
return obsConst;
}
Aggregations