Search in sources :

Example 1 with DataColumn

use of org.openforis.collect.relational.model.DataColumn 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 2 with DataColumn

use of org.openforis.collect.relational.model.DataColumn in project collect by openforis.

the class Mondrian4SchemaGenerator method createDimensionAttributes.

private List<Attribute> createDimensionAttributes(DataTable dataTable, AttributeDefinition attrDefn) {
    List<Attribute> attributes = new ArrayList<Attribute>();
    if (attrDefn instanceof CodeAttributeDefinition && !((CodeAttributeDefinition) attrDefn).getList().isExternal()) {
        CodeAttributeDefinition codeAttrDefn = (CodeAttributeDefinition) attrDefn;
        CodeTable codeListTable = rdbSchema.getCodeListTable(codeAttrDefn);
        String codeListTableName = codeListTable.getName();
        Attribute attribute = new Attribute();
        FieldDefinition<String> codeFieldDef = codeAttrDefn.getCodeFieldDefinition();
        attribute.name = codeFieldDef.getName();
        attribute.caption = getAttributeCaption(codeFieldDef);
        attribute.table = codeListTableName;
        attribute.keyColumn = CodeListTables.getCodeColumnName(rdbConfig, codeListTableName);
        attribute.nameColumn = CodeListTables.getLabelColumnName(rdbConfig, codeListTableName);
        attributes.add(attribute);
    } else if (attrDefn.hasMainField()) {
        attributes.addAll(createAttributesForFields(dataTable, attrDefn));
    } else if (attrDefn instanceof DateAttributeDefinition || attrDefn instanceof TimeAttributeDefinition) {
        List<DataColumn> dataColumns = dataTable.getDataColumns(attrDefn);
        DataColumn dataColumn = dataColumns.get(0);
        Attribute attribute = new Attribute();
        attribute.name = attrDefn.getName();
        attribute.caption = getDimensionCaption(attrDefn);
        attribute.keyColumn = dataColumn.getName();
        attributes.add(attribute);
        attributes.addAll(createAttributesForFields(dataTable, attrDefn));
    } else {
    // TODO
    // every field makes the Key of the Attribute ?! then nameColumn must be specified
    // Attribute attribute = new Attribute();
    // attribute.name = attrDefn.getName();
    // attribute.caption = getDimensionCaption(attrDefn);
    // Key key = new Key();
    // for (FieldDefinition<?> fieldDef : attrDefn.getFieldDefinitions()) {
    // DataColumn dataColumn = dataTable.getDataColumn(fieldDef);
    // if (dataColumn != null) {
    // Column column = new Column();
    // column.name = dataColumn.getName();
    // key.list().add(column);
    // }
    // }
    // attribute.children.add(key);
    // Name name = new Name();
    // name.list().add(e)
    // attribute.children.add(name);
    // attributes.add(attribute);
    }
    return attributes;
}
Also used : CodeTable(org.openforis.collect.relational.model.CodeTable) TimeAttributeDefinition(org.openforis.idm.metamodel.TimeAttributeDefinition) Attribute(mondrian.olap.MondrianDef.Attribute) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) ArrayList(java.util.ArrayList) DataColumn(org.openforis.collect.relational.model.DataColumn) DateAttributeDefinition(org.openforis.idm.metamodel.DateAttributeDefinition)

Example 3 with DataColumn

use of org.openforis.collect.relational.model.DataColumn in project collect by openforis.

the class Mondrian4SchemaGenerator method createAttributesForFields.

private List<Attribute> createAttributesForFields(DataTable dataTable, AttributeDefinition attrDefn) {
    List<FieldDefinition<?>> fieldDefs = attrDefn.getFieldDefinitions();
    List<Attribute> attributes = new ArrayList<Attribute>(fieldDefs.size());
    for (FieldDefinition<?> fieldDef : fieldDefs) {
        DataColumn col = dataTable.getDataColumn(fieldDef);
        if (col != null) {
            Attribute attribute = new Attribute();
            String fieldName = fieldDef.getName();
            attribute.name = fieldName;
            attribute.caption = getAttributeCaption(fieldDef);
            attribute.keyColumn = col.getName();
            // if (attrDefn instanceof DateAttributeDefinition) {
            // attribute.levelType = getDateFieldLevelType(fieldName);
            // }
            attributes.add(attribute);
        }
    }
    return attributes;
}
Also used : Attribute(mondrian.olap.MondrianDef.Attribute) FieldDefinition(org.openforis.idm.metamodel.FieldDefinition) ArrayList(java.util.ArrayList) DataColumn(org.openforis.collect.relational.model.DataColumn)

Aggregations

DataColumn (org.openforis.collect.relational.model.DataColumn)3 ArrayList (java.util.ArrayList)2 Attribute (mondrian.olap.MondrianDef.Attribute)2 CodeTable (org.openforis.collect.relational.model.CodeTable)2 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)2 DataTable (org.openforis.collect.relational.model.DataTable)1 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)1 DateAttributeDefinition (org.openforis.idm.metamodel.DateAttributeDefinition)1 FieldDefinition (org.openforis.idm.metamodel.FieldDefinition)1 NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)1 TaxonAttributeDefinition (org.openforis.idm.metamodel.TaxonAttributeDefinition)1 TimeAttributeDefinition (org.openforis.idm.metamodel.TimeAttributeDefinition)1