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
25 import java.util.Objects;
26
27 import javax.xml.bind.annotation.XmlAccessType;
28 import javax.xml.bind.annotation.XmlAccessorType;
29 import javax.xml.bind.annotation.XmlElement;
30 import javax.xml.bind.annotation.XmlRootElement;
31 import javax.xml.bind.annotation.XmlType;
32
33
34
35
36 @XmlAccessorType(XmlAccessType.FIELD)
37 @XmlType(name = "role", namespace = "http://org.opencastproject.security")
38 @XmlRootElement(name = "role", namespace = "http://org.opencastproject.security")
39 public final class JaxbRole implements Role {
40
41
42 @XmlElement(name = "name")
43 protected String name;
44
45
46 @XmlElement(name = "description")
47 protected String description;
48
49 @XmlElement(name = "organization")
50 protected JaxbOrganization organization;
51
52 @XmlElement(name = "organization-id")
53 protected String organizationId;
54
55 @XmlElement(name = "type")
56 protected Type type = Type.INTERNAL;
57
58
59
60
61 public JaxbRole() {
62 }
63
64
65
66
67
68
69
70
71
72 public JaxbRole(String name, JaxbOrganization organization) throws IllegalArgumentException {
73 super();
74 this.name = name;
75 this.organizationId = organization.getId();
76 }
77
78
79
80
81
82
83
84
85
86
87
88 public JaxbRole(String name, JaxbOrganization organization, String description) throws IllegalArgumentException {
89 this(name, organization);
90 this.description = description;
91 }
92
93
94
95
96
97
98
99
100
101
102
103
104
105 public JaxbRole(String name, JaxbOrganization organization, String description, Type type)
106 throws IllegalArgumentException {
107 this(name, organization, description);
108 this.type = type;
109 }
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124 public JaxbRole(String name, String organizationId, String description, Type type) throws IllegalArgumentException {
125 super();
126 this.name = name;
127 this.organizationId = organizationId;
128 this.description = description;
129 this.type = type;
130 }
131
132 public static JaxbRole fromRole(Role role) {
133 if (role instanceof JaxbRole) {
134 return (JaxbRole) role;
135 }
136 return new JaxbRole(role.getName(), role.getOrganizationId(), role.getDescription(), role.getType());
137 }
138
139
140
141
142
143
144 @Override
145 public String getName() {
146 return name;
147 }
148
149
150
151
152
153
154 @Override
155 public String getDescription() {
156 return description;
157 }
158
159
160
161
162 public String getOrganizationId() {
163 if (organizationId != null) {
164 return organizationId;
165 }
166 if (organization != null) {
167 return organization.getId();
168 }
169 return null;
170 }
171
172
173
174
175
176
177 public Type getType() {
178 return type;
179 }
180
181
182
183
184
185
186 @Override
187 public int hashCode() {
188 return Objects.hash(name, getOrganizationId());
189 }
190
191
192
193
194
195
196 @Override
197 public boolean equals(Object obj) {
198 if (!(obj instanceof Role)) {
199 return false;
200 }
201 Role other = (Role) obj;
202 return name.equals(other.getName())
203 && Objects.equals(getOrganizationId(), other.getOrganizationId());
204 }
205
206
207
208
209
210
211 @Override
212 public String toString() {
213 return name + ":" + getOrganizationId();
214 }
215 }