| .. | .. |
|---|
| 30 | 30 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) |
|---|
| 31 | 31 | @Entity |
|---|
| 32 | 32 | @Table(name = "user") |
|---|
| 33 | | -@NamedQueries( |
|---|
| 34 | | - { @NamedQuery(name = "list-users", query = "SELECT u FROM User u"), @NamedQuery(name = "get-user", query = "SELECT u FROM User u where u.username = :username"), |
|---|
| 35 | | - @NamedQuery(name = "auth-user", query = "SELECT u FROM User u where u.username = :username and u.password = :password"), @NamedQuery(name = "delete-all-users", query = "delete FROM User u") }) |
|---|
| 33 | +@NamedQueries({ @NamedQuery(name = "list-users", query = "SELECT u FROM User u"), |
|---|
| 34 | + @NamedQuery(name = "get-user", query = "SELECT u FROM User u where u.username = :username"), |
|---|
| 35 | + @NamedQuery(name = "auth-user", query = "SELECT u FROM User u where u.username = :username and u.password = :password"), |
|---|
| 36 | + @NamedQuery(name = "delete-all-users", query = "delete FROM User u") }) |
|---|
| 36 | 37 | public class User implements Serializable { |
|---|
| 37 | 38 | |
|---|
| 38 | | - private static final long serialVersionUID = 1L; |
|---|
| 39 | + private static final long serialVersionUID = 1L; |
|---|
| 39 | 40 | |
|---|
| 40 | | - @Id |
|---|
| 41 | | - private String username; |
|---|
| 41 | + @Id |
|---|
| 42 | + private String username; |
|---|
| 42 | 43 | |
|---|
| 43 | | - private String password; |
|---|
| 44 | + private String password; |
|---|
| 44 | 45 | |
|---|
| 45 | | - @JsonProperty(value = "first_name") |
|---|
| 46 | | - @Column(name = "first_name") |
|---|
| 47 | | - private String firstName; |
|---|
| 46 | + @JsonProperty(value = "first_name") |
|---|
| 47 | + @Column(name = "first_name") |
|---|
| 48 | + private String firstName; |
|---|
| 48 | 49 | |
|---|
| 49 | | - @JsonProperty(value = "last_name") |
|---|
| 50 | | - @Column(name = "last_name") |
|---|
| 51 | | - private String lastName; |
|---|
| 50 | + @JsonProperty(value = "last_name") |
|---|
| 51 | + @Column(name = "last_name") |
|---|
| 52 | + private String lastName; |
|---|
| 52 | 53 | |
|---|
| 53 | | - private int roles; |
|---|
| 54 | + private int roles; |
|---|
| 54 | 55 | |
|---|
| 55 | | - @Column(name = "last_login") |
|---|
| 56 | | - private Date lastLogin; |
|---|
| 56 | + @Column(name = "last_login") |
|---|
| 57 | + private Date lastLogin; |
|---|
| 57 | 58 | |
|---|
| 58 | | - @Column(name = "modification_timestamp") |
|---|
| 59 | | - private Date modificationTimestamp; |
|---|
| 59 | + @Column(name = "modification_timestamp") |
|---|
| 60 | + private Date modificationTimestamp; |
|---|
| 60 | 61 | |
|---|
| 61 | | - @Column(name = "creation_timestamp") |
|---|
| 62 | | - private Date creationTimestamp; |
|---|
| 62 | + @Column(name = "creation_timestamp") |
|---|
| 63 | + private Date creationTimestamp; |
|---|
| 63 | 64 | |
|---|
| 64 | | - private String lang; |
|---|
| 65 | + private String lang; |
|---|
| 65 | 66 | |
|---|
| 66 | | - @JsonIgnore |
|---|
| 67 | | - @ManyToMany |
|---|
| 68 | | - @JoinTable(name = "user_organization", // |
|---|
| 69 | | - joinColumns = |
|---|
| 70 | | - { @JoinColumn(name = "username", referencedColumnName = "username") }, // |
|---|
| 71 | | - inverseJoinColumns = |
|---|
| 72 | | - { @JoinColumn(name = "organization_id", referencedColumnName = "id") } // |
|---|
| 73 | | - ) |
|---|
| 74 | | - private Set<Organization> organizations; |
|---|
| 67 | + @JsonIgnore |
|---|
| 68 | + @ManyToMany |
|---|
| 69 | + @JoinTable(name = "user_organization", // |
|---|
| 70 | + joinColumns = { @JoinColumn(name = "username", referencedColumnName = "username") }, // |
|---|
| 71 | + inverseJoinColumns = { @JoinColumn(name = "organization_id", referencedColumnName = "id") } // |
|---|
| 72 | + ) |
|---|
| 73 | + private Set<Organization> organizations; |
|---|
| 75 | 74 | |
|---|
| 76 | | - public String getUsername() { |
|---|
| 77 | | - return username; |
|---|
| 78 | | - } |
|---|
| 75 | + public String getUsername() { |
|---|
| 76 | + return username; |
|---|
| 77 | + } |
|---|
| 79 | 78 | |
|---|
| 80 | | - public void setUsername(String username) { |
|---|
| 81 | | - this.username = username; |
|---|
| 82 | | - } |
|---|
| 79 | + public void setUsername(String username) { |
|---|
| 80 | + this.username = username; |
|---|
| 81 | + } |
|---|
| 83 | 82 | |
|---|
| 84 | | - public String getPassword() { |
|---|
| 85 | | - return password; |
|---|
| 86 | | - } |
|---|
| 83 | + public String getPassword() { |
|---|
| 84 | + return password; |
|---|
| 85 | + } |
|---|
| 87 | 86 | |
|---|
| 88 | | - public void setPassword(String password) { |
|---|
| 89 | | - this.password = password; |
|---|
| 90 | | - } |
|---|
| 87 | + public void setPassword(String password) { |
|---|
| 88 | + this.password = password; |
|---|
| 89 | + } |
|---|
| 91 | 90 | |
|---|
| 92 | | - public List<Integer> getRoles() { |
|---|
| 93 | | - if (roles == 0) |
|---|
| 94 | | - return null; |
|---|
| 95 | | - List<Integer> aux = new ArrayList<>(); |
|---|
| 96 | | - for (int rol : Rol.ALL) { |
|---|
| 97 | | - if ((roles & rol) != 0) // Each rol is a number with only 1 bit == 1 in binary representation |
|---|
| 98 | | - aux.add(rol); |
|---|
| 99 | | - } |
|---|
| 100 | | - return aux; |
|---|
| 101 | | - } |
|---|
| 91 | + public List<Integer> getRoles() { |
|---|
| 92 | + if (roles == 0) { |
|---|
| 93 | + return null; |
|---|
| 94 | + } |
|---|
| 95 | + List<Integer> aux = new ArrayList<>(); |
|---|
| 96 | + for (int rol : Rol.ALL) { |
|---|
| 97 | + if ((roles & rol) != 0) { // Each rol is a number with only 1 bit == |
|---|
| 98 | + // 1 in binary representation |
|---|
| 99 | + aux.add(rol); |
|---|
| 100 | + } |
|---|
| 101 | + } |
|---|
| 102 | + return aux; |
|---|
| 103 | + } |
|---|
| 102 | 104 | |
|---|
| 103 | | - public void setRoles(List<Integer> roles) { |
|---|
| 104 | | - this.roles = 0; |
|---|
| 105 | | - if (roles != null) |
|---|
| 106 | | - for (Integer rol : roles) { |
|---|
| 107 | | - this.roles |= rol; |
|---|
| 108 | | - } |
|---|
| 109 | | - } |
|---|
| 105 | + public void setRoles(List<Integer> roles) { |
|---|
| 106 | + this.roles = 0; |
|---|
| 107 | + if (roles != null) { |
|---|
| 108 | + for (Integer rol : roles) { |
|---|
| 109 | + this.roles |= rol; |
|---|
| 110 | + } |
|---|
| 111 | + } |
|---|
| 112 | + } |
|---|
| 110 | 113 | |
|---|
| 111 | | - public String getFirstName() { |
|---|
| 112 | | - return firstName; |
|---|
| 113 | | - } |
|---|
| 114 | + public String getFirstName() { |
|---|
| 115 | + return firstName; |
|---|
| 116 | + } |
|---|
| 114 | 117 | |
|---|
| 115 | | - public void setFirstName(String firstName) { |
|---|
| 116 | | - this.firstName = firstName; |
|---|
| 117 | | - } |
|---|
| 118 | + public void setFirstName(String firstName) { |
|---|
| 119 | + this.firstName = firstName; |
|---|
| 120 | + } |
|---|
| 118 | 121 | |
|---|
| 119 | | - public String getLastName() { |
|---|
| 120 | | - return lastName; |
|---|
| 121 | | - } |
|---|
| 122 | + public String getLastName() { |
|---|
| 123 | + return lastName; |
|---|
| 124 | + } |
|---|
| 122 | 125 | |
|---|
| 123 | | - public void setLastName(String lastName) { |
|---|
| 124 | | - this.lastName = lastName; |
|---|
| 125 | | - } |
|---|
| 126 | + public void setLastName(String lastName) { |
|---|
| 127 | + this.lastName = lastName; |
|---|
| 128 | + } |
|---|
| 126 | 129 | |
|---|
| 127 | | - public Date getLastLogin() { |
|---|
| 128 | | - return lastLogin; |
|---|
| 129 | | - } |
|---|
| 130 | + public Date getLastLogin() { |
|---|
| 131 | + return lastLogin; |
|---|
| 132 | + } |
|---|
| 130 | 133 | |
|---|
| 131 | | - public void setLastLogin(Date lastLogin) { |
|---|
| 132 | | - this.lastLogin = lastLogin; |
|---|
| 133 | | - } |
|---|
| 134 | + public void setLastLogin(Date lastLogin) { |
|---|
| 135 | + this.lastLogin = lastLogin; |
|---|
| 136 | + } |
|---|
| 134 | 137 | |
|---|
| 135 | | - public Date getModificationTimestamp() { |
|---|
| 136 | | - return modificationTimestamp; |
|---|
| 137 | | - } |
|---|
| 138 | + public Date getModificationTimestamp() { |
|---|
| 139 | + return modificationTimestamp; |
|---|
| 140 | + } |
|---|
| 138 | 141 | |
|---|
| 139 | | - public void setModificationTimestamp(Date modificationTimestamp) { |
|---|
| 140 | | - this.modificationTimestamp = modificationTimestamp; |
|---|
| 141 | | - } |
|---|
| 142 | + public void setModificationTimestamp(Date modificationTimestamp) { |
|---|
| 143 | + this.modificationTimestamp = modificationTimestamp; |
|---|
| 144 | + } |
|---|
| 142 | 145 | |
|---|
| 143 | | - public Date getCreationTimestamp() { |
|---|
| 144 | | - return creationTimestamp; |
|---|
| 145 | | - } |
|---|
| 146 | + public Date getCreationTimestamp() { |
|---|
| 147 | + return creationTimestamp; |
|---|
| 148 | + } |
|---|
| 146 | 149 | |
|---|
| 147 | | - public void setCreationTimestamp(Date creationTimestamp) { |
|---|
| 148 | | - this.creationTimestamp = creationTimestamp; |
|---|
| 149 | | - } |
|---|
| 150 | + public void setCreationTimestamp(Date creationTimestamp) { |
|---|
| 151 | + this.creationTimestamp = creationTimestamp; |
|---|
| 152 | + } |
|---|
| 150 | 153 | |
|---|
| 151 | | - @Override |
|---|
| 152 | | - public String toString() { |
|---|
| 153 | | - return "{User: " + username + " Name: " + firstName + " " + lastName + ", last login: " + lastLogin + "}"; |
|---|
| 154 | | - } |
|---|
| 154 | + @Override |
|---|
| 155 | + public String toString() { |
|---|
| 156 | + return "{User: " + username + " Name: " + firstName + " " + lastName + ", last login: " + lastLogin + "}"; |
|---|
| 157 | + } |
|---|
| 155 | 158 | |
|---|
| 156 | | - public String getLang() { |
|---|
| 157 | | - return lang; |
|---|
| 158 | | - } |
|---|
| 159 | + public String getLang() { |
|---|
| 160 | + return lang; |
|---|
| 161 | + } |
|---|
| 159 | 162 | |
|---|
| 160 | | - public void setLang(String lang) { |
|---|
| 161 | | - this.lang = lang; |
|---|
| 162 | | - } |
|---|
| 163 | + public void setLang(String lang) { |
|---|
| 164 | + this.lang = lang; |
|---|
| 165 | + } |
|---|
| 163 | 166 | |
|---|
| 164 | | - public Set<Organization> getOrganizations() { |
|---|
| 165 | | - return organizations; |
|---|
| 166 | | - } |
|---|
| 167 | + public Set<Organization> getOrganizations() { |
|---|
| 168 | + return organizations; |
|---|
| 169 | + } |
|---|
| 167 | 170 | |
|---|
| 168 | | - public void setOrganizations(Set<Organization> organizations) { |
|---|
| 169 | | - this.organizations = organizations; |
|---|
| 170 | | - } |
|---|
| 171 | + public void setOrganizations(Set<Organization> organizations) { |
|---|
| 172 | + this.organizations = organizations; |
|---|
| 173 | + } |
|---|
| 171 | 174 | |
|---|
| 172 | | - @JsonProperty("organizations_ids") |
|---|
| 173 | | - public void setOrgsIds(List<Integer> orgsIds) { |
|---|
| 174 | | - organizations = new HashSet<>(); |
|---|
| 175 | | - for (Integer orgid : orgsIds) { |
|---|
| 176 | | - Organization o = new Organization(); |
|---|
| 177 | | - o.setId(orgid); |
|---|
| 178 | | - organizations.add(o); |
|---|
| 179 | | - } |
|---|
| 180 | | - } |
|---|
| 175 | + @JsonProperty("organizations_ids") |
|---|
| 176 | + public void setOrgsIds(List<Integer> orgsIds) { |
|---|
| 177 | + organizations = new HashSet<>(); |
|---|
| 178 | + for (Integer orgid : orgsIds) { |
|---|
| 179 | + Organization o = new Organization(); |
|---|
| 180 | + o.setId(orgid); |
|---|
| 181 | + organizations.add(o); |
|---|
| 182 | + } |
|---|
| 183 | + } |
|---|
| 181 | 184 | |
|---|
| 182 | | - @JsonProperty("organizations_ids") |
|---|
| 183 | | - public Set<Integer> getOrgsIds() { |
|---|
| 184 | | - if (organizations == null) |
|---|
| 185 | | - return null; |
|---|
| 186 | | - Set<Integer> ids = new HashSet<>(); |
|---|
| 187 | | - for (Organization org : organizations) { |
|---|
| 188 | | - ids.add(org.getId()); |
|---|
| 189 | | - } |
|---|
| 190 | | - return ids; |
|---|
| 191 | | - } |
|---|
| 185 | + @JsonProperty("organizations_ids") |
|---|
| 186 | + public Set<Integer> getOrgsIds() { |
|---|
| 187 | + if (organizations == null) { |
|---|
| 188 | + return null; |
|---|
| 189 | + } |
|---|
| 190 | + Set<Integer> ids = new HashSet<>(); |
|---|
| 191 | + for (Organization org : organizations) { |
|---|
| 192 | + ids.add(org.getId()); |
|---|
| 193 | + } |
|---|
| 194 | + return ids; |
|---|
| 195 | + } |
|---|
| 192 | 196 | |
|---|
| 193 | | - @JsonIgnore |
|---|
| 194 | | - public Set<Integer> getAllOrgsIds() { |
|---|
| 195 | | - if (organizations == null) |
|---|
| 196 | | - return null; |
|---|
| 197 | | - Set<Integer> ids = new HashSet<>(); |
|---|
| 198 | | - includeAllOrgs(this.organizations, ids); |
|---|
| 199 | | - return ids; |
|---|
| 200 | | - } |
|---|
| 197 | + @JsonIgnore |
|---|
| 198 | + public Set<Integer> getAllOrgsIds() { |
|---|
| 199 | + if (organizations == null) { |
|---|
| 200 | + return null; |
|---|
| 201 | + } |
|---|
| 202 | + Set<Integer> ids = new HashSet<>(); |
|---|
| 203 | + includeAllOrgs(this.organizations, ids); |
|---|
| 204 | + return ids; |
|---|
| 205 | + } |
|---|
| 201 | 206 | |
|---|
| 202 | | - private void includeAllOrgs(Set<Organization> list, Set<Integer> orgIds) { |
|---|
| 203 | | - for (Organization org : list) { |
|---|
| 204 | | - orgIds.add(org.getId()); |
|---|
| 205 | | - includeAllOrgs(org.getChildOrganizations(), orgIds); |
|---|
| 206 | | - } |
|---|
| 207 | | - } |
|---|
| 207 | + private void includeAllOrgs(Set<Organization> list, Set<Integer> orgIds) { |
|---|
| 208 | + for (Organization org : list) { |
|---|
| 209 | + orgIds.add(org.getId()); |
|---|
| 210 | + includeAllOrgs(org.getChildOrganizations(), orgIds); |
|---|
| 211 | + } |
|---|
| 212 | + } |
|---|
| 208 | 213 | |
|---|
| 209 | | - static public class Rol { |
|---|
| 210 | | - static public final int ADVANCE = 0x01; |
|---|
| 211 | | - static public final int ADMIN = 0x02; |
|---|
| 212 | | - static public final int[] ALL = new int[] |
|---|
| 213 | | - { ADVANCE, ADMIN }; |
|---|
| 214 | | - } |
|---|
| 214 | + public static class Rol { |
|---|
| 215 | + public static final int ADVANCE = 0x01; |
|---|
| 216 | + public static final int ADMIN = 0x02; |
|---|
| 217 | + public static final int[] ALL = new int[] { ADVANCE, ADMIN }; |
|---|
| 218 | + } |
|---|
| 215 | 219 | |
|---|
| 216 | 220 | } |
|---|