| .. | .. |
|---|
| 1 | +/* |
|---|
| 2 | +* Copyright @ 2013 CurisTEC, S.A.S. All Rights Reserved. |
|---|
| 3 | +*/ |
|---|
| 1 | 4 | package net.curisit.securis.db; |
|---|
| 2 | 5 | |
|---|
| 3 | 6 | import java.io.Serializable; |
|---|
| .. | .. |
|---|
| 32 | 35 | import net.curisit.integrity.commons.Utils; |
|---|
| 33 | 36 | |
|---|
| 34 | 37 | /** |
|---|
| 35 | | - * Entity implementation class for Entity: pack |
|---|
| 36 | | - * |
|---|
| 37 | | - */ |
|---|
| 38 | +* Pack |
|---|
| 39 | +* <p> |
|---|
| 40 | +* Group/bundle of licenses for an organization and application (via LicenseType). |
|---|
| 41 | +* Tracks capacity, availability, status, and validity windows. |
|---|
| 42 | +* |
|---|
| 43 | +* Mapping details: |
|---|
| 44 | +* - Table: pack |
|---|
| 45 | +* - ManyToOne to Organization, LicenseType, User (createdBy) |
|---|
| 46 | +* - OneToMany licenses (lazy) |
|---|
| 47 | +* - Custom type: net.curisit.securis.db.common.PackStatusType |
|---|
| 48 | +* - Named queries for listing and filtering by org/app. |
|---|
| 49 | +* |
|---|
| 50 | +* @author JRA |
|---|
| 51 | +* Last reviewed by JRA on Oct 5, 2025. |
|---|
| 52 | +*/ |
|---|
| 38 | 53 | @JsonAutoDetect |
|---|
| 39 | 54 | @JsonInclude(Include.NON_NULL) |
|---|
| 40 | 55 | @Entity |
|---|
| 41 | 56 | @Table(name = "pack") |
|---|
| 42 | 57 | @JsonIgnoreProperties(ignoreUnknown = true) |
|---|
| 43 | | -@NamedQueries({ @NamedQuery(name = "list-packs", query = "SELECT pa FROM Pack pa"), // |
|---|
| 44 | | - @NamedQuery(name = "pack-by-code", query = "SELECT pa FROM Pack pa where pa.code = :code"), // |
|---|
| 45 | | - @NamedQuery(name = "list-packs-by-lic-type", query = "SELECT pa FROM Pack pa where pa.licenseType.id = :lt_id"), // |
|---|
| 46 | | - @NamedQuery(name = "list-packs-by-orgs-apps", query = "SELECT pa FROM Pack pa where pa.organization.id in :list_ids_org and pa.licenseType.application.id in :list_ids_app "), // |
|---|
| 47 | | - @NamedQuery(name = "list-packs-by-apps", query = "SELECT pa FROM Pack pa where pa.licenseType.application.id in :list_ids_app ") }) |
|---|
| 58 | +@NamedQueries({ |
|---|
| 59 | + @NamedQuery(name = "list-packs", query = "SELECT pa FROM Pack pa"), |
|---|
| 60 | + @NamedQuery(name = "pack-by-code", query = "SELECT pa FROM Pack pa where pa.code = :code"), |
|---|
| 61 | + @NamedQuery(name = "list-packs-by-lic-type", query = "SELECT pa FROM Pack pa where pa.licenseType.id = :lt_id"), |
|---|
| 62 | + @NamedQuery(name = "list-packs-by-orgs-apps", query = "SELECT pa FROM Pack pa where pa.organization.id in :list_ids_org and pa.licenseType.application.id in :list_ids_app "), |
|---|
| 63 | + @NamedQuery(name = "list-packs-by-apps", query = "SELECT pa FROM Pack pa where pa.licenseType.application.id in :list_ids_app ") |
|---|
| 64 | +}) |
|---|
| 48 | 65 | public class Pack implements Serializable { |
|---|
| 49 | 66 | |
|---|
| 50 | | - private static final long serialVersionUID = 1L; |
|---|
| 67 | + private static final long serialVersionUID = 1L; |
|---|
| 51 | 68 | |
|---|
| 52 | | - @Id |
|---|
| 53 | | - @GeneratedValue |
|---|
| 54 | | - private Integer id; |
|---|
| 69 | + @Id |
|---|
| 70 | + @GeneratedValue |
|---|
| 71 | + private Integer id; |
|---|
| 55 | 72 | |
|---|
| 56 | | - private String code; |
|---|
| 73 | + private String code; |
|---|
| 74 | + private String comments; |
|---|
| 75 | + private Boolean frozen; |
|---|
| 57 | 76 | |
|---|
| 58 | | - private String comments; |
|---|
| 77 | + @Column(name = "creation_timestamp") |
|---|
| 78 | + @JsonProperty("creation_timestamp") |
|---|
| 79 | + private Date creationTimestamp; |
|---|
| 59 | 80 | |
|---|
| 60 | | - private Boolean frozen; |
|---|
| 81 | + @JsonIgnore |
|---|
| 82 | + @ManyToOne |
|---|
| 83 | + @JoinColumn(name = "organization_id") |
|---|
| 84 | + private Organization organization; |
|---|
| 61 | 85 | |
|---|
| 62 | | - @Column(name = "creation_timestamp") |
|---|
| 63 | | - @JsonProperty("creation_timestamp") |
|---|
| 64 | | - private Date creationTimestamp; |
|---|
| 86 | + @JsonIgnore |
|---|
| 87 | + @ManyToOne |
|---|
| 88 | + @JoinColumn(name = "license_type_id") |
|---|
| 89 | + private LicenseType licenseType; |
|---|
| 65 | 90 | |
|---|
| 66 | | - @JsonIgnore |
|---|
| 67 | | - @ManyToOne |
|---|
| 68 | | - @JoinColumn(name = "organization_id") |
|---|
| 69 | | - private Organization organization; |
|---|
| 91 | + @JsonIgnore |
|---|
| 92 | + @ManyToOne |
|---|
| 93 | + @JoinColumn(name = "created_by") |
|---|
| 94 | + private User createdBy; |
|---|
| 70 | 95 | |
|---|
| 71 | | - @JsonIgnore |
|---|
| 72 | | - @ManyToOne |
|---|
| 73 | | - @JoinColumn(name = "license_type_id") |
|---|
| 74 | | - private LicenseType licenseType; |
|---|
| 96 | + @JsonIgnore |
|---|
| 97 | + @OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST, CascadeType.REMOVE, CascadeType.REFRESH }, mappedBy = "pack") |
|---|
| 98 | + private Set<License> licenses; |
|---|
| 75 | 99 | |
|---|
| 76 | | - @JsonIgnore |
|---|
| 77 | | - @ManyToOne |
|---|
| 78 | | - @JoinColumn(name = "created_by") |
|---|
| 79 | | - private User createdBy; |
|---|
| 100 | + @Column(name = "num_licenses") |
|---|
| 101 | + @JsonProperty("num_licenses") |
|---|
| 102 | + private int numLicenses; |
|---|
| 80 | 103 | |
|---|
| 81 | | - @JsonIgnore |
|---|
| 82 | | - @OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST, CascadeType.REMOVE, CascadeType.REFRESH }, mappedBy = "pack") |
|---|
| 83 | | - private Set<License> licenses; |
|---|
| 104 | + @Column(name = "init_valid_date") |
|---|
| 105 | + @JsonProperty("init_valid_date") |
|---|
| 106 | + private Date initValidDate; |
|---|
| 84 | 107 | |
|---|
| 85 | | - @Column(name = "num_licenses") |
|---|
| 86 | | - @JsonProperty("num_licenses") |
|---|
| 87 | | - private int numLicenses; |
|---|
| 108 | + @Column(name = "end_valid_date") |
|---|
| 109 | + @JsonProperty("end_valid_date") |
|---|
| 110 | + private Date endValidDate; |
|---|
| 88 | 111 | |
|---|
| 89 | | - @Column(name = "init_valid_date") |
|---|
| 90 | | - @JsonProperty("init_valid_date") |
|---|
| 91 | | - private Date initValidDate; |
|---|
| 112 | + @Type(type = "net.curisit.securis.db.common.PackStatusType") |
|---|
| 113 | + private PackStatus status; |
|---|
| 92 | 114 | |
|---|
| 93 | | - @Column(name = "end_valid_date") |
|---|
| 94 | | - @JsonProperty("end_valid_date") |
|---|
| 95 | | - private Date endValidDate; |
|---|
| 115 | + @Column(name = "license_preactivation") |
|---|
| 116 | + @JsonProperty("license_preactivation") |
|---|
| 117 | + private boolean licensePreactivation; |
|---|
| 96 | 118 | |
|---|
| 97 | | - @Type(type = "net.curisit.securis.db.common.PackStatusType") |
|---|
| 98 | | - private PackStatus status; |
|---|
| 119 | + @Column(name = "preactivation_valid_period") |
|---|
| 120 | + @JsonProperty("preactivation_valid_period") |
|---|
| 121 | + private Integer preactivationValidPeriod; |
|---|
| 99 | 122 | |
|---|
| 100 | | - @Column(name = "license_preactivation") |
|---|
| 101 | | - @JsonProperty("license_preactivation") |
|---|
| 102 | | - private boolean licensePreactivation; |
|---|
| 123 | + @Column(name = "renew_valid_period") |
|---|
| 124 | + @JsonProperty("renew_valid_period") |
|---|
| 125 | + private Integer renewValidPeriod; |
|---|
| 103 | 126 | |
|---|
| 104 | | - @Column(name = "preactivation_valid_period") |
|---|
| 105 | | - @JsonProperty("preactivation_valid_period") |
|---|
| 106 | | - private Integer preactivationValidPeriod; |
|---|
| 127 | + @OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST, CascadeType.REMOVE, CascadeType.REFRESH }, mappedBy = "pack") |
|---|
| 128 | + private Set<PackMetadata> metadata; |
|---|
| 107 | 129 | |
|---|
| 108 | | - @Column(name = "renew_valid_period") |
|---|
| 109 | | - @JsonProperty("renew_valid_period") |
|---|
| 110 | | - private Integer renewValidPeriod; |
|---|
| 130 | + // ---------------- Getters & setters ---------------- |
|---|
| 111 | 131 | |
|---|
| 112 | | - @OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST, CascadeType.REMOVE, CascadeType.REFRESH }, mappedBy = "pack") |
|---|
| 113 | | - private Set<PackMetadata> metadata; |
|---|
| 132 | + /** |
|---|
| 133 | + * getId<p> |
|---|
| 134 | + * Return primary key. |
|---|
| 135 | + * |
|---|
| 136 | + * @return id |
|---|
| 137 | + */ |
|---|
| 138 | + public Integer getId() { return id; } |
|---|
| 114 | 139 | |
|---|
| 115 | | - public Integer getId() { |
|---|
| 116 | | - return id; |
|---|
| 117 | | - } |
|---|
| 140 | + /** |
|---|
| 141 | + * setId<p> |
|---|
| 142 | + * Set primary key. |
|---|
| 143 | + * |
|---|
| 144 | + * @param id |
|---|
| 145 | + */ |
|---|
| 146 | + public void setId(Integer id) { this.id = id; } |
|---|
| 118 | 147 | |
|---|
| 119 | | - public void setId(Integer id) { |
|---|
| 120 | | - this.id = id; |
|---|
| 121 | | - } |
|---|
| 148 | + /** |
|---|
| 149 | + * getCode<p> |
|---|
| 150 | + * Return pack code. |
|---|
| 151 | + * |
|---|
| 152 | + * @return packCode |
|---|
| 153 | + */ |
|---|
| 154 | + public String getCode() { return code; } |
|---|
| 122 | 155 | |
|---|
| 123 | | - public String getCode() { |
|---|
| 124 | | - return code; |
|---|
| 125 | | - } |
|---|
| 156 | + /** |
|---|
| 157 | + * setCode<p> |
|---|
| 158 | + * Set pack code. |
|---|
| 159 | + * |
|---|
| 160 | + * @param packCode |
|---|
| 161 | + */ |
|---|
| 162 | + public void setCode(String code) { this.code = code; } |
|---|
| 126 | 163 | |
|---|
| 127 | | - public void setCode(String code) { |
|---|
| 128 | | - this.code = code; |
|---|
| 129 | | - } |
|---|
| 164 | + /** |
|---|
| 165 | + * getCreationTimestamp<p> |
|---|
| 166 | + * Return creation timestamp. |
|---|
| 167 | + * |
|---|
| 168 | + * @return creationTimestamp |
|---|
| 169 | + */ |
|---|
| 170 | + public Date getCreationTimestamp() { return creationTimestamp; } |
|---|
| 130 | 171 | |
|---|
| 131 | | - public Date getCreationTimestamp() { |
|---|
| 132 | | - return creationTimestamp; |
|---|
| 133 | | - } |
|---|
| 172 | + /** |
|---|
| 173 | + * setCreationTimestamp<p> |
|---|
| 174 | + * Set creation timestamp. |
|---|
| 175 | + * |
|---|
| 176 | + * @param creationTimestamp |
|---|
| 177 | + */ |
|---|
| 178 | + public void setCreationTimestamp(Date creationTimestamp) { this.creationTimestamp = creationTimestamp; } |
|---|
| 134 | 179 | |
|---|
| 135 | | - public void setCreationTimestamp(Date creationTimestamp) { |
|---|
| 136 | | - this.creationTimestamp = creationTimestamp; |
|---|
| 137 | | - } |
|---|
| 180 | + /** |
|---|
| 181 | + * getOrganization<p> |
|---|
| 182 | + * Return owning organization (entity). |
|---|
| 183 | + * |
|---|
| 184 | + * @return organization |
|---|
| 185 | + */ |
|---|
| 186 | + public Organization getOrganization() { return organization; } |
|---|
| 138 | 187 | |
|---|
| 139 | | - public Organization getOrganization() { |
|---|
| 140 | | - return organization; |
|---|
| 141 | | - } |
|---|
| 188 | + /** |
|---|
| 189 | + * setOrganization<p> |
|---|
| 190 | + * Set owning organization (entity). |
|---|
| 191 | + * |
|---|
| 192 | + * @param organization |
|---|
| 193 | + */ |
|---|
| 194 | + public void setOrganization(Organization organization) { this.organization = organization; } |
|---|
| 142 | 195 | |
|---|
| 143 | | - public void setOrganization(Organization organization) { |
|---|
| 144 | | - this.organization = organization; |
|---|
| 145 | | - } |
|---|
| 196 | + /** |
|---|
| 197 | + * getLicenseType<p> |
|---|
| 198 | + * Return license type (entity). |
|---|
| 199 | + * |
|---|
| 200 | + * @return licenseType |
|---|
| 201 | + */ |
|---|
| 202 | + public LicenseType getLicenseType() { return licenseType; } |
|---|
| 146 | 203 | |
|---|
| 147 | | - public LicenseType getLicenseType() { |
|---|
| 148 | | - return licenseType; |
|---|
| 149 | | - } |
|---|
| 204 | + /** |
|---|
| 205 | + * setLicenseType<p> |
|---|
| 206 | + * Set license type (entity). |
|---|
| 207 | + * |
|---|
| 208 | + * @param licenseType |
|---|
| 209 | + */ |
|---|
| 210 | + public void setLicenseType(LicenseType licenseType) { this.licenseType = licenseType; } |
|---|
| 150 | 211 | |
|---|
| 151 | | - public void setLicenseType(LicenseType licenseType) { |
|---|
| 152 | | - this.licenseType = licenseType; |
|---|
| 153 | | - } |
|---|
| 212 | + /** |
|---|
| 213 | + * getCreatedBy<p> |
|---|
| 214 | + * Return creator (entity). |
|---|
| 215 | + * |
|---|
| 216 | + * @return user |
|---|
| 217 | + */ |
|---|
| 218 | + public User getCreatedBy() { return createdBy; } |
|---|
| 154 | 219 | |
|---|
| 155 | | - public User getCreatedBy() { |
|---|
| 156 | | - return createdBy; |
|---|
| 157 | | - } |
|---|
| 220 | + /** |
|---|
| 221 | + * setCreatedBy<p> |
|---|
| 222 | + * Set creator (entity). |
|---|
| 223 | + * |
|---|
| 224 | + * @param user |
|---|
| 225 | + */ |
|---|
| 226 | + public void setCreatedBy(User createdBy) { this.createdBy = createdBy; } |
|---|
| 158 | 227 | |
|---|
| 159 | | - public void setCreatedBy(User createdBy) { |
|---|
| 160 | | - this.createdBy = createdBy; |
|---|
| 161 | | - } |
|---|
| 228 | + /** |
|---|
| 229 | + * getNumLicenses<p> |
|---|
| 230 | + * Return capacity (licenses). |
|---|
| 231 | + * |
|---|
| 232 | + * @return numLicenses |
|---|
| 233 | + * Number of licenses |
|---|
| 234 | + */ |
|---|
| 235 | + public int getNumLicenses() { return numLicenses; } |
|---|
| 162 | 236 | |
|---|
| 163 | | - public int getNumLicenses() { |
|---|
| 164 | | - return numLicenses; |
|---|
| 165 | | - } |
|---|
| 237 | + /** |
|---|
| 238 | + * setNumLicenses<p> |
|---|
| 239 | + * Set capacity (licenses). |
|---|
| 240 | + * |
|---|
| 241 | + * @param numLicenses |
|---|
| 242 | + * Number of licenses |
|---|
| 243 | + */ |
|---|
| 244 | + public void setNumLicenses(int numLicenses) { this.numLicenses = numLicenses; } |
|---|
| 166 | 245 | |
|---|
| 167 | | - public void setNumLicenses(int numLicenses) { |
|---|
| 168 | | - this.numLicenses = numLicenses; |
|---|
| 169 | | - } |
|---|
| 246 | + /** |
|---|
| 247 | + * getNumActivations<p> |
|---|
| 248 | + * Count ACTIVE/PRE_ACTIVE licenses in this pack. |
|---|
| 249 | + * |
|---|
| 250 | + * @return numActivations |
|---|
| 251 | + * number of activated licenses |
|---|
| 252 | + */ |
|---|
| 253 | + @JsonProperty("num_activations") |
|---|
| 254 | + public int getNumActivations() { |
|---|
| 255 | + if (licenses == null) return 0; |
|---|
| 256 | + int num = 0; |
|---|
| 257 | + for (License lic : licenses) { |
|---|
| 258 | + if (lic.getStatus() == LicenseStatus.ACTIVE || lic.getStatus() == LicenseStatus.PRE_ACTIVE) num++; |
|---|
| 259 | + } |
|---|
| 260 | + return num; |
|---|
| 261 | + } |
|---|
| 170 | 262 | |
|---|
| 171 | | - @JsonProperty("num_activations") |
|---|
| 172 | | - public int getNumActivations() { |
|---|
| 173 | | - if (licenses == null) { |
|---|
| 174 | | - return 0; |
|---|
| 175 | | - } |
|---|
| 176 | | - int num = 0; |
|---|
| 177 | | - for (License lic : licenses) { |
|---|
| 178 | | - if (lic.getStatus() == LicenseStatus.ACTIVE || lic.getStatus() == LicenseStatus.PRE_ACTIVE) { |
|---|
| 179 | | - num++; |
|---|
| 180 | | - } |
|---|
| 181 | | - } |
|---|
| 182 | | - return num; |
|---|
| 183 | | - } |
|---|
| 263 | + /** |
|---|
| 264 | + * getNumCreations<p> |
|---|
| 265 | + * Count all created licenses (including waiting for activation). Ignores CANCELLED. |
|---|
| 266 | + * |
|---|
| 267 | + * @return numCreations |
|---|
| 268 | + * number of created licenses |
|---|
| 269 | + */ |
|---|
| 270 | + @JsonProperty("num_creations") |
|---|
| 271 | + public int getNumCreations() { |
|---|
| 272 | + if (licenses == null) return 0; |
|---|
| 273 | + int num = 0; |
|---|
| 274 | + for (License lic : licenses) { |
|---|
| 275 | + if (lic.getStatus() != LicenseStatus.CANCELLED) num++; |
|---|
| 276 | + } |
|---|
| 277 | + return num; |
|---|
| 278 | + } |
|---|
| 184 | 279 | |
|---|
| 185 | | - /** |
|---|
| 186 | | - * Counts all created licenses, It counts active licenses and licenses |
|---|
| 187 | | - * waiting for activation This number will be used to control the max number |
|---|
| 188 | | - * of licenses created. Ignore canceled licenses. |
|---|
| 189 | | - * |
|---|
| 190 | | - * @return |
|---|
| 191 | | - */ |
|---|
| 192 | | - @JsonProperty("num_creations") |
|---|
| 193 | | - public int getNumCreations() { |
|---|
| 194 | | - if (licenses == null) { |
|---|
| 195 | | - return 0; |
|---|
| 196 | | - } |
|---|
| 197 | | - int num = 0; |
|---|
| 198 | | - for (License lic : licenses) { |
|---|
| 199 | | - if (lic.getStatus() != LicenseStatus.CANCELLED) { |
|---|
| 200 | | - num++; |
|---|
| 201 | | - } |
|---|
| 202 | | - } |
|---|
| 203 | | - return num; |
|---|
| 204 | | - } |
|---|
| 280 | + /** |
|---|
| 281 | + * getNumAvailables<p> |
|---|
| 282 | + * Number of available licenses in this pack: capacity - activations. |
|---|
| 283 | + * |
|---|
| 284 | + * @return numAvailable |
|---|
| 285 | + * Number of available licenses |
|---|
| 286 | + */ |
|---|
| 287 | + @JsonProperty("num_available") |
|---|
| 288 | + public int getNumAvailables() { return numLicenses - getNumActivations(); } |
|---|
| 205 | 289 | |
|---|
| 206 | | - /** |
|---|
| 207 | | - * Number of available licenses in this pack |
|---|
| 208 | | - * |
|---|
| 209 | | - * @return |
|---|
| 210 | | - */ |
|---|
| 211 | | - @JsonProperty("num_available") |
|---|
| 212 | | - public int getNumAvailables() { |
|---|
| 213 | | - return numLicenses - getNumActivations(); |
|---|
| 214 | | - } |
|---|
| 290 | + /** |
|---|
| 291 | + * getOrgName<p> |
|---|
| 292 | + * Expose organization name. |
|---|
| 293 | + * |
|---|
| 294 | + * @return orgName |
|---|
| 295 | + */ |
|---|
| 296 | + @JsonProperty("organization_name") |
|---|
| 297 | + public String getOrgName() { return organization == null ? null : organization.getName(); } |
|---|
| 215 | 298 | |
|---|
| 216 | | - @JsonProperty("organization_name") |
|---|
| 217 | | - public String getOrgName() { |
|---|
| 218 | | - return organization == null ? null : organization.getName(); |
|---|
| 219 | | - } |
|---|
| 299 | + /** |
|---|
| 300 | + * getAppName<p> |
|---|
| 301 | + * Expose application name via license type. |
|---|
| 302 | + * |
|---|
| 303 | + * @return appName |
|---|
| 304 | + */ |
|---|
| 305 | + @JsonProperty("application_name") |
|---|
| 306 | + public String getAppName() { |
|---|
| 307 | + if (licenseType == null) return null; |
|---|
| 308 | + Application app = licenseType.getApplication(); |
|---|
| 309 | + return app == null ? null : app.getName(); |
|---|
| 310 | + } |
|---|
| 220 | 311 | |
|---|
| 221 | | - @JsonProperty("application_name") |
|---|
| 222 | | - public String getAppName() { |
|---|
| 223 | | - if (licenseType == null) { |
|---|
| 224 | | - return null; |
|---|
| 225 | | - } |
|---|
| 226 | | - Application app = licenseType.getApplication(); |
|---|
| 227 | | - return app == null ? null : app.getName(); |
|---|
| 228 | | - } |
|---|
| 312 | + /** |
|---|
| 313 | + * getOrgId<p> |
|---|
| 314 | + * Expose organization id. |
|---|
| 315 | + * |
|---|
| 316 | + * @return orgId |
|---|
| 317 | + */ |
|---|
| 318 | + @JsonProperty("organization_id") |
|---|
| 319 | + public Integer getOrgId() { return organization == null ? null : organization.getId(); } |
|---|
| 229 | 320 | |
|---|
| 230 | | - @JsonProperty("organization_id") |
|---|
| 231 | | - public Integer getOrgId() { |
|---|
| 232 | | - return organization == null ? null : organization.getId(); |
|---|
| 233 | | - } |
|---|
| 321 | + /** |
|---|
| 322 | + * setOrgId<p> |
|---|
| 323 | + * Setter by id for JSON binding (creates shallow Organization). |
|---|
| 324 | + * |
|---|
| 325 | + * @param orgId |
|---|
| 326 | + */ |
|---|
| 327 | + @JsonProperty("organization_id") |
|---|
| 328 | + public void setOrgId(Integer idOrg) { |
|---|
| 329 | + if (idOrg == null) { |
|---|
| 330 | + organization = null; |
|---|
| 331 | + } else { |
|---|
| 332 | + organization = new Organization(); |
|---|
| 333 | + organization.setId(idOrg); |
|---|
| 334 | + } |
|---|
| 335 | + } |
|---|
| 234 | 336 | |
|---|
| 235 | | - @JsonProperty("organization_id") |
|---|
| 236 | | - public void setOrgId(Integer idOrg) { |
|---|
| 237 | | - if (idOrg == null) { |
|---|
| 238 | | - organization = null; |
|---|
| 239 | | - } else { |
|---|
| 240 | | - organization = new Organization(); |
|---|
| 241 | | - organization.setId(idOrg); |
|---|
| 242 | | - } |
|---|
| 243 | | - } |
|---|
| 337 | + /** |
|---|
| 338 | + * setLicTypeId<p> |
|---|
| 339 | + * Setter by id for JSON binding (creates shallow LicenseType). |
|---|
| 340 | + * |
|---|
| 341 | + * @param licTypeId |
|---|
| 342 | + */ |
|---|
| 343 | + @JsonProperty("license_type_id") |
|---|
| 344 | + public void setLicTypeId(Integer idLT) { |
|---|
| 345 | + if (idLT == null) { |
|---|
| 346 | + licenseType = null; |
|---|
| 347 | + } else { |
|---|
| 348 | + licenseType = new LicenseType(); |
|---|
| 349 | + licenseType.setId(idLT); |
|---|
| 350 | + } |
|---|
| 351 | + } |
|---|
| 244 | 352 | |
|---|
| 245 | | - @JsonProperty("license_type_id") |
|---|
| 246 | | - public void setLicTypeId(Integer idLT) { |
|---|
| 247 | | - if (idLT == null) { |
|---|
| 248 | | - licenseType = null; |
|---|
| 249 | | - } else { |
|---|
| 250 | | - licenseType = new LicenseType(); |
|---|
| 251 | | - licenseType.setId(idLT); |
|---|
| 252 | | - } |
|---|
| 253 | | - } |
|---|
| 353 | + /** |
|---|
| 354 | + * getLicTypeId<p> |
|---|
| 355 | + * Expose license type id. |
|---|
| 356 | + * |
|---|
| 357 | + * @return licTypeId |
|---|
| 358 | + */ |
|---|
| 359 | + @JsonProperty("license_type_id") |
|---|
| 360 | + public Integer getLicTypeId() { return licenseType == null ? null : licenseType.getId(); } |
|---|
| 254 | 361 | |
|---|
| 255 | | - @JsonProperty("license_type_id") |
|---|
| 256 | | - public Integer getLicTypeId() { |
|---|
| 257 | | - return licenseType == null ? null : licenseType.getId(); |
|---|
| 258 | | - } |
|---|
| 362 | + /** |
|---|
| 363 | + * getCreatedById<p> |
|---|
| 364 | + * Expose creator username. |
|---|
| 365 | + * |
|---|
| 366 | + * @return username |
|---|
| 367 | + */ |
|---|
| 368 | + @JsonProperty("created_by_id") |
|---|
| 369 | + public String getCreatedById() { return createdBy == null ? null : createdBy.getUsername(); } |
|---|
| 259 | 370 | |
|---|
| 260 | | - @JsonProperty("created_by_id") |
|---|
| 261 | | - public String getCreatedById() { |
|---|
| 262 | | - return createdBy == null ? null : createdBy.getUsername(); |
|---|
| 263 | | - } |
|---|
| 371 | + /** |
|---|
| 372 | + * setCreatedById<p> |
|---|
| 373 | + * Setter by username (creates shallow User). |
|---|
| 374 | + * |
|---|
| 375 | + * @param username |
|---|
| 376 | + */ |
|---|
| 377 | + @JsonProperty("created_by_id") |
|---|
| 378 | + public void setCreatedById(String username) { |
|---|
| 379 | + createdBy = new User(); |
|---|
| 380 | + createdBy.setUsername(username); |
|---|
| 381 | + } |
|---|
| 264 | 382 | |
|---|
| 265 | | - @JsonProperty("created_by_id") |
|---|
| 266 | | - public void setCreatedById(String username) { |
|---|
| 267 | | - createdBy = new User(); |
|---|
| 268 | | - createdBy.setUsername(username); |
|---|
| 269 | | - } |
|---|
| 383 | + /** |
|---|
| 384 | + * getCreatedByname<p> |
|---|
| 385 | + * Expose creator full display name. |
|---|
| 386 | + * |
|---|
| 387 | + * @return userName |
|---|
| 388 | + */ |
|---|
| 389 | + @JsonProperty("created_by_name") |
|---|
| 390 | + public String getCreatedByname() { |
|---|
| 391 | + return createdBy == null ? null |
|---|
| 392 | + : String.format("%s %s (%s)", createdBy.getFirstName(), |
|---|
| 393 | + createdBy.getLastName() != null ? createdBy.getLastName() : "", |
|---|
| 394 | + createdBy.getUsername()); |
|---|
| 395 | + } |
|---|
| 270 | 396 | |
|---|
| 271 | | - @JsonProperty("created_by_name") |
|---|
| 272 | | - public String getCreatedByname() { |
|---|
| 273 | | - return createdBy == null ? null |
|---|
| 274 | | - : String.format("%s %s (%s)", createdBy.getFirstName(), createdBy.getLastName() != null ? createdBy.getLastName() : "", createdBy.getUsername()); |
|---|
| 275 | | - } |
|---|
| 397 | + /** |
|---|
| 398 | + * getLicenseTypeCode<p> |
|---|
| 399 | + * Expose license type code. |
|---|
| 400 | + * |
|---|
| 401 | + * @return licenseTypeCode |
|---|
| 402 | + */ |
|---|
| 403 | + @JsonProperty("licensetype_code") |
|---|
| 404 | + public String getLicenseTypeCode() { return licenseType == null ? null : licenseType.getCode(); } |
|---|
| 276 | 405 | |
|---|
| 277 | | - @JsonProperty("licensetype_code") |
|---|
| 278 | | - public String getLicenseTypeCode() { |
|---|
| 279 | | - return licenseType == null ? null : licenseType.getCode(); |
|---|
| 280 | | - } |
|---|
| 406 | + /** |
|---|
| 407 | + * getComments<p> |
|---|
| 408 | + * Return comments. |
|---|
| 409 | + * |
|---|
| 410 | + * @return comments |
|---|
| 411 | + */ |
|---|
| 412 | + public String getComments() { return comments; } |
|---|
| 281 | 413 | |
|---|
| 282 | | - public String getComments() { |
|---|
| 283 | | - return comments; |
|---|
| 284 | | - } |
|---|
| 414 | + /** |
|---|
| 415 | + * setComments<p> |
|---|
| 416 | + * Set comments. |
|---|
| 417 | + * |
|---|
| 418 | + * @param comments |
|---|
| 419 | + */ |
|---|
| 420 | + public void setComments(String comments) { this.comments = comments; } |
|---|
| 285 | 421 | |
|---|
| 286 | | - public void setComments(String comments) { |
|---|
| 287 | | - this.comments = comments; |
|---|
| 288 | | - } |
|---|
| 422 | + /** |
|---|
| 423 | + * isLicensePreactivation<p> |
|---|
| 424 | + * Whether licenses are pre-activated. |
|---|
| 425 | + * |
|---|
| 426 | + * @return isLicensePreactivation |
|---|
| 427 | + */ |
|---|
| 428 | + public boolean isLicensePreactivation() { return licensePreactivation; } |
|---|
| 289 | 429 | |
|---|
| 290 | | - public boolean isLicensePreactivation() { |
|---|
| 291 | | - return licensePreactivation; |
|---|
| 292 | | - } |
|---|
| 430 | + /** |
|---|
| 431 | + * setLicensePreactivation<p> |
|---|
| 432 | + * Set pre-activation flag. |
|---|
| 433 | + * |
|---|
| 434 | + * @param licensePreactivation |
|---|
| 435 | + */ |
|---|
| 436 | + public void setLicensePreactivation(boolean licensePreactivation) { this.licensePreactivation = licensePreactivation; } |
|---|
| 293 | 437 | |
|---|
| 294 | | - public void setLicensePreactivation(boolean licensePreactivation) { |
|---|
| 295 | | - this.licensePreactivation = licensePreactivation; |
|---|
| 296 | | - } |
|---|
| 438 | + /** |
|---|
| 439 | + * getMetadata<p> |
|---|
| 440 | + * Return pack metadata entries. |
|---|
| 441 | + * |
|---|
| 442 | + * @return metadata |
|---|
| 443 | + */ |
|---|
| 444 | + public Set<PackMetadata> getMetadata() { return metadata; } |
|---|
| 297 | 445 | |
|---|
| 298 | | - public Set<PackMetadata> getMetadata() { |
|---|
| 299 | | - return metadata; |
|---|
| 300 | | - } |
|---|
| 446 | + /** |
|---|
| 447 | + * setMetadata<p> |
|---|
| 448 | + * Set pack metadata entries. |
|---|
| 449 | + * |
|---|
| 450 | + * @param metadata |
|---|
| 451 | + */ |
|---|
| 452 | + public void setMetadata(Set<PackMetadata> metadata) { this.metadata = metadata; } |
|---|
| 301 | 453 | |
|---|
| 302 | | - public void setMetadata(Set<PackMetadata> metadata) { |
|---|
| 303 | | - this.metadata = metadata; |
|---|
| 304 | | - } |
|---|
| 454 | + /** |
|---|
| 455 | + * getStatus<p> |
|---|
| 456 | + * Return pack status. |
|---|
| 457 | + * |
|---|
| 458 | + * @return packStatus |
|---|
| 459 | + */ |
|---|
| 460 | + public PackStatus getStatus() { return status; } |
|---|
| 305 | 461 | |
|---|
| 306 | | - public PackStatus getStatus() { |
|---|
| 307 | | - return status; |
|---|
| 308 | | - } |
|---|
| 462 | + /** |
|---|
| 463 | + * setStatus<p> |
|---|
| 464 | + * Set pack status. |
|---|
| 465 | + * |
|---|
| 466 | + * @param packStatus |
|---|
| 467 | + */ |
|---|
| 468 | + public void setStatus(PackStatus status) { this.status = status; } |
|---|
| 309 | 469 | |
|---|
| 310 | | - public void setStatus(PackStatus status) { |
|---|
| 311 | | - this.status = status; |
|---|
| 312 | | - } |
|---|
| 470 | + /** |
|---|
| 471 | + * getInitValidDate<p> |
|---|
| 472 | + * Return start of validity window. |
|---|
| 473 | + * |
|---|
| 474 | + * @return initValidDate |
|---|
| 475 | + */ |
|---|
| 476 | + public Date getInitValidDate() { return initValidDate; } |
|---|
| 313 | 477 | |
|---|
| 314 | | - public Date getInitValidDate() { |
|---|
| 315 | | - return initValidDate; |
|---|
| 316 | | - } |
|---|
| 478 | + /** |
|---|
| 479 | + * setInitValidDate<p> |
|---|
| 480 | + * Set start of validity window. |
|---|
| 481 | + * |
|---|
| 482 | + * @param initValidDate |
|---|
| 483 | + */ |
|---|
| 484 | + public void setInitValidDate(Date initValidDate) { this.initValidDate = initValidDate; } |
|---|
| 317 | 485 | |
|---|
| 318 | | - public void setInitValidDate(Date initValidDate) { |
|---|
| 319 | | - this.initValidDate = initValidDate; |
|---|
| 320 | | - } |
|---|
| 486 | + /** |
|---|
| 487 | + * getEndValidDate<p> |
|---|
| 488 | + * Return end of validity window. |
|---|
| 489 | + * |
|---|
| 490 | + * @return endValidDate |
|---|
| 491 | + */ |
|---|
| 492 | + public Date getEndValidDate() { return endValidDate; } |
|---|
| 321 | 493 | |
|---|
| 322 | | - public Date getEndValidDate() { |
|---|
| 323 | | - return endValidDate; |
|---|
| 324 | | - } |
|---|
| 494 | + /** |
|---|
| 495 | + * setEndValidDate<p> |
|---|
| 496 | + * Set end of validity window. |
|---|
| 497 | + * |
|---|
| 498 | + * @param endValidDate |
|---|
| 499 | + */ |
|---|
| 500 | + public void setEndValidDate(Date endValidDate) { this.endValidDate = endValidDate; } |
|---|
| 325 | 501 | |
|---|
| 326 | | - public void setEndValidDate(Date endValidDate) { |
|---|
| 327 | | - this.endValidDate = endValidDate; |
|---|
| 328 | | - } |
|---|
| 502 | + /** |
|---|
| 503 | + * getLicenses<p> |
|---|
| 504 | + * Return contained licenses (entity set). |
|---|
| 505 | + * |
|---|
| 506 | + * @return licenses |
|---|
| 507 | + */ |
|---|
| 508 | + public Set<License> getLicenses() { return licenses; } |
|---|
| 329 | 509 | |
|---|
| 330 | | - public Set<License> getLicenses() { |
|---|
| 331 | | - return licenses; |
|---|
| 332 | | - } |
|---|
| 510 | + /** |
|---|
| 511 | + * setLicenses<p> |
|---|
| 512 | + * Set contained licenses (entity set). |
|---|
| 513 | + * |
|---|
| 514 | + * @param licenses |
|---|
| 515 | + */ |
|---|
| 516 | + public void setLicenses(Set<License> licenses) { this.licenses = licenses; } |
|---|
| 333 | 517 | |
|---|
| 334 | | - public void setLicenses(Set<License> licenses) { |
|---|
| 335 | | - this.licenses = licenses; |
|---|
| 336 | | - } |
|---|
| 518 | + /** |
|---|
| 519 | + * getPreactivationValidPeriod<p> |
|---|
| 520 | + * Return preactivation validity (days). |
|---|
| 521 | + * |
|---|
| 522 | + * @return preactivationValidPeriod |
|---|
| 523 | + */ |
|---|
| 524 | + public Integer getPreactivationValidPeriod() { return preactivationValidPeriod; } |
|---|
| 337 | 525 | |
|---|
| 338 | | - public Integer getPreactivationValidPeriod() { |
|---|
| 339 | | - return preactivationValidPeriod; |
|---|
| 340 | | - } |
|---|
| 526 | + /** |
|---|
| 527 | + * setPreactivationValidPeriod<p> |
|---|
| 528 | + * Set preactivation validity (days). |
|---|
| 529 | + * |
|---|
| 530 | + * @param preactivationValidPeriod |
|---|
| 531 | + */ |
|---|
| 532 | + public void setPreactivationValidPeriod(Integer preactivationValidPeriod) { this.preactivationValidPeriod = preactivationValidPeriod; } |
|---|
| 341 | 533 | |
|---|
| 342 | | - public void setPreactivationValidPeriod(Integer preactivationValidPeriod) { |
|---|
| 343 | | - this.preactivationValidPeriod = preactivationValidPeriod; |
|---|
| 344 | | - } |
|---|
| 534 | + /** |
|---|
| 535 | + * getRenewValidPeriod<p> |
|---|
| 536 | + * Return renewal validity (days). |
|---|
| 537 | + * |
|---|
| 538 | + * @return renewValidPeriod |
|---|
| 539 | + */ |
|---|
| 540 | + public Integer getRenewValidPeriod() { return renewValidPeriod; } |
|---|
| 345 | 541 | |
|---|
| 346 | | - public Integer getRenewValidPeriod() { |
|---|
| 347 | | - return renewValidPeriod; |
|---|
| 348 | | - } |
|---|
| 542 | + /** |
|---|
| 543 | + * setRenewValidPeriod<p> |
|---|
| 544 | + * Set renewal validity (days). |
|---|
| 545 | + * |
|---|
| 546 | + * @param renewValidPeriod |
|---|
| 547 | + */ |
|---|
| 548 | + public void setRenewValidPeriod(Integer renewValidPeriod) { this.renewValidPeriod = renewValidPeriod; } |
|---|
| 349 | 549 | |
|---|
| 350 | | - public void setRenewValidPeriod(Integer renewValidPeriod) { |
|---|
| 351 | | - this.renewValidPeriod = renewValidPeriod; |
|---|
| 352 | | - } |
|---|
| 550 | + // ---------------- Object methods ---------------- |
|---|
| 353 | 551 | |
|---|
| 354 | | - @Override |
|---|
| 355 | | - public boolean equals(Object obj) { |
|---|
| 356 | | - if (!(obj instanceof Application)) |
|---|
| 357 | | - return false; |
|---|
| 358 | | - return id.equals(Pack.class.cast(obj).id); |
|---|
| 359 | | - } |
|---|
| 552 | + /** |
|---|
| 553 | + * equals<p> |
|---|
| 554 | + * Compare the current object with the given object |
|---|
| 555 | + * |
|---|
| 556 | + * @param object |
|---|
| 557 | + * @return isEquals |
|---|
| 558 | + */ |
|---|
| 559 | + @Override |
|---|
| 560 | + public boolean equals(Object obj) { |
|---|
| 561 | + if (!(obj instanceof Application)) return false; |
|---|
| 562 | + return id != null && id.equals(Pack.class.cast(obj).id); |
|---|
| 563 | + } |
|---|
| 360 | 564 | |
|---|
| 361 | | - @Override |
|---|
| 362 | | - public int hashCode() { |
|---|
| 363 | | - return (id == null ? 0 : id.hashCode()); |
|---|
| 364 | | - } |
|---|
| 565 | + /** |
|---|
| 566 | + * hashCode<p> |
|---|
| 567 | + * Get the object hashCode |
|---|
| 568 | + * |
|---|
| 569 | + * @return hashCode |
|---|
| 570 | + */ |
|---|
| 571 | + @Override |
|---|
| 572 | + public int hashCode() { return (id == null ? 0 : id.hashCode()); } |
|---|
| 365 | 573 | |
|---|
| 366 | | - @Override |
|---|
| 367 | | - public String toString() { |
|---|
| 368 | | - return String.format("Pack: ID: %d, code: %s", id, code); |
|---|
| 369 | | - } |
|---|
| 574 | + /** |
|---|
| 575 | + * toString<p> |
|---|
| 576 | + * Get the string describing the current object |
|---|
| 577 | + * |
|---|
| 578 | + * @return object string |
|---|
| 579 | + */ |
|---|
| 580 | + @Override |
|---|
| 581 | + public String toString() { return String.format("Pack: ID: %d, code: %s", id, code); } |
|---|
| 370 | 582 | |
|---|
| 371 | | - public boolean isFrozen() { |
|---|
| 372 | | - return frozen != null && frozen; |
|---|
| 373 | | - } |
|---|
| 583 | + /** |
|---|
| 584 | + * isFrozen<p> |
|---|
| 585 | + * Null-safe boolean getter. |
|---|
| 586 | + * |
|---|
| 587 | + * @return isFrozen |
|---|
| 588 | + */ |
|---|
| 589 | + public boolean isFrozen() { return frozen != null && frozen; } |
|---|
| 374 | 590 | |
|---|
| 375 | | - public void setFrozen(Boolean frozen) { |
|---|
| 376 | | - this.frozen = frozen; |
|---|
| 377 | | - } |
|---|
| 591 | + /** |
|---|
| 592 | + * setFrozen<p> |
|---|
| 593 | + * Set frozen flag (nullable wrapper). |
|---|
| 594 | + * |
|---|
| 595 | + * @param frozen |
|---|
| 596 | + */ |
|---|
| 597 | + public void setFrozen(Boolean frozen) { this.frozen = frozen; } |
|---|
| 378 | 598 | |
|---|
| 379 | | - public static class Action { |
|---|
| 380 | | - public static final int CREATE = 1; |
|---|
| 381 | | - public static final int ACTIVATION = 2; |
|---|
| 382 | | - public static final int PUT_ONHOLD = 3; |
|---|
| 383 | | - public static final int CANCEL = 4; |
|---|
| 384 | | - public static final int DELETE = 5; |
|---|
| 385 | | - } |
|---|
| 599 | + // ---------------- Status transitions ---------------- |
|---|
| 386 | 600 | |
|---|
| 387 | | - public static class Status { |
|---|
| 601 | + /** |
|---|
| 602 | + * Action<p> |
|---|
| 603 | + * Available actions for the Pack |
|---|
| 604 | + */ |
|---|
| 605 | + public static class Action { |
|---|
| 606 | + public static final int CREATE = 1; |
|---|
| 607 | + public static final int ACTIVATION = 2; |
|---|
| 608 | + public static final int PUT_ONHOLD = 3; |
|---|
| 609 | + public static final int CANCEL = 4; |
|---|
| 610 | + public static final int DELETE = 5; |
|---|
| 611 | + } |
|---|
| 388 | 612 | |
|---|
| 389 | | - private static final Map<Integer, List<PackStatus>> transitions = Utils.createMap( // |
|---|
| 390 | | - Action.ACTIVATION, Arrays.asList(PackStatus.CREATED, PackStatus.ON_HOLD, PackStatus.EXPIRED), // |
|---|
| 391 | | - Action.PUT_ONHOLD, Arrays.asList(PackStatus.ACTIVE), // |
|---|
| 392 | | - Action.CANCEL, Arrays.asList(PackStatus.ACTIVE, PackStatus.ON_HOLD, PackStatus.EXPIRED), // |
|---|
| 393 | | - Action.DELETE, Arrays.asList(PackStatus.CANCELLED, PackStatus.CREATED) // |
|---|
| 394 | | - ); |
|---|
| 613 | + /** |
|---|
| 614 | + * Status<p> |
|---|
| 615 | + * Pack status |
|---|
| 616 | + */ |
|---|
| 617 | + public static class Status { |
|---|
| 395 | 618 | |
|---|
| 396 | | - /** |
|---|
| 397 | | - * It checks if a given action is valid for the License, passing the |
|---|
| 398 | | - * action and the current license status |
|---|
| 399 | | - * |
|---|
| 400 | | - * @param oldStatus |
|---|
| 401 | | - * @param newStatus |
|---|
| 402 | | - * @return |
|---|
| 403 | | - */ |
|---|
| 404 | | - public static boolean isActionValid(Integer action, PackStatus currentStatus) { |
|---|
| 405 | | - List<PackStatus> validStatuses = transitions.get(action); |
|---|
| 619 | + private static final Map<Integer, List<PackStatus>> transitions = Utils.createMap( |
|---|
| 620 | + Action.ACTIVATION, Arrays.asList(PackStatus.CREATED, PackStatus.ON_HOLD, PackStatus.EXPIRED), |
|---|
| 621 | + Action.PUT_ONHOLD, Arrays.asList(PackStatus.ACTIVE), |
|---|
| 622 | + Action.CANCEL, Arrays.asList(PackStatus.ACTIVE, PackStatus.ON_HOLD, PackStatus.EXPIRED), |
|---|
| 623 | + Action.DELETE, Arrays.asList(PackStatus.CANCELLED, PackStatus.CREATED) |
|---|
| 624 | + ); |
|---|
| 406 | 625 | |
|---|
| 407 | | - return validStatuses != null && validStatuses.contains(currentStatus); |
|---|
| 408 | | - } |
|---|
| 409 | | - } |
|---|
| 626 | + /** |
|---|
| 627 | + * isActionValid<p> |
|---|
| 628 | + * Validate whether an action is allowed given the current pack status. |
|---|
| 629 | + * |
|---|
| 630 | + * @param action action constant |
|---|
| 631 | + * @param currentStatus current pack status |
|---|
| 632 | + * @return true if allowed |
|---|
| 633 | + */ |
|---|
| 634 | + public static boolean isActionValid(Integer action, PackStatus currentStatus) { |
|---|
| 635 | + List<PackStatus> validStatuses = transitions.get(action); |
|---|
| 636 | + return validStatuses != null && validStatuses.contains(currentStatus); |
|---|
| 637 | + } |
|---|
| 638 | + } |
|---|
| 410 | 639 | } |
|---|
| 640 | + |
|---|