Search in sources :

Example 1 with RangeAttributeDefinition

use of org.openforis.idm.metamodel.RangeAttributeDefinition in project collect by openforis.

the class NodeDefinitionProxy method fromList.

static List<NodeDefinitionProxy> fromList(EntityDefinitionProxy parent, List<? extends NodeDefinition> list) {
    List<NodeDefinitionProxy> proxies = new ArrayList<NodeDefinitionProxy>();
    if (list != null) {
        for (NodeDefinition n : list) {
            NodeDefinitionProxy p = null;
            CollectSurvey survey = (CollectSurvey) n.getSurvey();
            UIOptions uiOptions = survey.getUIOptions();
            boolean hidden = uiOptions.isHidden(n);
            if (!hidden) {
                if (n instanceof AttributeDefinition) {
                    if (n instanceof BooleanAttributeDefinition) {
                        p = new BooleanAttributeDefinitionProxy(parent, (BooleanAttributeDefinition) n);
                    } else if (n instanceof CodeAttributeDefinition) {
                        p = new CodeAttributeDefinitionProxy(parent, (CodeAttributeDefinition) n);
                    } else if (n instanceof CoordinateAttributeDefinition) {
                        p = new CoordinateAttributeDefinitionProxy(parent, (CoordinateAttributeDefinition) n);
                    } else if (n instanceof DateAttributeDefinition) {
                        p = new DateAttributeDefinitionProxy(parent, (DateAttributeDefinition) n);
                    } else if (n instanceof FileAttributeDefinition) {
                        p = new FileAttributeDefinitionProxy(parent, (FileAttributeDefinition) n);
                    } else if (n instanceof NumberAttributeDefinition) {
                        p = new NumberAttributeDefinitionProxy(parent, (NumberAttributeDefinition) n);
                    } else if (n instanceof RangeAttributeDefinition) {
                        p = new RangeAttributeDefinitionProxy(parent, (RangeAttributeDefinition) n);
                    } else if (n instanceof TaxonAttributeDefinition) {
                        p = new TaxonAttributeDefinitionProxy(parent, (TaxonAttributeDefinition) n);
                    } else if (n instanceof TextAttributeDefinition) {
                        p = new TextAttributeDefinitionProxy(parent, (TextAttributeDefinition) n);
                    } else if (n instanceof TimeAttributeDefinition) {
                        p = new TimeAttributeDefinitionProxy(parent, (TimeAttributeDefinition) n);
                    } else {
                        throw new RuntimeException("AttributeDefinition not supported: " + n.getClass().getSimpleName());
                    }
                } else if (n instanceof EntityDefinition) {
                    p = new EntityDefinitionProxy(parent, (EntityDefinition) n);
                }
                if (p != null) {
                    proxies.add(p);
                }
            }
        }
    }
    return proxies;
}
Also used : TaxonAttributeDefinition(org.openforis.idm.metamodel.TaxonAttributeDefinition) UIOptions(org.openforis.collect.metamodel.ui.UIOptions) ArrayList(java.util.ArrayList) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) FileAttributeDefinition(org.openforis.idm.metamodel.FileAttributeDefinition) CoordinateAttributeDefinition(org.openforis.idm.metamodel.CoordinateAttributeDefinition) NumberAttributeDefinition(org.openforis.idm.metamodel.NumberAttributeDefinition) TimeAttributeDefinition(org.openforis.idm.metamodel.TimeAttributeDefinition) BooleanAttributeDefinition(org.openforis.idm.metamodel.BooleanAttributeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) TextAttributeDefinition(org.openforis.idm.metamodel.TextAttributeDefinition) RangeAttributeDefinition(org.openforis.idm.metamodel.RangeAttributeDefinition) DateAttributeDefinition(org.openforis.idm.metamodel.DateAttributeDefinition) TaxonAttributeDefinition(org.openforis.idm.metamodel.TaxonAttributeDefinition) DateAttributeDefinition(org.openforis.idm.metamodel.DateAttributeDefinition) CoordinateAttributeDefinition(org.openforis.idm.metamodel.CoordinateAttributeDefinition) BooleanAttributeDefinition(org.openforis.idm.metamodel.BooleanAttributeDefinition) FileAttributeDefinition(org.openforis.idm.metamodel.FileAttributeDefinition) TimeAttributeDefinition(org.openforis.idm.metamodel.TimeAttributeDefinition) NumberAttributeDefinition(org.openforis.idm.metamodel.NumberAttributeDefinition) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) TextAttributeDefinition(org.openforis.idm.metamodel.TextAttributeDefinition) CollectSurvey(org.openforis.collect.model.CollectSurvey) RangeAttributeDefinition(org.openforis.idm.metamodel.RangeAttributeDefinition)

Example 2 with RangeAttributeDefinition

use of org.openforis.idm.metamodel.RangeAttributeDefinition in project collect by openforis.

the class BaseAttributeUpdateRequestProxy method parseCompositeAttributeValue.

protected Value parseCompositeAttributeValue(CodeListManager codeListManager, Entity parentEntity, String attributeName, Object value) {
    EntityDefinition parentEntityDefn = parentEntity.getDefinition();
    AttributeDefinition defn = (AttributeDefinition) parentEntityDefn.getChildDefinition(attributeName);
    if (defn instanceof CodeAttributeDefinition) {
        if (value instanceof String) {
            String stringVal = (String) value;
            Value result = parseCode(codeListManager, parentEntity, (CodeAttributeDefinition) defn, stringVal);
            return result;
        } else {
            throw new IllegalArgumentException("Invalid value type: expected String");
        }
    } else if (defn instanceof RangeAttributeDefinition) {
        if (value instanceof String) {
            String stringVal = (String) value;
            RangeAttributeDefinition rangeDef = (RangeAttributeDefinition) defn;
            RangeAttributeDefinition.Type type = rangeDef.getType();
            NumericRange<?> range = null;
            // todo check if unit is required here or is set later by the client
            Unit unit = null;
            switch(type) {
                case INTEGER:
                    range = IntegerRange.parseIntegerRange(stringVal, unit);
                    break;
                case REAL:
                    range = RealRange.parseRealRange(stringVal, unit);
                    break;
            }
            return range;
        } else {
            throw new IllegalArgumentException("Invalid value type: expected String");
        }
    } else {
        throw new IllegalArgumentException("Invalid AttributeDefinition: expected CodeAttributeDefinition or RangeAttributeDefinition");
    }
}
Also used : NumericRange(org.openforis.idm.model.NumericRange) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) Value(org.openforis.idm.model.Value) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) RangeAttributeDefinition(org.openforis.idm.metamodel.RangeAttributeDefinition) Unit(org.openforis.idm.metamodel.Unit) RangeAttributeDefinition(org.openforis.idm.metamodel.RangeAttributeDefinition)

Example 3 with RangeAttributeDefinition

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

Example 4 with RangeAttributeDefinition

use of org.openforis.idm.metamodel.RangeAttributeDefinition 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;
    }
}
Also used : IntegerRange(org.openforis.idm.model.IntegerRange) RealRange(org.openforis.idm.model.RealRange) Unit(org.openforis.idm.metamodel.Unit) IntegerRangeAttribute(org.openforis.idm.model.IntegerRangeAttribute) RangeAttributeDefinition(org.openforis.idm.metamodel.RangeAttributeDefinition)

Aggregations

RangeAttributeDefinition (org.openforis.idm.metamodel.RangeAttributeDefinition)4 Unit (org.openforis.idm.metamodel.Unit)3 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)2 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)2 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)2 ArrayList (java.util.ArrayList)1 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)1 CollectSurvey (org.openforis.collect.model.CollectSurvey)1 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)1 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)1 DateAttributeDefinition (org.openforis.idm.metamodel.DateAttributeDefinition)1 FileAttributeDefinition (org.openforis.idm.metamodel.FileAttributeDefinition)1 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)1 NumberAttributeDefinition (org.openforis.idm.metamodel.NumberAttributeDefinition)1 TaxonAttributeDefinition (org.openforis.idm.metamodel.TaxonAttributeDefinition)1 TextAttributeDefinition (org.openforis.idm.metamodel.TextAttributeDefinition)1 TimeAttributeDefinition (org.openforis.idm.metamodel.TimeAttributeDefinition)1 IntegerRange (org.openforis.idm.model.IntegerRange)1 IntegerRangeAttribute (org.openforis.idm.model.IntegerRangeAttribute)1 NumericRange (org.openforis.idm.model.NumericRange)1