1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.opencastproject.security.api;
23
24 import org.opencastproject.util.EqualsUtil;
25
26 import java.util.HashSet;
27 import java.util.Set;
28
29 import javax.xml.bind.annotation.XmlAccessType;
30 import javax.xml.bind.annotation.XmlAccessorType;
31 import javax.xml.bind.annotation.XmlElement;
32 import javax.xml.bind.annotation.XmlElementWrapper;
33 import javax.xml.bind.annotation.XmlRootElement;
34 import javax.xml.bind.annotation.XmlType;
35
36
37
38
39 @XmlAccessorType(XmlAccessType.FIELD)
40 @XmlType(name = "group", namespace = "http://org.opencastproject.security")
41 @XmlRootElement(name = "group", namespace = "http://org.opencastproject.security")
42 public final class JaxbGroup implements Group {
43
44 @XmlElement(name = "id")
45 protected String groupId;
46
47 @XmlElement(name = "organization")
48 protected JaxbOrganization organization;
49
50 @XmlElement(name = "name")
51 protected String name;
52
53 @XmlElement(name = "description")
54 protected String description;
55
56 @XmlElement(name = "role")
57 protected String role;
58
59 @XmlElement(name = "member")
60 @XmlElementWrapper(name = "members")
61 protected Set<String> members;
62
63 @XmlElement(name = "role")
64 @XmlElementWrapper(name = "roles")
65 protected Set<JaxbRole> roles;
66
67
68
69
70 public JaxbGroup() {
71 }
72
73
74
75
76
77
78
79
80
81
82
83
84
85 public JaxbGroup(String groupId, JaxbOrganization organization, String name, String description) {
86 super();
87 this.groupId = groupId;
88 this.organization = organization;
89 this.name = name;
90 this.description = description;
91 this.role = ROLE_PREFIX + groupId.toUpperCase();
92 this.roles = new HashSet<JaxbRole>();
93 }
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109 public JaxbGroup(String groupId, JaxbOrganization organization, String name, String description,
110 Set<JaxbRole> roles) {
111 this(groupId, organization, name, description);
112 this.roles = roles;
113 }
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131 public JaxbGroup(String groupId, JaxbOrganization organization, String name, String description, Set<JaxbRole> roles,
132 Set<String> members) {
133 this(groupId, organization, name, description, roles);
134 this.members = members;
135 }
136
137 public static JaxbGroup fromGroup(Group group) {
138 JaxbOrganization organization = JaxbOrganization.fromOrganization(group.getOrganization());
139 Set<JaxbRole> roles = new HashSet<JaxbRole>();
140 for (Role role : group.getRoles()) {
141 if (role instanceof JaxbRole) {
142 roles.add((JaxbRole) role);
143 } else {
144 roles.add(JaxbRole.fromRole(role));
145 }
146 }
147 return new JaxbGroup(group.getGroupId(), organization, group.getName(), group.getDescription(), roles,
148 group.getMembers());
149 }
150
151
152
153
154 @Override
155 public String getGroupId() {
156 return groupId;
157 }
158
159
160
161
162 @Override
163 public String getName() {
164 return name;
165 }
166
167
168
169
170 @Override
171 public Organization getOrganization() {
172 return organization;
173 }
174
175
176
177
178 @Override
179 public String getDescription() {
180 return description;
181 }
182
183
184
185
186 @Override
187 public String getRole() {
188 return role;
189 }
190
191
192
193
194 @Override
195 public Set<String> getMembers() {
196 return members;
197 }
198
199
200
201
202 @Override
203 public Set<Role> getRoles() {
204 return new HashSet<Role>(roles);
205 }
206
207
208
209
210
211
212 @Override
213 public int hashCode() {
214 return EqualsUtil.hash(groupId, organization);
215 }
216
217
218
219
220
221
222 @Override
223 public boolean equals(Object obj) {
224 if (!(obj instanceof Group)) {
225 return false;
226 }
227 Group other = (Group) obj;
228 return groupId.equals(other.getGroupId()) && organization.equals(other.getOrganization());
229 }
230
231
232
233
234
235
236 @Override
237 public String toString() {
238 return new StringBuilder(groupId).append(":").append(organization).toString();
239 }
240
241 }