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 }
134 return new JaxbOrganization(org.getId(), org.getName(), org.getServers(), org.getAdminRole(),
135 org.getAnonymousRole(), org.getProperties());
136 }
137
138
139
140
141 @Override
142 public String getId() {
143 return id;
144 }
145
146
147
148
149 @Override
150 public String getName() {
151 return name;
152 }
153
154
155
156
157 @Override
158 public Map<String, Integer> getServers() {
159 Map<String, Integer> map = new HashMap<String, Integer>();
160 if (servers != null) {
161 for (OrgServer server : servers) {
162 map.put(server.getName(), server.getPort());
163 }
164 }
165 return map;
166 }
167
168
169
170
171 @Override
172 public String getAdminRole() {
173 return adminRole;
174 }
175
176
177
178
179 @Override
180 public String getAnonymousRole() {
181 return anonymousRole;
182 }
183
184
185
186
187 @Override
188 public Map<String, String> getProperties() {
189 Map<String, String> map = new HashMap<String, String>();
190 for (OrgProperty prop : properties) {
191 map.put(prop.getKey(), prop.getValue());
192 }
193 return map;
194 }
195
196
197
198
199
200
201 @Override
202 public String toString() {
203 return id;
204 }
205
206
207
208
209
210
211 @Override
212 public boolean equals(Object obj) {
213 if (!(obj instanceof Organization)) {
214 return false;
215 }
216 return ((Organization) obj).getId().equals(id);
217 }
218
219
220
221
222
223
224 @Override
225 public int hashCode() {
226 return EqualsUtil.hash(id);
227 }
228
229
230
231
232 @XmlAccessorType(XmlAccessType.FIELD)
233 @XmlType(name = "server", namespace = "http://org.opencastproject.security")
234 public static class OrgServer {
235
236
237 @XmlAttribute
238 protected String name;
239
240
241 @XmlAttribute
242 protected int port;
243
244
245
246
247 public OrgServer() {
248 }
249
250
251
252
253
254
255
256
257
258 public OrgServer(String name, int port) {
259 this.name = name;
260 this.port = port;
261 }
262
263
264
265
266 public String getName() {
267 return name;
268 }
269
270
271
272
273 public int getPort() {
274 return port;
275 }
276 }
277
278
279
280
281 @XmlAccessorType(XmlAccessType.FIELD)
282 @XmlType(name = "property", namespace = "http://org.opencastproject.security")
283 public static class OrgProperty {
284
285
286 @XmlAttribute
287 protected String key;
288
289
290 @XmlValue
291 protected String value;
292
293
294
295
296 public OrgProperty() {
297 }
298
299
300
301
302
303
304
305
306
307 public OrgProperty(String key, String value) {
308 this.key = key;
309 this.value = value;
310 }
311
312
313
314
315 public String getKey() {
316 return key;
317 }
318
319
320
321
322 public String getValue() {
323 return value;
324 }
325 }
326
327 }