Search in sources :

Example 1 with Unit

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;
    }
}
Also used : Unit(org.openforis.idm.metamodel.Unit) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 2 with Unit

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();
}
Also used : NumberAttributeDefinition(org.openforis.idm.metamodel.NumberAttributeDefinition) Unit(org.openforis.idm.metamodel.Unit)

Example 3 with Unit

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()));
}
Also used : RealAttribute(org.openforis.idm.model.RealAttribute) Unit(org.openforis.idm.metamodel.Unit) Test(org.junit.Test)

Example 4 with Unit

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);
}
Also used : Unit(org.openforis.idm.metamodel.Unit)

Example 5 with 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);
}
Also used : Unit(org.openforis.idm.metamodel.Unit)

Aggregations

Unit (org.openforis.idm.metamodel.Unit)23 CollectSurvey (org.openforis.collect.model.CollectSurvey)3 RangeAttributeDefinition (org.openforis.idm.metamodel.RangeAttributeDefinition)3 Test (org.junit.Test)2 NumberAttributeDefinition (org.openforis.idm.metamodel.NumberAttributeDefinition)2 IntegerRange (org.openforis.idm.model.IntegerRange)2 NumberAttribute (org.openforis.idm.model.NumberAttribute)2 RealAttribute (org.openforis.idm.model.RealAttribute)2 RealRange (org.openforis.idm.model.RealRange)2 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)1 NodeChangeSet (org.openforis.collect.model.NodeChangeSet)1 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)1 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)1 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)1 NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)1 Survey (org.openforis.idm.metamodel.Survey)1 IntegerRangeAttribute (org.openforis.idm.model.IntegerRangeAttribute)1 IntegerValue (org.openforis.idm.model.IntegerValue)1 NumericRange (org.openforis.idm.model.NumericRange)1 RealValue (org.openforis.idm.model.RealValue)1