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