Search in sources :

Example 6 with AttributeDefault

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);
}
Also used : AttributeDefault(org.openforis.idm.metamodel.AttributeDefault) NumericAttributeDefinition(org.openforis.idm.metamodel.NumericAttributeDefinition) Test(org.junit.Test)

Example 7 with AttributeDefault

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();
    }
}
Also used : UIOptions(org.openforis.collect.metamodel.ui.UIOptions) AttributeDefault(org.openforis.idm.metamodel.AttributeDefault) Check(org.openforis.idm.metamodel.validation.Check) CollectAnnotations(org.openforis.collect.metamodel.CollectAnnotations) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 8 with AttributeDefault

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);
}
Also used : UIOptions(org.openforis.collect.metamodel.ui.UIOptions) AttributeDefault(org.openforis.idm.metamodel.AttributeDefault) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CollectAnnotations(org.openforis.collect.metamodel.CollectAnnotations) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 9 with AttributeDefault

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);
        }
    }
}
Also used : CustomCheck(org.openforis.idm.metamodel.validation.CustomCheck) DistanceCheck(org.openforis.idm.metamodel.validation.DistanceCheck) UniquenessCheck(org.openforis.idm.metamodel.validation.UniquenessCheck) AttributeDefault(org.openforis.idm.metamodel.AttributeDefault) CustomCheck(org.openforis.idm.metamodel.validation.CustomCheck) UniquenessCheck(org.openforis.idm.metamodel.validation.UniquenessCheck) Check(org.openforis.idm.metamodel.validation.Check) DistanceCheck(org.openforis.idm.metamodel.validation.DistanceCheck) ComparisonCheck(org.openforis.idm.metamodel.validation.ComparisonCheck) ComparisonCheck(org.openforis.idm.metamodel.validation.ComparisonCheck)

Example 10 with AttributeDefault

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();
    }
}
Also used : AttributeDefault(org.openforis.idm.metamodel.AttributeDefault) NotifyChange(org.zkoss.bind.annotation.NotifyChange) GlobalCommand(org.zkoss.bind.annotation.GlobalCommand) Command(org.zkoss.bind.annotation.Command)

Aggregations

AttributeDefault (org.openforis.idm.metamodel.AttributeDefault)14 Test (org.junit.Test)4 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)4 NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)4 Schema (org.openforis.idm.metamodel.Schema)3 CollectAnnotations (org.openforis.collect.metamodel.CollectAnnotations)2 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)2 CollectSurvey (org.openforis.collect.model.CollectSurvey)2 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)2 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)2 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)2 NumberAttributeDefinition (org.openforis.idm.metamodel.NumberAttributeDefinition)2 Survey (org.openforis.idm.metamodel.Survey)2 SurveyContext (org.openforis.idm.metamodel.SurveyContext)2 Check (org.openforis.idm.metamodel.validation.Check)2 CustomCheck (org.openforis.idm.metamodel.validation.CustomCheck)2 InvalidExpressionException (org.openforis.idm.model.expression.InvalidExpressionException)2 ArrayList (java.util.ArrayList)1 TimeAttributeDefinition (org.openforis.idm.metamodel.TimeAttributeDefinition)1 ComparisonCheck (org.openforis.idm.metamodel.validation.ComparisonCheck)1