Joaquín Reñé
2025-10-07 146a0fb8b0e90f9196e569152f649baf60d6cc8f
securis/src/main/java/net/curisit/securis/db/Organization.java
....@@ -1,3 +1,6 @@
1
+/*
2
+* Copyright @ 2013 CurisTEC, S.A.S. All Rights Reserved.
3
+*/
14 package net.curisit.securis.db;
25
36 import java.io.Serializable;
....@@ -32,164 +35,253 @@
3235 import com.fasterxml.jackson.annotation.JsonProperty;
3336
3437 /**
35
- * Entity implementation class for Entity: organization
36
- *
37
- */
38
+* Organization
39
+* <p>
40
+* Represents a customer/tenant organization. Manages parent/children hierarchy
41
+* and user membership.
42
+*
43
+* Mapping details:
44
+* - Table: organization
45
+* - ManyToMany users via user_organization (ignored in default JSON).
46
+* - Self-referencing parent/children relation.
47
+* - Named queries for listing, filtering by ids, and children discovery.
48
+*
49
+* @author JRA
50
+* Last reviewed by JRA on Oct 5, 2025.
51
+*/
3852 @JsonAutoDetect
3953 @JsonInclude(Include.NON_NULL)
4054 @JsonIgnoreProperties(ignoreUnknown = true)
4155 @Entity
4256 @Table(name = "organization")
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") })
57
+@NamedQueries({
58
+ @NamedQuery(name = "list-organizations", query = "SELECT o FROM Organization o"),
59
+ @NamedQuery(name = "list-organizations-by-ids", query = "SELECT o FROM Organization o where id in :list_ids"),
60
+ @NamedQuery(name = "find-children-org", query = "SELECT o FROM Organization o where o.parentOrganization = :parentOrganization")
61
+})
4662 public class Organization implements Serializable {
4763
48
- @SuppressWarnings("unused")
49
- private static final Logger LOG = LogManager.getLogger(Organization.class);
64
+ @SuppressWarnings("unused")
65
+ private static final Logger LOG = LogManager.getLogger(Organization.class);
5066
51
- private static final long serialVersionUID = 1L;
67
+ private static final long serialVersionUID = 1L;
5268
53
- @Id
54
- @GeneratedValue
55
- private Integer id;
69
+ @Id
70
+ @GeneratedValue
71
+ private Integer id;
5672
57
- private String code;
58
- private String name;
59
- private String description;
73
+ private String code;
74
+ private String name;
75
+ private String description;
6076
61
- @Column(name = "creation_timestamp")
62
- @JsonProperty("creation_timestamp")
63
- private Date creationTimestamp;
77
+ @Column(name = "creation_timestamp")
78
+ @JsonProperty("creation_timestamp")
79
+ private Date creationTimestamp;
6480
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;
81
+ @JsonIgnore
82
+ @ManyToMany(cascade = CascadeType.REMOVE)
83
+ @JoinTable(name = "user_organization",
84
+ joinColumns = { @JoinColumn(name = "organization_id", referencedColumnName = "id") },
85
+ inverseJoinColumns = { @JoinColumn(name = "username", referencedColumnName = "username") })
86
+ private Set<User> users;
7287
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;
88
+ @JsonIgnore
89
+ @ManyToOne
90
+ @JoinColumn(name = "org_parent_id")
91
+ private Organization parentOrganization;
7892
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;
93
+ @JsonIgnore
94
+ @OneToMany(fetch = FetchType.LAZY, mappedBy = "parentOrganization")
95
+ private Set<Organization> childOrganizations;
8396
84
- public Integer getId() {
85
- return id;
86
- }
97
+ // ---------------- Getters & setters ----------------
8798
88
- public void setId(Integer id) {
89
- this.id = id;
90
- }
99
+ /**
100
+ * getId<p>
101
+ * Return primary key.
102
+ *
103
+ * @return id
104
+ */
105
+ public Integer getId() { return id; }
91106
92
- public String getName() {
93
- return name;
94
- }
107
+ /**
108
+ * setId<p>
109
+ * Set primary key.
110
+ *
111
+ * @param id
112
+ */
113
+ public void setId(Integer id) { this.id = id; }
95114
96
- public void setName(String name) {
97
- this.name = name;
98
- }
115
+ /**
116
+ * getName<p>
117
+ * Return display name.
118
+ *
119
+ * @return name
120
+ */
121
+ public String getName() { return name; }
99122
100
- public String getDescription() {
101
- return description;
102
- }
123
+ /**
124
+ * setName<p>
125
+ * Set display name.
126
+ *
127
+ * @param name
128
+ */
129
+ public void setName(String name) { this.name = name; }
103130
104
- public void setDescription(String description) {
105
- this.description = description;
106
- }
131
+ /**
132
+ * getDescription<p>
133
+ * Return optional description.
134
+ *
135
+ * @return description
136
+ */
137
+ public String getDescription() { return description; }
107138
108
- public String getCode() {
109
- return code;
110
- }
139
+ /**
140
+ * setDescription<p>
141
+ * Set optional description.
142
+ *
143
+ * @param description
144
+ */
145
+ public void setDescription(String description) { this.description = description; }
111146
112
- public void setCode(String code) {
113
- this.code = code;
114
- }
147
+ /**
148
+ * getCode<p>
149
+ * Return short code.
150
+ *
151
+ * @return code
152
+ */
153
+ public String getCode() { return code; }
115154
116
- public Date getCreationTimestamp() {
117
- return creationTimestamp;
118
- }
155
+ /**
156
+ * setCode<p>
157
+ * Set short code.
158
+ *
159
+ * @param code
160
+ */
161
+ public void setCode(String code) { this.code = code; }
119162
120
- public void setCreationTimestamp(Date creationTimestamp) {
121
- this.creationTimestamp = creationTimestamp;
122
- }
163
+ /**
164
+ * getCreationTimestamp<p>
165
+ * Return creation timestamp.
166
+ *
167
+ * @return creationTimeStamp
168
+ */
169
+ public Date getCreationTimestamp() { return creationTimestamp; }
123170
124
- public Set<User> getUsers() {
125
- return users;
126
- }
171
+ /**
172
+ * setCreationTimestamp<p>
173
+ * Set creation timestamp.
174
+ *
175
+ * @param creationTimestamp
176
+ */
177
+ public void setCreationTimestamp(Date creationTimestamp) { this.creationTimestamp = creationTimestamp; }
127178
128
- public void setUsers(Set<User> users) {
129
- this.users = users;
130
- }
179
+ /**
180
+ * getUsers<p>
181
+ * Return member users (entity set).
182
+ *
183
+ * @return users
184
+ */
185
+ public Set<User> getUsers() { return users; }
131186
132
- public Organization getParentOrganization() {
133
- return parentOrganization;
134
- }
187
+ /**
188
+ * setUsers<p>
189
+ * Set member users.
190
+ *
191
+ * @param users
192
+ */
193
+ public void setUsers(Set<User> users) { this.users = users; }
135194
136
- public void setParentOrganization(Organization parentOrganization) {
137
- this.parentOrganization = parentOrganization;
138
- }
195
+ /**
196
+ * getParentOrganization<p>
197
+ * Return parent org (entity).
198
+ *
199
+ * @return parentOrganization
200
+ */
201
+ public Organization getParentOrganization() { return parentOrganization; }
139202
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
- }
203
+ /**
204
+ * setParentOrganization<p>
205
+ * Set parent org (entity).
206
+ *
207
+ * @param parentOrganization
208
+ */
209
+ public void setParentOrganization(Organization parentOrganization) { this.parentOrganization = parentOrganization; }
152210
153
- @JsonProperty("org_parent_id")
154
- public Integer getParentOrgId() {
155
- return parentOrganization == null ? null : parentOrganization.getId();
156
- }
211
+ // JSON helpers for parent organization
157212
158
- @JsonProperty("org_parent_name")
159
- public String getParentOrgName() {
160
- return parentOrganization == null ? null : parentOrganization.getName();
161
- }
213
+ /**
214
+ * setParentOrgId<p>
215
+ * Setter by id (creates shallow Organization).
216
+ *
217
+ * @param orgId
218
+ */
219
+ @JsonProperty("org_parent_id")
220
+ public void setParentOrgId(Integer orgId) {
221
+ if (orgId != null) {
222
+ parentOrganization = new Organization();
223
+ parentOrganization.setId(orgId);
224
+ } else {
225
+ parentOrganization = null;
226
+ }
227
+ }
162228
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
- }
229
+ /**
230
+ * getParentOrgId<p>
231
+ * Expose parent org id.
232
+ *
233
+ * @return parentOrgId
234
+ */
235
+ @JsonProperty("org_parent_id")
236
+ public Integer getParentOrgId() { return parentOrganization == null ? null : parentOrganization.getId(); }
174237
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
- }
238
+ /**
239
+ * getParentOrgName<p>
240
+ * Expose parent org name.
241
+ *
242
+ * @return parentOrgName
243
+ */
244
+ @JsonProperty("org_parent_name")
245
+ public String getParentOrgName() { return parentOrganization == null ? null : parentOrganization.getName(); }
186246
187
- public Set<Organization> getChildOrganizations() {
188
- return childOrganizations;
189
- }
247
+ // JSON helpers for users
190248
191
- public void setChildOrganizations(Set<Organization> childOrganizations) {
192
- this.childOrganizations = childOrganizations;
193
- }
249
+ /**
250
+ * setUsersIds<p>
251
+ * Replace users set from a list of usernames.
252
+ *
253
+ * @param userId list
254
+ */
255
+ @JsonProperty("users_ids")
256
+ public void setUsersIds(List<String> usersIds) {
257
+ users = new HashSet<>();
258
+ if (usersIds != null) {
259
+ for (String userid : usersIds) {
260
+ User u = new User();
261
+ u.setUsername(userid);
262
+ users.add(u);
263
+ }
264
+ }
265
+ }
194266
267
+ /**
268
+ * getUsersIds<p>
269
+ * Expose member usernames.
270
+ *
271
+ * @return userId list
272
+ */
273
+ @JsonProperty("users_ids")
274
+ public Set<String> getUsersIds() {
275
+ if (users == null) return null;
276
+ Set<String> ids = new HashSet<>();
277
+ for (User user : users) { ids.add(user.getUsername()); }
278
+ return ids;
279
+ }
280
+
281
+ /** getChildOrganizations<p>Return children (entity set). */
282
+ public Set<Organization> getChildOrganizations() { return childOrganizations; }
283
+
284
+ /** setChildOrganizations<p>Set children (entity set). */
285
+ public void setChildOrganizations(Set<Organization> childOrganizations) { this.childOrganizations = childOrganizations; }
195286 }
287
+