1 13 14 package mondrian.olap; 15 import mondrian.resource.MondrianResource; 16 17 import java.util.List ; 18 import java.util.ArrayList ; 19 20 24 public class CubeAccess { 25 26 private boolean hasRestrictions; 27 28 private Hierarchy[] noAccessHierarchies; 29 30 private Member[] limitedMembers; 31 private final List <Hierarchy> hierarchyList = new ArrayList <Hierarchy>(); 32 private final List <Member> memberList = new ArrayList <Member>(); 33 private final Cube mdxCube; 34 35 43 public CubeAccess(Cube mdxCube) { 44 this.mdxCube = mdxCube; 45 noAccessHierarchies = null; 46 limitedMembers = null; 47 hasRestrictions = false; 48 } 49 50 public boolean hasRestrictions() { 51 return hasRestrictions; 52 } 53 54 public Hierarchy[] getNoAccessHierarchies() { 55 return noAccessHierarchies; 56 } 57 58 public Member[] getLimitedMembers() { 59 return limitedMembers; 60 } 61 62 public List <Hierarchy> getNoAccessHierarchyList() { 63 return hierarchyList; 64 } 65 66 public List <Member> getLimitedMemberList() { 67 return memberList; 68 } 69 70 public boolean isHierarchyAllowed(Hierarchy mdxHierarchy) { 71 String hierName = mdxHierarchy.getUniqueName(); 72 if(noAccessHierarchies == null || hierName == null) { 73 return true; 74 } 75 for (Hierarchy noAccessHierarchy : noAccessHierarchies) { 76 if (hierName.equalsIgnoreCase(noAccessHierarchy.getUniqueName())) { 77 return false; 78 } 79 } 80 return true; 81 } 82 83 public Member getLimitedMemberForHierarchy(Hierarchy mdxHierarchy) { 84 String hierName = mdxHierarchy.getUniqueName(); 85 if (limitedMembers == null || hierName == null) { 86 return null; 87 } 88 for (Member limitedMember : limitedMembers) { 89 Hierarchy limitedHierarchy = limitedMember.getHierarchy(); 90 if (hierName.equalsIgnoreCase(limitedHierarchy.getUniqueName())) { 91 return limitedMember; 92 } 93 } 94 return null; 95 } 96 97 100 public void addGrantCubeSlicer(String sHierarchy, 101 String sMember, 102 boolean bMember) { 103 if (bMember) { 104 boolean fail = false; 105 String [] sMembers = Util.explode(sMember); 106 SchemaReader schemaReader = mdxCube.getSchemaReader(null); 107 Member member = schemaReader.getMemberByUniqueName(sMembers, fail); 108 if (member == null) { 109 throw MondrianResource.instance().MdxCubeSlicerMemberError.ex( 110 sMember, sHierarchy, mdxCube.getUniqueName()); 111 } 112 if (getLimitedMemberForHierarchy(member.getHierarchy()) == null) { 114 memberList.add(member); 115 } 116 } else { 117 boolean fail = false; 118 Hierarchy hierarchy = mdxCube.lookupHierarchy(sHierarchy, fail); 119 if (hierarchy == null) { 120 throw MondrianResource.instance().MdxCubeSlicerHierarchyError.ex( 121 sHierarchy, mdxCube.getUniqueName()); 122 } 123 hierarchyList.add(hierarchy); 124 } 125 } 126 127 131 public void normalizeCubeAccess() { 132 if (memberList.size() > 0) { 133 limitedMembers = memberList.toArray(new Member[memberList.size()]); 134 hasRestrictions = true; 135 } 136 if (hierarchyList.size() > 0) { 137 noAccessHierarchies = 138 hierarchyList.toArray( 139 new Hierarchy[ hierarchyList.size()]); 140 hasRestrictions = true; 141 } 142 } 143 144 public boolean equals(Object object) { 145 if (!(object instanceof CubeAccess)) { 146 return false; 147 } 148 CubeAccess cubeAccess = (CubeAccess) object; 149 List <Hierarchy> hierarchyList = cubeAccess.getNoAccessHierarchyList(); 150 List <Member> limitedMemberList = cubeAccess.getLimitedMemberList(); 151 152 if ((this.hierarchyList.size() != hierarchyList.size()) || 153 (this.memberList.size() != limitedMemberList.size())) { 154 return false; 155 } 156 for (Hierarchy o : hierarchyList) { 157 if (!this.hierarchyList.contains(o)) { 158 return false; 159 } 160 } 161 for (Member member : limitedMemberList) { 162 if (!this.memberList.contains(member)) { 163 return false; 164 } 165 } 166 return true; 167 } 168 } 169 170 | Popular Tags |