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