| .. | .. |
|---|
| 2 | 2 | |
|---|
| 3 | 3 | import java.io.Serializable; |
|---|
| 4 | 4 | import java.util.ArrayList; |
|---|
| 5 | +import java.util.Collection; |
|---|
| 5 | 6 | import java.util.Date; |
|---|
| 6 | 7 | import java.util.HashSet; |
|---|
| 7 | 8 | import java.util.List; |
|---|
| 8 | 9 | import java.util.Set; |
|---|
| 10 | +import java.util.stream.Collectors; |
|---|
| 9 | 11 | |
|---|
| 10 | 12 | import javax.persistence.Column; |
|---|
| 11 | 13 | import javax.persistence.Entity; |
|---|
| .. | .. |
|---|
| 76 | 78 | inverseJoinColumns = { @JoinColumn(name = "organization_id", referencedColumnName = "id") } // |
|---|
| 77 | 79 | ) |
|---|
| 78 | 80 | 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; |
|---|
| 79 | 89 | |
|---|
| 80 | 90 | public String getUsername() { |
|---|
| 81 | 91 | return username; |
|---|
| .. | .. |
|---|
| 182 | 192 | this.organizations = organizations; |
|---|
| 183 | 193 | } |
|---|
| 184 | 194 | |
|---|
| 195 | + public Set<Application> getApplications() { |
|---|
| 196 | + return applications; |
|---|
| 197 | + } |
|---|
| 198 | + |
|---|
| 199 | + public void setApplications(Set<Application> applications) { |
|---|
| 200 | + this.applications = applications; |
|---|
| 201 | + } |
|---|
| 202 | + |
|---|
| 185 | 203 | @JsonProperty("organizations_ids") |
|---|
| 186 | 204 | public void setOrgsIds(List<Integer> orgsIds) { |
|---|
| 187 | 205 | organizations = new HashSet<>(); |
|---|
| .. | .. |
|---|
| 204 | 222 | return ids; |
|---|
| 205 | 223 | } |
|---|
| 206 | 224 | |
|---|
| 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 | + |
|---|
| 207 | 247 | @JsonIgnore |
|---|
| 208 | 248 | public Set<Integer> getAllOrgsIds() { |
|---|
| 209 | 249 | if (organizations == null) { |
|---|
| .. | .. |
|---|
| 214 | 254 | return ids; |
|---|
| 215 | 255 | } |
|---|
| 216 | 256 | |
|---|
| 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 | + */ |
|---|
| 217 | 273 | private void includeAllOrgs(Set<Organization> list, Set<Integer> orgIds) { |
|---|
| 218 | 274 | for (Organization org : list) { |
|---|
| 219 | 275 | orgIds.add(org.getId()); |
|---|
| .. | .. |
|---|
| 229 | 285 | this.email = email; |
|---|
| 230 | 286 | } |
|---|
| 231 | 287 | |
|---|
| 288 | + /** |
|---|
| 289 | + * Numeric rol mask. Be aware to use different bit position for each role |
|---|
| 290 | + * |
|---|
| 291 | + * @author rob |
|---|
| 292 | + */ |
|---|
| 232 | 293 | public static class Rol { |
|---|
| 233 | 294 | public static final int ADVANCE = 0x01; |
|---|
| 234 | 295 | 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 }; |
|---|
| 236 | 298 | } |
|---|
| 237 | 299 | |
|---|
| 238 | 300 | } |
|---|