| .. | .. |
|---|
| 26 | 26 | |
|---|
| 27 | 27 | import com.fasterxml.jackson.annotation.JsonAutoDetect; |
|---|
| 28 | 28 | import com.fasterxml.jackson.annotation.JsonIgnore; |
|---|
| 29 | +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|---|
| 29 | 30 | import com.fasterxml.jackson.annotation.JsonInclude; |
|---|
| 30 | 31 | import com.fasterxml.jackson.annotation.JsonInclude.Include; |
|---|
| 31 | 32 | import com.fasterxml.jackson.annotation.JsonProperty; |
|---|
| .. | .. |
|---|
| 36 | 37 | */ |
|---|
| 37 | 38 | @JsonAutoDetect |
|---|
| 38 | 39 | @JsonInclude(Include.NON_NULL) |
|---|
| 40 | +@JsonIgnoreProperties(ignoreUnknown = true) |
|---|
| 39 | 41 | @Entity |
|---|
| 40 | 42 | @Table(name = "organization") |
|---|
| 41 | | -@NamedQueries({ |
|---|
| 42 | | - @NamedQuery(name = "list-organizations", query = "SELECT o FROM Organization o"), |
|---|
| 43 | | - @NamedQuery(name = "list-organizations-by-ids", query = "SELECT o FROM Organization o where id in :list_ids"), |
|---|
| 44 | | - @NamedQuery(name = "find-children-org", query = "SELECT o FROM Organization o where o.parentOrganization = :parentOrganization") |
|---|
| 45 | | -}) |
|---|
| 43 | +@NamedQueries({ @NamedQuery(name = "list-organizations", query = "SELECT o FROM Organization o"), |
|---|
| 44 | + @NamedQuery(name = "list-organizations-by-ids", query = "SELECT o FROM Organization o where id in :list_ids"), |
|---|
| 45 | + @NamedQuery(name = "find-children-org", query = "SELECT o FROM Organization o where o.parentOrganization = :parentOrganization") }) |
|---|
| 46 | 46 | public class Organization implements Serializable { |
|---|
| 47 | 47 | |
|---|
| 48 | | - @SuppressWarnings("unused") |
|---|
| 49 | | - private static final Logger LOG = LogManager.getLogger(Organization.class); |
|---|
| 48 | + @SuppressWarnings("unused") |
|---|
| 49 | + private static final Logger LOG = LogManager.getLogger(Organization.class); |
|---|
| 50 | 50 | |
|---|
| 51 | | - private static final long serialVersionUID = 1L; |
|---|
| 51 | + private static final long serialVersionUID = 1L; |
|---|
| 52 | 52 | |
|---|
| 53 | | - @Id |
|---|
| 54 | | - @GeneratedValue |
|---|
| 55 | | - private Integer id; |
|---|
| 53 | + @Id |
|---|
| 54 | + @GeneratedValue |
|---|
| 55 | + private Integer id; |
|---|
| 56 | 56 | |
|---|
| 57 | | - private String code; |
|---|
| 58 | | - private String name; |
|---|
| 59 | | - private String description; |
|---|
| 57 | + private String code; |
|---|
| 58 | + private String name; |
|---|
| 59 | + private String description; |
|---|
| 60 | 60 | |
|---|
| 61 | | - @Column(name = "creation_timestamp") |
|---|
| 62 | | - @JsonProperty("creation_timestamp") |
|---|
| 63 | | - private Date creationTimestamp; |
|---|
| 61 | + @Column(name = "creation_timestamp") |
|---|
| 62 | + @JsonProperty("creation_timestamp") |
|---|
| 63 | + private Date creationTimestamp; |
|---|
| 64 | 64 | |
|---|
| 65 | | - @JsonIgnore |
|---|
| 66 | | - // We don't include the users to limit the size of each row a the listing |
|---|
| 67 | | - @ManyToMany(cascade = CascadeType.REMOVE) |
|---|
| 68 | | - @JoinTable(name = "user_organization", // |
|---|
| 69 | | - joinColumns = { |
|---|
| 70 | | - @JoinColumn(name = "organization_id", referencedColumnName = "id") |
|---|
| 71 | | - }, // |
|---|
| 72 | | - inverseJoinColumns = { |
|---|
| 73 | | - @JoinColumn(name = "username", referencedColumnName = "username") |
|---|
| 74 | | - }) |
|---|
| 75 | | - private Set<User> users; |
|---|
| 65 | + @JsonIgnore |
|---|
| 66 | + // We don't include the users to limit the size of each row a the listing |
|---|
| 67 | + @ManyToMany(cascade = CascadeType.REMOVE) |
|---|
| 68 | + @JoinTable(name = "user_organization", // |
|---|
| 69 | + joinColumns = { @JoinColumn(name = "organization_id", referencedColumnName = "id") }, // |
|---|
| 70 | + inverseJoinColumns = { @JoinColumn(name = "username", referencedColumnName = "username") }) |
|---|
| 71 | + private Set<User> users; |
|---|
| 76 | 72 | |
|---|
| 77 | | - @JsonIgnore |
|---|
| 78 | | - // We don't include the users to limit the size of each row a the listing |
|---|
| 79 | | - @ManyToOne |
|---|
| 80 | | - @JoinColumn(name = "org_parent_id") |
|---|
| 81 | | - private Organization parentOrganization; |
|---|
| 73 | + @JsonIgnore |
|---|
| 74 | + // We don't include the users to limit the size of each row a the listing |
|---|
| 75 | + @ManyToOne |
|---|
| 76 | + @JoinColumn(name = "org_parent_id") |
|---|
| 77 | + private Organization parentOrganization; |
|---|
| 82 | 78 | |
|---|
| 83 | | - @JsonIgnore |
|---|
| 84 | | - // We don't include the users to limit the size of each row a the listing |
|---|
| 85 | | - @OneToMany(fetch = FetchType.LAZY, mappedBy = "parentOrganization") |
|---|
| 86 | | - private Set<Organization> childOrganizations; |
|---|
| 79 | + @JsonIgnore |
|---|
| 80 | + // We don't include the users to limit the size of each row a the listing |
|---|
| 81 | + @OneToMany(fetch = FetchType.LAZY, mappedBy = "parentOrganization") |
|---|
| 82 | + private Set<Organization> childOrganizations; |
|---|
| 87 | 83 | |
|---|
| 88 | | - public Integer getId() { |
|---|
| 89 | | - return id; |
|---|
| 90 | | - } |
|---|
| 84 | + public Integer getId() { |
|---|
| 85 | + return id; |
|---|
| 86 | + } |
|---|
| 91 | 87 | |
|---|
| 92 | | - public void setId(Integer id) { |
|---|
| 93 | | - this.id = id; |
|---|
| 94 | | - } |
|---|
| 88 | + public void setId(Integer id) { |
|---|
| 89 | + this.id = id; |
|---|
| 90 | + } |
|---|
| 95 | 91 | |
|---|
| 96 | | - public String getName() { |
|---|
| 97 | | - return name; |
|---|
| 98 | | - } |
|---|
| 92 | + public String getName() { |
|---|
| 93 | + return name; |
|---|
| 94 | + } |
|---|
| 99 | 95 | |
|---|
| 100 | | - public void setName(String name) { |
|---|
| 101 | | - this.name = name; |
|---|
| 102 | | - } |
|---|
| 96 | + public void setName(String name) { |
|---|
| 97 | + this.name = name; |
|---|
| 98 | + } |
|---|
| 103 | 99 | |
|---|
| 104 | | - public String getDescription() { |
|---|
| 105 | | - return description; |
|---|
| 106 | | - } |
|---|
| 100 | + public String getDescription() { |
|---|
| 101 | + return description; |
|---|
| 102 | + } |
|---|
| 107 | 103 | |
|---|
| 108 | | - public void setDescription(String description) { |
|---|
| 109 | | - this.description = description; |
|---|
| 110 | | - } |
|---|
| 104 | + public void setDescription(String description) { |
|---|
| 105 | + this.description = description; |
|---|
| 106 | + } |
|---|
| 111 | 107 | |
|---|
| 112 | | - public String getCode() { |
|---|
| 113 | | - return code; |
|---|
| 114 | | - } |
|---|
| 108 | + public String getCode() { |
|---|
| 109 | + return code; |
|---|
| 110 | + } |
|---|
| 115 | 111 | |
|---|
| 116 | | - public void setCode(String code) { |
|---|
| 117 | | - this.code = code; |
|---|
| 118 | | - } |
|---|
| 112 | + public void setCode(String code) { |
|---|
| 113 | + this.code = code; |
|---|
| 114 | + } |
|---|
| 119 | 115 | |
|---|
| 120 | | - public Date getCreationTimestamp() { |
|---|
| 121 | | - return creationTimestamp; |
|---|
| 122 | | - } |
|---|
| 116 | + public Date getCreationTimestamp() { |
|---|
| 117 | + return creationTimestamp; |
|---|
| 118 | + } |
|---|
| 123 | 119 | |
|---|
| 124 | | - public void setCreationTimestamp(Date creationTimestamp) { |
|---|
| 125 | | - this.creationTimestamp = creationTimestamp; |
|---|
| 126 | | - } |
|---|
| 120 | + public void setCreationTimestamp(Date creationTimestamp) { |
|---|
| 121 | + this.creationTimestamp = creationTimestamp; |
|---|
| 122 | + } |
|---|
| 127 | 123 | |
|---|
| 128 | | - public Set<User> getUsers() { |
|---|
| 129 | | - return users; |
|---|
| 130 | | - } |
|---|
| 124 | + public Set<User> getUsers() { |
|---|
| 125 | + return users; |
|---|
| 126 | + } |
|---|
| 131 | 127 | |
|---|
| 132 | | - public void setUsers(Set<User> users) { |
|---|
| 133 | | - this.users = users; |
|---|
| 134 | | - } |
|---|
| 128 | + public void setUsers(Set<User> users) { |
|---|
| 129 | + this.users = users; |
|---|
| 130 | + } |
|---|
| 135 | 131 | |
|---|
| 136 | | - public Organization getParentOrganization() { |
|---|
| 137 | | - return parentOrganization; |
|---|
| 138 | | - } |
|---|
| 132 | + public Organization getParentOrganization() { |
|---|
| 133 | + return parentOrganization; |
|---|
| 134 | + } |
|---|
| 139 | 135 | |
|---|
| 140 | | - public void setParentOrganization(Organization parentOrganization) { |
|---|
| 141 | | - this.parentOrganization = parentOrganization; |
|---|
| 142 | | - } |
|---|
| 136 | + public void setParentOrganization(Organization parentOrganization) { |
|---|
| 137 | + this.parentOrganization = parentOrganization; |
|---|
| 138 | + } |
|---|
| 143 | 139 | |
|---|
| 144 | | - // Roberto: Following methods are necessary to include in the REST list |
|---|
| 145 | | - // response |
|---|
| 146 | | - // information about the referenced entities. |
|---|
| 147 | | - @JsonProperty("org_parent_id") |
|---|
| 148 | | - public void setParentOrgId(Integer orgId) { |
|---|
| 149 | | - if (orgId != null) { |
|---|
| 150 | | - parentOrganization = new Organization(); |
|---|
| 151 | | - parentOrganization.setId(orgId); |
|---|
| 152 | | - } else { |
|---|
| 153 | | - parentOrganization = null; |
|---|
| 154 | | - } |
|---|
| 155 | | - } |
|---|
| 140 | + // Roberto: Following methods are necessary to include in the REST list |
|---|
| 141 | + // response |
|---|
| 142 | + // information about the referenced entities. |
|---|
| 143 | + @JsonProperty("org_parent_id") |
|---|
| 144 | + public void setParentOrgId(Integer orgId) { |
|---|
| 145 | + if (orgId != null) { |
|---|
| 146 | + parentOrganization = new Organization(); |
|---|
| 147 | + parentOrganization.setId(orgId); |
|---|
| 148 | + } else { |
|---|
| 149 | + parentOrganization = null; |
|---|
| 150 | + } |
|---|
| 151 | + } |
|---|
| 156 | 152 | |
|---|
| 157 | | - @JsonProperty("org_parent_id") |
|---|
| 158 | | - public Integer getParentOrgId() { |
|---|
| 159 | | - return parentOrganization == null ? null : parentOrganization.getId(); |
|---|
| 160 | | - } |
|---|
| 153 | + @JsonProperty("org_parent_id") |
|---|
| 154 | + public Integer getParentOrgId() { |
|---|
| 155 | + return parentOrganization == null ? null : parentOrganization.getId(); |
|---|
| 156 | + } |
|---|
| 161 | 157 | |
|---|
| 162 | | - @JsonProperty("org_parent_name") |
|---|
| 163 | | - public String getParentOrgName() { |
|---|
| 164 | | - return parentOrganization == null ? null : parentOrganization.getName(); |
|---|
| 165 | | - } |
|---|
| 158 | + @JsonProperty("org_parent_name") |
|---|
| 159 | + public String getParentOrgName() { |
|---|
| 160 | + return parentOrganization == null ? null : parentOrganization.getName(); |
|---|
| 161 | + } |
|---|
| 166 | 162 | |
|---|
| 167 | | - @JsonProperty("users_ids") |
|---|
| 168 | | - public void setUsersIds(List<String> usersIds) { |
|---|
| 169 | | - users = new HashSet<>(); |
|---|
| 170 | | - if (usersIds != null) { |
|---|
| 171 | | - for (String userid : usersIds) { |
|---|
| 172 | | - User u = new User(); |
|---|
| 173 | | - u.setUsername(userid); |
|---|
| 174 | | - users.add(u); |
|---|
| 175 | | - } |
|---|
| 176 | | - } |
|---|
| 177 | | - } |
|---|
| 163 | + @JsonProperty("users_ids") |
|---|
| 164 | + public void setUsersIds(List<String> usersIds) { |
|---|
| 165 | + users = new HashSet<>(); |
|---|
| 166 | + if (usersIds != null) { |
|---|
| 167 | + for (String userid : usersIds) { |
|---|
| 168 | + User u = new User(); |
|---|
| 169 | + u.setUsername(userid); |
|---|
| 170 | + users.add(u); |
|---|
| 171 | + } |
|---|
| 172 | + } |
|---|
| 173 | + } |
|---|
| 178 | 174 | |
|---|
| 179 | | - @JsonProperty("users_ids") |
|---|
| 180 | | - public Set<String> getUsersIds() { |
|---|
| 181 | | - if (users == null) { |
|---|
| 182 | | - return null; |
|---|
| 183 | | - } |
|---|
| 184 | | - Set<String> ids = new HashSet<>(); |
|---|
| 185 | | - for (User user : users) { |
|---|
| 186 | | - ids.add(user.getUsername()); |
|---|
| 187 | | - } |
|---|
| 188 | | - return ids; |
|---|
| 189 | | - } |
|---|
| 175 | + @JsonProperty("users_ids") |
|---|
| 176 | + public Set<String> getUsersIds() { |
|---|
| 177 | + if (users == null) { |
|---|
| 178 | + return null; |
|---|
| 179 | + } |
|---|
| 180 | + Set<String> ids = new HashSet<>(); |
|---|
| 181 | + for (User user : users) { |
|---|
| 182 | + ids.add(user.getUsername()); |
|---|
| 183 | + } |
|---|
| 184 | + return ids; |
|---|
| 185 | + } |
|---|
| 190 | 186 | |
|---|
| 191 | | - public Set<Organization> getChildOrganizations() { |
|---|
| 192 | | - return childOrganizations; |
|---|
| 193 | | - } |
|---|
| 187 | + public Set<Organization> getChildOrganizations() { |
|---|
| 188 | + return childOrganizations; |
|---|
| 189 | + } |
|---|
| 194 | 190 | |
|---|
| 195 | | - public void setChildOrganizations(Set<Organization> childOrganizations) { |
|---|
| 196 | | - this.childOrganizations = childOrganizations; |
|---|
| 197 | | - } |
|---|
| 191 | + public void setChildOrganizations(Set<Organization> childOrganizations) { |
|---|
| 192 | + this.childOrganizations = childOrganizations; |
|---|
| 193 | + } |
|---|
| 198 | 194 | |
|---|
| 199 | 195 | } |
|---|