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.ArrayList;
27 import java.util.HashMap;
28 import java.util.List;
29 import java.util.Map;
30 import java.util.Map.Entry;
31
32 import javax.xml.bind.annotation.XmlAccessType;
33 import javax.xml.bind.annotation.XmlAccessorType;
34 import javax.xml.bind.annotation.XmlAttribute;
35 import javax.xml.bind.annotation.XmlElement;
36 import javax.xml.bind.annotation.XmlElementWrapper;
37 import javax.xml.bind.annotation.XmlID;
38 import javax.xml.bind.annotation.XmlRootElement;
39 import javax.xml.bind.annotation.XmlType;
40 import javax.xml.bind.annotation.XmlValue;
41
42
43
44
45 @XmlAccessorType(XmlAccessType.FIELD)
46 @XmlType(name = "organization", namespace = "http://org.opencastproject.security")
47 @XmlRootElement(name = "organization", namespace = "http://org.opencastproject.security")
48 public class JaxbOrganization implements Organization {
49
50
51 @XmlID
52 @XmlAttribute
53 protected String id = null;
54
55
56 @XmlElement(name = "name")
57 protected String name = null;
58
59
60 @XmlElement(name = "server")
61 @XmlElementWrapper(name = "servers")
62 protected List<OrgServer> servers = null;
63
64
65 @XmlElement(name = "adminRole")
66 protected String adminRole = null;
67
68
69 @XmlElement(name = "anonymousRole")
70 protected String anonymousRole = null;
71
72
73 @XmlElement(name = "property")
74 @XmlElementWrapper(name = "properties")
75 protected List<OrgProperty> properties = null;
76
77
78
79
80 public JaxbOrganization() {
81 }
82
83 public JaxbOrganization(String orgId) {
84 this.id = orgId;
85 }
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103 public JaxbOrganization(String id, String name, Map<String, Integer> servers, String adminRole, String anonymousRole,
104 Map<String, String> properties) {
105 this();
106 this.id = id;
107 this.name = name;
108 this.servers = new ArrayList<JaxbOrganization.OrgServer>();
109 if (servers != null && !servers.isEmpty()) {
110 for (Entry<String, Integer> entry : servers.entrySet()) {
111 this.servers.add(new OrgServer(entry.getKey(), entry.getValue()));
112 }
113 }
114 this.adminRole = adminRole;
115 this.anonymousRole = anonymousRole;
116 this.properties = new ArrayList<JaxbOrganization.OrgProperty>();
117 if (properties != null && !properties.isEmpty()) {
118 for (Entry<String, String> entry : properties.entrySet()) {
119 this.properties.add(new OrgProperty(entry.getKey(), entry.getValue()));
120 }
121 }
122 }
123
124
125
126
127
128
129
130 public static JaxbOrganization fromOrganization(Organization org) {
131 if (org instanceof JaxbOrganization)
132 return (JaxbOrganization) org;
133 return new JaxbOrganization(org.getId(), org.getName(), org.getServers(), org.getAdminRole(),
134 org.getAnonymousRole(), org.getProperties());
135 }
136
137
138
139
140 @Override
141 public String getId() {
142 return id;
143 }
144
145
146
147
148 @Override
149 public String getName() {
150 return name;
151 }
152
153
154
155
156 @Override
157 public Map<String, Integer> getServers() {
158 Map<String, Integer> map = new HashMap<String, Integer>();
159 if (servers != null) {
160 for (OrgServer server : servers) {
161 map.put(server.getName(), server.getPort());
162 }
163 }
164 return map;
165 }
166
167
168
169
170 @Override
171 public String getAdminRole() {
172 return adminRole;
173 }
174
175
176
177
178 @Override
179 public String getAnonymousRole() {
180 return anonymousRole;
181 }
182
183
184
185
186 @Override
187 public Map<String, String> getProperties() {
188 Map<String, String> map = new HashMap<String, String>();
189 for (OrgProperty prop : properties) {
190 map.put(prop.getKey(), prop.getValue());
191 }
192 return map;
193 }
194
195
196
197
198
199
200 @Override
201 public String toString() {
202 return id;
203 }
204
205
206
207
208
209
210 @Override
211 public boolean equals(Object obj) {
212 if (!(obj instanceof Organization))
213 return false;
214 return ((Organization) obj).getId().equals(id);
215 }
216
217
218
219
220
221
222 @Override
223 public int hashCode() {
224 return EqualsUtil.hash(id);
225 }
226
227
228
229
230 @XmlAccessorType(XmlAccessType.FIELD)
231 @XmlType(name = "server", namespace = "http://org.opencastproject.security")
232 public static class OrgServer {
233
234
235 @XmlAttribute
236 protected String name;
237
238
239 @XmlAttribute
240 protected int port;
241
242
243
244
245 public OrgServer() {
246 }
247
248
249
250
251
252
253
254
255
256 public OrgServer(String name, int port) {
257 this.name = name;
258 this.port = port;
259 }
260
261
262
263
264 public String getName() {
265 return name;
266 }
267
268
269
270
271 public int getPort() {
272 return port;
273 }
274 }
275
276
277
278
279 @XmlAccessorType(XmlAccessType.FIELD)
280 @XmlType(name = "property", namespace = "http://org.opencastproject.security")
281 public static class OrgProperty {
282
283
284 @XmlAttribute
285 protected String key;
286
287
288 @XmlValue
289 protected String value;
290
291
292
293
294 public OrgProperty() {
295 }
296
297
298
299
300
301
302
303
304
305 public OrgProperty(String key, String value) {
306 this.key = key;
307 this.value = value;
308 }
309
310
311
312
313 public String getKey() {
314 return key;
315 }
316
317
318
319
320 public String getValue() {
321 return value;
322 }
323 }
324
325 }