| .. | .. |
|---|
| 17 | 17 | import javax.persistence.Table; |
|---|
| 18 | 18 | |
|---|
| 19 | 19 | import org.codehaus.jackson.annotate.JsonAutoDetect; |
|---|
| 20 | +import org.codehaus.jackson.annotate.JsonIgnore; |
|---|
| 21 | +import org.codehaus.jackson.annotate.JsonProperty; |
|---|
| 20 | 22 | import org.codehaus.jackson.map.annotate.JsonSerialize; |
|---|
| 21 | 23 | |
|---|
| 22 | 24 | /** |
|---|
| .. | .. |
|---|
| 42 | 44 | @Column(name = "creation_timestamp") |
|---|
| 43 | 45 | private Date creationTimestamp; |
|---|
| 44 | 46 | |
|---|
| 47 | + @JsonIgnore |
|---|
| 45 | 48 | @ManyToOne |
|---|
| 46 | 49 | @JoinColumn(name = "organization_id") |
|---|
| 47 | 50 | private Organization organization; |
|---|
| 48 | 51 | |
|---|
| 52 | + @JsonIgnore |
|---|
| 49 | 53 | @ManyToOne |
|---|
| 50 | 54 | @JoinColumn(name = "license_type_id") |
|---|
| 51 | 55 | private LicenseType licenseType; |
|---|
| 52 | 56 | |
|---|
| 57 | + @JsonIgnore |
|---|
| 53 | 58 | @ManyToOne |
|---|
| 54 | 59 | @JoinColumn(name = "created_by") |
|---|
| 55 | 60 | private User createdBy; |
|---|
| 56 | 61 | |
|---|
| 62 | + @JsonIgnore |
|---|
| 57 | 63 | @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "pack") |
|---|
| 58 | 64 | private Set<License> licenses; |
|---|
| 59 | 65 | |
|---|
| 66 | + @JoinColumn(name = "num_licenses") |
|---|
| 60 | 67 | private int numLicenses; |
|---|
| 61 | 68 | |
|---|
| 62 | 69 | public int getId() { |
|---|
| 63 | 70 | return id; |
|---|
| 71 | + } |
|---|
| 72 | + |
|---|
| 73 | + public void setId(int id) { |
|---|
| 74 | + this.id = id; |
|---|
| 64 | 75 | } |
|---|
| 65 | 76 | |
|---|
| 66 | 77 | public String getCode() { |
|---|
| .. | .. |
|---|
| 111 | 122 | this.numLicenses = numLicenses; |
|---|
| 112 | 123 | } |
|---|
| 113 | 124 | |
|---|
| 125 | + @JsonProperty("num_activations") |
|---|
| 126 | + public int getNumActivations() { |
|---|
| 127 | + if (licenses == null) |
|---|
| 128 | + return 0; |
|---|
| 129 | + int num = 0; |
|---|
| 130 | + for (License lic : licenses) { |
|---|
| 131 | + if (lic.getStatus() == License.Status.ACTIVE) |
|---|
| 132 | + num++; |
|---|
| 133 | + } |
|---|
| 134 | + return num; |
|---|
| 135 | + } |
|---|
| 136 | + |
|---|
| 137 | + /** |
|---|
| 138 | + * 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. |
|---|
| 139 | + * |
|---|
| 140 | + * @return |
|---|
| 141 | + */ |
|---|
| 142 | + @JsonProperty("num_creations") |
|---|
| 143 | + public int getNumCreations() { |
|---|
| 144 | + if (licenses == null) |
|---|
| 145 | + return 0; |
|---|
| 146 | + int num = 0; |
|---|
| 147 | + for (License lic : licenses) { |
|---|
| 148 | + if (lic.getStatus() != License.Status.CANCELED) |
|---|
| 149 | + num++; |
|---|
| 150 | + } |
|---|
| 151 | + return num; |
|---|
| 152 | + } |
|---|
| 153 | + |
|---|
| 154 | + /** |
|---|
| 155 | + * Number of available licenses in this pack |
|---|
| 156 | + * |
|---|
| 157 | + * @return |
|---|
| 158 | + */ |
|---|
| 159 | + @JsonProperty("num_available") |
|---|
| 160 | + public int getNumAvailables() { |
|---|
| 161 | + return numLicenses - getNumCreations(); |
|---|
| 162 | + } |
|---|
| 163 | + |
|---|
| 164 | + @JsonProperty("organization_name") |
|---|
| 165 | + public String getOrgName() { |
|---|
| 166 | + return organization == null ? null : organization.getName(); |
|---|
| 167 | + } |
|---|
| 168 | + |
|---|
| 169 | + @JsonProperty("application_name") |
|---|
| 170 | + public String getAppName() { |
|---|
| 171 | + if (licenseType == null) |
|---|
| 172 | + return null; |
|---|
| 173 | + Application app = licenseType.getApplication(); |
|---|
| 174 | + return app == null ? null : app.getName(); |
|---|
| 175 | + } |
|---|
| 176 | + |
|---|
| 177 | + @JsonProperty("organization_id") |
|---|
| 178 | + public Integer getOrgId() { |
|---|
| 179 | + return organization == null ? null : organization.getId(); |
|---|
| 180 | + } |
|---|
| 181 | + |
|---|
| 182 | + @JsonProperty("organization_id") |
|---|
| 183 | + public void setOrgId(Integer idOrg) { |
|---|
| 184 | + if (idOrg == null) { |
|---|
| 185 | + organization = null; |
|---|
| 186 | + } else { |
|---|
| 187 | + organization = new Organization(); |
|---|
| 188 | + organization.setId(idOrg); |
|---|
| 189 | + } |
|---|
| 190 | + } |
|---|
| 191 | + |
|---|
| 192 | + @JsonProperty("license_type_id") |
|---|
| 193 | + public Integer getLicTypeId() { |
|---|
| 194 | + return licenseType == null ? null : licenseType.getId(); |
|---|
| 195 | + } |
|---|
| 196 | + |
|---|
| 197 | + @JsonProperty("created_by_id") |
|---|
| 198 | + public String getCreatedById() { |
|---|
| 199 | + return createdBy == null ? null : createdBy.getUsername(); |
|---|
| 200 | + } |
|---|
| 201 | + |
|---|
| 202 | + @JsonProperty("created_by_id") |
|---|
| 203 | + public void setCreatedById(String username) { |
|---|
| 204 | + createdBy = new User(); |
|---|
| 205 | + createdBy.setUsername(username); |
|---|
| 206 | + } |
|---|
| 207 | + |
|---|
| 208 | + @JsonProperty("licensetype_code") |
|---|
| 209 | + public String getLicenseTypcode() { |
|---|
| 210 | + return licenseType == null ? null : licenseType.getCode(); |
|---|
| 211 | + } |
|---|
| 212 | + |
|---|
| 114 | 213 | } |
|---|