Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
RoleHierarchyBean |
|
| 1.0;1 |
1 | /* | |
2 | * Copyright (c) 2009, Swiss Federal Department of Defence Civil Protection and Sport | |
3 | * (http://www.vbs.admin.ch) | |
4 | * Copyright (c) 2009, Ergon Informatik AG (http://www.ergon.ch) | |
5 | * All rights reserved. | |
6 | * | |
7 | * Licensed under the Open Permis License which accompanies this distribution, | |
8 | * and is available at http://www.openpermis.org/BSDlicenceKent.txt | |
9 | */ | |
10 | package org.openpermis.policy.bean; | |
11 | ||
12 | import java.util.Set; | |
13 | ||
14 | import org.openpermis.policy.RoleHierarchy; | |
15 | ||
16 | /** | |
17 | * A hierarchy of roles. | |
18 | * @since 0.1.0 | |
19 | */ | |
20 | public interface RoleHierarchyBean | |
21 | extends RoleHierarchy, PartBean, IdentifiableBean | |
22 | { | |
23 | ||
24 | //---- Reading Methods | |
25 | ||
26 | /** | |
27 | * @param role the role to search. | |
28 | * @return if role exists | |
29 | * @since 0.3.0 | |
30 | */ | |
31 | public boolean roleExists (String role); | |
32 | ||
33 | /** | |
34 | * Returns a list of all roles in this hierarchy. | |
35 | * @return list of roles in this hierarchy. | |
36 | * @since 0.1.0 | |
37 | */ | |
38 | public Set<String> getRoles (); | |
39 | ||
40 | /** | |
41 | * Returns a list of all roles with no parents. | |
42 | * @return list of all roles with no parents. | |
43 | * @since 0.3.0 | |
44 | */ | |
45 | public Set<String> getRootRoles (); | |
46 | ||
47 | /** | |
48 | * Returns a list of all roles with no children. | |
49 | * precondition: role exists. | |
50 | * @return list of all roles with no children. | |
51 | * @since 0.3.0 | |
52 | */ | |
53 | public Set<String> getLeafRoles (); | |
54 | ||
55 | /** | |
56 | * Returns a unmodifiable list of all children. | |
57 | * precondition: role exists. | |
58 | * @return list of children roles. | |
59 | * @since 0.3.0 | |
60 | */ | |
61 | public Set<String> getChildRoles (String role); | |
62 | ||
63 | /** | |
64 | * Returns a unmodifiable list of all parents. | |
65 | * precondition: role exists. | |
66 | * @return list of parent roles. | |
67 | * @since 0.3.0 | |
68 | */ | |
69 | public Set<String> getParentRoles (String role); | |
70 | ||
71 | /** | |
72 | * Returns true if role is root, i.e. has no parents. | |
73 | * precondition: role exists. | |
74 | * @param role the role to check. | |
75 | * @return {@code true} if found. | |
76 | * @since 0.3.0 | |
77 | */ | |
78 | public boolean isRootRole (String role); | |
79 | ||
80 | /** | |
81 | * Returns true if role is leaf, i.e. has no children. | |
82 | * precondition: role exists. | |
83 | * @param role the role to check. | |
84 | * @return {@code true} if found. | |
85 | * @since 0.3.0 | |
86 | */ | |
87 | public boolean isLeafRole (String role); | |
88 | ||
89 | /** | |
90 | * Returns true if subRole is a sub-role of role. | |
91 | * precondition: both roles exist. | |
92 | * @param role the role to start search from. | |
93 | * @param subRole the role to find. | |
94 | * @return {@code true} if found. | |
95 | * @since 0.3.0 | |
96 | */ | |
97 | public boolean isSubRole (String role, String subRole); | |
98 | ||
99 | /** | |
100 | * Returns true if superRole is a super-role of role. | |
101 | * precondition: both roles exist. | |
102 | * @param role the role to start search from.. | |
103 | * @param superRole the role to find. | |
104 | * @return {@code true} if found. | |
105 | * @since 0.3.0 | |
106 | */ | |
107 | public boolean isSuperRole (String role, String superRole); | |
108 | ||
109 | /** | |
110 | * Returns true if childRole is a child-role of role. | |
111 | * precondition: both roles exist. | |
112 | * @param role the role to start search from.. | |
113 | * @param childRole the role to find. | |
114 | * @return {@code true} if found. | |
115 | * @since 0.3.0 | |
116 | */ | |
117 | public boolean isChildRole (String role, String childRole); | |
118 | ||
119 | /** | |
120 | * Returns true if parentRole is a parent-role of role. | |
121 | * precondition: both roles exist. | |
122 | * @param role the role to start search from.. | |
123 | * @param parentRole the role to find. | |
124 | * @return {@code true} if found. | |
125 | * @since 0.3.0 | |
126 | */ | |
127 | public boolean isParentRole (String role, String parentRole); | |
128 | ||
129 | ||
130 | //---- Changing Methods | |
131 | ||
132 | /** | |
133 | * Set new children roles of a role. | |
134 | * precondition: all roles exist. | |
135 | * @param role role to set children for. | |
136 | * @param childrenRoles children roles to set | |
137 | * @since 0.3.0 | |
138 | */ | |
139 | public void setChildRoles (String role, Set<String> childrenRoles); | |
140 | ||
141 | /** | |
142 | * Set new parent roles of a role. | |
143 | * precondition: all roles exist. | |
144 | * @param role role to set parents for. | |
145 | * @param parentRoles parent roles to set | |
146 | * @since 0.3.0 | |
147 | */ | |
148 | public void setParentRoles (String role, Set<String> parentRoles); | |
149 | ||
150 | /** | |
151 | * Convenience method: | |
152 | * add an edge between two roles. | |
153 | * Nothing is done if either role is null oder edge already exists. | |
154 | * @param parentRole parent role. | |
155 | * @param childRole child role | |
156 | * @return {@code true} if edge was added | |
157 | * @since 0.3.0 | |
158 | */ | |
159 | public boolean connectRoles (String parentRole, String childRole); | |
160 | ||
161 | /** | |
162 | * Convenience method: | |
163 | * remove an edge between two roles. | |
164 | * Nothing is done if either role is null oder edge not exists. | |
165 | * @param parentRole parent role. | |
166 | * @param childRole child role | |
167 | * @return {@code true} if edge was removed | |
168 | * @since 0.3.0 | |
169 | */ | |
170 | public boolean disconnectRoles (String parentRole, String childRole); | |
171 | ||
172 | /** | |
173 | * Adds a new role in this role hierarchy. | |
174 | * precondition: role not yet exists. | |
175 | * @param role the new role to be added. | |
176 | * @since 0.3.0 | |
177 | */ | |
178 | public void addRole (String role); | |
179 | ||
180 | /** | |
181 | * Adds a new role in this role hierarchy. | |
182 | * precondition: role not yet exists, parentRole exists. | |
183 | * @param role the new role to be added. | |
184 | * @param parentRole the parent where the role is appended. | |
185 | * @since 0.3.0 | |
186 | */ | |
187 | public void addRole (String role, String parentRole); | |
188 | ||
189 | /** | |
190 | * Adds a new role in this role hierarchy. | |
191 | * precondition: role not yet exists, parentRoles exist. | |
192 | * @param role the new role to be added. | |
193 | * @param parentRoles the parents where the role is appended. | |
194 | * @since 0.3.0 | |
195 | */ | |
196 | public void addRole (String role, Set<String> parentRoles); | |
197 | ||
198 | /** | |
199 | * Removes a role from role hierarchy. | |
200 | * precondition: role exists. | |
201 | * @param role the role to be removed. | |
202 | * @since 0.3.0 | |
203 | */ | |
204 | public void removeRole (String role); | |
205 | ||
206 | /** | |
207 | * Renames an existing role. | |
208 | * <p>The renamed role will keep its super and sub roles. | |
209 | * @param role the role to be renamed. | |
210 | * @param newName the new name for the role | |
211 | * @return {@code true} if role was renamed. | |
212 | * @since 0.3.0 | |
213 | */ | |
214 | public boolean renameRole (String role, String newName); | |
215 | ||
216 | } |