Search in sources :

Example 6 with NumericAttributeDefinition

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

Example 7 with NumericAttributeDefinition

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;
}
Also used : CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) ArrayList(java.util.ArrayList) CodeListLevel(org.openforis.idm.metamodel.CodeListLevel) NumericAttributeDefinition(org.openforis.idm.metamodel.NumericAttributeDefinition)

Example 8 with NumericAttributeDefinition

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;
}
Also used : CodeTable(org.openforis.collect.relational.model.CodeTable) DataTable(org.openforis.collect.relational.model.DataTable) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) TaxonAttributeDefinition(org.openforis.idm.metamodel.TaxonAttributeDefinition) DataColumn(org.openforis.collect.relational.model.DataColumn) BooleanAttributeDefinition(org.openforis.idm.metamodel.BooleanAttributeDefinition) NumericAttributeDefinition(org.openforis.idm.metamodel.NumericAttributeDefinition)

Example 9 with NumericAttributeDefinition

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;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Schema(org.openforis.idm.metamodel.Schema) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) NumericAttributeDefinition(org.openforis.idm.metamodel.NumericAttributeDefinition) Stack(java.util.Stack)

Example 10 with NumericAttributeDefinition

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;
}
Also used : CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) DateAttributeDefinition(org.openforis.idm.metamodel.DateAttributeDefinition) BooleanAttributeDefinition(org.openforis.idm.metamodel.BooleanAttributeDefinition) CodeListItem(org.openforis.idm.metamodel.CodeListItem) NumericAttributeDefinition(org.openforis.idm.metamodel.NumericAttributeDefinition)

Aggregations

NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)13 Test (org.junit.Test)4 AttributeDefault (org.openforis.idm.metamodel.AttributeDefault)4 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)4 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)3 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)3 ArrayList (java.util.ArrayList)2 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)2 Schema (org.openforis.idm.metamodel.Schema)2 List (java.util.List)1 Stack (java.util.Stack)1 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)1 CollectSurvey (org.openforis.collect.model.CollectSurvey)1 NodeChangeSet (org.openforis.collect.model.NodeChangeSet)1 CodeTable (org.openforis.collect.relational.model.CodeTable)1 DataColumn (org.openforis.collect.relational.model.DataColumn)1 DataTable (org.openforis.collect.relational.model.DataTable)1 CodeListItem (org.openforis.idm.metamodel.CodeListItem)1 CodeListLevel (org.openforis.idm.metamodel.CodeListLevel)1 DateAttributeDefinition (org.openforis.idm.metamodel.DateAttributeDefinition)1