Search in sources :

Example 16 with Hierarchy

use of mondrian.olap.Hierarchy in project mondrian by pentaho.

the class RestrictedMemberReaderTest method testDefaultMember_multiRoot.

public void testDefaultMember_multiRoot() {
    RolapHierarchy hierarchy = Mockito.mock(RolapHierarchy.class);
    MemberReader delegateMemberReader = Mockito.mock(MemberReader.class);
    HierarchyAccess roleAccess = Mockito.mock(HierarchyAccess.class);
    Role role = Mockito.mock(Role.class);
    RolapMember member0 = mockMember();
    RolapMember member1 = mockMember();
    RolapMember member2 = mockMember();
    List<RolapMember> rootMembers = Arrays.asList(new RolapMember[] { member0, member1, member2 });
    RolapMember hierDefaultMember = member1;
    Mockito.doReturn(roleAccess).when(role).getAccessDetails(Mockito.any(Hierarchy.class));
    Mockito.doReturn(hierarchy).when(delegateMemberReader).getHierarchy();
    Mockito.doReturn(hierDefaultMember).when(hierarchy).getDefaultMember();
    rmr = Mockito.spy(new RestrictedMemberReader(delegateMemberReader, role));
    Mockito.doReturn(rootMembers).when(rmr).getRootMembers();
    Mockito.doReturn(Access.CUSTOM).when(roleAccess).getAccess(member0);
    Mockito.doReturn(Access.NONE).when(roleAccess).getAccess(member1);
    Mockito.doReturn(Access.NONE).when(roleAccess).getAccess(member2);
    Assert.assertSame("on Access C-N-N", member0, rmr.getDefaultMember());
    Mockito.doReturn(Access.NONE).when(roleAccess).getAccess(member0);
    Mockito.doReturn(Access.NONE).when(roleAccess).getAccess(member1);
    Mockito.doReturn(Access.CUSTOM).when(roleAccess).getAccess(member2);
    Assert.assertSame("on Access N-N-C", member2, rmr.getDefaultMember());
    Mockito.doReturn(Access.CUSTOM).when(roleAccess).getAccess(member0);
    Mockito.doReturn(Access.CUSTOM).when(roleAccess).getAccess(member1);
    Mockito.doReturn(Access.CUSTOM).when(roleAccess).getAccess(member2);
    Assert.assertSame("on Access C-C-C", hierDefaultMember, rmr.getDefaultMember());
    Mockito.doReturn(Access.CUSTOM).when(roleAccess).getAccess(member0);
    Mockito.doReturn(Access.NONE).when(roleAccess).getAccess(member1);
    Mockito.doReturn(Access.CUSTOM).when(roleAccess).getAccess(member2);
    Assert.assertTrue("on Access C-N-C", rmr.getDefaultMember() instanceof MultiCardinalityDefaultMember);
    Mockito.doReturn(Access.NONE).when(roleAccess).getAccess(anyRolapMember());
    Assert.assertTrue("on Access.NONE", rmr.getDefaultMember() instanceof MultiCardinalityDefaultMember);
}
Also used : Role(mondrian.olap.Role) Hierarchy(mondrian.olap.Hierarchy) MultiCardinalityDefaultMember(mondrian.rolap.RestrictedMemberReader.MultiCardinalityDefaultMember) HierarchyAccess(mondrian.olap.Role.HierarchyAccess)

Example 17 with Hierarchy

use of mondrian.olap.Hierarchy in project mondrian by pentaho.

the class RolapCubeHierarchyTest method testInit_FactCube_FactTableDiffers.

public void testInit_FactCube_FactTableDiffers() {
    RolapCubeDimension cubeDimension = mock(RolapCubeDimension.class);
    RolapCube cubeDimension_cube = mock(RolapCube.class);
    boolean cubeDimension_cube_isVirtual = true;
    String cubeDimension_uniqueName = "TheDimUniqueName";
    RolapSchema cubeDimension_schema = mock(RolapSchema.class);
    RolapConnection cubeDimension_schema_connection = mock(RolapConnection.class);
    DataSource cubeDimension_schema_connection_DS = mock(DataSource.class);
    MondrianDef.CubeDimension cubeDim = null;
    RolapHierarchy rolapHierarchy = mock(RolapHierarchy.class);
    Hierarchy rolapHierarchy_hierarchy = null;
    String rolapHierarchy_uniqueName = "TheDimUniqueName";
    Level[] rolapHierarchy_levels = new Level[] {};
    RelationOrJoin rolapHierarchy_relation = mock(Relation.class);
    String subName = null;
    int ordinal = 0;
    RolapCube factCube = mock(RolapCube.class);
    RelationOrJoin factCube_Fact = mock(Relation.class);
    boolean factCube_Fact_equals = false;
    // check
    assertEquals(factCube_Fact_equals, factCube_Fact.equals(rolapHierarchy_relation));
    assertEquals(factCube_Fact_equals, rolapHierarchy_relation.equals(factCube_Fact));
    doReturn(cubeDimension_cube).when(cubeDimension).getCube();
    doReturn(cubeDimension_cube_isVirtual).when(cubeDimension_cube).isVirtual();
    doReturn(cubeDimension_schema).when(cubeDimension).getSchema();
    doReturn(cubeDimension_schema_connection).when(cubeDimension_schema).getInternalConnection();
    doReturn(cubeDimension_schema_connection_DS).when(cubeDimension_schema_connection).getDataSource();
    doReturn(cubeDimension_uniqueName).when(cubeDimension).getUniqueName();
    doReturn(rolapHierarchy_hierarchy).when(rolapHierarchy).getHierarchy();
    doReturn(rolapHierarchy_levels).when(rolapHierarchy).getLevels();
    doReturn(rolapHierarchy_uniqueName).when(rolapHierarchy).getUniqueName();
    doReturn(rolapHierarchy_relation).when(rolapHierarchy).getRelation();
    doReturn(factCube_Fact).when(factCube).getFact();
    RolapCubeHierarchy rch = new RolapCubeHierarchy(cubeDimension, cubeDim, rolapHierarchy, subName, ordinal, factCube);
    assertEquals(false, rch.isUsingCubeFact());
}
Also used : DataSource(javax.sql.DataSource) Hierarchy(mondrian.olap.Hierarchy) MondrianDef(mondrian.olap.MondrianDef) Level(mondrian.olap.Level) RelationOrJoin(mondrian.olap.MondrianDef.RelationOrJoin)

Example 18 with Hierarchy

use of mondrian.olap.Hierarchy in project mondrian by pentaho.

the class RolapCubeHierarchyTest method testInit_FactCube_NoFactTable.

public void testInit_FactCube_NoFactTable() {
    RolapCubeDimension cubeDimension = mock(RolapCubeDimension.class);
    RolapCube cubeDimension_cube = mock(RolapCube.class);
    boolean cubeDimension_cube_isVirtual = true;
    String cubeDimension_uniqueName = "TheDimUniqueName";
    RolapSchema cubeDimension_schema = mock(RolapSchema.class);
    RolapConnection cubeDimension_schema_connection = mock(RolapConnection.class);
    DataSource cubeDimension_schema_connection_DS = mock(DataSource.class);
    MondrianDef.CubeDimension cubeDim = null;
    RolapHierarchy rolapHierarchy = mock(RolapHierarchy.class);
    Hierarchy rolapHierarchy_hierarchy = null;
    String rolapHierarchy_uniqueName = "TheDimUniqueName";
    Level[] rolapHierarchy_levels = new Level[] {};
    String subName = null;
    int ordinal = 0;
    RolapCube factCube = mock(RolapCube.class);
    RolapCube factCube_Fact = null;
    doReturn(cubeDimension_cube).when(cubeDimension).getCube();
    doReturn(cubeDimension_cube_isVirtual).when(cubeDimension_cube).isVirtual();
    doReturn(cubeDimension_schema).when(cubeDimension).getSchema();
    doReturn(cubeDimension_schema_connection).when(cubeDimension_schema).getInternalConnection();
    doReturn(cubeDimension_schema_connection_DS).when(cubeDimension_schema_connection).getDataSource();
    doReturn(cubeDimension_uniqueName).when(cubeDimension).getUniqueName();
    doReturn(rolapHierarchy_hierarchy).when(rolapHierarchy).getHierarchy();
    doReturn(rolapHierarchy_levels).when(rolapHierarchy).getLevels();
    doReturn(rolapHierarchy_uniqueName).when(rolapHierarchy).getUniqueName();
    doReturn(factCube_Fact).when(factCube).getFact();
    RolapCubeHierarchy rch = new RolapCubeHierarchy(cubeDimension, cubeDim, rolapHierarchy, subName, ordinal, factCube);
    assertEquals(true, rch.isUsingCubeFact());
}
Also used : DataSource(javax.sql.DataSource) Hierarchy(mondrian.olap.Hierarchy) MondrianDef(mondrian.olap.MondrianDef) Level(mondrian.olap.Level)

Example 19 with Hierarchy

use of mondrian.olap.Hierarchy in project mondrian by pentaho.

the class RolapCubeHierarchyTest method testInit_NoFactCube.

public void testInit_NoFactCube() {
    RolapCubeDimension cubeDimension = mock(RolapCubeDimension.class);
    RolapCube cubeDimension_cube = mock(RolapCube.class);
    boolean cubeDimension_cube_isVirtual = true;
    String cubeDimension_uniqueName = "TheDimUniqueName";
    RolapSchema cubeDimension_schema = mock(RolapSchema.class);
    RolapConnection cubeDimension_schema_connection = mock(RolapConnection.class);
    DataSource cubeDimension_schema_connection_DS = mock(DataSource.class);
    MondrianDef.CubeDimension cubeDim = null;
    RolapHierarchy rolapHierarchy = mock(RolapHierarchy.class);
    Hierarchy rolapHierarchy_hierarchy = null;
    String rolapHierarchy_uniqueName = "TheDimUniqueName";
    Level[] rolapHierarchy_levels = new Level[] {};
    String subName = null;
    int ordinal = 0;
    RolapCube factCube = null;
    doReturn(cubeDimension_cube).when(cubeDimension).getCube();
    doReturn(cubeDimension_cube_isVirtual).when(cubeDimension_cube).isVirtual();
    doReturn(cubeDimension_schema).when(cubeDimension).getSchema();
    doReturn(cubeDimension_schema_connection).when(cubeDimension_schema).getInternalConnection();
    doReturn(cubeDimension_schema_connection_DS).when(cubeDimension_schema_connection).getDataSource();
    doReturn(cubeDimension_uniqueName).when(cubeDimension).getUniqueName();
    doReturn(rolapHierarchy_hierarchy).when(rolapHierarchy).getHierarchy();
    doReturn(rolapHierarchy_levels).when(rolapHierarchy).getLevels();
    doReturn(rolapHierarchy_uniqueName).when(rolapHierarchy).getUniqueName();
    RolapCubeHierarchy rch = new RolapCubeHierarchy(cubeDimension, cubeDim, rolapHierarchy, subName, ordinal, factCube);
    assertEquals("If factCube is null", true, rch.isUsingCubeFact());
    rch = new RolapCubeHierarchy(cubeDimension, cubeDim, rolapHierarchy, subName, ordinal);
    assertEquals("If factCube is not specified", true, rch.isUsingCubeFact());
}
Also used : DataSource(javax.sql.DataSource) Hierarchy(mondrian.olap.Hierarchy) MondrianDef(mondrian.olap.MondrianDef) Level(mondrian.olap.Level)

Example 20 with Hierarchy

use of mondrian.olap.Hierarchy in project mondrian by pentaho.

the class ExistingFunDef method compileCall.

public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
    final IterCalc setArg = compiler.compileIter(call.getArg(0));
    final Type myType = call.getArg(0).getType();
    return new AbstractListCalc(call, new Calc[] { setArg }) {

        public boolean dependsOn(Hierarchy hierarchy) {
            return myType.usesHierarchy(hierarchy, false);
        }

        public TupleList evaluateList(Evaluator evaluator) {
            TupleIterable setTuples = setArg.evaluateIterable(evaluator);
            TupleList result = TupleCollections.createList(setTuples.getArity());
            List<Member> contextMembers = Arrays.asList(evaluator.getMembers());
            List<Hierarchy> argDims = null;
            List<Hierarchy> contextDims = getHierarchies(contextMembers);
            for (List<Member> tuple : setTuples) {
                if (argDims == null) {
                    argDims = getHierarchies(tuple);
                }
                if (existsInTuple(tuple, contextMembers, argDims, contextDims, evaluator)) {
                    result.add(tuple);
                }
            }
            return result;
        }
    };
}
Also used : TupleList(mondrian.calc.TupleList) Hierarchy(mondrian.olap.Hierarchy) Type(mondrian.olap.type.Type) TupleIterable(mondrian.calc.TupleIterable) IterCalc(mondrian.calc.IterCalc) AbstractListCalc(mondrian.calc.impl.AbstractListCalc) Evaluator(mondrian.olap.Evaluator) Member(mondrian.olap.Member)

Aggregations

Hierarchy (mondrian.olap.Hierarchy)27 Level (mondrian.olap.Level)9 Member (mondrian.olap.Member)8 Role (mondrian.olap.Role)8 HierarchyAccess (mondrian.olap.Role.HierarchyAccess)7 MultiCardinalityDefaultMember (mondrian.rolap.RestrictedMemberReader.MultiCardinalityDefaultMember)6 MondrianDef (mondrian.olap.MondrianDef)5 DataSource (javax.sql.DataSource)4 Dimension (mondrian.olap.Dimension)4 mondrian.olap (mondrian.olap)3 Schema (mondrian.olap.Schema)3 RolapCube (mondrian.rolap.RolapCube)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 Axis (mondrian.olap.Axis)2 RelationOrJoin (mondrian.olap.MondrianDef.RelationOrJoin)2 LimitedRollupMember (mondrian.rolap.RolapHierarchy.LimitedRollupMember)2 Level (org.apache.log4j.Level)2