role.java
来自「数据仓库展示程序」· Java 代码 · 共 474 行 · 第 1/2 页
JAVA
474 行
public Hierarchy getHierarchy() {
return hierarchy;
}
public Level getTopLevel() {
return topLevel;
}
public Level getBottomLevel() {
return bottomLevel;
}
public Map getMemberGrants() {
return Collections.unmodifiableMap(memberGrants);
}
}
/**
* Defines access to a dimension.
*
* @param dimension Hierarchy whose access to grant/deny.
* @param access An {@link Access access code}
*
* @pre dimension != null
* @pre access == Access.ALL || access == Access.NONE
* @pre isMutable()
*/
public void grant(Dimension dimension, int access) {
Util.assertPrecondition(dimension != null, "dimension != null");
Util.assertPrecondition(access == Access.ALL || access == Access.NONE, "access == Access.ALL || access == Access.NONE");
Util.assertPrecondition(isMutable(), "isMutable()");
grants.put(dimension, toInteger(access));
}
/**
* Returns the access this role has to a given dimension.
*
* @pre dimension != null
* @post Access.instance().isValid(return)
*/
public int getAccess(Dimension dimension) {
Util.assertPrecondition(dimension != null, "dimension != null");
Integer i = (Integer) grants.get(dimension);
if (i != null) {
return toAccess(i);
}
// If the role has access to a cube this dimension is part of, that's
// good enough.
for (Iterator grantsIter = grants.keySet().iterator(); grantsIter.hasNext();) {
Object object = grantsIter.next();
if (!(object instanceof Cube)) {
continue;
}
final int access = toAccess((Integer) grants.get(object));
if (access == Access.NONE) {
continue;
}
final Dimension[] dimensions = ((Cube) object).getDimensions();
for (int j = 0; j < dimensions.length; j++) {
if (dimensions[j] == dimension) {
return access;
}
}
}
// Check access at the schema level.
switch (getAccess(dimension.getSchema())) {
case Access.ALL:
case Access.ALL_DIMENSIONS:
return Access.ALL;
default:
return Access.NONE;
}
}
/**
* Defines access to a hierarchy.
*
* @param hierarchy Hierarchy whose access to grant/deny.
* @param access An {@link Access access code}
* @param topLevel Top-most level which can be accessed, or null if the
* highest level. May only be specified if <code>access</code> is
* {@link Access#CUSTOM}.
* @param bottomLevel Bottom-most level which can be accessed, or null if
* the lowest level. May only be specified if <code>access</code> is
* {@link Access#CUSTOM}.
*
* @pre hierarchy != null
* @pre Access.instance().isValid(access)
* @pre (access == Access.CUSTOM) || (topLevel == null && bottomLevel == null)
* @pre topLevel == null || topLevel.getHierarchy() == hierarchy
* @pre bottomLevel == null || bottomLevel.getHierarchy() == hierarchy
* @pre isMutable()
*/
public void grant(Hierarchy hierarchy,
int access,
Level topLevel,
Level bottomLevel) {
Util.assertPrecondition(hierarchy != null, "hierarchy != null");
Util.assertPrecondition(Access.instance().isValid(access));
Util.assertPrecondition((access == Access.CUSTOM) || (topLevel == null && bottomLevel == null), "access == Access.CUSTOM) || (topLevel == null && bottomLevel == null)");
Util.assertPrecondition(topLevel == null || topLevel.getHierarchy() == hierarchy, "topLevel == null || topLevel.getHierarchy() == hierarchy");
Util.assertPrecondition(bottomLevel == null || bottomLevel.getHierarchy() == hierarchy, "bottomLevel == null || bottomLevel.getHierarchy() == hierarchy");
Util.assertPrecondition(isMutable(), "isMutable()");
grants.put(hierarchy, new HierarchyAccess(hierarchy, access, topLevel, bottomLevel));
}
/**
* Returns the access this role has to a given hierarchy.
*
* @pre hierarchy != null
* @post return == Access.NONE || return == Access.ALL || return == Access.CUSTOM
*/
public int getAccess(Hierarchy hierarchy) {
Util.assertPrecondition(hierarchy != null, "hierarchy != null");
HierarchyAccess access = (HierarchyAccess) grants.get(hierarchy);
if (access != null) {
return access.access;
}
return getAccess(hierarchy.getDimension());
}
/**
* Returns the details of this hierarchy's access, or null if the hierarchy
* has not been given explicit access.
*
* @pre hierarchy != null
*/
public HierarchyAccess getAccessDetails(Hierarchy hierarchy) {
Util.assertPrecondition(hierarchy != null, "hierarchy != null");
return (HierarchyAccess) grants.get(hierarchy);
}
/**
* Returns the access this role has to a given level.
*
* @pre level != null
* @post Access.instance().isValid(return)
*/
public int getAccess(Level level) {
Util.assertPrecondition(level != null, "level != null");
HierarchyAccess access = (HierarchyAccess) grants.get(level.getHierarchy());
if (access != null) {
if (access.topLevel != null &&
level.getDepth() < access.topLevel.getDepth()) {
return Access.NONE;
}
if (access.bottomLevel != null &&
level.getDepth() > access.bottomLevel.getDepth()) {
return Access.NONE;
}
return access.access;
}
return getAccess(level.getDimension());
}
/**
* Defines access to a member in a hierarchy.
*
* <p>Notes:<ol>
* <li>The order of grants matters. If you grant/deny access to a
* member, previous grants/denials to its descendants are ignored.</li>
* <li>Member grants do not supersde top/bottom levels set using {@link
* #grant(Hierarchy,int,Level,Level)}.
* <li>If you have access to a member, then you can see its ancestors
* <em>even those explicitly denied</em>, up to the top level.
* </ol>
*
* @pre member != null
* @pre Access.instance().isValid(access)
* @pre isMutable()
* @pre getAccess(member.getHierarchy()) == Access.CUSTOM
*/
public void grant(Member member, int access) {
Util.assertPrecondition(member != null, "member != null");
Util.assertPrecondition(Access.instance().isValid(access), "Access.instance().isValid(access)");
Util.assertPrecondition(isMutable(), "isMutable()");
Util.assertPrecondition(getAccess(member.getHierarchy()) == Access.CUSTOM, "getAccess(member.getHierarchy()) == Access.CUSTOM");
HierarchyAccess hierarchyAccess = (HierarchyAccess) grants.get(member.getHierarchy());
Util.assertTrue(hierarchyAccess != null && hierarchyAccess.access == Access.CUSTOM);
hierarchyAccess.grant(member, access);
}
/**
* Returns the access this role has to a given member.
*
* @pre member != null
* @pre isMutable()
* @post return == Access.NONE || return == Access.ALL || return == Access.CUSTOM
*/
public int getAccess(Member member) {
Util.assertPrecondition(member != null, "member != null");
HierarchyAccess hierarchyAccess = (HierarchyAccess)
grants.get(member.getHierarchy());
if (hierarchyAccess != null) {
return hierarchyAccess.getAccess(member);
}
return getAccess(member.getDimension());
}
/**
* Returns the access this role has to a given named set.
*
* @pre set != null
* @pre isMutable()
* @post return == Access.NONE || return == Access.ALL
*/
public int getAccess(NamedSet set) {
Util.assertPrecondition(set != null, "set != null");
return Access.ALL;
}
/**
* Returns whether this role is allowed to see a given element.
* @pre olapElement != null
*/
public boolean canAccess(OlapElement olapElement) {
Util.assertPrecondition(olapElement != null, "olapElement != null");
if (olapElement instanceof Cube) {
return getAccess((Cube) olapElement) != Access.NONE;
} else if (olapElement instanceof Dimension) {
return getAccess((Dimension) olapElement) != Access.NONE;
} else if (olapElement instanceof Hierarchy) {
return getAccess((Hierarchy) olapElement) != Access.NONE;
} else if (olapElement instanceof Level) {
return getAccess((Level) olapElement) != Access.NONE;
} else if (olapElement instanceof Member) {
return getAccess((Member) olapElement) != Access.NONE;
} else if (olapElement instanceof NamedSet) {
return getAccess((NamedSet) olapElement) != Access.NONE;
} else {
return false;
}
}
}
// End Role.java
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?