use of org.openforis.idm.model.expression.InvalidExpressionException in project collect by openforis.
the class RecordUpdater method performDefaultValueApply.
/**
* Applies the first default value (if any) that is applicable to the attribute.
* The condition of the corresponding DefaultValue will be verified.
*
* @param attribute
* @return
*/
private <V extends Value> V performDefaultValueApply(Attribute<?, V> attribute) {
AttributeDefinition attributeDefn = (AttributeDefinition) attribute.getDefinition();
List<AttributeDefault> defaults = attributeDefn.getAttributeDefaults();
for (AttributeDefault attributeDefault : defaults) {
try {
if (attributeDefault.evaluateCondition(attribute)) {
V value = attributeDefault.evaluate(attribute);
if (value != null) {
attribute.setValue(value);
setDefaultValueApplied(attribute, true);
attribute.updateSummaryInfo();
return value;
}
}
} catch (InvalidExpressionException e) {
throw new RuntimeException("Error applying default value for attribute " + attributeDefn.getPath());
}
}
return null;
}
Aggregations