use of org.n52.series.db.beans.DatasetEntity in project SOS by 52North.
the class DeleteObservationHelper method checkForFirstLastReference.
default void checkForFirstLastReference(DataEntity<?> observation, Session session) {
DatasetEntity dataset = observation.getDataset();
if (dataset.getFirstObservation() != null && dataset.getFirstObservation().getId() != null && observation.getId() != null && dataset.getFirstObservation().getId().equals(observation.getId())) {
dataset.setFirstObservation(null);
}
if (dataset.getLastObservation() != null && dataset.getLastObservation().getId() != null && observation.getId() != null && dataset.getLastObservation().getId().equals(observation.getId())) {
dataset.setLastObservation(null);
}
session.update(dataset);
session.flush();
}
use of org.n52.series.db.beans.DatasetEntity 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.series.db.beans.DatasetEntity in project SOS by 52North.
the class DeleteDataHelper method getDatasetForOffering.
default List<DatasetEntity> getDatasetForOffering(OfferingEntity offering, Session session) {
AbstractSeriesDAO seriesDAO = getDaoFactory().getSeriesDAO();
Criteria c = seriesDAO.getDefaultAllSeriesCriteria(session);
seriesDAO.addOfferingToCriteria(c, offering);
return c.list();
}
use of org.n52.series.db.beans.DatasetEntity in project SOS by 52North.
the class InsertObservationHandler method insertObservation.
private void insertObservation(OmObservation sosObservation, InsertObservationCache cache, CompositeOwsException exceptions, Session session) throws OwsExceptionReport, CodedException {
checkSpatialFilteringProfile(sosObservation);
OmObservationConstellation sosObsConst = sosObservation.getObservationConstellation();
cache.addOfferings(sosObsConst.getOfferings());
AbstractFeatureEntity hFeature = null;
// if (sosObsConst.getOfferings().size() > 1) {
//
// }
String offeringID = sosObsConst.getOfferings().iterator().next();
DatasetEntity hDataset = cache.get(sosObsConst, offeringID);
if (hDataset == null) {
if (!cache.isChecked(sosObsConst, offeringID)) {
try {
hDataset = getDaoFactory().getSeriesDAO().checkSeries(sosObsConst, offeringID, session, Sos2Constants.InsertObservationParams.observationType.name());
// add to cache table
cache.putConstellation(sosObsConst, offeringID, hDataset);
} catch (OwsExceptionReport owse) {
exceptions.add(owse);
}
// mark as checked
cache.checkConstellation(sosObsConst, offeringID);
}
}
if (hDataset != null) {
// getFeature feature from local cache or create if necessary
hFeature = getFeature(sosObsConst.getFeatureOfInterest(), cache, session);
// AbstractFeature/offering combo
if (!cache.isChecked(sosObsConst.getFeatureOfInterest(), offeringID)) {
getDaoFactory().getFeatureOfInterestDAO().checkOrInsertRelatedFeatureRelation(hFeature, hDataset.getOffering(), session);
cache.checkFeature(sosObsConst.getFeatureOfInterest(), offeringID);
}
AbstractObservationDAO observationDAO = getDaoFactory().getObservationDAO();
DatasetEntity dataset = null;
if (sosObservation.getValue() instanceof SingleObservationValue) {
dataset = observationDAO.insertObservationSingleValue(hDataset, hFeature, sosObservation, cache.getCodespaceCache(), cache.getUnitCache(), cache.getFormatCache(), session);
} else if (sosObservation.getValue() instanceof MultiObservationValues) {
dataset = observationDAO.insertObservationMultiValue(hDataset, hFeature, sosObservation, cache.getCodespaceCache(), cache.getUnitCache(), cache.getFormatCache(), session);
}
if (dataset != null && !cache.get(sosObsConst, offeringID).equals(dataset)) {
cache.putConstellation(sosObsConst, offeringID, dataset);
}
}
}
use of org.n52.series.db.beans.DatasetEntity in project SOS by 52North.
the class InsertResultHandler method insertObservationConstellationForProfiles.
private DatasetEntity insertObservationConstellationForProfiles(AbstractSeriesDAO obsConstDao, FormatDAO obsTypeDao, OmObservation o, Session session) throws OwsExceptionReport {
ProcedureEntity procedure = getDaoFactory().getProcedureDAO().getProcedureForIdentifier(o.getObservationConstellation().getProcedureIdentifier(), session);
PhenomenonEntity observableProperty = getDaoFactory().getObservablePropertyDAO().getOrInsertObservableProperty(o.getObservationConstellation().getObservableProperty(), session);
OfferingEntity offering = getDaoFactory().getOfferingDAO().getOfferingForIdentifier(o.getObservationConstellation().getOfferings().iterator().next(), session);
CategoryEntity category = getDaoFactory().getCategoryDAO().getOrInsertCategory(observableProperty, session);
DatasetEntity oc = obsConstDao.checkOrInsertSeries(procedure, observableProperty, offering, category, false, session);
if (o.getObservationConstellation().isSetObservationType()) {
oc.setOmObservationType(obsTypeDao.getFormatEntityObject(o.getObservationConstellation().getObservationType(), session));
}
return oc;
}
Aggregations