rsanchez
2017-04-10 8d99c88af55041ff06e6b9372b6b1f66220bed38
securis/src/main/java/net/curisit/securis/db/User.java
....@@ -2,10 +2,12 @@
22
33 import java.io.Serializable;
44 import java.util.ArrayList;
5
+import java.util.Collection;
56 import java.util.Date;
67 import java.util.HashSet;
78 import java.util.List;
89 import java.util.Set;
10
+import java.util.stream.Collectors;
911
1012 import javax.persistence.Column;
1113 import javax.persistence.Entity;
....@@ -76,6 +78,14 @@
7678 inverseJoinColumns = { @JoinColumn(name = "organization_id", referencedColumnName = "id") } //
7779 )
7880 private Set<Organization> organizations;
81
+
82
+ @JsonIgnore
83
+ @ManyToMany
84
+ @JoinTable(name = "user_application", //
85
+ joinColumns = { @JoinColumn(name = "username", referencedColumnName = "username") }, //
86
+ inverseJoinColumns = { @JoinColumn(name = "application_id", referencedColumnName = "id") } //
87
+ )
88
+ private Set<Application> applications;
7989
8090 public String getUsername() {
8191 return username;
....@@ -182,6 +192,14 @@
182192 this.organizations = organizations;
183193 }
184194
195
+ public Set<Application> getApplications() {
196
+ return applications;
197
+ }
198
+
199
+ public void setApplications(Set<Application> applications) {
200
+ this.applications = applications;
201
+ }
202
+
185203 @JsonProperty("organizations_ids")
186204 public void setOrgsIds(List<Integer> orgsIds) {
187205 organizations = new HashSet<>();
....@@ -204,6 +222,28 @@
204222 return ids;
205223 }
206224
225
+ @JsonProperty("applications_ids")
226
+ public void setAppsIds(Collection<Integer> appIds) {
227
+ applications = new HashSet<>();
228
+ for (Integer appid : appIds) {
229
+ Application a = new Application();
230
+ a.setId(appid);
231
+ applications.add(a);
232
+ }
233
+ }
234
+
235
+ @JsonProperty("applications_ids")
236
+ public Set<Integer> getAppsIds() {
237
+ if (applications == null) {
238
+ return null;
239
+ }
240
+ Set<Integer> ids = new HashSet<>();
241
+ for (Application app : applications) {
242
+ ids.add(app.getId());
243
+ }
244
+ return ids;
245
+ }
246
+
207247 @JsonIgnore
208248 public Set<Integer> getAllOrgsIds() {
209249 if (organizations == null) {
....@@ -214,6 +254,22 @@
214254 return ids;
215255 }
216256
257
+ @JsonIgnore
258
+ public Set<Integer> getAllAppsIds() {
259
+ if (applications == null) {
260
+ return null;
261
+ }
262
+ Set<Integer> ids = this.applications.parallelStream().map(app -> app.getId()).collect(Collectors.toSet());
263
+
264
+ return ids;
265
+ }
266
+
267
+ /**
268
+ * Walk into the organization hierarchy to include all descendants
269
+ *
270
+ * @param list
271
+ * @param orgIds
272
+ */
217273 private void includeAllOrgs(Set<Organization> list, Set<Integer> orgIds) {
218274 for (Organization org : list) {
219275 orgIds.add(org.getId());
....@@ -229,10 +285,16 @@
229285 this.email = email;
230286 }
231287
288
+ /**
289
+ * Numeric rol mask. Be aware to use different bit position for each role
290
+ *
291
+ * @author rob
292
+ */
232293 public static class Rol {
233294 public static final int ADVANCE = 0x01;
234295 public static final int ADMIN = 0x02;
235
- public static final int[] ALL = new int[] { ADVANCE, ADMIN };
296
+ public static final int BASIC = 0x04;
297
+ public static final int[] ALL = new int[] { ADVANCE, ADMIN, BASIC };
236298 }
237299
238300 }