Search in sources :

Example 1 with Attribute

use of mondrian.olap.MondrianDef.Attribute 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 2 with Attribute

use of mondrian.olap.MondrianDef.Attribute 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)

Example 3 with Attribute

use of mondrian.olap.MondrianDef.Attribute in project collect by openforis.

the class Mondrian4SchemaGenerator method createDimension.

private Dimension createDimension(DataTable dataTable, AttributeDefinition attrDefn) {
    List<Attribute> attrs = createDimensionAttributes(dataTable, attrDefn);
    if (attrs.isEmpty()) {
        return null;
    } else {
        Dimension dimension = new Dimension();
        dimension.name = attrDefn.getName();
        dimension.caption = getDimensionCaption(attrDefn);
        if (attrDefn.hasMainField()) {
            dimension.key = attrDefn.getMainFieldName();
        } else {
            dimension.key = attrDefn.getName();
        }
        dimension.table = dataTable.getName();
        Attributes attributes = new Attributes();
        attributes.list().addAll(attrs);
        dimension.children.add(attributes);
        List<Level> hierarchyLevels = createHierarchyLevels(attrDefn);
        if (!hierarchyLevels.isEmpty()) {
            Hierarchies hierarchies = new Hierarchies();
            Hierarchy hierarchy = new Hierarchy();
            hierarchy.name = attrDefn.getName() + "_full_hierarchy";
            hierarchy.children.addAll(hierarchyLevels);
            hierarchies.list().add(hierarchy);
            dimension.children.add(hierarchies);
        }
        return dimension;
    }
}
Also used : Hierarchy(mondrian.olap.MondrianDef.Hierarchy) Hierarchies(mondrian.olap.MondrianDef.Hierarchies) Attribute(mondrian.olap.MondrianDef.Attribute) Attributes(mondrian.olap.MondrianDef.Attributes) Level(mondrian.olap.MondrianDef.Level) Dimension(mondrian.olap.MondrianDef.Dimension)

Aggregations

Attribute (mondrian.olap.MondrianDef.Attribute)3 ArrayList (java.util.ArrayList)2 DataColumn (org.openforis.collect.relational.model.DataColumn)2 Attributes (mondrian.olap.MondrianDef.Attributes)1 Dimension (mondrian.olap.MondrianDef.Dimension)1 Hierarchies (mondrian.olap.MondrianDef.Hierarchies)1 Hierarchy (mondrian.olap.MondrianDef.Hierarchy)1 Level (mondrian.olap.MondrianDef.Level)1 CodeTable (org.openforis.collect.relational.model.CodeTable)1 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)1 DateAttributeDefinition (org.openforis.idm.metamodel.DateAttributeDefinition)1 FieldDefinition (org.openforis.idm.metamodel.FieldDefinition)1 TimeAttributeDefinition (org.openforis.idm.metamodel.TimeAttributeDefinition)1