Skip to content

Commit

Permalink
MONDRIAN: Makes HierarchyAccessImpl.topLevel and HierarchyAccessImpl.…
Browse files Browse the repository at this point in the history
…bottomLevel never null.

[git-p4: depot-paths = "//open/mondrian/": change = 14551]
  • Loading branch information
lucboudreau committed Aug 15, 2011
1 parent 1fe8d16 commit 23d4125
Showing 1 changed file with 27 additions and 33 deletions.
60 changes: 27 additions & 33 deletions src/main/mondrian/olap/RoleImpl.java
Expand Up @@ -22,7 +22,7 @@
* <code>RoleImpl</code> is Mondrian's default implementation for the
* <code>Role</code> interface.
*
* @author jhyde
* @author jhyde, lucboudreau
* @since Oct 5, 2002
* @version $Id$
*/
Expand Down Expand Up @@ -348,8 +348,8 @@ public HierarchyAccess getAccessDetails(Hierarchy hierarchy) {
this,
hierarchy,
hierarchyAccess,
hierarchy.getLevels()[0],
hierarchy.getLevels()[hierarchy.getLevels().length - 1],
null,
null,
RollupPolicy.HIDDEN);
}

Expand Down Expand Up @@ -379,14 +379,10 @@ private static boolean checkLevelIsOkWithRestrictions(
{
// Check if this level is explicitly excluded by top/bototm
// level restrictions.
if (hierarchyAccess.topLevel != null
&& level.getDepth() < hierarchyAccess.topLevel.getDepth())
{
if (level.getDepth() < hierarchyAccess.topLevel.getDepth()) {
return false;
}
if (hierarchyAccess.bottomLevel != null
&& level.getDepth() > hierarchyAccess.bottomLevel.getDepth())
{
if (level.getDepth() > hierarchyAccess.bottomLevel.getDepth()) {
return false;
}
return true;
Expand Down Expand Up @@ -468,11 +464,9 @@ public boolean canAccess(OlapElement olapElement) {
* @return element representing all access to a given hierarchy
*/
public static HierarchyAccess createAllAccess(Hierarchy hierarchy) {
final Level[] levels = hierarchy.getLevels();
return new HierarchyAccessImpl(
Util.createRootRole(hierarchy.getDimension().getSchema()),
hierarchy, Access.ALL, levels[0],
levels[levels.length - 1], Role.RollupPolicy.FULL);
hierarchy, Access.ALL, null, null, Role.RollupPolicy.FULL);
}

/**
Expand Down Expand Up @@ -502,7 +496,15 @@ private static class HierarchyAccessImpl implements Role.HierarchyAccess {
private final Role role;

/**
* Creates a <code>HierarchyAccessImpl</code>
* Creates a <code>HierarchyAccessImpl</code>.
* @param role A role this access belongs to.
* @param hierarchy A hierarchy this object describes.
* @param access The access granted to this role for this hierarchy.
* @param topLevel The top level to restrict the role to, or null to
* grant access up top the top level of the hierarchy parameter.
* @param bottomLevel The bottom level to restrict the role to, or null
* to grant access down to the bottom level of the hierarchy parameter.
* @param rollupPolicy The rollup policy to apply.
*/
HierarchyAccessImpl(
Role role,
Expand All @@ -512,14 +514,20 @@ private static class HierarchyAccessImpl implements Role.HierarchyAccess {
Level bottomLevel,
RollupPolicy rollupPolicy)
{
this.role = role;
assert role != null;
assert hierarchy != null;
assert access != null;
assert rollupPolicy != null;
this.role = role;
this.hierarchy = hierarchy;
this.access = access;
this.topLevel = topLevel;
this.bottomLevel = bottomLevel;
assert rollupPolicy != null;
this.rollupPolicy = rollupPolicy;
this.topLevel = topLevel == null
? hierarchy.getLevels()[0]
: topLevel;
this.bottomLevel = bottomLevel == null
? hierarchy.getLevels()[hierarchy.getLevels().length - 1]
: bottomLevel;
}

public HierarchyAccess clone() {
Expand Down Expand Up @@ -649,8 +657,6 @@ public Access getAccess(Member member) {
// member grants defined at this level but the member fits
// those bounds, we give access.
if (memberGrants.size() == 0
&& (bottomLevel != null
|| topLevel != null)
&& checkLevelIsOkWithRestrictions(
this,
member.getLevel()))
Expand All @@ -661,24 +667,12 @@ && checkLevelIsOkWithRestrictions(
return Access.NONE;
}

Level getTopLevel() {
return topLevel == null
? hierarchy.getLevels()[0]
: topLevel;
}

public final int getTopLevelDepth() {
return getTopLevel().getDepth();
}

Level getBottomLevel() {
return bottomLevel == null
? hierarchy.getLevels()[hierarchy.getLevels().length - 1]
: bottomLevel;
return topLevel.getDepth();
}

public final int getBottomLevelDepth() {
return getBottomLevel().getDepth();
return bottomLevel.getDepth();
}

public RollupPolicy getRollupPolicy() {
Expand Down

0 comments on commit 23d4125

Please sign in to comment.