use of org.openforis.idm.metamodel.Unit in project collect by openforis.
the class UnitFormValidator method validateNameUniqueness.
protected boolean validateNameUniqueness(ValidationContext ctx) {
SurveyObjectBaseVM<Unit> viewModel = getVM(ctx);
Unit editedItem = viewModel.getEditedItem();
CollectSurvey survey = viewModel.getSurvey();
String name = (String) getValue(ctx, NAME_FIELD);
Unit existingItem = survey.getUnit(name);
if (existingItem != null && existingItem.getId() != editedItem.getId()) {
String message = Labels.getLabel(ITEM_NAME_ALREADY_DEFINED_MESSAGE_KEY);
addInvalidMessage(ctx, NAME_FIELD, message);
return false;
} else {
return true;
}
}
use of org.openforis.idm.metamodel.Unit in project collect by openforis.
the class AttributeValueUtils method extractNormalizedValue.
private static Object extractNormalizedValue(NumberAttribute<?, ?> attr) {
NumberAttributeDefinition 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) {
double normalizedValue = getNormalizedValue(attr.getValue(), defaultUnit).doubleValue();
return normalizedValue;
}
}
NumberValue<?> value = attr.getValue();
return value.getValue();
}
use of org.openforis.idm.metamodel.Unit in project collect by openforis.
the class ComparisonCheckTest method testLteWithNormalizedValuesPassOnLt.
@Test
public void testLteWithNormalizedValuesPassOnLt() {
RealAttribute plotDistance = EntityBuilder.addValue(cluster, "plot_distance", 25000d);
Unit unit = survey.getUnit("cm");
plotDistance.setUnit(unit);
ValidationResults results = validate(plotDistance);
assertFalse(containsComparisonCheck(results.getErrors()));
}
use of org.openforis.idm.metamodel.Unit in project collect by openforis.
the class NumberAttribute method getValue.
@Override
public T getValue() {
N value = (N) getNumberField().getValue();
Unit unit = getUnit();
return createValue(value, unit);
}
use of org.openforis.idm.metamodel.Unit in project collect by openforis.
the class NumberAttribute method setValueInFields.
@Override
protected void setValueInFields(T value) {
N number = value.getValue();
Unit unit = value.getUnit();
Integer unitId = unit == null ? null : unit.getId();
getNumberField().setValue(number);
getUnitField().setValue(unitId);
}
Aggregations