Roberto Sánchez
2014-01-10 59cdd2b7ebceae94fbecdb1eeb46a969666dc88f
securis/src/main/java/net/curisit/securis/db/Organization.java
....@@ -1,6 +1,7 @@
11 package net.curisit.securis.db;
22
33 import java.io.Serializable;
4
+import java.util.ArrayList;
45 import java.util.Date;
56 import java.util.List;
67
....@@ -17,7 +18,11 @@
1718 import javax.persistence.Table;
1819
1920 import org.codehaus.jackson.annotate.JsonAutoDetect;
21
+import org.codehaus.jackson.annotate.JsonIgnore;
22
+import org.codehaus.jackson.annotate.JsonProperty;
2023 import org.codehaus.jackson.map.annotate.JsonSerialize;
24
+import org.slf4j.Logger;
25
+import org.slf4j.LoggerFactory;
2126
2227 /**
2328 * Entity implementation class for Entity: organization
....@@ -30,6 +35,9 @@
3035 @NamedQueries(
3136 { @NamedQuery(name = "list-organizations", query = "SELECT o FROM Organization o") })
3237 public class Organization implements Serializable {
38
+
39
+ @SuppressWarnings("unused")
40
+ private static final Logger log = LoggerFactory.getLogger(Organization.class);
3341
3442 private static final long serialVersionUID = 1L;
3543
....@@ -44,20 +52,28 @@
4452 @Column(name = "creation_timestamp")
4553 private Date creationTimestamp;
4654
55
+ @JsonIgnore
56
+ // We don't include the users to limit the size of each row a the listing
4757 @ManyToMany
4858 @JoinTable(name = "user_organization", //
4959 joinColumns =
5060 { @JoinColumn(name = "organization_id", referencedColumnName = "id") }, //
5161 inverseJoinColumns =
52
- { @JoinColumn(name = "user_id", referencedColumnName = "username") })
62
+ { @JoinColumn(name = "username", referencedColumnName = "username") })
5363 private List<User> users;
5464
65
+ @JsonIgnore
66
+ // We don't include the users to limit the size of each row a the listing
5567 @ManyToOne
5668 @JoinColumn(name = "org_parent_id")
5769 private Organization parentOrganization;
5870
5971 public int getId() {
6072 return id;
73
+ }
74
+
75
+ public void setId(int id) {
76
+ this.id = id;
6177 }
6278
6379 public String getName() {
....@@ -108,4 +124,43 @@
108124 this.parentOrganization = parentOrganization;
109125 }
110126
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
+
111166 }