Search in sources :

Example 6 with FormatEntity

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);
        }
    }
}
Also used : InvalidParameterValueException(org.n52.shetland.ogc.ows.exception.InvalidParameterValueException) GetObservationByIdRequest(org.n52.shetland.ogc.sos.request.GetObservationByIdRequest) AbstractFeatureEntity(org.n52.series.db.beans.AbstractFeatureEntity) CodedException(org.n52.shetland.ogc.ows.exception.CodedException) LoggerFactory(org.slf4j.LoggerFactory) DescribableEntity(org.n52.series.db.beans.DescribableEntity) Filter(org.n52.shetland.ogc.filter.Filter) ObservationFactory(org.n52.sos.ds.hibernate.dao.observation.ObservationFactory) Query(org.hibernate.query.Query) ResultFilterRestrictions(org.n52.sos.ds.hibernate.util.ResultFilterRestrictions) DataEntity(org.n52.series.db.beans.DataEntity) Collection(java.util.Collection) SubQueryIdentifier(org.n52.sos.ds.hibernate.util.ResultFilterRestrictions.SubQueryIdentifier) Set(java.util.Set) UUID(java.util.UUID) SpatialFilter(org.n52.shetland.ogc.filter.SpatialFilter) Collectors(java.util.stream.Collectors) GetObservationRequest(org.n52.shetland.ogc.sos.request.GetObservationRequest) FormatEntity(org.n52.series.db.beans.FormatEntity) DatasetType(org.n52.series.db.beans.dataset.DatasetType) List(java.util.List) CollectionHelper(org.n52.shetland.util.CollectionHelper) FetchMode(org.hibernate.FetchMode) HibernateHelper(org.n52.sos.ds.hibernate.util.HibernateHelper) Geometry(org.locationtech.jts.geom.Geometry) PlatformEntity(org.n52.series.db.beans.PlatformEntity) FormatDAO(org.n52.sos.ds.hibernate.dao.FormatDAO) Criteria(org.hibernate.Criteria) ProjectionList(org.hibernate.criterion.ProjectionList) DatastreamEntity(org.n52.series.db.beans.sta.DatastreamEntity) Restrictions(org.hibernate.criterion.Restrictions) OmObservationConstellation(org.n52.shetland.ogc.om.OmObservationConstellation) Session(org.hibernate.Session) DatasetEntity(org.n52.series.db.beans.DatasetEntity) HashSet(java.util.HashSet) OfferingEntity(org.n52.series.db.beans.OfferingEntity) GetResultRequest(org.n52.shetland.ogc.sos.request.GetResultRequest) DateTimeHelper(org.n52.shetland.util.DateTimeHelper) Strings(com.google.common.base.Strings) GetDataAvailabilityRequest(org.n52.shetland.ogc.sos.gda.GetDataAvailabilityRequest) ProcedureEntity(org.n52.series.db.beans.ProcedureEntity) LinkedHashSet(java.util.LinkedHashSet) Criterion(org.hibernate.criterion.Criterion) Sos2Constants(org.n52.shetland.ogc.sos.Sos2Constants) Logger(org.slf4j.Logger) CategoryEntity(org.n52.series.db.beans.CategoryEntity) AbstractIdentifierNameDescriptionDAO(org.n52.sos.ds.hibernate.dao.AbstractIdentifierNameDescriptionDAO) ObservationContext(org.n52.sos.ds.hibernate.dao.observation.ObservationContext) Projections(org.hibernate.criterion.Projections) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport) SpatialRestrictions(org.n52.sos.ds.hibernate.util.SpatialRestrictions) AbstractPhenomenon(org.n52.shetland.ogc.om.AbstractPhenomenon) DaoFactory(org.n52.sos.ds.hibernate.dao.DaoFactory) ComparisonFilter(org.n52.shetland.ogc.filter.ComparisonFilter) DetachedCriteria(org.hibernate.criterion.DetachedCriteria) PhenomenonEntity(org.n52.series.db.beans.PhenomenonEntity) ResultFilterClasses(org.n52.sos.ds.hibernate.util.ResultFilterClasses) TimeExtrema(org.n52.sos.ds.hibernate.util.TimeExtrema) QuantityDataEntity(org.n52.series.db.beans.QuantityDataEntity) ValueType(org.n52.series.db.beans.dataset.ValueType) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) Subqueries(org.hibernate.criterion.Subqueries) FormatEntity(org.n52.series.db.beans.FormatEntity) FormatDAO(org.n52.sos.ds.hibernate.dao.FormatDAO) DatasetEntity(org.n52.series.db.beans.DatasetEntity) Criteria(org.hibernate.Criteria) DetachedCriteria(org.hibernate.criterion.DetachedCriteria)

Example 7 with FormatEntity

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);
    }
}
Also used : Transaction(org.hibernate.Transaction) HibernateException(org.hibernate.HibernateException) FormatEntity(org.n52.series.db.beans.FormatEntity) Session(org.hibernate.Session)

Example 8 with FormatEntity

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);
    }
}
Also used : Transaction(org.hibernate.Transaction) HibernateException(org.hibernate.HibernateException) FormatEntity(org.n52.series.db.beans.FormatEntity) Criteria(org.hibernate.Criteria) Session(org.hibernate.Session)

Example 9 with FormatEntity

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));
    }
}
Also used : FormatEntity(org.n52.series.db.beans.FormatEntity)

Example 10 with FormatEntity

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);
    }
}
Also used : FormatEntity(org.n52.series.db.beans.FormatEntity)

Aggregations

FormatEntity (org.n52.series.db.beans.FormatEntity)24 Session (org.hibernate.Session)7 OfferingEntity (org.n52.series.db.beans.OfferingEntity)7 ProcedureEntity (org.n52.series.db.beans.ProcedureEntity)7 Transaction (org.hibernate.Transaction)6 Criteria (org.hibernate.Criteria)5 HibernateException (org.hibernate.HibernateException)5 UnitEntity (org.n52.series.db.beans.UnitEntity)5 DatasetEntity (org.n52.series.db.beans.DatasetEntity)4 NoApplicableCodeException (org.n52.shetland.ogc.ows.exception.NoApplicableCodeException)4 DateTime (org.joda.time.DateTime)3 ParseException (org.locationtech.jts.io.ParseException)3 GeoJsonReader (org.locationtech.jts.io.geojson.GeoJsonReader)3 AbstractFeatureEntity (org.n52.series.db.beans.AbstractFeatureEntity)3 CategoryEntity (org.n52.series.db.beans.CategoryEntity)3 FeatureEntity (org.n52.series.db.beans.FeatureEntity)3 PhenomenonEntity (org.n52.series.db.beans.PhenomenonEntity)3 AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)3 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)3 HashSet (java.util.HashSet)2