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