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/Pack.java | 822 +++++++++++++++++++++++++++++++++++++---------------------
1 files changed, 526 insertions(+), 296 deletions(-)
diff --git a/securis/src/main/java/net/curisit/securis/db/Pack.java b/securis/src/main/java/net/curisit/securis/db/Pack.java
index aee90fa..94dd5dd 100644
--- a/securis/src/main/java/net/curisit/securis/db/Pack.java
+++ b/securis/src/main/java/net/curisit/securis/db/Pack.java
@@ -1,3 +1,6 @@
+/*
+* Copyright @ 2013 CurisTEC, S.A.S. All Rights Reserved.
+*/
package net.curisit.securis.db;
import java.io.Serializable;
@@ -32,379 +35,606 @@
import net.curisit.integrity.commons.Utils;
/**
- * Entity implementation class for Entity: pack
- *
- */
+* Pack
+* <p>
+* Group/bundle of licenses for an organization and application (via LicenseType).
+* Tracks capacity, availability, status, and validity windows.
+*
+* Mapping details:
+* - Table: pack
+* - ManyToOne to Organization, LicenseType, User (createdBy)
+* - OneToMany licenses (lazy)
+* - Custom type: net.curisit.securis.db.common.PackStatusType
+* - Named queries for listing and filtering by org/app.
+*
+* @author JRA
+* Last reviewed by JRA on Oct 5, 2025.
+*/
@JsonAutoDetect
@JsonInclude(Include.NON_NULL)
@Entity
@Table(name = "pack")
@JsonIgnoreProperties(ignoreUnknown = true)
-@NamedQueries({ @NamedQuery(name = "list-packs", query = "SELECT pa FROM Pack pa"), //
- @NamedQuery(name = "pack-by-code", query = "SELECT pa FROM Pack pa where pa.code = :code"), //
- @NamedQuery(name = "list-packs-by-lic-type", query = "SELECT pa FROM Pack pa where pa.licenseType.id = :lt_id"), //
- @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 "), //
- @NamedQuery(name = "list-packs-by-apps", query = "SELECT pa FROM Pack pa where pa.licenseType.application.id in :list_ids_app ") })
+@NamedQueries({
+ @NamedQuery(name = "list-packs", query = "SELECT pa FROM Pack pa"),
+ @NamedQuery(name = "pack-by-code", query = "SELECT pa FROM Pack pa where pa.code = :code"),
+ @NamedQuery(name = "list-packs-by-lic-type", query = "SELECT pa FROM Pack pa where pa.licenseType.id = :lt_id"),
+ @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 "),
+ @NamedQuery(name = "list-packs-by-apps", query = "SELECT pa FROM Pack pa where pa.licenseType.application.id in :list_ids_app ")
+})
public class Pack implements Serializable {
- 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 code;
+ private String comments;
+ private Boolean frozen;
- private String comments;
+ @Column(name = "creation_timestamp")
+ @JsonProperty("creation_timestamp")
+ private Date creationTimestamp;
- private Boolean frozen;
+ @JsonIgnore
+ @ManyToOne
+ @JoinColumn(name = "organization_id")
+ private Organization organization;
- @Column(name = "creation_timestamp")
- @JsonProperty("creation_timestamp")
- private Date creationTimestamp;
+ @JsonIgnore
+ @ManyToOne
+ @JoinColumn(name = "license_type_id")
+ private LicenseType licenseType;
- @JsonIgnore
- @ManyToOne
- @JoinColumn(name = "organization_id")
- private Organization organization;
+ @JsonIgnore
+ @ManyToOne
+ @JoinColumn(name = "created_by")
+ private User createdBy;
- @JsonIgnore
- @ManyToOne
- @JoinColumn(name = "license_type_id")
- private LicenseType licenseType;
+ @JsonIgnore
+ @OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST, CascadeType.REMOVE, CascadeType.REFRESH }, mappedBy = "pack")
+ private Set<License> licenses;
- @JsonIgnore
- @ManyToOne
- @JoinColumn(name = "created_by")
- private User createdBy;
+ @Column(name = "num_licenses")
+ @JsonProperty("num_licenses")
+ private int numLicenses;
- @JsonIgnore
- @OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST, CascadeType.REMOVE, CascadeType.REFRESH }, mappedBy = "pack")
- private Set<License> licenses;
+ @Column(name = "init_valid_date")
+ @JsonProperty("init_valid_date")
+ private Date initValidDate;
- @Column(name = "num_licenses")
- @JsonProperty("num_licenses")
- private int numLicenses;
+ @Column(name = "end_valid_date")
+ @JsonProperty("end_valid_date")
+ private Date endValidDate;
- @Column(name = "init_valid_date")
- @JsonProperty("init_valid_date")
- private Date initValidDate;
+ @Type(type = "net.curisit.securis.db.common.PackStatusType")
+ private PackStatus status;
- @Column(name = "end_valid_date")
- @JsonProperty("end_valid_date")
- private Date endValidDate;
+ @Column(name = "license_preactivation")
+ @JsonProperty("license_preactivation")
+ private boolean licensePreactivation;
- @Type(type = "net.curisit.securis.db.common.PackStatusType")
- private PackStatus status;
+ @Column(name = "preactivation_valid_period")
+ @JsonProperty("preactivation_valid_period")
+ private Integer preactivationValidPeriod;
- @Column(name = "license_preactivation")
- @JsonProperty("license_preactivation")
- private boolean licensePreactivation;
+ @Column(name = "renew_valid_period")
+ @JsonProperty("renew_valid_period")
+ private Integer renewValidPeriod;
- @Column(name = "preactivation_valid_period")
- @JsonProperty("preactivation_valid_period")
- private Integer preactivationValidPeriod;
+ @OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST, CascadeType.REMOVE, CascadeType.REFRESH }, mappedBy = "pack")
+ private Set<PackMetadata> metadata;
- @Column(name = "renew_valid_period")
- @JsonProperty("renew_valid_period")
- private Integer renewValidPeriod;
+ // ---------------- Getters & setters ----------------
- @OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST, CascadeType.REMOVE, CascadeType.REFRESH }, mappedBy = "pack")
- private Set<PackMetadata> metadata;
+ /**
+ * getId<p>
+ * Return primary key.
+ *
+ * @return id
+ */
+ public Integer getId() { return id; }
- public Integer getId() {
- return id;
- }
+ /**
+ * setId<p>
+ * Set primary key.
+ *
+ * @param id
+ */
+ public void setId(Integer id) { this.id = id; }
- public void setId(Integer id) {
- this.id = id;
- }
+ /**
+ * getCode<p>
+ * Return pack code.
+ *
+ * @return packCode
+ */
+ public String getCode() { return code; }
- public String getCode() {
- return code;
- }
+ /**
+ * setCode<p>
+ * Set pack code.
+ *
+ * @param packCode
+ */
+ public void setCode(String code) { this.code = code; }
- public void setCode(String code) {
- this.code = code;
- }
+ /**
+ * getCreationTimestamp<p>
+ * Return creation timestamp.
+ *
+ * @return creationTimestamp
+ */
+ public Date getCreationTimestamp() { return creationTimestamp; }
- public Date getCreationTimestamp() {
- return creationTimestamp;
- }
+ /**
+ * setCreationTimestamp<p>
+ * Set creation timestamp.
+ *
+ * @param creationTimestamp
+ */
+ public void setCreationTimestamp(Date creationTimestamp) { this.creationTimestamp = creationTimestamp; }
- public void setCreationTimestamp(Date creationTimestamp) {
- this.creationTimestamp = creationTimestamp;
- }
+ /**
+ * getOrganization<p>
+ * Return owning organization (entity).
+ *
+ * @return organization
+ */
+ public Organization getOrganization() { return organization; }
- public Organization getOrganization() {
- return organization;
- }
+ /**
+ * setOrganization<p>
+ * Set owning organization (entity).
+ *
+ * @param organization
+ */
+ public void setOrganization(Organization organization) { this.organization = organization; }
- public void setOrganization(Organization organization) {
- this.organization = organization;
- }
+ /**
+ * getLicenseType<p>
+ * Return license type (entity).
+ *
+ * @return licenseType
+ */
+ public LicenseType getLicenseType() { return licenseType; }
- public LicenseType getLicenseType() {
- return licenseType;
- }
+ /**
+ * setLicenseType<p>
+ * Set license type (entity).
+ *
+ * @param licenseType
+ */
+ public void setLicenseType(LicenseType licenseType) { this.licenseType = licenseType; }
- public void setLicenseType(LicenseType licenseType) {
- this.licenseType = licenseType;
- }
+ /**
+ * getCreatedBy<p>
+ * Return creator (entity).
+ *
+ * @return user
+ */
+ public User getCreatedBy() { return createdBy; }
- public User getCreatedBy() {
- return createdBy;
- }
+ /**
+ * setCreatedBy<p>
+ * Set creator (entity).
+ *
+ * @param user
+ */
+ public void setCreatedBy(User createdBy) { this.createdBy = createdBy; }
- public void setCreatedBy(User createdBy) {
- this.createdBy = createdBy;
- }
+ /**
+ * getNumLicenses<p>
+ * Return capacity (licenses).
+ *
+ * @return numLicenses
+ * Number of licenses
+ */
+ public int getNumLicenses() { return numLicenses; }
- public int getNumLicenses() {
- return numLicenses;
- }
+ /**
+ * setNumLicenses<p>
+ * Set capacity (licenses).
+ *
+ * @param numLicenses
+ * Number of licenses
+ */
+ public void setNumLicenses(int numLicenses) { this.numLicenses = numLicenses; }
- public void setNumLicenses(int numLicenses) {
- this.numLicenses = numLicenses;
- }
+ /**
+ * getNumActivations<p>
+ * Count ACTIVE/PRE_ACTIVE licenses in this pack.
+ *
+ * @return numActivations
+ * number of activated licenses
+ */
+ @JsonProperty("num_activations")
+ public int getNumActivations() {
+ if (licenses == null) return 0;
+ int num = 0;
+ for (License lic : licenses) {
+ if (lic.getStatus() == LicenseStatus.ACTIVE || lic.getStatus() == LicenseStatus.PRE_ACTIVE) num++;
+ }
+ return num;
+ }
- @JsonProperty("num_activations")
- public int getNumActivations() {
- if (licenses == null) {
- return 0;
- }
- int num = 0;
- for (License lic : licenses) {
- if (lic.getStatus() == LicenseStatus.ACTIVE || lic.getStatus() == LicenseStatus.PRE_ACTIVE) {
- num++;
- }
- }
- return num;
- }
+ /**
+ * getNumCreations<p>
+ * Count all created licenses (including waiting for activation). Ignores CANCELLED.
+ *
+ * @return numCreations
+ * number of created licenses
+ */
+ @JsonProperty("num_creations")
+ public int getNumCreations() {
+ if (licenses == null) return 0;
+ int num = 0;
+ for (License lic : licenses) {
+ if (lic.getStatus() != LicenseStatus.CANCELLED) num++;
+ }
+ return num;
+ }
- /**
- * Counts all created licenses, It counts active licenses and licenses
- * waiting for activation This number will be used to control the max number
- * of licenses created. Ignore canceled licenses.
- *
- * @return
- */
- @JsonProperty("num_creations")
- public int getNumCreations() {
- if (licenses == null) {
- return 0;
- }
- int num = 0;
- for (License lic : licenses) {
- if (lic.getStatus() != LicenseStatus.CANCELLED) {
- num++;
- }
- }
- return num;
- }
+ /**
+ * getNumAvailables<p>
+ * Number of available licenses in this pack: capacity - activations.
+ *
+ * @return numAvailable
+ * Number of available licenses
+ */
+ @JsonProperty("num_available")
+ public int getNumAvailables() { return numLicenses - getNumActivations(); }
- /**
- * Number of available licenses in this pack
- *
- * @return
- */
- @JsonProperty("num_available")
- public int getNumAvailables() {
- return numLicenses - getNumActivations();
- }
+ /**
+ * getOrgName<p>
+ * Expose organization name.
+ *
+ * @return orgName
+ */
+ @JsonProperty("organization_name")
+ public String getOrgName() { return organization == null ? null : organization.getName(); }
- @JsonProperty("organization_name")
- public String getOrgName() {
- return organization == null ? null : organization.getName();
- }
+ /**
+ * getAppName<p>
+ * Expose application name via license type.
+ *
+ * @return appName
+ */
+ @JsonProperty("application_name")
+ public String getAppName() {
+ if (licenseType == null) return null;
+ Application app = licenseType.getApplication();
+ return app == null ? null : app.getName();
+ }
- @JsonProperty("application_name")
- public String getAppName() {
- if (licenseType == null) {
- return null;
- }
- Application app = licenseType.getApplication();
- return app == null ? null : app.getName();
- }
+ /**
+ * getOrgId<p>
+ * Expose organization id.
+ *
+ * @return orgId
+ */
+ @JsonProperty("organization_id")
+ public Integer getOrgId() { return organization == null ? null : organization.getId(); }
- @JsonProperty("organization_id")
- public Integer getOrgId() {
- return organization == null ? null : organization.getId();
- }
+ /**
+ * setOrgId<p>
+ * Setter by id for JSON binding (creates shallow Organization).
+ *
+ * @param orgId
+ */
+ @JsonProperty("organization_id")
+ public void setOrgId(Integer idOrg) {
+ if (idOrg == null) {
+ organization = null;
+ } else {
+ organization = new Organization();
+ organization.setId(idOrg);
+ }
+ }
- @JsonProperty("organization_id")
- public void setOrgId(Integer idOrg) {
- if (idOrg == null) {
- organization = null;
- } else {
- organization = new Organization();
- organization.setId(idOrg);
- }
- }
+ /**
+ * setLicTypeId<p>
+ * Setter by id for JSON binding (creates shallow LicenseType).
+ *
+ * @param licTypeId
+ */
+ @JsonProperty("license_type_id")
+ public void setLicTypeId(Integer idLT) {
+ if (idLT == null) {
+ licenseType = null;
+ } else {
+ licenseType = new LicenseType();
+ licenseType.setId(idLT);
+ }
+ }
- @JsonProperty("license_type_id")
- public void setLicTypeId(Integer idLT) {
- if (idLT == null) {
- licenseType = null;
- } else {
- licenseType = new LicenseType();
- licenseType.setId(idLT);
- }
- }
+ /**
+ * getLicTypeId<p>
+ * Expose license type id.
+ *
+ * @return licTypeId
+ */
+ @JsonProperty("license_type_id")
+ public Integer getLicTypeId() { return licenseType == null ? null : licenseType.getId(); }
- @JsonProperty("license_type_id")
- public Integer getLicTypeId() {
- return licenseType == null ? null : licenseType.getId();
- }
+ /**
+ * getCreatedById<p>
+ * Expose creator username.
+ *
+ * @return username
+ */
+ @JsonProperty("created_by_id")
+ public String getCreatedById() { return createdBy == null ? null : createdBy.getUsername(); }
- @JsonProperty("created_by_id")
- public String getCreatedById() {
- return createdBy == null ? null : createdBy.getUsername();
- }
+ /**
+ * setCreatedById<p>
+ * Setter by username (creates shallow User).
+ *
+ * @param username
+ */
+ @JsonProperty("created_by_id")
+ public void setCreatedById(String username) {
+ createdBy = new User();
+ createdBy.setUsername(username);
+ }
- @JsonProperty("created_by_id")
- public void setCreatedById(String username) {
- createdBy = new User();
- createdBy.setUsername(username);
- }
+ /**
+ * getCreatedByname<p>
+ * Expose creator full display name.
+ *
+ * @return userName
+ */
+ @JsonProperty("created_by_name")
+ public String getCreatedByname() {
+ return createdBy == null ? null
+ : String.format("%s %s (%s)", createdBy.getFirstName(),
+ createdBy.getLastName() != null ? createdBy.getLastName() : "",
+ createdBy.getUsername());
+ }
- @JsonProperty("created_by_name")
- public String getCreatedByname() {
- return createdBy == null ? null
- : String.format("%s %s (%s)", createdBy.getFirstName(), createdBy.getLastName() != null ? createdBy.getLastName() : "", createdBy.getUsername());
- }
+ /**
+ * getLicenseTypeCode<p>
+ * Expose license type code.
+ *
+ * @return licenseTypeCode
+ */
+ @JsonProperty("licensetype_code")
+ public String getLicenseTypeCode() { return licenseType == null ? null : licenseType.getCode(); }
- @JsonProperty("licensetype_code")
- public String getLicenseTypeCode() {
- return licenseType == null ? null : licenseType.getCode();
- }
+ /**
+ * getComments<p>
+ * Return comments.
+ *
+ * @return comments
+ */
+ public String getComments() { return comments; }
- public String getComments() {
- return comments;
- }
+ /**
+ * setComments<p>
+ * Set comments.
+ *
+ * @param comments
+ */
+ public void setComments(String comments) { this.comments = comments; }
- public void setComments(String comments) {
- this.comments = comments;
- }
+ /**
+ * isLicensePreactivation<p>
+ * Whether licenses are pre-activated.
+ *
+ * @return isLicensePreactivation
+ */
+ public boolean isLicensePreactivation() { return licensePreactivation; }
- public boolean isLicensePreactivation() {
- return licensePreactivation;
- }
+ /**
+ * setLicensePreactivation<p>
+ * Set pre-activation flag.
+ *
+ * @param licensePreactivation
+ */
+ public void setLicensePreactivation(boolean licensePreactivation) { this.licensePreactivation = licensePreactivation; }
- public void setLicensePreactivation(boolean licensePreactivation) {
- this.licensePreactivation = licensePreactivation;
- }
+ /**
+ * getMetadata<p>
+ * Return pack metadata entries.
+ *
+ * @return metadata
+ */
+ public Set<PackMetadata> getMetadata() { return metadata; }
- public Set<PackMetadata> getMetadata() {
- return metadata;
- }
+ /**
+ * setMetadata<p>
+ * Set pack metadata entries.
+ *
+ * @param metadata
+ */
+ public void setMetadata(Set<PackMetadata> metadata) { this.metadata = metadata; }
- public void setMetadata(Set<PackMetadata> metadata) {
- this.metadata = metadata;
- }
+ /**
+ * getStatus<p>
+ * Return pack status.
+ *
+ * @return packStatus
+ */
+ public PackStatus getStatus() { return status; }
- public PackStatus getStatus() {
- return status;
- }
+ /**
+ * setStatus<p>
+ * Set pack status.
+ *
+ * @param packStatus
+ */
+ public void setStatus(PackStatus status) { this.status = status; }
- public void setStatus(PackStatus status) {
- this.status = status;
- }
+ /**
+ * getInitValidDate<p>
+ * Return start of validity window.
+ *
+ * @return initValidDate
+ */
+ public Date getInitValidDate() { return initValidDate; }
- public Date getInitValidDate() {
- return initValidDate;
- }
+ /**
+ * setInitValidDate<p>
+ * Set start of validity window.
+ *
+ * @param initValidDate
+ */
+ public void setInitValidDate(Date initValidDate) { this.initValidDate = initValidDate; }
- public void setInitValidDate(Date initValidDate) {
- this.initValidDate = initValidDate;
- }
+ /**
+ * getEndValidDate<p>
+ * Return end of validity window.
+ *
+ * @return endValidDate
+ */
+ public Date getEndValidDate() { return endValidDate; }
- public Date getEndValidDate() {
- return endValidDate;
- }
+ /**
+ * setEndValidDate<p>
+ * Set end of validity window.
+ *
+ * @param endValidDate
+ */
+ public void setEndValidDate(Date endValidDate) { this.endValidDate = endValidDate; }
- public void setEndValidDate(Date endValidDate) {
- this.endValidDate = endValidDate;
- }
+ /**
+ * getLicenses<p>
+ * Return contained licenses (entity set).
+ *
+ * @return licenses
+ */
+ public Set<License> getLicenses() { return licenses; }
- public Set<License> getLicenses() {
- return licenses;
- }
+ /**
+ * setLicenses<p>
+ * Set contained licenses (entity set).
+ *
+ * @param licenses
+ */
+ public void setLicenses(Set<License> licenses) { this.licenses = licenses; }
- public void setLicenses(Set<License> licenses) {
- this.licenses = licenses;
- }
+ /**
+ * getPreactivationValidPeriod<p>
+ * Return preactivation validity (days).
+ *
+ * @return preactivationValidPeriod
+ */
+ public Integer getPreactivationValidPeriod() { return preactivationValidPeriod; }
- public Integer getPreactivationValidPeriod() {
- return preactivationValidPeriod;
- }
+ /**
+ * setPreactivationValidPeriod<p>
+ * Set preactivation validity (days).
+ *
+ * @param preactivationValidPeriod
+ */
+ public void setPreactivationValidPeriod(Integer preactivationValidPeriod) { this.preactivationValidPeriod = preactivationValidPeriod; }
- public void setPreactivationValidPeriod(Integer preactivationValidPeriod) {
- this.preactivationValidPeriod = preactivationValidPeriod;
- }
+ /**
+ * getRenewValidPeriod<p>
+ * Return renewal validity (days).
+ *
+ * @return renewValidPeriod
+ */
+ public Integer getRenewValidPeriod() { return renewValidPeriod; }
- public Integer getRenewValidPeriod() {
- return renewValidPeriod;
- }
+ /**
+ * setRenewValidPeriod<p>
+ * Set renewal validity (days).
+ *
+ * @param renewValidPeriod
+ */
+ public void setRenewValidPeriod(Integer renewValidPeriod) { this.renewValidPeriod = renewValidPeriod; }
- public void setRenewValidPeriod(Integer renewValidPeriod) {
- this.renewValidPeriod = renewValidPeriod;
- }
+ // ---------------- Object methods ----------------
- @Override
- public boolean equals(Object obj) {
- if (!(obj instanceof Application))
- return false;
- return id.equals(Pack.class.cast(obj).id);
- }
+ /**
+ * equals<p>
+ * Compare the current object with the given object
+ *
+ * @param object
+ * @return isEquals
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof Application)) return false;
+ return id != null && id.equals(Pack.class.cast(obj).id);
+ }
- @Override
- public int hashCode() {
- return (id == null ? 0 : id.hashCode());
- }
+ /**
+ * hashCode<p>
+ * Get the object hashCode
+ *
+ * @return hashCode
+ */
+ @Override
+ public int hashCode() { return (id == null ? 0 : id.hashCode()); }
- @Override
- public String toString() {
- return String.format("Pack: ID: %d, code: %s", id, code);
- }
+ /**
+ * toString<p>
+ * Get the string describing the current object
+ *
+ * @return object string
+ */
+ @Override
+ public String toString() { return String.format("Pack: ID: %d, code: %s", id, code); }
- public boolean isFrozen() {
- return frozen != null && frozen;
- }
+ /**
+ * isFrozen<p>
+ * Null-safe boolean getter.
+ *
+ * @return isFrozen
+ */
+ public boolean isFrozen() { return frozen != null && frozen; }
- public void setFrozen(Boolean frozen) {
- this.frozen = frozen;
- }
+ /**
+ * setFrozen<p>
+ * Set frozen flag (nullable wrapper).
+ *
+ * @param frozen
+ */
+ public void setFrozen(Boolean frozen) { this.frozen = frozen; }
- public static class Action {
- public static final int CREATE = 1;
- public static final int ACTIVATION = 2;
- public static final int PUT_ONHOLD = 3;
- public static final int CANCEL = 4;
- public static final int DELETE = 5;
- }
+ // ---------------- Status transitions ----------------
- public static class Status {
+ /**
+ * Action<p>
+ * Available actions for the Pack
+ */
+ public static class Action {
+ public static final int CREATE = 1;
+ public static final int ACTIVATION = 2;
+ public static final int PUT_ONHOLD = 3;
+ public static final int CANCEL = 4;
+ public static final int DELETE = 5;
+ }
- private static final Map<Integer, List<PackStatus>> transitions = Utils.createMap( //
- Action.ACTIVATION, Arrays.asList(PackStatus.CREATED, PackStatus.ON_HOLD, PackStatus.EXPIRED), //
- Action.PUT_ONHOLD, Arrays.asList(PackStatus.ACTIVE), //
- Action.CANCEL, Arrays.asList(PackStatus.ACTIVE, PackStatus.ON_HOLD, PackStatus.EXPIRED), //
- Action.DELETE, Arrays.asList(PackStatus.CANCELLED, PackStatus.CREATED) //
- );
+ /**
+ * Status<p>
+ * Pack status
+ */
+ public static class Status {
- /**
- * It checks if a given action is valid for the License, passing the
- * action and the current license status
- *
- * @param oldStatus
- * @param newStatus
- * @return
- */
- public static boolean isActionValid(Integer action, PackStatus currentStatus) {
- List<PackStatus> validStatuses = transitions.get(action);
+ private static final Map<Integer, List<PackStatus>> transitions = Utils.createMap(
+ Action.ACTIVATION, Arrays.asList(PackStatus.CREATED, PackStatus.ON_HOLD, PackStatus.EXPIRED),
+ Action.PUT_ONHOLD, Arrays.asList(PackStatus.ACTIVE),
+ Action.CANCEL, Arrays.asList(PackStatus.ACTIVE, PackStatus.ON_HOLD, PackStatus.EXPIRED),
+ Action.DELETE, Arrays.asList(PackStatus.CANCELLED, PackStatus.CREATED)
+ );
- return validStatuses != null && validStatuses.contains(currentStatus);
- }
- }
+ /**
+ * isActionValid<p>
+ * Validate whether an action is allowed given the current pack status.
+ *
+ * @param action action constant
+ * @param currentStatus current pack status
+ * @return true if allowed
+ */
+ public static boolean isActionValid(Integer action, PackStatus currentStatus) {
+ List<PackStatus> validStatuses = transitions.get(action);
+ return validStatuses != null && validStatuses.contains(currentStatus);
+ }
+ }
}
+
--
Gitblit v1.3.2