use of org.openforis.idm.metamodel.Unit in project collect by openforis.
the class NumberValueUnitValidator method evaluate.
@Override
public ValidationResultFlag evaluate(NumberAttribute<?, ?> attribute) {
Unit unit = attribute.getUnit();
NumberAttributeDefinition defn = attribute.getDefinition();
List<Unit> units = defn.getUnits();
if (units.size() > 1 && unit == null) {
Number number = attribute.getNumber();
if (number != null && number.doubleValue() != 0) {
return ValidationResultFlag.ERROR;
} else {
return ValidationResultFlag.OK;
}
} else {
return ValidationResultFlag.OK;
}
}
use of org.openforis.idm.metamodel.Unit in project collect by openforis.
the class NumericRangeUnitValidator method evaluate.
@Override
public ValidationResultFlag evaluate(NumericRangeAttribute<?, ?> attribute) {
Unit unit = attribute.getUnit();
RangeAttributeDefinition defn = attribute.getDefinition();
List<Unit> units = defn.getUnits();
if (units.size() > 1 && unit == null) {
Number from = attribute.getFrom();
Number to = attribute.getTo();
if (from != null && from.doubleValue() != 0 || to != null && to.doubleValue() != 0) {
return ValidationResultFlag.ERROR;
} else {
return ValidationResultFlag.OK;
}
} else {
return ValidationResultFlag.OK;
}
}
use of org.openforis.idm.metamodel.Unit in project collect by openforis.
the class NumberAttribute method getUnit.
public Unit getUnit() {
Integer unitId = getUnitId();
Unit unit = null;
if (unitId != null) {
unit = getSurvey().getUnit(unitId);
} else {
String unitName = getUnitName();
if (unitName != null) {
unit = getSurvey().getUnit(unitName);
}
}
return unit;
}
use of org.openforis.idm.metamodel.Unit in project collect by openforis.
the class NumericRangeAttribute method setValueInFields.
@Override
protected void setValueInFields(T value) {
N from = value.getFrom();
N to = value.getTo();
Unit unit = value.getUnit();
Integer unitId = unit == null ? null : unit.getId();
getFromField().setValue(from);
getToField().setValue(to);
getUnitField().setValue(unitId);
}
use of org.openforis.idm.metamodel.Unit in project collect by openforis.
the class NumericRangeAttribute method getValue.
@Override
public T getValue() {
N from = getFromField().getValue();
N to = getToField().getValue();
Unit unit = getUnit();
return createRange(from, to, unit);
}
Aggregations