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;
}
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;
}
Aggregations