| .. | .. |
|---|
| 1 | 1 | package net.curisit.securis.db; |
|---|
| 2 | 2 | |
|---|
| 3 | 3 | import java.io.Serializable; |
|---|
| 4 | +import java.util.ArrayList; |
|---|
| 4 | 5 | import java.util.Date; |
|---|
| 5 | 6 | import java.util.List; |
|---|
| 6 | 7 | |
|---|
| .. | .. |
|---|
| 17 | 18 | import javax.persistence.Table; |
|---|
| 18 | 19 | |
|---|
| 19 | 20 | import org.codehaus.jackson.annotate.JsonAutoDetect; |
|---|
| 21 | +import org.codehaus.jackson.annotate.JsonIgnore; |
|---|
| 22 | +import org.codehaus.jackson.annotate.JsonProperty; |
|---|
| 20 | 23 | import org.codehaus.jackson.map.annotate.JsonSerialize; |
|---|
| 24 | +import org.slf4j.Logger; |
|---|
| 25 | +import org.slf4j.LoggerFactory; |
|---|
| 21 | 26 | |
|---|
| 22 | 27 | /** |
|---|
| 23 | 28 | * Entity implementation class for Entity: organization |
|---|
| .. | .. |
|---|
| 30 | 35 | @NamedQueries( |
|---|
| 31 | 36 | { @NamedQuery(name = "list-organizations", query = "SELECT o FROM Organization o") }) |
|---|
| 32 | 37 | public class Organization implements Serializable { |
|---|
| 38 | + |
|---|
| 39 | + @SuppressWarnings("unused") |
|---|
| 40 | + private static final Logger log = LoggerFactory.getLogger(Organization.class); |
|---|
| 33 | 41 | |
|---|
| 34 | 42 | private static final long serialVersionUID = 1L; |
|---|
| 35 | 43 | |
|---|
| .. | .. |
|---|
| 44 | 52 | @Column(name = "creation_timestamp") |
|---|
| 45 | 53 | private Date creationTimestamp; |
|---|
| 46 | 54 | |
|---|
| 55 | + @JsonIgnore |
|---|
| 56 | + // We don't include the users to limit the size of each row a the listing |
|---|
| 47 | 57 | @ManyToMany |
|---|
| 48 | 58 | @JoinTable(name = "user_organization", // |
|---|
| 49 | 59 | joinColumns = |
|---|
| 50 | 60 | { @JoinColumn(name = "organization_id", referencedColumnName = "id") }, // |
|---|
| 51 | 61 | inverseJoinColumns = |
|---|
| 52 | | - { @JoinColumn(name = "user_id", referencedColumnName = "username") }) |
|---|
| 62 | + { @JoinColumn(name = "username", referencedColumnName = "username") }) |
|---|
| 53 | 63 | private List<User> users; |
|---|
| 54 | 64 | |
|---|
| 65 | + @JsonIgnore |
|---|
| 66 | + // We don't include the users to limit the size of each row a the listing |
|---|
| 55 | 67 | @ManyToOne |
|---|
| 56 | 68 | @JoinColumn(name = "org_parent_id") |
|---|
| 57 | 69 | private Organization parentOrganization; |
|---|
| 58 | 70 | |
|---|
| 59 | 71 | public int getId() { |
|---|
| 60 | 72 | return id; |
|---|
| 73 | + } |
|---|
| 74 | + |
|---|
| 75 | + public void setId(int id) { |
|---|
| 76 | + this.id = id; |
|---|
| 61 | 77 | } |
|---|
| 62 | 78 | |
|---|
| 63 | 79 | public String getName() { |
|---|
| .. | .. |
|---|
| 108 | 124 | this.parentOrganization = parentOrganization; |
|---|
| 109 | 125 | } |
|---|
| 110 | 126 | |
|---|
| 127 | + // Roberto: Following methods are necessary to include in the REST list response |
|---|
| 128 | + // information about the referenced entities. |
|---|
| 129 | + @JsonProperty("org_parent_id") |
|---|
| 130 | + public void setParentOrgId(Integer orgId) { |
|---|
| 131 | + parentOrganization = new Organization(); |
|---|
| 132 | + parentOrganization.setId(orgId); |
|---|
| 133 | + } |
|---|
| 134 | + |
|---|
| 135 | + @JsonProperty("org_parent_id") |
|---|
| 136 | + public Integer getParentOrgId() { |
|---|
| 137 | + return parentOrganization == null ? null : parentOrganization.getId(); |
|---|
| 138 | + } |
|---|
| 139 | + |
|---|
| 140 | + @JsonProperty("org_parent_name") |
|---|
| 141 | + public String getParentOrgName() { |
|---|
| 142 | + return parentOrganization == null ? null : parentOrganization.getName(); |
|---|
| 143 | + } |
|---|
| 144 | + |
|---|
| 145 | + @JsonProperty("users_ids") |
|---|
| 146 | + public void setUsersIds(List<String> usersIds) { |
|---|
| 147 | + users = new ArrayList<>(); |
|---|
| 148 | + for (String userid : usersIds) { |
|---|
| 149 | + User u = new User(); |
|---|
| 150 | + u.setUsername(userid); |
|---|
| 151 | + users.add(u); |
|---|
| 152 | + } |
|---|
| 153 | + } |
|---|
| 154 | + |
|---|
| 155 | + @JsonProperty("users_ids") |
|---|
| 156 | + public List<String> getUsersIds() { |
|---|
| 157 | + if (users == null) |
|---|
| 158 | + return null; |
|---|
| 159 | + List<String> ids = new ArrayList<>(); |
|---|
| 160 | + for (User user : users) { |
|---|
| 161 | + ids.add(user.getUsername()); |
|---|
| 162 | + } |
|---|
| 163 | + return ids; |
|---|
| 164 | + } |
|---|
| 165 | + |
|---|
| 111 | 166 | } |
|---|