Search in sources :

Example 1 with MultiCardinalityDefaultMember

use of mondrian.rolap.RestrictedMemberReader.MultiCardinalityDefaultMember in project mondrian by pentaho.

the class SqlConstraintUtils method getRolesConstraints.

public static Map<RolapLevel, List<RolapMember>> getRolesConstraints(Evaluator evaluator) {
    Member[] mm = evaluator.getMembers();
    SchemaReader schemaReader = evaluator.getSchemaReader();
    Map<RolapLevel, List<RolapMember>> roleConstraints = new LinkedHashMap<RolapLevel, List<RolapMember>>(mm.length);
    for (Member member : mm) {
        boolean isRolesMember = (member instanceof LimitedRollupMember) || (member instanceof MultiCardinalityDefaultMember);
        if (isRolesMember) {
            List<Level> hierarchyLevels = schemaReader.getHierarchyLevels(member.getHierarchy());
            for (Level affectedLevel : hierarchyLevels) {
                List<Member> availableMembers = schemaReader.getLevelMembers(affectedLevel, false);
                List<RolapMember> slicerMembers = new ArrayList<RolapMember>(availableMembers.size());
                for (Member available : availableMembers) {
                    if (!available.isAll()) {
                        slicerMembers.add((RolapMember) available);
                    }
                }
                if (!slicerMembers.isEmpty()) {
                    roleConstraints.put((RolapLevel) affectedLevel, slicerMembers);
                }
            }
        }
    }
    return roleConstraints.isEmpty() ? Collections.<RolapLevel, List<RolapMember>>emptyMap() : roleConstraints;
}
Also used : SchemaReader(mondrian.olap.SchemaReader) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) LimitedRollupMember(mondrian.rolap.RolapHierarchy.LimitedRollupMember) MultiCardinalityDefaultMember(mondrian.rolap.RestrictedMemberReader.MultiCardinalityDefaultMember) List(java.util.List) FilteredIterableList(mondrian.util.FilteredIterableList) ArrayList(java.util.ArrayList) TupleList(mondrian.calc.TupleList) Level(mondrian.olap.Level) Member(mondrian.olap.Member) LimitedRollupMember(mondrian.rolap.RolapHierarchy.LimitedRollupMember) MultiCardinalityDefaultMember(mondrian.rolap.RestrictedMemberReader.MultiCardinalityDefaultMember)

Example 2 with MultiCardinalityDefaultMember

use of mondrian.rolap.RestrictedMemberReader.MultiCardinalityDefaultMember in project mondrian by pentaho.

the class RestrictedMemberReaderTest method testDefaultMember_noDefaultMember_roleAccess.

public void testDefaultMember_noDefaultMember_roleAccess() {
    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();
    List<RolapMember> rootMembers = Arrays.asList(new RolapMember[] { member0 });
    RolapMember hierDefaultMember = null;
    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(null).when(roleAccess).getAccess(anyRolapMember());
    Assert.assertSame("on Access is null", member0, rmr.getDefaultMember());
    Mockito.doReturn(Access.ALL).when(roleAccess).getAccess(anyRolapMember());
    Assert.assertSame("on Access.ALL", member0, rmr.getDefaultMember());
    Mockito.doReturn(Access.CUSTOM).when(roleAccess).getAccess(anyRolapMember());
    Assert.assertSame("on Access.CUSTOM", member0, rmr.getDefaultMember());
    Mockito.doReturn(Access.NONE).when(roleAccess).getAccess(anyRolapMember());
    Assert.assertNotSame("on Access.NONE", member0, rmr.getDefaultMember());
    Assert.assertTrue(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 3 with MultiCardinalityDefaultMember

use of mondrian.rolap.RestrictedMemberReader.MultiCardinalityDefaultMember in project mondrian by pentaho.

the class RestrictedMemberReaderTest method testDefaultMember_roleAccess.

public void testDefaultMember_roleAccess() {
    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();
    List<RolapMember> rootMembers = Arrays.asList(new RolapMember[] { member0 });
    RolapMember hierDefaultMember = member0;
    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(null).when(roleAccess).getAccess(anyRolapMember());
    Assert.assertSame("on Access is null", hierDefaultMember, rmr.getDefaultMember());
    Mockito.doReturn(Access.ALL).when(roleAccess).getAccess(anyRolapMember());
    Assert.assertSame("on Access.ALL", hierDefaultMember, rmr.getDefaultMember());
    Mockito.doReturn(Access.CUSTOM).when(roleAccess).getAccess(anyRolapMember());
    Assert.assertSame("on Access.CUSTOM", hierDefaultMember, rmr.getDefaultMember());
    Mockito.doReturn(Access.NONE).when(roleAccess).getAccess(anyRolapMember());
    Assert.assertNotSame("on Access.NONE", hierDefaultMember, rmr.getDefaultMember());
    Assert.assertTrue(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 4 with MultiCardinalityDefaultMember

use of mondrian.rolap.RestrictedMemberReader.MultiCardinalityDefaultMember in project mondrian by pentaho.

the class RestrictedMemberReaderTest method testDefaultMember_multiRootMeasure.

public void testDefaultMember_multiRootMeasure() {
    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(true).when(member0).isMeasure();
    Mockito.doReturn(true).when(member1).isMeasure();
    Mockito.doReturn(true).when(member1).isMeasure();
    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.assertSame("on Access C-N-C", member0, rmr.getDefaultMember());
    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 5 with MultiCardinalityDefaultMember

use of mondrian.rolap.RestrictedMemberReader.MultiCardinalityDefaultMember 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)

Aggregations

MultiCardinalityDefaultMember (mondrian.rolap.RestrictedMemberReader.MultiCardinalityDefaultMember)6 Role (mondrian.olap.Role)5 Hierarchy (mondrian.olap.Hierarchy)4 HierarchyAccess (mondrian.olap.Role.HierarchyAccess)4 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 TupleList (mondrian.calc.TupleList)2 Level (mondrian.olap.Level)2 Member (mondrian.olap.Member)2 LimitedRollupMember (mondrian.rolap.RolapHierarchy.LimitedRollupMember)2 FilteredIterableList (mondrian.util.FilteredIterableList)2 SchemaReader (mondrian.olap.SchemaReader)1