From 146a0fb8b0e90f9196e569152f649baf60d6cc8f Mon Sep 17 00:00:00 2001
From: Joaquín Reñé <jrene@curisit.net>
Date: Tue, 07 Oct 2025 14:52:57 +0000
Subject: [PATCH] #4410 - Comments on classes

---
 securis/src/main/java/net/curisit/securis/db/Organization.java |  340 ++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 216 insertions(+), 124 deletions(-)

diff --git a/securis/src/main/java/net/curisit/securis/db/Organization.java b/securis/src/main/java/net/curisit/securis/db/Organization.java
index 6b8b217..b70b8b8 100644
--- a/securis/src/main/java/net/curisit/securis/db/Organization.java
+++ b/securis/src/main/java/net/curisit/securis/db/Organization.java
@@ -1,3 +1,6 @@
+/*
+* Copyright @ 2013 CurisTEC, S.A.S. All Rights Reserved.
+*/
 package net.curisit.securis.db;
 
 import java.io.Serializable;
@@ -32,164 +35,253 @@
 import com.fasterxml.jackson.annotation.JsonProperty;
 
 /**
- * Entity implementation class for Entity: organization
- * 
- */
+* Organization
+* <p>
+* Represents a customer/tenant organization. Manages parent/children hierarchy
+* and user membership.
+*
+* Mapping details:
+* - Table: organization
+* - ManyToMany users via user_organization (ignored in default JSON).
+* - Self-referencing parent/children relation.
+* - Named queries for listing, filtering by ids, and children discovery.
+* 
+* @author JRA
+* Last reviewed by JRA on Oct 5, 2025.
+*/
 @JsonAutoDetect
 @JsonInclude(Include.NON_NULL)
 @JsonIgnoreProperties(ignoreUnknown = true)
 @Entity
 @Table(name = "organization")
-@NamedQueries({ @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"),
-		@NamedQuery(name = "find-children-org", query = "SELECT o FROM Organization o where o.parentOrganization = :parentOrganization") })
+@NamedQueries({
+    @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"),
+    @NamedQuery(name = "find-children-org", query = "SELECT o FROM Organization o where o.parentOrganization = :parentOrganization")
+})
 public class Organization implements Serializable {
 
-	@SuppressWarnings("unused")
-	private static final Logger LOG = LogManager.getLogger(Organization.class);
+    @SuppressWarnings("unused")
+    private static final Logger LOG = LogManager.getLogger(Organization.class);
 
-	private static final long serialVersionUID = 1L;
+    private static final long serialVersionUID = 1L;
 
-	@Id
-	@GeneratedValue
-	private Integer id;
+    @Id
+    @GeneratedValue
+    private Integer id;
 
-	private String code;
-	private String name;
-	private String description;
+    private String code;
+    private String name;
+    private String description;
 
-	@Column(name = "creation_timestamp")
-	@JsonProperty("creation_timestamp")
-	private Date creationTimestamp;
+    @Column(name = "creation_timestamp")
+    @JsonProperty("creation_timestamp")
+    private Date creationTimestamp;
 
-	@JsonIgnore
-	// We don't include the users to limit the size of each row a the listing
-	@ManyToMany(cascade = CascadeType.REMOVE)
-	@JoinTable(name = "user_organization", //
-			joinColumns = { @JoinColumn(name = "organization_id", referencedColumnName = "id") }, //
-			inverseJoinColumns = { @JoinColumn(name = "username", referencedColumnName = "username") })
-	private Set<User> users;
+    @JsonIgnore
+    @ManyToMany(cascade = CascadeType.REMOVE)
+    @JoinTable(name = "user_organization",
+        joinColumns = { @JoinColumn(name = "organization_id", referencedColumnName = "id") },
+        inverseJoinColumns = { @JoinColumn(name = "username", referencedColumnName = "username") })
+    private Set<User> users;
 
-	@JsonIgnore
-	// We don't include the users to limit the size of each row a the listing
-	@ManyToOne
-	@JoinColumn(name = "org_parent_id")
-	private Organization parentOrganization;
+    @JsonIgnore
+    @ManyToOne
+    @JoinColumn(name = "org_parent_id")
+    private Organization parentOrganization;
 
-	@JsonIgnore
-	// We don't include the users to limit the size of each row a the listing
-	@OneToMany(fetch = FetchType.LAZY, mappedBy = "parentOrganization")
-	private Set<Organization> childOrganizations;
+    @JsonIgnore
+    @OneToMany(fetch = FetchType.LAZY, mappedBy = "parentOrganization")
+    private Set<Organization> childOrganizations;
 
-	public Integer getId() {
-		return id;
-	}
+    // ---------------- Getters & setters ----------------
 
-	public void setId(Integer id) {
-		this.id = id;
-	}
+    /** 
+     * getId<p>
+     * Return primary key.
+     * 
+     * @return id
+     */
+    public Integer getId() { return id; }
 
-	public String getName() {
-		return name;
-	}
+    /** 
+     * setId<p>
+     * Set primary key. 
+     * 
+     * @param id
+     */
+    public void setId(Integer id) { this.id = id; }
 
-	public void setName(String name) {
-		this.name = name;
-	}
+    /** 
+     * getName<p>
+     * Return display name. 
+     * 
+     * @return name
+     */
+    public String getName() { return name; }
 
-	public String getDescription() {
-		return description;
-	}
+    /** 
+     * setName<p>
+     * Set display name. 
+     * 
+     * @param name
+     */
+    public void setName(String name) { this.name = name; }
 
-	public void setDescription(String description) {
-		this.description = description;
-	}
+    /** 
+     * getDescription<p>
+     * Return optional description. 
+     * 
+     * @return description
+     */
+    public String getDescription() { return description; }
 
-	public String getCode() {
-		return code;
-	}
+    /** 
+     * setDescription<p>
+     * Set optional description. 
+     * 
+     * @param description
+     */
+    public void setDescription(String description) { this.description = description; }
 
-	public void setCode(String code) {
-		this.code = code;
-	}
+    /** 
+     * getCode<p>
+     * Return short code. 
+     * 
+     * @return code
+     */
+    public String getCode() { return code; }
 
-	public Date getCreationTimestamp() {
-		return creationTimestamp;
-	}
+    /** 
+     * setCode<p>
+     * Set short code. 
+     * 
+     * @param code
+     */
+    public void setCode(String code) { this.code = code; }
 
-	public void setCreationTimestamp(Date creationTimestamp) {
-		this.creationTimestamp = creationTimestamp;
-	}
+    /** 
+     * getCreationTimestamp<p>
+     * Return creation timestamp. 
+     * 
+     * @return creationTimeStamp
+     */
+    public Date getCreationTimestamp() { return creationTimestamp; }
 
-	public Set<User> getUsers() {
-		return users;
-	}
+    /** 
+     * setCreationTimestamp<p>
+     * Set creation timestamp. 
+     * 
+     * @param creationTimestamp
+     */
+    public void setCreationTimestamp(Date creationTimestamp) { this.creationTimestamp = creationTimestamp; }
 
-	public void setUsers(Set<User> users) {
-		this.users = users;
-	}
+    /** 
+     * getUsers<p>
+     * Return member users (entity set). 
+     * 
+     * @return users
+     */
+    public Set<User> getUsers() { return users; }
 
-	public Organization getParentOrganization() {
-		return parentOrganization;
-	}
+    /** 
+     * setUsers<p>
+     * Set member users. 
+     * 
+     * @param users
+     */
+    public void setUsers(Set<User> users) { this.users = users; }
 
-	public void setParentOrganization(Organization parentOrganization) {
-		this.parentOrganization = parentOrganization;
-	}
+    /** 
+     * getParentOrganization<p>
+     * Return parent org (entity). 
+     * 
+     * @return parentOrganization
+     */
+    public Organization getParentOrganization() { return parentOrganization; }
 
-	// Roberto: Following methods are necessary to include in the REST list
-	// response
-	// information about the referenced entities.
-	@JsonProperty("org_parent_id")
-	public void setParentOrgId(Integer orgId) {
-		if (orgId != null) {
-			parentOrganization = new Organization();
-			parentOrganization.setId(orgId);
-		} else {
-			parentOrganization = null;
-		}
-	}
+    /** 
+     * setParentOrganization<p>
+     * Set parent org (entity). 
+     * 
+     * @param parentOrganization
+     */
+    public void setParentOrganization(Organization parentOrganization) { this.parentOrganization = parentOrganization; }
 
-	@JsonProperty("org_parent_id")
-	public Integer getParentOrgId() {
-		return parentOrganization == null ? null : parentOrganization.getId();
-	}
+    // JSON helpers for parent organization
 
-	@JsonProperty("org_parent_name")
-	public String getParentOrgName() {
-		return parentOrganization == null ? null : parentOrganization.getName();
-	}
+    /** 
+     * setParentOrgId<p>
+     * Setter by id (creates shallow Organization). 
+     * 
+     * @param orgId
+     */
+    @JsonProperty("org_parent_id")
+    public void setParentOrgId(Integer orgId) {
+        if (orgId != null) {
+            parentOrganization = new Organization();
+            parentOrganization.setId(orgId);
+        } else {
+            parentOrganization = null;
+        }
+    }
 
-	@JsonProperty("users_ids")
-	public void setUsersIds(List<String> usersIds) {
-		users = new HashSet<>();
-		if (usersIds != null) {
-			for (String userid : usersIds) {
-				User u = new User();
-				u.setUsername(userid);
-				users.add(u);
-			}
-		}
-	}
+    /** 
+     * getParentOrgId<p>
+     * Expose parent org id. 
+     * 
+     * @return parentOrgId
+     */
+    @JsonProperty("org_parent_id")
+    public Integer getParentOrgId() { return parentOrganization == null ? null : parentOrganization.getId(); }
 
-	@JsonProperty("users_ids")
-	public Set<String> getUsersIds() {
-		if (users == null) {
-			return null;
-		}
-		Set<String> ids = new HashSet<>();
-		for (User user : users) {
-			ids.add(user.getUsername());
-		}
-		return ids;
-	}
+    /** 
+     * getParentOrgName<p>
+     * Expose parent org name. 
+     * 
+     * @return parentOrgName
+     */
+    @JsonProperty("org_parent_name")
+    public String getParentOrgName() { return parentOrganization == null ? null : parentOrganization.getName(); }
 
-	public Set<Organization> getChildOrganizations() {
-		return childOrganizations;
-	}
+    // JSON helpers for users
 
-	public void setChildOrganizations(Set<Organization> childOrganizations) {
-		this.childOrganizations = childOrganizations;
-	}
+    /** 
+     * setUsersIds<p>
+     * Replace users set from a list of usernames. 
+     * 
+     * @param userId list
+     */
+    @JsonProperty("users_ids")
+    public void setUsersIds(List<String> usersIds) {
+        users = new HashSet<>();
+        if (usersIds != null) {
+            for (String userid : usersIds) {
+                User u = new User();
+                u.setUsername(userid);
+                users.add(u);
+            }
+        }
+    }
 
+    /** 
+     * getUsersIds<p>
+     * Expose member usernames. 
+     * 
+     * @return userId list
+     */
+    @JsonProperty("users_ids")
+    public Set<String> getUsersIds() {
+        if (users == null) return null;
+        Set<String> ids = new HashSet<>();
+        for (User user : users) { ids.add(user.getUsername()); }
+        return ids;
+    }
+
+    /** getChildOrganizations<p>Return children (entity set). */
+    public Set<Organization> getChildOrganizations() { return childOrganizations; }
+
+    /** setChildOrganizations<p>Set children (entity set). */
+    public void setChildOrganizations(Set<Organization> childOrganizations) { this.childOrganizations = childOrganizations; }
 }
+

--
Gitblit v1.3.2