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