use of org.openforis.idm.metamodel.NumericAttributeDefinition in project collect by openforis.
the class NumericAttributeDefinitionPR method onStartDefinition.
@Override
protected void onStartDefinition() throws XmlParseException, XmlPullParserException, IOException {
super.onStartDefinition();
String typeStr = getAttribute(TYPE, false);
NumericAttributeDefinition defn = (NumericAttributeDefinition) getDefinition();
try {
Type type = typeStr == null ? Type.REAL : Type.valueOf(typeStr.toUpperCase());
defn.setType(type);
} catch (IllegalArgumentException e) {
throw new XmlParseException(getParser(), "unknown type " + typeStr);
}
}
use of org.openforis.idm.metamodel.NumericAttributeDefinition in project collect by openforis.
the class DefaultValueTest method addItem.
protected Entity addItem(Entity rootEntity, Integer qtyValue, Double priceValue) {
EntityDefinition rootEntityDefn = rootEntity.getDefinition();
EntityDefinition itemDefn = (EntityDefinition) rootEntityDefn.getChildDefinition("item");
Entity item = (Entity) itemDefn.createNode();
if (qtyValue != null) {
NodeDefinition qtyDefn = itemDefn.getChildDefinition("qty");
IntegerAttribute qty = (IntegerAttribute) qtyDefn.createNode();
qty.setValue(new IntegerValue(qtyValue, null));
qty.updateSummaryInfo();
item.add(qty);
}
if (priceValue != null) {
NumericAttributeDefinition priceDefn = (NumericAttributeDefinition) itemDefn.getChildDefinition("price");
RealAttribute price = (RealAttribute) priceDefn.createNode();
price.setValue(new RealValue(priceValue, null));
price.updateSummaryInfo();
item.add(price);
}
NumericAttributeDefinition totalDefn = (NumericAttributeDefinition) itemDefn.getChildDefinition("total");
RealAttribute total = (RealAttribute) totalDefn.createNode();
item.add(total);
rootEntity.add(item);
return item;
}
use of org.openforis.idm.metamodel.NumericAttributeDefinition in project collect by openforis.
the class DefaultValueTest method testConditionRespected.
@Test
public void testConditionRespected() throws InvalidExpressionException {
NumericAttributeDefinition totalDefn = (NumericAttributeDefinition) schema.getDefinitionByPath("bill/item/total");
List<AttributeDefault> attributeDefaults = totalDefn.getAttributeDefaults();
Entity rootEntity = record.getRootEntity();
Entity item = addItem(rootEntity, 10, 0d);
RealAttribute total = (RealAttribute) item.getChild("total", 0);
AttributeDefault constantAttributeDefault = attributeDefaults.get(1);
RealValue calculatedTotal = constantAttributeDefault.evaluate(total);
assertEquals(new RealValue(0d, null), calculatedTotal);
}
use of org.openforis.idm.metamodel.NumericAttributeDefinition in project collect by openforis.
the class DefaultValueTest method testNullValue.
@Test
public void testNullValue() throws InvalidExpressionException {
NumericAttributeDefinition totalDefn = (NumericAttributeDefinition) schema.getDefinitionByPath("bill/item/total");
List<AttributeDefault> attributeDefaults = totalDefn.getAttributeDefaults();
AttributeDefault exprAttributeDefault = attributeDefaults.get(0);
Entity rootEntity = record.getRootEntity();
Entity item = addItem(rootEntity, null, 5.5d);
RealAttribute total = (RealAttribute) item.getChild("total", 0);
RealValue calculatedTotal = exprAttributeDefault.evaluate(total);
assertEquals(0d, calculatedTotal.getValue(), 0);
}
use of org.openforis.idm.metamodel.NumericAttributeDefinition in project collect by openforis.
the class DefaultValueTest method testConditionNotRespected.
@Test
public void testConditionNotRespected() throws InvalidExpressionException {
NumericAttributeDefinition totalDefn = (NumericAttributeDefinition) schema.getDefinitionByPath("bill/item/total");
List<AttributeDefault> attributeDefaults = totalDefn.getAttributeDefaults();
AttributeDefault exprAttributeDefault = attributeDefaults.get(0);
Entity rootEntity = record.getRootEntity();
Entity item = addItem(rootEntity, 10, 0d);
RealAttribute total = (RealAttribute) item.getChild("total", 0);
boolean condition = exprAttributeDefault.evaluateCondition(total);
assertFalse(condition);
}
Aggregations