Roberto Sánchez
2014-01-17 c8eb07e8dc020346aaee0d859040ccabb79349bd
securis/src/main/java/net/curisit/securis/db/Pack.java
....@@ -17,6 +17,8 @@
1717 import javax.persistence.Table;
1818
1919 import org.codehaus.jackson.annotate.JsonAutoDetect;
20
+import org.codehaus.jackson.annotate.JsonIgnore;
21
+import org.codehaus.jackson.annotate.JsonProperty;
2022 import org.codehaus.jackson.map.annotate.JsonSerialize;
2123
2224 /**
....@@ -42,25 +44,34 @@
4244 @Column(name = "creation_timestamp")
4345 private Date creationTimestamp;
4446
47
+ @JsonIgnore
4548 @ManyToOne
4649 @JoinColumn(name = "organization_id")
4750 private Organization organization;
4851
52
+ @JsonIgnore
4953 @ManyToOne
5054 @JoinColumn(name = "license_type_id")
5155 private LicenseType licenseType;
5256
57
+ @JsonIgnore
5358 @ManyToOne
5459 @JoinColumn(name = "created_by")
5560 private User createdBy;
5661
62
+ @JsonIgnore
5763 @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "pack")
5864 private Set<License> licenses;
5965
66
+ @JoinColumn(name = "num_licenses")
6067 private int numLicenses;
6168
6269 public int getId() {
6370 return id;
71
+ }
72
+
73
+ public void setId(int id) {
74
+ this.id = id;
6475 }
6576
6677 public String getCode() {
....@@ -111,4 +122,92 @@
111122 this.numLicenses = numLicenses;
112123 }
113124
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
+
114213 }