Search in sources :

Example 1 with NumericRangeAttribute

use of org.openforis.idm.model.NumericRangeAttribute in project collect by openforis.

the class CollectValidator method isReasonBlankAlwaysSpecified.

static boolean isReasonBlankAlwaysSpecified(Attribute<?, ?> attribute) {
    int fieldCount = 0;
    // ignore unit for numeric attributes
    if (attribute instanceof NumberAttribute || attribute instanceof CodeAttribute) {
        fieldCount = 1;
    } else if (attribute instanceof NumericRangeAttribute) {
        fieldCount = 2;
    } else {
        fieldCount = attribute.getFieldCount();
    }
    AttributeDefinition defn = attribute.getDefinition();
    CollectSurvey survey = (CollectSurvey) defn.getSurvey();
    UIOptions uiOptions = survey.getUIOptions();
    for (int i = 0; i < fieldCount; i++) {
        Field<?> field = attribute.getField(i);
        boolean visible = uiOptions.isVisibleField(defn, field.getName());
        if (visible) {
            FieldSymbol symbol = FieldSymbol.valueOf(field.getSymbol());
            if (symbol == null || !symbol.isReasonBlank()) {
                return false;
            }
        }
    }
    return true;
}
Also used : CodeAttribute(org.openforis.idm.model.CodeAttribute) FieldSymbol(org.openforis.collect.model.FieldSymbol) NumericRangeAttribute(org.openforis.idm.model.NumericRangeAttribute) UIOptions(org.openforis.collect.metamodel.ui.UIOptions) NumberAttribute(org.openforis.idm.model.NumberAttribute) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 2 with NumericRangeAttribute

use of org.openforis.idm.model.NumericRangeAttribute in project collect by openforis.

the class RecordConverter method convertToLatestUnitStorage.

/**
 * This is a workaround: it avoids to refer to the old unit field to get data
 *
 * TODO remove this conversion or apply only for records stored using version prior to 3.0 Alpha 5
 *
 * @param survey
 * @param rootEntity
 */
protected void convertToLatestUnitStorage(CollectRecord record) {
    final CollectSurvey survey = (CollectSurvey) record.getSurvey();
    Entity rootEntity = record.getRootEntity();
    rootEntity.traverse(new NodeVisitor() {

        @Override
        public void visit(Node<? extends NodeDefinition> node, int idx) {
            if (node instanceof NumberAttribute<?, ?> || node instanceof NumericRangeAttribute<?, ?>) {
                Field<String> unitNameField;
                Field<Integer> unitField;
                if (node instanceof NumberAttribute<?, ?>) {
                    unitNameField = ((NumberAttribute<?, ?>) node).getUnitNameField();
                    unitField = ((NumberAttribute<?, ?>) node).getUnitField();
                } else {
                    unitNameField = ((NumericRangeAttribute<?, ?>) node).getUnitNameField();
                    unitField = ((NumericRangeAttribute<?, ?>) node).getUnitField();
                }
                if (unitNameField.hasData()) {
                    moveDataToNewUnitField(survey, unitNameField, unitField);
                }
            }
        }
    });
}
Also used : Entity(org.openforis.idm.model.Entity) Field(org.openforis.idm.model.Field) NumericRangeAttribute(org.openforis.idm.model.NumericRangeAttribute) NumberAttribute(org.openforis.idm.model.NumberAttribute) CollectSurvey(org.openforis.collect.model.CollectSurvey) NodeVisitor(org.openforis.idm.model.NodeVisitor)

Aggregations

CollectSurvey (org.openforis.collect.model.CollectSurvey)2 NumberAttribute (org.openforis.idm.model.NumberAttribute)2 NumericRangeAttribute (org.openforis.idm.model.NumericRangeAttribute)2 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)1 FieldSymbol (org.openforis.collect.model.FieldSymbol)1 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)1 CodeAttribute (org.openforis.idm.model.CodeAttribute)1 Entity (org.openforis.idm.model.Entity)1 Field (org.openforis.idm.model.Field)1 NodeVisitor (org.openforis.idm.model.NodeVisitor)1