Search in sources :

Example 1 with FeatureTypeProperty

use of de.symeda.sormas.api.feature.FeatureTypeProperty in project SORMAS-Project by hzi-braunschweig.

the class FeatureConfigurationFacadeEjb method isPropertyValueTrue.

@Override
public boolean isPropertyValueTrue(FeatureType featureType, FeatureTypeProperty property) {
    if (!featureType.getSupportedProperties().contains(property)) {
        throw new IllegalArgumentException("Feature type " + featureType + " does not support property " + property + ".");
    }
    if (!Boolean.class.isAssignableFrom(property.getReturnType())) {
        throw new IllegalArgumentException("Feature type property " + property + " does not have specified return type " + Boolean.class.getSimpleName() + ".");
    }
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Object> cq = cb.createQuery(Object.class);
    Root<FeatureConfiguration> root = cq.from(FeatureConfiguration.class);
    cq.where(cb.and(cb.equal(root.get(FeatureConfiguration.FEATURE_TYPE), featureType)));
    cq.select(root.get(FeatureConfiguration.PROPERTIES));
    Map<FeatureTypeProperty, Object> properties = null;
    try {
        properties = (Map<FeatureTypeProperty, Object>) em.createQuery(cq).getSingleResult();
    } catch (NoResultException e) {
    // NOOP
    }
    boolean result;
    if (properties != null && properties.containsKey(property)) {
        result = (boolean) properties.get(property);
    } else {
        // Compare the expected property value with the default value
        result = (boolean) featureType.getSupportedPropertyDefaults().get(property);
    }
    return result;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) FeatureTypeProperty(de.symeda.sormas.api.feature.FeatureTypeProperty) NoResultException(javax.persistence.NoResultException)

Example 2 with FeatureTypeProperty

use of de.symeda.sormas.api.feature.FeatureTypeProperty in project SORMAS-Project by hzi-braunschweig.

the class FeatureConfigurationDao method isPropertyValueTrue.

public boolean isPropertyValueTrue(FeatureType featureType, FeatureTypeProperty property) {
    if (!featureType.getSupportedProperties().contains(property)) {
        throw new IllegalArgumentException("Feature type " + featureType + " does not support property " + property + ".");
    }
    if (!Boolean.class.isAssignableFrom(property.getReturnType())) {
        throw new IllegalArgumentException("Feature type property " + property + " does not have specified return type " + Boolean.class.getSimpleName() + ".");
    }
    Map<FeatureTypeProperty, Object> propertyObjectMap;
    try {
        QueryBuilder builder = queryBuilder();
        Where where = builder.where();
        where.eq(FeatureConfiguration.FEATURE_TYPE, featureType);
        builder.selectColumns(FeatureConfiguration.PROPERTIES);
        FeatureConfiguration featureConfiguration = (FeatureConfiguration) builder.queryForFirst();
        if (featureConfiguration != null && featureConfiguration.getPropertiesJson() != null) {
            propertyObjectMap = featureConfiguration.getPropertiesMap();
        } else {
            return featureType.getSupportedPropertyDefaults().get(property) == Boolean.TRUE;
        }
    } catch (SQLException e) {
        Log.e(getTableName(), "Could not perform isPropertyValueTrue");
        throw new RuntimeException(e);
    }
    boolean result;
    if (propertyObjectMap != null && propertyObjectMap.containsKey(property)) {
        result = propertyObjectMap.get(property) == Boolean.TRUE;
    } else {
        // Compare the expected property value with the default value
        result = featureType.getSupportedPropertyDefaults().get(property) == Boolean.TRUE;
    }
    return result;
}
Also used : SQLException(java.sql.SQLException) FeatureTypeProperty(de.symeda.sormas.api.feature.FeatureTypeProperty) QueryBuilder(com.j256.ormlite.stmt.QueryBuilder) Where(com.j256.ormlite.stmt.Where)

Aggregations

FeatureTypeProperty (de.symeda.sormas.api.feature.FeatureTypeProperty)2 QueryBuilder (com.j256.ormlite.stmt.QueryBuilder)1 Where (com.j256.ormlite.stmt.Where)1 SQLException (java.sql.SQLException)1 NoResultException (javax.persistence.NoResultException)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1