Roberto Sánchez
2014-01-18 602c4c4501dcd89cbce1d6ba61ba6bc75761d643
securis/src/main/java/net/curisit/securis/db/User.java
....@@ -3,7 +3,9 @@
33 import java.io.Serializable;
44 import java.util.ArrayList;
55 import java.util.Date;
6
+import java.util.HashSet;
67 import java.util.List;
8
+import java.util.Set;
79
810 import javax.persistence.Column;
911 import javax.persistence.Entity;
....@@ -70,7 +72,7 @@
7072 inverseJoinColumns =
7173 { @JoinColumn(name = "organization_id", referencedColumnName = "id") } //
7274 )
73
- private List<Organization> organizations;
75
+ private Set<Organization> organizations;
7476
7577 public String getUsername() {
7678 return username;
....@@ -160,17 +162,17 @@
160162 this.lang = lang;
161163 }
162164
163
- public List<Organization> getOrganizations() {
165
+ public Set<Organization> getOrganizations() {
164166 return organizations;
165167 }
166168
167
- public void setOrganizations(List<Organization> organizations) {
169
+ public void setOrganizations(Set<Organization> organizations) {
168170 this.organizations = organizations;
169171 }
170172
171173 @JsonProperty("organizations_ids")
172174 public void setOrgsIds(List<Integer> orgsIds) {
173
- organizations = new ArrayList<>();
175
+ organizations = new HashSet<>();
174176 for (Integer orgid : orgsIds) {
175177 Organization o = new Organization();
176178 o.setId(orgid);
....@@ -189,6 +191,22 @@
189191 return ids;
190192 }
191193
194
+ @JsonIgnore
195
+ public Set<Integer> getAllOrgsIds() {
196
+ if (organizations == null)
197
+ return null;
198
+ Set<Integer> ids = new HashSet<>();
199
+ includeAllOrgs(this.organizations, ids);
200
+ return ids;
201
+ }
202
+
203
+ private void includeAllOrgs(Set<Organization> list, Set<Integer> orgIds) {
204
+ for (Organization org : list) {
205
+ orgIds.add(org.getId());
206
+ includeAllOrgs(org.getChildOrganizations(), orgIds);
207
+ }
208
+ }
209
+
192210 static public class Rol {
193211 static public final int ADVANCE = 0x01;
194212 static public final int ADMIN = 0x02;