1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
package pt.digitalis.dif.controller.security.objects; |
7 | |
|
8 | |
import java.util.Map; |
9 | |
import java.util.Set; |
10 | |
|
11 | |
import pt.digitalis.dif.controller.security.managers.IIdentityManager; |
12 | |
import pt.digitalis.dif.exception.security.IdentityManagerException; |
13 | |
import pt.digitalis.dif.ioc.DIFIoCRegistry; |
14 | |
import pt.digitalis.dif.utils.ObjectFormatter; |
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | 0 | public class DIFGroupImpl implements IDIFGroup { |
23 | |
|
24 | |
|
25 | 0 | static private IIdentityManager identityManager = DIFIoCRegistry.getRegistry().getImplementation( |
26 | 0 | IIdentityManager.class); |
27 | |
|
28 | |
|
29 | |
private String groupDescription; |
30 | |
|
31 | |
|
32 | |
private String groupID; |
33 | |
|
34 | |
|
35 | |
private String groupName; |
36 | |
|
37 | |
|
38 | |
private boolean isDefault; |
39 | |
|
40 | |
|
41 | |
private String parentGroup; |
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | 0 | public DIFGroupImpl() |
47 | 0 | {} |
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | 0 | public DIFGroupImpl(IDIFGroup group) |
56 | |
{ |
57 | 0 | this.groupID = group.getID(); |
58 | 0 | this.groupName = group.getName(); |
59 | 0 | this.groupDescription = group.getDescription(); |
60 | 0 | this.parentGroup = group.getParentGroupID(); |
61 | 0 | } |
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
@Override |
67 | |
protected Object clone() throws CloneNotSupportedException |
68 | |
{ |
69 | 0 | return new DIFGroupImpl(this); |
70 | |
} |
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
public IDIFGroup cloneGroup() |
76 | |
{ |
77 | |
try |
78 | |
{ |
79 | 0 | return (IDIFGroup) this.clone(); |
80 | |
} |
81 | 0 | catch (CloneNotSupportedException e) |
82 | |
{ |
83 | 0 | return null; |
84 | |
} |
85 | |
} |
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
@Override |
91 | |
public boolean equals(Object obj) |
92 | |
{ |
93 | 0 | if (this == obj) |
94 | 0 | return true; |
95 | 0 | if (obj == null) |
96 | 0 | return false; |
97 | 0 | if (getClass() != obj.getClass()) |
98 | 0 | return false; |
99 | 0 | DIFGroupImpl other = (DIFGroupImpl) obj; |
100 | 0 | if (groupID == null) |
101 | |
{ |
102 | 0 | if (other.groupID != null) |
103 | 0 | return false; |
104 | |
} |
105 | 0 | else if (!groupID.equals(other.groupID)) |
106 | 0 | return false; |
107 | 0 | return true; |
108 | |
} |
109 | |
|
110 | |
|
111 | |
public String getDescription() |
112 | |
{ |
113 | 0 | return this.groupDescription; |
114 | |
} |
115 | |
|
116 | |
|
117 | |
public String getID() |
118 | |
{ |
119 | 0 | return this.groupID; |
120 | |
} |
121 | |
|
122 | |
|
123 | |
public String getName() |
124 | |
{ |
125 | 0 | return this.groupName; |
126 | |
} |
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
public IDIFGroup getParentGroup() throws IdentityManagerException |
132 | |
{ |
133 | 0 | return DIFGroupImpl.identityManager.getGroup(this.getParentGroupID()); |
134 | |
} |
135 | |
|
136 | |
|
137 | |
public String getParentGroupID() |
138 | |
{ |
139 | 0 | return this.parentGroup; |
140 | |
} |
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
public Set<String> getUserIDs() throws IdentityManagerException |
146 | |
{ |
147 | 0 | return identityManager.getUserIDsInGroup(groupID); |
148 | |
} |
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
public Map<String, IDIFUser> getUsers() throws IdentityManagerException |
154 | |
{ |
155 | 0 | return identityManager.getGroupUsers(groupID); |
156 | |
} |
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
@Override |
162 | |
public int hashCode() |
163 | |
{ |
164 | 0 | final int prime = 31; |
165 | 0 | int result = 1; |
166 | 0 | result = prime * result + ((groupID == null) ? 0 : groupID.hashCode()); |
167 | 0 | return result; |
168 | |
} |
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | |
public boolean isDefault() |
174 | |
{ |
175 | 0 | return this.isDefault; |
176 | |
} |
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
public void setDefault(boolean isDefault) |
182 | |
{ |
183 | 0 | this.isDefault = isDefault; |
184 | 0 | } |
185 | |
|
186 | |
|
187 | |
public void setDescription(String newDescription) |
188 | |
{ |
189 | 0 | this.groupDescription = newDescription; |
190 | 0 | } |
191 | |
|
192 | |
|
193 | |
public void setID(String newGroupId) |
194 | |
{ |
195 | 0 | this.groupID = newGroupId; |
196 | 0 | } |
197 | |
|
198 | |
|
199 | |
public void setName(String newName) |
200 | |
{ |
201 | 0 | this.groupName = newName; |
202 | 0 | } |
203 | |
|
204 | |
|
205 | |
public void setParentGroupID(String newParent) |
206 | |
{ |
207 | 0 | this.parentGroup = newParent; |
208 | 0 | } |
209 | |
|
210 | |
|
211 | |
|
212 | |
|
213 | |
@Override |
214 | |
public String toString() |
215 | |
{ |
216 | 0 | ObjectFormatter formatter = new ObjectFormatter(); |
217 | |
|
218 | 0 | formatter.addItem("ID", getID()); |
219 | 0 | formatter.addItemIfNotNull("Name", getName()); |
220 | 0 | formatter.addItemIfNotNull("Description", getDescription()); |
221 | 0 | formatter.addItemIfNotNull("Parent Group", getParentGroupID()); |
222 | |
|
223 | 0 | return formatter.getFormatedObject(); |
224 | |
} |
225 | |
} |