From 4f5711b8ec555ab8307516ce178b454445d3833f Mon Sep 17 00:00:00 2001
From: rsanchez <rsanchez@curisit.net>
Date: Fri, 24 Mar 2017 10:03:47 +0000
Subject: [PATCH] #3535 - Apply metadata changes in cascade
---
securis/src/main/java/net/curisit/securis/db/Pack.java | 572 ++++++++++++++++++++++++++++----------------------------
1 files changed, 287 insertions(+), 285 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 2cb6da8..3885630 100644
--- a/securis/src/main/java/net/curisit/securis/db/Pack.java
+++ b/securis/src/main/java/net/curisit/securis/db/Pack.java
@@ -20,8 +20,6 @@
import javax.persistence.OneToMany;
import javax.persistence.Table;
-import net.curisit.integrity.commons.Utils;
-
import org.hibernate.annotations.Type;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
@@ -30,6 +28,8 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
+
+import net.curisit.integrity.commons.Utils;
/**
* Entity implementation class for Entity: pack
@@ -40,358 +40,360 @@
@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-orgs", query = "SELECT pa FROM Pack pa where pa.organization.id in :list_ids")
-})
+@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", query = "SELECT pa FROM Pack pa where pa.organization.id in :list_ids") })
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 String comments;
- @Column(name = "creation_timestamp")
- @JsonProperty("creation_timestamp")
- private Date creationTimestamp;
+ @Column(name = "creation_timestamp")
+ @JsonProperty("creation_timestamp")
+ private Date creationTimestamp;
- @JsonIgnore
- @ManyToOne
- @JoinColumn(name = "organization_id")
- private Organization organization;
+ @JsonIgnore
+ @ManyToOne
+ @JoinColumn(name = "organization_id")
+ private Organization organization;
- @JsonIgnore
- @ManyToOne
- @JoinColumn(name = "license_type_id")
- private LicenseType licenseType;
+ @JsonIgnore
+ @ManyToOne
+ @JoinColumn(name = "license_type_id")
+ private LicenseType licenseType;
- @JsonIgnore
- @ManyToOne
- @JoinColumn(name = "created_by")
- private User createdBy;
+ @JsonIgnore
+ @ManyToOne
+ @JoinColumn(name = "created_by")
+ private User createdBy;
- @JsonIgnore
- @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "pack")
- private Set<License> licenses;
+ @JsonIgnore
+ @OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST, CascadeType.REMOVE, CascadeType.REFRESH }, mappedBy = "pack")
+ private Set<License> licenses;
- @Column(name = "num_licenses")
- @JsonProperty("num_licenses")
- private int numLicenses;
+ @Column(name = "num_licenses")
+ @JsonProperty("num_licenses")
+ private int numLicenses;
- @Column(name = "init_valid_date")
- @JsonProperty("init_valid_date")
- private Date initValidDate;
+ @Column(name = "init_valid_date")
+ @JsonProperty("init_valid_date")
+ private Date initValidDate;
- @Column(name = "end_valid_date")
- @JsonProperty("end_valid_date")
- private Date endValidDate;
+ @Column(name = "end_valid_date")
+ @JsonProperty("end_valid_date")
+ private Date endValidDate;
- @Type(type = "net.curisit.securis.db.common.PackStatusType")
- private PackStatus status;
+ @Type(type = "net.curisit.securis.db.common.PackStatusType")
+ private PackStatus status;
- @Column(name = "license_preactivation")
- @JsonProperty("license_preactivation")
- private boolean licensePreactivation;
+ @Column(name = "license_preactivation")
+ @JsonProperty("license_preactivation")
+ private boolean licensePreactivation;
- @Column(name = "preactivation_valid_period")
- @JsonProperty("preactivation_valid_period")
- private Integer preactivationValidPeriod;
+ @Column(name = "preactivation_valid_period")
+ @JsonProperty("preactivation_valid_period")
+ private Integer preactivationValidPeriod;
- @Column(name = "renew_valid_period")
- @JsonProperty("renew_valid_period")
- private Integer renewValidPeriod;
+ @Column(name = "renew_valid_period")
+ @JsonProperty("renew_valid_period")
+ private Integer renewValidPeriod;
- @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "pack")
- private Set<PackMetadata> metadata;
+ @OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST, CascadeType.REMOVE, CascadeType.REFRESH }, mappedBy = "pack")
+ private Set<PackMetadata> metadata;
- public Integer getId() {
- return id;
- }
+ public Integer getId() {
+ return id;
+ }
- public void setId(Integer id) {
- this.id = id;
- }
+ public void setId(Integer id) {
+ this.id = id;
+ }
- public String getCode() {
- return code;
- }
+ public String getCode() {
+ return code;
+ }
- public void setCode(String code) {
- this.code = code;
- }
+ public void setCode(String code) {
+ this.code = code;
+ }
- public Date getCreationTimestamp() {
- return creationTimestamp;
- }
+ public Date getCreationTimestamp() {
+ return creationTimestamp;
+ }
- public void setCreationTimestamp(Date creationTimestamp) {
- this.creationTimestamp = creationTimestamp;
- }
+ public void setCreationTimestamp(Date creationTimestamp) {
+ this.creationTimestamp = creationTimestamp;
+ }
- public Organization getOrganization() {
- return organization;
- }
+ public Organization getOrganization() {
+ return organization;
+ }
- public void setOrganization(Organization organization) {
- this.organization = organization;
- }
+ public void setOrganization(Organization organization) {
+ this.organization = organization;
+ }
- public LicenseType getLicenseType() {
- return licenseType;
- }
+ public LicenseType getLicenseType() {
+ return licenseType;
+ }
- public void setLicenseType(LicenseType licenseType) {
- this.licenseType = licenseType;
- }
+ public void setLicenseType(LicenseType licenseType) {
+ this.licenseType = licenseType;
+ }
- public User getCreatedBy() {
- return createdBy;
- }
+ public User getCreatedBy() {
+ return createdBy;
+ }
- public void setCreatedBy(User createdBy) {
- this.createdBy = createdBy;
- }
+ public void setCreatedBy(User createdBy) {
+ this.createdBy = createdBy;
+ }
- public int getNumLicenses() {
- return numLicenses;
- }
+ public int getNumLicenses() {
+ return numLicenses;
+ }
- public void setNumLicenses(int numLicenses) {
- this.numLicenses = numLicenses;
- }
+ public void setNumLicenses(int numLicenses) {
+ this.numLicenses = numLicenses;
+ }
- @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;
+ }
- /**
- * 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;
- }
+ /**
+ * 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;
+ }
- /**
- * Number of available licenses in this pack
- *
- * @return
- */
- @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();
+ }
- @JsonProperty("organization_name")
- public String getOrgName() {
- return organization == null ? null : organization.getName();
- }
+ @JsonProperty("organization_name")
+ public String getOrgName() {
+ return organization == null ? null : organization.getName();
+ }
- @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();
+ }
- @JsonProperty("organization_id")
- public Integer getOrgId() {
- return organization == null ? null : organization.getId();
- }
+ @JsonProperty("organization_id")
+ public Integer getOrgId() {
+ return organization == null ? null : organization.getId();
+ }
- @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);
+ }
+ }
- @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);
+ }
+ }
- @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();
+ }
- @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();
+ }
- @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);
+ }
- @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());
+ }
- @JsonProperty("licensetype_code")
- public String getLicenseTypeCode() {
- return licenseType == null ? null : licenseType.getCode();
- }
+ @JsonProperty("licensetype_code")
+ public String getLicenseTypeCode() {
+ return licenseType == null ? null : licenseType.getCode();
+ }
- public String getComments() {
- return comments;
- }
+ public String getComments() {
+ return comments;
+ }
- public void setComments(String comments) {
- this.comments = comments;
- }
+ public void setComments(String comments) {
+ this.comments = comments;
+ }
- public boolean isLicensePreactivation() {
- return licensePreactivation;
- }
+ public boolean isLicensePreactivation() {
+ return licensePreactivation;
+ }
- public void setLicensePreactivation(boolean licensePreactivation) {
- this.licensePreactivation = licensePreactivation;
- }
+ public void setLicensePreactivation(boolean licensePreactivation) {
+ this.licensePreactivation = licensePreactivation;
+ }
- public Set<PackMetadata> getMetadata() {
- return metadata;
- }
+ public Set<PackMetadata> getMetadata() {
+ return metadata;
+ }
- public void setMetadata(Set<PackMetadata> metadata) {
- this.metadata = metadata;
- }
+ public void setMetadata(Set<PackMetadata> metadata) {
+ this.metadata = metadata;
+ }
- public PackStatus getStatus() {
- return status;
- }
+ public PackStatus getStatus() {
+ return status;
+ }
- public void setStatus(PackStatus status) {
- this.status = status;
- }
+ public void setStatus(PackStatus status) {
+ this.status = status;
+ }
- public Date getInitValidDate() {
- return initValidDate;
- }
+ public Date getInitValidDate() {
+ return initValidDate;
+ }
- public void setInitValidDate(Date initValidDate) {
- this.initValidDate = initValidDate;
- }
+ public void setInitValidDate(Date initValidDate) {
+ this.initValidDate = initValidDate;
+ }
- public Date getEndValidDate() {
- return endValidDate;
- }
+ public Date getEndValidDate() {
+ return endValidDate;
+ }
- public void setEndValidDate(Date endValidDate) {
- this.endValidDate = endValidDate;
- }
+ public void setEndValidDate(Date endValidDate) {
+ this.endValidDate = endValidDate;
+ }
- public Set<License> getLicenses() {
- return licenses;
- }
+ public Set<License> getLicenses() {
+ return licenses;
+ }
- public void setLicenses(Set<License> licenses) {
- this.licenses = licenses;
- }
+ public void setLicenses(Set<License> licenses) {
+ this.licenses = licenses;
+ }
- @Override
- public boolean equals(Object obj) {
- if (!(obj instanceof Pack))
- return false;
- Pack other = (Pack) obj;
- return id.equals(other.id);
- }
+ public Integer getPreactivationValidPeriod() {
+ return preactivationValidPeriod;
+ }
- @Override
- public int hashCode() {
+ public void setPreactivationValidPeriod(Integer preactivationValidPeriod) {
+ this.preactivationValidPeriod = preactivationValidPeriod;
+ }
- return (id == null ? 0 : id.hashCode());
- }
+ public Integer getRenewValidPeriod() {
+ return renewValidPeriod;
+ }
- public Integer getPreactivationValidPeriod() {
- return preactivationValidPeriod;
- }
+ public void setRenewValidPeriod(Integer renewValidPeriod) {
+ this.renewValidPeriod = renewValidPeriod;
+ }
- public void setPreactivationValidPeriod(Integer preactivationValidPeriod) {
- this.preactivationValidPeriod = preactivationValidPeriod;
- }
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof Application))
+ return false;
+ return id.equals(Pack.class.cast(obj).id);
+ }
- public Integer getRenewValidPeriod() {
- return renewValidPeriod;
- }
+ @Override
+ public int hashCode() {
+ return (id == null ? 0 : id.hashCode());
+ }
- public void setRenewValidPeriod(Integer renewValidPeriod) {
- this.renewValidPeriod = renewValidPeriod;
- }
+ @Override
+ public String toString() {
+ return String.format("Pack: ID: %d, code: %s", id, code);
+ }
- 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;
- }
+ 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;
+ }
- public static class Status {
+ public static class Status {
- 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) //
- );
+ 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) //
+ );
- /**
- * 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);
+ /**
+ * 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);
- return validStatuses != null && validStatuses.contains(currentStatus);
- }
- }
+ return validStatuses != null && validStatuses.contains(currentStatus);
+ }
+ }
}
--
Gitblit v1.3.2