use of org.openforis.idm.metamodel.NumericAttributeDefinition in project collect by openforis.
the class DefaultValueTest method testNotNullValues.
@Test
public void testNotNullValues() throws InvalidExpressionException {
NumericAttributeDefinition totalDefn = (NumericAttributeDefinition) schema.getDefinitionByPath("bill/item/total");
Entity rootEntity = record.getRootEntity();
Entity item = addItem(rootEntity, 10, 5.5d);
RealAttribute total = (RealAttribute) item.getChild("total", 0);
List<AttributeDefault> attributeDefaults = totalDefn.getAttributeDefaults();
AttributeDefault exprAttributeDefault = attributeDefaults.get(0);
RealValue calculatedTotal = exprAttributeDefault.evaluate(total);
assertEquals(new RealValue(55d, null), calculatedTotal);
}
use of org.openforis.idm.metamodel.NumericAttributeDefinition in project collect by openforis.
the class MondrianCubeGenerator method generateLevel.
private List<Level> generateLevel(NodeDefinition nodeDef) {
List<Level> levels = new ArrayList<Level>();
String attrLabel = extractFailsafeLabel(nodeDef);
Level level = new Level(attrLabel);
levels.add(level);
if (nodeDef instanceof NumericAttributeDefinition) {
level.type = ((NumericAttributeDefinition) nodeDef).getType() == Type.INTEGER ? INTEGER_DATATYPE : NUMERIC_DATATYPE;
} else if (nodeDef instanceof CodeAttributeDefinition) {
level.type = ((CodeAttributeDefinition) nodeDef).getList().isExternal() ? STRING_DATATYPE : INTEGER_DATATYPE;
} else {
level.type = STRING_DATATYPE;
}
level.levelType = "Regular";
if (nodeDef instanceof CodeAttributeDefinition) {
CodeAttributeDefinition codeDef = (CodeAttributeDefinition) nodeDef;
String codeTableName = extractCodeListTableName(codeDef);
level.table = codeTableName;
level.column = codeTableName + rdbConfig.getIdColumnSuffix();
level.nameColumn = codeTableName.substring(0, codeTableName.length() - rdbConfig.getCodeListTableSuffix().length()) + "_label_" + language;
Level levelId = new Level(attrLabel + " - ID");
levelId.type = "String";
levelId.table = codeTableName;
levelId.column = codeTableName + rdbConfig.getIdColumnSuffix();
levelId.nameColumn = extractCodeListName(codeDef);
levels.add(levelId);
} else {
level.column = nodeDef.getName();
}
return levels;
}
use of org.openforis.idm.metamodel.NumericAttributeDefinition in project collect by openforis.
the class NewMondrianSchemaGenerator method generateLevel.
private Level generateLevel(AttributeDefinition nodeDef) {
DataTable dataTable = rdbSchema.getDataTable(nodeDef.getParentDefinition());
Level level = new Level(determineDimensionName(nodeDef), determineLevelCaption(nodeDef));
level.levelType = "Regular";
if (nodeDef instanceof NumericAttributeDefinition) {
level.type = ((NumericAttributeDefinition) nodeDef).getType() == Type.INTEGER ? INTEGER_DATATYPE : NUMERIC_DATATYPE;
} else if (nodeDef instanceof BooleanAttributeDefinition) {
level.type = BOOLEAN_DATATYPE;
} else if (nodeDef instanceof CodeAttributeDefinition) {
level.type = ((CodeAttributeDefinition) nodeDef).getList().isExternal() ? STRING_DATATYPE : INTEGER_DATATYPE;
} else {
level.type = STRING_DATATYPE;
}
if (nodeDef instanceof CodeAttributeDefinition && !((CodeAttributeDefinition) nodeDef).getList().isExternal()) {
CodeAttributeDefinition codeDef = (CodeAttributeDefinition) nodeDef;
CodeTable codeListTable = rdbSchema.getCodeListTable(codeDef);
level.table = codeListTable.getName();
level.column = codeListTable.getPrimaryKeyConstraint().getPrimaryKeyColumn().getName();
level.nameColumn = CodeListTables.getLabelColumnName(rdbConfig, codeDef.getList(), codeDef.getLevelIndex(), language);
} else if (nodeDef instanceof TaxonAttributeDefinition) {
DataColumn dataColumn = dataTable.getDataColumn(((TaxonAttributeDefinition) nodeDef).getCodeFieldDefinition());
level.column = dataColumn.getName();
} else if (nodeDef.isMultiple()) {
// TODO skip multiple attributes?
level.column = nodeDef.getName();
} else {
DataColumn dataColumn = dataTable.getDataColumn(nodeDef.getMainFieldDefinition());
level.column = dataColumn.getName();
}
return level;
}
use of org.openforis.idm.metamodel.NumericAttributeDefinition in project collect by openforis.
the class UnitsVM method getReferences.
protected List<NodeDefinition> getReferences(Unit item) {
List<NodeDefinition> references = new ArrayList<NodeDefinition>();
Schema schema = survey.getSchema();
List<EntityDefinition> rootEntities = schema.getRootEntityDefinitions();
Stack<NodeDefinition> stack = new Stack<NodeDefinition>();
stack.addAll(rootEntities);
while (!stack.isEmpty()) {
NodeDefinition defn = stack.pop();
if (defn instanceof EntityDefinition) {
stack.addAll(((EntityDefinition) defn).getChildDefinitions());
} else if (defn instanceof NumericAttributeDefinition) {
List<Unit> units = ((NumericAttributeDefinition) defn).getUnits();
if (units.contains(item)) {
references.add(defn);
}
}
}
return references;
}
use of org.openforis.idm.metamodel.NumericAttributeDefinition in project collect by openforis.
the class CollectEarthGridTemplateGenerator method getDummyValue.
private String getDummyValue(AttributeDefinition attrDef, Integer ord) {
String attrName = attrDef.getName();
String value;
if (attrDef instanceof NumericAttributeDefinition || attrDef instanceof BooleanAttributeDefinition) {
value = "0";
if (ord != null) {
value = ord + "";
}
} else if (attrDef instanceof DateAttributeDefinition) {
value = "1/1/2000";
} else if (attrDef instanceof CodeAttributeDefinition) {
CodeListItem firstAvailableItem = getFirstAvailableCodeItem(attrDef);
value = firstAvailableItem == null ? "0" : firstAvailableItem.getCode();
} else {
value = attrName;
if (ord != null) {
value += "_" + ord;
}
}
return value;
}
Aggregations