Search in sources :

Example 1 with Dimension

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

the class Mondrian4SchemaGenerator method createCube.

private Cube createCube(DataTable dataTable) {
    NodeDefinition nodeDef = dataTable.getNodeDefinition();
    Cube cube = new Cube();
    cube.name = nodeDef.getName();
    MeasureGroups measureGroups = new MondrianDef.MeasureGroups();
    MeasureGroup measureGroup = new MeasureGroup();
    measureGroup.name = cube.name;
    Measures measures = new Measures();
    List<Measure> measureList = createMeasures(dataTable);
    measures.list().addAll(measureList);
    measureGroup.children.add(measures);
    measureGroup.table = dataTable.getName();
    DimensionLinks dimensionLinks = new DimensionLinks();
    measureGroup.children.add(dimensionLinks);
    measureGroups.list().add(measureGroup);
    cube.children.add(measureGroups);
    if (nodeDef instanceof EntityDefinition) {
        Dimensions dimensions = new Dimensions();
        Queue<NodeDefinition> queue = new LinkedList<NodeDefinition>();
        queue.addAll(((EntityDefinition) nodeDef).getChildDefinitions());
        while (!queue.isEmpty()) {
            NodeDefinition def = queue.poll();
            if (def instanceof AttributeDefinition) {
                AttributeDefinition attrDef = (AttributeDefinition) def;
                Dimension dimension = createDimension(dataTable, attrDef);
                if (dimension != null) {
                    dimensions.list().add(dimension);
                    // add dimension link
                    DimensionLink dimensionLink = createDimensionLink(dimension, attrDef);
                    dimensionLinks.list().add(dimensionLink);
                }
            } else if (!def.isMultiple()) {
                queue.addAll(((EntityDefinition) def).getChildDefinitions());
            }
        }
        cube.children.add(dimensions);
    }
    return cube;
}
Also used : MeasureGroup(mondrian.olap.MondrianDef.MeasureGroup) DimensionLinks(mondrian.olap.MondrianDef.DimensionLinks) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) Dimensions(mondrian.olap.MondrianDef.Dimensions) DateAttributeDefinition(org.openforis.idm.metamodel.DateAttributeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) TimeAttributeDefinition(org.openforis.idm.metamodel.TimeAttributeDefinition) Dimension(mondrian.olap.MondrianDef.Dimension) LinkedList(java.util.LinkedList) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Measures(mondrian.olap.MondrianDef.Measures) Cube(mondrian.olap.MondrianDef.Cube) Measure(mondrian.olap.MondrianDef.Measure) MeasureGroups(mondrian.olap.MondrianDef.MeasureGroups) DimensionLink(mondrian.olap.MondrianDef.DimensionLink)

Example 2 with Dimension

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

Dimension (mondrian.olap.MondrianDef.Dimension)2 LinkedList (java.util.LinkedList)1 Attribute (mondrian.olap.MondrianDef.Attribute)1 Attributes (mondrian.olap.MondrianDef.Attributes)1 Cube (mondrian.olap.MondrianDef.Cube)1 DimensionLink (mondrian.olap.MondrianDef.DimensionLink)1 DimensionLinks (mondrian.olap.MondrianDef.DimensionLinks)1 Dimensions (mondrian.olap.MondrianDef.Dimensions)1 Hierarchies (mondrian.olap.MondrianDef.Hierarchies)1 Hierarchy (mondrian.olap.MondrianDef.Hierarchy)1 Level (mondrian.olap.MondrianDef.Level)1 Measure (mondrian.olap.MondrianDef.Measure)1 MeasureGroup (mondrian.olap.MondrianDef.MeasureGroup)1 MeasureGroups (mondrian.olap.MondrianDef.MeasureGroups)1 Measures (mondrian.olap.MondrianDef.Measures)1 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)1 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)1 DateAttributeDefinition (org.openforis.idm.metamodel.DateAttributeDefinition)1 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)1 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)1