use of org.openforis.idm.metamodel.AttributeDefault in project collect by openforis.
the class DefaultValueTest method testNotNullValues.
@Test
public void testNotNullValues() throws InvalidExpressionException {
NumericAttributeDefinition totalDefn = (NumericAttributeDefinition) schema.getDefinitionByPath("bill/item/total");
Entity rootEntity = record.getRootEntity();
Entity item = addItem(rootEntity, 10, 5.5d);
RealAttribute total = (RealAttribute) item.getChild("total", 0);
List<AttributeDefault> attributeDefaults = totalDefn.getAttributeDefaults();
AttributeDefault exprAttributeDefault = attributeDefaults.get(0);
RealValue calculatedTotal = exprAttributeDefault.evaluate(total);
assertEquals(new RealValue(55d, null), calculatedTotal);
}
use of org.openforis.idm.metamodel.AttributeDefault in project collect by openforis.
the class AttributeDefinitionFormObject method loadFrom.
@Override
public void loadFrom(T source, String languageCode) {
super.loadFrom(source, languageCode);
key = source.isKey();
attributeDefaults = new ArrayList<AttributeDefault>(source.getAttributeDefaults());
CollectSurvey survey = (CollectSurvey) source.getSurvey();
CollectAnnotations annotations = survey.getAnnotations();
phaseToApplyDefaultValue = annotations.getPhaseToApplyDefaultValue(source).name();
editable = annotations.isEditable(source);
measurement = annotations.isMeasurementAttribute(source);
showInMapBalloon = annotations.isShowInMapBalloon(source);
checks = new ArrayList<Check<?>>(source.getChecks());
UIOptions uiOptions = getUIOptions(source);
visibleFields = uiOptions.getVisibleFields(source);
if (source.getReferencedAttribute() != null) {
referencedAttributePath = source.getReferencedAttribute().getPath();
}
}
use of org.openforis.idm.metamodel.AttributeDefault in project collect by openforis.
the class AttributeDefinitionFormObject method saveTo.
@Override
public void saveTo(T dest, String languageCode) {
super.saveTo(dest, languageCode);
dest.setKey(key);
// save attribute defaults
dest.removeAllAttributeDefaults();
if (attributeDefaults != null) {
for (AttributeDefault attrDefault : attributeDefaults) {
dest.addAttributeDefault(attrDefault);
}
}
dest.setReferencedAttribute(referencedAttributePath == null ? null : (AttributeDefinition) dest.getSchema().getDefinitionByPath(referencedAttributePath));
CollectSurvey survey = (CollectSurvey) dest.getSurvey();
CollectAnnotations annotations = survey.getAnnotations();
annotations.setPhaseToApplyDefaultValue(dest, Step.valueOf(phaseToApplyDefaultValue));
annotations.setEditable(dest, editable);
annotations.setMeasurementAttribute(dest, measurement);
annotations.setShowInMapBalloon(dest, showInMapBalloon);
// save checks
dest.removeAllChecks();
if (checks != null) {
for (Check<?> check : checks) {
dest.addCheck(check);
}
}
UIOptions uiOptions = getUIOptions(dest);
uiOptions.setVisibleFields(dest, visibleFields);
}
use of org.openforis.idm.metamodel.AttributeDefault in project collect by openforis.
the class StateDependencyMap method registerDependencies.
private void registerDependencies(AttributeDefinition attributeDefinition) {
List<AttributeDefault> attributeDefaults = attributeDefinition.getAttributeDefaults();
for (AttributeDefault attributeDefault : attributeDefaults) {
registerDependencies(attributeDefinition, attributeDefault.getCondition(), defaultValueDependencies);
registerDependencies(attributeDefinition, attributeDefault.getExpression(), defaultValueDependencies);
}
List<Check> checks = attributeDefinition.getChecks();
for (Check check : checks) {
registerDependencies(attributeDefinition, check.getCondition(), checkDependencies);
if (check instanceof ComparisonCheck) {
registerDependencies(attributeDefinition, ((ComparisonCheck) check).getEqualsExpression(), checkDependencies);
registerDependencies(attributeDefinition, ((ComparisonCheck) check).getLessThanExpression(), checkDependencies);
registerDependencies(attributeDefinition, ((ComparisonCheck) check).getLessThanOrEqualsExpression(), checkDependencies);
registerDependencies(attributeDefinition, ((ComparisonCheck) check).getGreaterThanExpression(), checkDependencies);
registerDependencies(attributeDefinition, ((ComparisonCheck) check).getGreaterThanOrEqualsExpression(), checkDependencies);
} else if (check instanceof CustomCheck) {
registerDependencies(attributeDefinition, ((CustomCheck) check).getExpression(), checkDependencies);
} else if (check instanceof DistanceCheck) {
registerDependencies(attributeDefinition, ((DistanceCheck) check).getDestinationPointExpression(), checkDependencies);
registerDependencies(attributeDefinition, ((DistanceCheck) check).getMaxDistanceExpression(), checkDependencies);
registerDependencies(attributeDefinition, ((DistanceCheck) check).getMinDistanceExpression(), checkDependencies);
registerDependencies(attributeDefinition, ((DistanceCheck) check).getSourcePointExpression(), checkDependencies);
} else if (check instanceof UniquenessCheck) {
registerDependencies(attributeDefinition, ((UniquenessCheck) check).getExpression(), checkDependencies);
}
}
}
use of org.openforis.idm.metamodel.AttributeDefault in project collect by openforis.
the class AttributeVM method addAttributeDefault.
@Command
@NotifyChange("attributeDefaults")
public void addAttributeDefault() {
if (checkCanInsertAttributeDefault()) {
editingNewAttributeDefault = true;
editedAttributeDefault = new AttributeDefault();
openAttributeDefaultEditPopUp();
}
}
Aggregations