use of org.n52.series.db.beans.FormatEntity in project SOS by 52North.
the class AbstractSeriesDAO method updateSeries.
private void updateSeries(DatasetEntity dataset, String observationType, Session session) {
FormatEntity obsType = new FormatDAO().getFormatEntityObject(observationType, session);
dataset.setOmObservationType(obsType);
session.saveOrUpdate(dataset);
// update hidden child observation constellations
// TODO should hidden child observation constellations be restricted to
// the parent observation type?
Set<String> offerings = dataset.getOffering().getChildren().stream().map(o -> o.getIdentifier()).collect(Collectors.toSet());
if (CollectionHelper.isNotEmpty(offerings)) {
Criteria c = session.createCriteria(getSeriesClass()).setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).add(Restrictions.eq(DatasetEntity.PROPERTY_PHENOMENON, dataset.getObservableProperty())).add(Restrictions.eq(DatasetEntity.PROPERTY_PROCEDURE, dataset.getProcedure())).add(Restrictions.eq(DatasetEntity.HIDDEN_CHILD, true));
c.createCriteria(DatasetEntity.PROPERTY_OFFERING).add(Restrictions.in(OfferingEntity.IDENTIFIER, offerings));
LOGGER.trace("QUERY updateSeries(observationConstellation, observationType): {}", HibernateHelper.getSqlString(c));
List<DatasetEntity> hiddenChildObsConsts = c.list();
for (DatasetEntity hiddenChildObsConst : hiddenChildObsConsts) {
hiddenChildObsConst.setOmObservationType(obsType);
session.saveOrUpdate(hiddenChildObsConst);
}
}
}
use of org.n52.series.db.beans.FormatEntity in project SOS by 52North.
the class H2Database method addObservationTypes.
/**
* Add some default entries of entity {@link ObservationType} to the test
* database.
*
* @throws OwsExceptionReport
* @see {@link #defaultObservationTypes}
*/
protected void addObservationTypes() throws OwsExceptionReport {
Session session = null;
Transaction transaction = null;
try {
session = getSession();
transaction = session.beginTransaction();
for (int i = 0; i < defaultObservationTypes.length; i++) {
final FormatEntity ot = new FormatEntity();
ot.setId((long) i);
ot.setFormat(defaultObservationTypes[i]);
session.save(ot);
}
session.flush();
transaction.commit();
} catch (final HibernateException he) {
if (transaction != null) {
transaction.rollback();
}
throw he;
} finally {
returnSession(session);
}
}
use of org.n52.series.db.beans.FormatEntity in project SOS by 52North.
the class H2Database method removeObservationTypes.
/**
* Removes all entries of entity {@link ObservationType} from the database.
*
* @throws OwsExceptionReport
*/
protected void removeObservationTypes() throws OwsExceptionReport {
Session session = null;
Transaction transaction = null;
try {
session = getSession();
transaction = session.beginTransaction();
Criteria criteria = session.createCriteria(FormatEntity.class);
try (ScrollableIterable<FormatEntity> i = ScrollableIterable.fromCriteria(criteria)) {
for (final FormatEntity o : i) {
session.delete(o);
}
}
session.flush();
transaction.commit();
} catch (final HibernateException he) {
if (transaction != null) {
transaction.rollback();
}
throw he;
} finally {
returnSession(session);
}
}
use of org.n52.series.db.beans.FormatEntity in project sensorweb-server-sta by 52North.
the class SensorService method checkFormat.
private void checkFormat(ProcedureEntity sensor) throws STACRUDException {
FormatEntity format;
synchronized (getLock(sensor.getFormat().getFormat())) {
if (!formatRepository.existsByFormat(sensor.getFormat().getFormat())) {
format = formatRepository.save(sensor.getFormat());
} else {
format = formatRepository.findByFormat(sensor.getFormat().getFormat());
}
}
sensor.setFormat(format);
if (sensor.hasProcedureHistory()) {
sensor.getProcedureHistory().forEach(pf -> pf.setFormat(format));
}
}
use of org.n52.series.db.beans.FormatEntity in project sensorweb-server-sta by 52North.
the class LocationService method checkLocationEncoding.
private void checkLocationEncoding(LocationEntity location) throws STACRUDException {
if (location.getLocationEncoding() != null) {
FormatEntity optionalLocationEncoding = createLocationEncoding(location.getLocationEncoding());
location.setLocationEncoding(optionalLocationEncoding);
}
}
Aggregations