use of org.openforis.idm.metamodel.Unit in project collect by openforis.
the class ComparisonCheckTest method testLteWithNormalizedValuesFailOnLt.
@Test
public void testLteWithNormalizedValuesFailOnLt() {
RealAttribute plotDistance = EntityBuilder.addValue(cluster, "plot_distance", 25000d);
Unit unit = survey.getUnit("m");
plotDistance.setUnit(unit);
ValidationResults results = validate(plotDistance);
assertTrue(containsComparisonCheck(results.getErrors()));
}
use of org.openforis.idm.metamodel.Unit in project collect by openforis.
the class AttributeValueUtils method extractNormalizedValue.
private static Object extractNormalizedValue(NumericRangeAttribute<?, ?> attr) {
NumericRange<?> value = attr.getValue();
RangeAttributeDefinition defn = attr.getDefinition();
List<Unit> units = defn.getUnits();
if (units != null && units.size() > 1) {
Unit unit = attr.getUnit();
Unit defaultUnit = defn.getDefaultUnit();
if (unit != null && defaultUnit != null && unit != defaultUnit) {
Number from = value.getFrom();
Number to = value.getTo();
NumericRange<?> normalizedValue;
if (attr instanceof IntegerRangeAttribute) {
int normalizedFrom = getNormalizedValue(from, unit, defaultUnit).intValue();
int normalizedTo = getNormalizedValue(to, unit, defaultUnit).intValue();
normalizedValue = new IntegerRange(normalizedFrom, normalizedTo, defaultUnit);
} else {
double normalizedFrom = getNormalizedValue(from, unit, defaultUnit).doubleValue();
double normalizedTo = getNormalizedValue(to, unit, defaultUnit).doubleValue();
normalizedValue = new RealRange(normalizedFrom, normalizedTo, defaultUnit);
}
return normalizedValue;
} else {
return value;
}
} else {
return value;
}
}
use of org.openforis.idm.metamodel.Unit in project collect by openforis.
the class UnitsVM method getItemsInternal.
@Override
protected List<Unit> getItemsInternal() {
CollectSurvey survey = getSurvey();
List<Unit> units = survey.getUnits();
return units;
}
Aggregations