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, Set<JaxbRole> roles) {
110 this(groupId, organization, name, description);
111 this.roles = roles;
112 }
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130 public JaxbGroup(String groupId, JaxbOrganization organization, String name, String description, Set<JaxbRole> roles,
131 Set<String> members) {
132 this(groupId, organization, name, description, roles);
133 this.members = members;
134 }
135
136 public static JaxbGroup fromGroup(Group group) {
137 JaxbOrganization organization = JaxbOrganization.fromOrganization(group.getOrganization());
138 Set<JaxbRole> roles = new HashSet<JaxbRole>();
139 for (Role role : group.getRoles()) {
140 if (role instanceof JaxbRole) {
141 roles.add((JaxbRole) role);
142 } else {
143 roles.add(JaxbRole.fromRole(role));
144 }
145 }
146 return new JaxbGroup(group.getGroupId(), organization, group.getName(), group.getDescription(), roles,
147 group.getMembers());
148 }
149
150
151
152
153 @Override
154 public String getGroupId() {
155 return groupId;
156 }
157
158
159
160
161 @Override
162 public String getName() {
163 return name;
164 }
165
166
167
168
169 @Override
170 public Organization getOrganization() {
171 return organization;
172 }
173
174
175
176
177 @Override
178 public String getDescription() {
179 return description;
180 }
181
182
183
184
185 @Override
186 public String getRole() {
187 return role;
188 }
189
190
191
192
193 @Override
194 public Set<String> getMembers() {
195 return members;
196 }
197
198
199
200
201 @Override
202 public Set<Role> getRoles() {
203 return new HashSet<Role>(roles);
204 }
205
206
207
208
209
210
211 @Override
212 public int hashCode() {
213 return EqualsUtil.hash(groupId, organization);
214 }
215
216
217
218
219
220
221 @Override
222 public boolean equals(Object obj) {
223 if (!(obj instanceof Group))
224 return false;
225 Group other = (Group) obj;
226 return groupId.equals(other.getGroupId()) && organization.equals(other.getOrganization());
227 }
228
229
230
231
232
233
234 @Override
235 public String toString() {
236 return new StringBuilder(groupId).append(":").append(organization).toString();
237 }
238
239 }