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;
}
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");
}
}
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;
}
}
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;
}
}
Aggregations