Skip to content

Instantly share code, notes, and snippets.

@standino
Created September 9, 2014 07:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save standino/75198cd6f4e78ec8bfeb to your computer and use it in GitHub Desktop.
Save standino/75198cd6f4e78ec8bfeb to your computer and use it in GitHub Desktop.
SaikuMondrianHelper.java setRoles
public static class PeopleRole extends DelegatingRole {
private final String repName;
public PeopleRole(Role role, Schema schema, String repName) {
super(((RoleImpl)role).makeMutableClone());
this.repName = repName;
defineGrantsForUser(schema);
defineGrantsForCategory(schema);
}
private void defineGrantsForUser(Schema schema) {
RoleImpl role = (RoleImpl)this.role;
role.grant(schema, Access.NONE);
Cube cube = schema.lookupCube("采销财务大表", true);
role.grant(cube, Access.ALL);
Hierarchy hierarchy = cube.lookupHierarchy(
new Id.NameSegment("部门"), false);
mondrian.olap.Level[] levels = hierarchy.getLevels();
mondrian.olap.Level topLevel = levels[6];
role.grant(hierarchy, Access.CUSTOM, null, null, RollupPolicy.FULL);
role.grant(hierarchy.getAllMember(), Access.NONE);
boolean foundMember = false;
List <Member> members =
schema.getSchemaReader().withLocus()
.getLevelMembers(topLevel, true);
for (Member member : members) {
// System.out.println("memeber unique name"+member.getUniqueName());
if (member.getUniqueName().contains("[" + repName + "]")) {
foundMember = true;
role.grant(member, Access.ALL);
}
}
}
private void defineGrantsForCategory(Schema schema) {
RoleImpl role = (RoleImpl)this.role;
role.grant(schema, Access.NONE);
Cube cube = schema.lookupCube("采销财务大表", true);
role.grant(cube, Access.ALL);
Hierarchy hierarchy = cube.lookupHierarchy(
new Id.NameSegment("分类"), false);
mondrian.olap.Level[] levels = hierarchy.getLevels();
mondrian.olap.Level topLevel = levels[6];
role.grant(hierarchy, Access.CUSTOM, null, null, RollupPolicy.FULL);
role.grant(hierarchy.getAllMember(), Access.NONE);
boolean foundMember = false;
List <Member> members =
schema.getSchemaReader().withLocus()
.getLevelMembers(topLevel, true);
for (Member member : members) {
// System.out.println("memeber unique name"+member.getUniqueName());
if (member.getUniqueName().contains("[" + 3396 + "]")) {
foundMember = true;
role.grant(member, Access.ALL);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment