| .. | .. |
|---|
| 3 | 3 | import java.io.Serializable; |
|---|
| 4 | 4 | import java.util.ArrayList; |
|---|
| 5 | 5 | import java.util.Date; |
|---|
| 6 | +import java.util.HashSet; |
|---|
| 6 | 7 | import java.util.List; |
|---|
| 8 | +import java.util.Set; |
|---|
| 7 | 9 | |
|---|
| 8 | 10 | import javax.persistence.Column; |
|---|
| 9 | 11 | import javax.persistence.Entity; |
|---|
| .. | .. |
|---|
| 70 | 72 | inverseJoinColumns = |
|---|
| 71 | 73 | { @JoinColumn(name = "organization_id", referencedColumnName = "id") } // |
|---|
| 72 | 74 | ) |
|---|
| 73 | | - private List<Organization> organizations; |
|---|
| 75 | + private Set<Organization> organizations; |
|---|
| 74 | 76 | |
|---|
| 75 | 77 | public String getUsername() { |
|---|
| 76 | 78 | return username; |
|---|
| .. | .. |
|---|
| 160 | 162 | this.lang = lang; |
|---|
| 161 | 163 | } |
|---|
| 162 | 164 | |
|---|
| 163 | | - public List<Organization> getOrganizations() { |
|---|
| 165 | + public Set<Organization> getOrganizations() { |
|---|
| 164 | 166 | return organizations; |
|---|
| 165 | 167 | } |
|---|
| 166 | 168 | |
|---|
| 167 | | - public void setOrganizations(List<Organization> organizations) { |
|---|
| 169 | + public void setOrganizations(Set<Organization> organizations) { |
|---|
| 168 | 170 | this.organizations = organizations; |
|---|
| 169 | 171 | } |
|---|
| 170 | 172 | |
|---|
| 171 | 173 | @JsonProperty("organizations_ids") |
|---|
| 172 | 174 | public void setOrgsIds(List<Integer> orgsIds) { |
|---|
| 173 | | - organizations = new ArrayList<>(); |
|---|
| 175 | + organizations = new HashSet<>(); |
|---|
| 174 | 176 | for (Integer orgid : orgsIds) { |
|---|
| 175 | 177 | Organization o = new Organization(); |
|---|
| 176 | 178 | o.setId(orgid); |
|---|
| .. | .. |
|---|
| 189 | 191 | return ids; |
|---|
| 190 | 192 | } |
|---|
| 191 | 193 | |
|---|
| 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 | + |
|---|
| 192 | 210 | static public class Rol { |
|---|
| 193 | 211 | static public final int ADVANCE = 0x01; |
|---|
| 194 | 212 | static public final int ADMIN = 0x02; |
|---|