Search in sources :

Example 1 with UnitEntity

use of org.n52.series.db.beans.UnitEntity in project SOS by 52North.

the class HibernatePredefinedInsertionHandler method convert.

private UnitEntity convert(Unit unit) {
    UnitEntity entity = new UnitEntity();
    entity.setSymbol(unit.getSymbol(), getDaoFactory().isStaSupportsUrls());
    entity.setName(unit.getName());
    entity.setLink(unit.getLink());
    if (unit.hasTranslations()) {
        Set<I18nEntity<? extends Describable>> trans = new LinkedHashSet<>();
        unit.getTranslations().forEach(i -> {
            I18nUnitEntity i18n = new I18nUnitEntity();
            i18n.setLocale(i.getLocale());
            i18n.setName(i.getName());
            i18n.setDescription(i.getDescription());
            trans.add(i18n);
        });
        entity.setTranslations(trans);
    }
    return entity;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Describable(org.n52.series.db.beans.Describable) I18nUnitEntity(org.n52.series.db.beans.i18n.I18nUnitEntity) I18nUnitEntity(org.n52.series.db.beans.i18n.I18nUnitEntity) UnitEntity(org.n52.series.db.beans.UnitEntity) I18nEntity(org.n52.series.db.beans.i18n.I18nEntity)

Example 2 with UnitEntity

use of org.n52.series.db.beans.UnitEntity in project SOS by 52North.

the class UnitDAO method getOrInsertUnit.

/**
 * Insert and get unit object
 *
 * @param unit
 *            Unit
 * @param session
 *            Hibernate session
 * @return Unit object
 */
public UnitEntity getOrInsertUnit(UoM unit, Session session) {
    UnitEntity result = getUnit(unit.getUom(), session);
    if (result == null) {
        result = new UnitEntity();
        result.setUnit(unit.getUom());
        if (unit.isSetName()) {
            result.setName(unit.getName());
        }
        if (unit.isSetLink()) {
            result.setLink(unit.getLink());
        }
        session.save(result);
        session.flush();
        session.refresh(result);
    }
    return result;
}
Also used : I18nUnitEntity(org.n52.series.db.beans.i18n.I18nUnitEntity) UnitEntity(org.n52.series.db.beans.UnitEntity)

Example 3 with UnitEntity

use of org.n52.series.db.beans.UnitEntity in project SOS by 52North.

the class UnitDAO method getUnit.

/**
 * Get unit object for unit
 *
 * @param unit
 *            Unit
 * @param session
 *            Hibernate session
 * @return Unit object
 */
public UnitEntity getUnit(String unit, Session session) {
    Criteria criteria = session.createCriteria(UnitEntity.class).add(Restrictions.eq(UnitEntity.PROPERTY_UNIT, unit));
    LOGGER.trace(QUERY_UNIT_TEMPLATE, HibernateHelper.getSqlString(criteria));
    return (UnitEntity) criteria.uniqueResult();
}
Also used : Criteria(org.hibernate.Criteria) I18nUnitEntity(org.n52.series.db.beans.i18n.I18nUnitEntity) UnitEntity(org.n52.series.db.beans.UnitEntity)

Example 4 with UnitEntity

use of org.n52.series.db.beans.UnitEntity in project SOS by 52North.

the class UnitDAO method getUnit.

/**
 * Get unit object for unit
 *
 * @param unit
 *            Unit
 * @param session
 *            Hibernate session
 * @return Unit object
 */
public UnitEntity getUnit(UoM unit, Session session) {
    Criteria criteria = session.createCriteria(UnitEntity.class).add(Restrictions.eq(UnitEntity.PROPERTY_UNIT, unit.getUom()));
    LOGGER.trace(QUERY_UNIT_TEMPLATE, HibernateHelper.getSqlString(criteria));
    return (UnitEntity) criteria.uniqueResult();
}
Also used : Criteria(org.hibernate.Criteria) I18nUnitEntity(org.n52.series.db.beans.i18n.I18nUnitEntity) UnitEntity(org.n52.series.db.beans.UnitEntity)

Example 5 with UnitEntity

use of org.n52.series.db.beans.UnitEntity in project SOS by 52North.

the class ParameterVisitor method addUnit.

protected void addUnit(ParameterEntity<?> vp, Value<?> v) {
    if (!v.isSetUnit() && vp instanceof HasUnit && ((HasUnit) vp).isSetUnit()) {
        UnitEntity unit = ((HasUnit) vp).getUnit();
        UoM uom = new UoM(unit.getUnit());
        if (unit.isSetName()) {
            uom.setName(unit.getName());
        }
        if (unit.isSetLink()) {
            uom.setLink(unit.getLink());
        }
        v.setUnit(uom);
    }
}
Also used : UoM(org.n52.shetland.ogc.UoM) UnitEntity(org.n52.series.db.beans.UnitEntity) HasUnit(org.n52.series.db.beans.HibernateRelations.HasUnit)

Aggregations

UnitEntity (org.n52.series.db.beans.UnitEntity)13 FormatEntity (org.n52.series.db.beans.FormatEntity)5 I18nUnitEntity (org.n52.series.db.beans.i18n.I18nUnitEntity)5 UoM (org.n52.shetland.ogc.UoM)5 QuantityValue (org.n52.shetland.ogc.om.values.QuantityValue)4 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)3 NoApplicableCodeException (org.n52.shetland.ogc.ows.exception.NoApplicableCodeException)3 BigDecimal (java.math.BigDecimal)2 Criteria (org.hibernate.Criteria)2 HibernateException (org.hibernate.HibernateException)2 Session (org.hibernate.Session)2 Transaction (org.hibernate.Transaction)2 DateTime (org.joda.time.DateTime)2 ParseException (org.locationtech.jts.io.ParseException)2 GeoJsonReader (org.locationtech.jts.io.geojson.GeoJsonReader)2 CodespaceEntity (org.n52.series.db.beans.CodespaceEntity)2 DatasetEntity (org.n52.series.db.beans.DatasetEntity)2 OfferingEntity (org.n52.series.db.beans.OfferingEntity)2 ProcedureEntity (org.n52.series.db.beans.ProcedureEntity)2 AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)2