Roberto Sánchez
2014-09-19 8d5386be38db25a2a41c3bf6c876adee21ca26cc
securis/src/main/java/net/curisit/securis/db/License.java
....@@ -35,284 +35,284 @@
3535 @Entity
3636 @Table(name = "license")
3737 @JsonIgnoreProperties(ignoreUnknown = true)
38
-@NamedQueries(
39
- { @NamedQuery(name = "list-licenses-by-pack", query = "SELECT l FROM License l where l.pack.id = :packId") })
38
+@NamedQueries({ @NamedQuery(name = "list-licenses-by-pack", query = "SELECT l FROM License l where l.pack.id = :packId") })
4039 public class License implements Serializable {
4140
42
- private static final long serialVersionUID = 1L;
41
+ private static final long serialVersionUID = 1L;
4342
44
- @Id
45
- @GeneratedValue
46
- private int id;
43
+ @Id
44
+ @GeneratedValue
45
+ private int id;
4746
48
- private String code;
47
+ private String code;
4948
50
- @JsonIgnore
51
- @ManyToOne
52
- @JoinColumn(name = "pack_id")
53
- private Pack pack;
49
+ @JsonIgnore
50
+ @ManyToOne
51
+ @JoinColumn(name = "pack_id")
52
+ private Pack pack;
5453
55
- @JsonIgnore
56
- @ManyToOne
57
- @JoinColumn(name = "created_by")
58
- private User createdBy;
54
+ @JsonIgnore
55
+ @ManyToOne
56
+ @JoinColumn(name = "created_by")
57
+ private User createdBy;
5958
60
- @JsonIgnore
61
- @ManyToOne
62
- @JoinColumn(name = "canceled_by")
63
- private User canceledBy;
59
+ @JsonIgnore
60
+ @ManyToOne
61
+ @JoinColumn(name = "canceled_by")
62
+ private User canceledBy;
6463
65
- private int status;
64
+ private int status;
6665
67
- @Column(name = "full_name")
68
- @JsonProperty("full_name")
69
- private String fullName;
66
+ @Column(name = "full_name")
67
+ @JsonProperty("full_name")
68
+ private String fullName;
7069
71
- private String email;
70
+ private String email;
7271
73
- @Column(name = "request_data")
74
- @JsonProperty("request_data")
75
- private String requestData;
72
+ @Column(name = "request_data")
73
+ @JsonProperty("request_data")
74
+ private String requestData;
7675
77
- @Column(name = "license_data")
78
- @JsonProperty("license_data")
79
- private String licenseData;
76
+ @Column(name = "license_data")
77
+ @JsonProperty("license_data")
78
+ private String licenseData;
8079
81
- @Column(name = "creation_timestamp")
82
- private Date creationTimestamp;
80
+ @Column(name = "creation_timestamp")
81
+ private Date creationTimestamp;
8382
84
- @Column(name = "modification_timestamp")
85
- private Date modificationTimestamp;
83
+ @Column(name = "modification_timestamp")
84
+ private Date modificationTimestamp;
8685
87
- @Column(name = "last_access_timestamp")
88
- private Date lastAccessTimestamp;
86
+ @Column(name = "last_access_timestamp")
87
+ private Date lastAccessTimestamp;
8988
90
- @Column(name = "expiration_date")
91
- private Date expirationDate;
89
+ @Column(name = "expiration_date")
90
+ private Date expirationDate;
9291
93
- private String comments;
92
+ private String comments;
9493
95
- @OneToMany(fetch = FetchType.LAZY, mappedBy = "license")
96
- private List<LicenseHistory> history;
94
+ @OneToMany(fetch = FetchType.LAZY, mappedBy = "license")
95
+ private List<LicenseHistory> history;
9796
98
- public int getId() {
99
- return id;
100
- }
97
+ public int getId() {
98
+ return id;
99
+ }
101100
102
- public String getCode() {
103
- return code;
104
- }
101
+ public String getCode() {
102
+ return code;
103
+ }
105104
106
- public void setCode(String code) {
107
- this.code = code;
108
- }
105
+ public void setCode(String code) {
106
+ this.code = code;
107
+ }
109108
110
- public Date getCreationTimestamp() {
111
- return creationTimestamp;
112
- }
109
+ public Date getCreationTimestamp() {
110
+ return creationTimestamp;
111
+ }
113112
114
- public void setCreationTimestamp(Date creationTimestamp) {
115
- this.creationTimestamp = creationTimestamp;
116
- }
113
+ public void setCreationTimestamp(Date creationTimestamp) {
114
+ this.creationTimestamp = creationTimestamp;
115
+ }
117116
118
- public User getCreatedBy() {
119
- return createdBy;
120
- }
117
+ public User getCreatedBy() {
118
+ return createdBy;
119
+ }
121120
122
- public void setCreatedBy(User createdBy) {
123
- this.createdBy = createdBy;
124
- }
121
+ public void setCreatedBy(User createdBy) {
122
+ this.createdBy = createdBy;
123
+ }
125124
126
- public Pack getPack() {
127
- return pack;
128
- }
125
+ public Pack getPack() {
126
+ return pack;
127
+ }
129128
130
- public void setPack(Pack pack) {
131
- this.pack = pack;
132
- }
129
+ public void setPack(Pack pack) {
130
+ this.pack = pack;
131
+ }
133132
134
- @JsonProperty("created_by_id")
135
- public String getCreatedById() {
136
- return createdBy == null ? null : createdBy.getUsername();
137
- }
133
+ @JsonProperty("created_by_id")
134
+ public String getCreatedById() {
135
+ return createdBy == null ? null : createdBy.getUsername();
136
+ }
138137
139
- @JsonProperty("created_by_id")
140
- public void setCreatedById(String username) {
141
- if (username == null) {
142
- createdBy = null;
143
- } else {
144
- createdBy = new User();
145
- createdBy.setUsername(username);
146
- }
147
- }
138
+ @JsonProperty("created_by_id")
139
+ public void setCreatedById(String username) {
140
+ if (username == null) {
141
+ createdBy = null;
142
+ } else {
143
+ createdBy = new User();
144
+ createdBy.setUsername(username);
145
+ }
146
+ }
148147
149
- @JsonProperty("canceled_by_id")
150
- public String getCanceledById() {
151
- return canceledBy == null ? null : canceledBy.getUsername();
152
- }
148
+ @JsonProperty("canceled_by_id")
149
+ public String getCanceledById() {
150
+ return canceledBy == null ? null : canceledBy.getUsername();
151
+ }
153152
154
- @JsonProperty("canceled_by_id")
155
- public void setCanceledById(String username) {
156
- if (username == null) {
157
- canceledBy = null;
158
- } else {
159
- canceledBy = new User();
160
- canceledBy.setUsername(username);
161
- }
162
- }
153
+ @JsonProperty("canceled_by_id")
154
+ public void setCanceledById(String username) {
155
+ if (username == null) {
156
+ canceledBy = null;
157
+ } else {
158
+ canceledBy = new User();
159
+ canceledBy.setUsername(username);
160
+ }
161
+ }
163162
164
- @JsonProperty("pack_code")
165
- public String getPackCode() {
166
- return pack == null ? null : pack.getCode();
167
- }
163
+ @JsonProperty("pack_code")
164
+ public String getPackCode() {
165
+ return pack == null ? null : pack.getCode();
166
+ }
168167
169
- @JsonProperty("pack_id")
170
- public Integer getPackId() {
171
- return pack == null ? null : pack.getId();
172
- }
168
+ @JsonProperty("pack_id")
169
+ public Integer getPackId() {
170
+ return pack == null ? null : pack.getId();
171
+ }
173172
174
- @JsonProperty("pack_id")
175
- public void setPackId(Integer idPack) {
176
- if (idPack == null) {
177
- pack = null;
178
- } else {
179
- pack = new Pack();
180
- pack.setId(idPack);
181
- }
182
- }
173
+ @JsonProperty("pack_id")
174
+ public void setPackId(Integer idPack) {
175
+ if (idPack == null) {
176
+ pack = null;
177
+ } else {
178
+ pack = new Pack();
179
+ pack.setId(idPack);
180
+ }
181
+ }
183182
184
- public int getStatus() {
185
- return status;
186
- }
183
+ public int getStatus() {
184
+ return status;
185
+ }
187186
188
- public void setStatus(int status) {
189
- this.status = status;
190
- }
187
+ public void setStatus(int status) {
188
+ this.status = status;
189
+ }
191190
192
- public Date getModificationTimestamp() {
193
- return modificationTimestamp;
194
- }
191
+ public Date getModificationTimestamp() {
192
+ return modificationTimestamp;
193
+ }
195194
196
- public void setModificationTimestamp(Date modificationTimestamp) {
197
- this.modificationTimestamp = modificationTimestamp;
198
- }
195
+ public void setModificationTimestamp(Date modificationTimestamp) {
196
+ this.modificationTimestamp = modificationTimestamp;
197
+ }
199198
200
- public String getFullName() {
201
- return fullName;
202
- }
199
+ public String getFullName() {
200
+ return fullName;
201
+ }
203202
204
- public void setFullName(String fullName) {
205
- this.fullName = fullName;
206
- }
203
+ public void setFullName(String fullName) {
204
+ this.fullName = fullName;
205
+ }
207206
208
- public String getEmail() {
209
- return email;
210
- }
207
+ public String getEmail() {
208
+ return email;
209
+ }
211210
212
- public void setEmail(String email) {
213
- this.email = email;
214
- }
211
+ public void setEmail(String email) {
212
+ this.email = email;
213
+ }
215214
216
- public void setId(int id) {
217
- this.id = id;
218
- }
215
+ public void setId(int id) {
216
+ this.id = id;
217
+ }
219218
220
- public User getCanceledBy() {
221
- return canceledBy;
222
- }
219
+ public User getCanceledBy() {
220
+ return canceledBy;
221
+ }
223222
224
- public void setCanceledBy(User canceledBy) {
225
- this.canceledBy = canceledBy;
226
- }
223
+ public void setCanceledBy(User canceledBy) {
224
+ this.canceledBy = canceledBy;
225
+ }
227226
228
- public Date getLastAccessTimestamp() {
229
- return lastAccessTimestamp;
230
- }
227
+ public Date getLastAccessTimestamp() {
228
+ return lastAccessTimestamp;
229
+ }
231230
232
- public void setLastAccessTimestamp(Date lastAccessTimestamp) {
233
- this.lastAccessTimestamp = lastAccessTimestamp;
234
- }
231
+ public void setLastAccessTimestamp(Date lastAccessTimestamp) {
232
+ this.lastAccessTimestamp = lastAccessTimestamp;
233
+ }
235234
236
- public String getRequestData() {
237
- return requestData;
238
- }
235
+ public String getRequestData() {
236
+ return requestData;
237
+ }
239238
240
- public void setRequestData(String requestData) {
241
- this.requestData = requestData;
242
- }
239
+ public void setRequestData(String requestData) {
240
+ this.requestData = requestData;
241
+ }
243242
244
- public String getLicenseData() {
245
- return licenseData;
246
- }
243
+ public String getLicenseData() {
244
+ return licenseData;
245
+ }
247246
248
- public void setLicenseData(String licenseData) {
249
- this.licenseData = licenseData;
250
- }
247
+ public void setLicenseData(String licenseData) {
248
+ this.licenseData = licenseData;
249
+ }
251250
252
- public String getComments() {
253
- return comments;
254
- }
251
+ public String getComments() {
252
+ return comments;
253
+ }
255254
256
- public void setComments(String comments) {
257
- this.comments = comments;
258
- }
255
+ public void setComments(String comments) {
256
+ this.comments = comments;
257
+ }
259258
260
- public List<LicenseHistory> getHistory() {
261
- return history;
262
- }
259
+ public List<LicenseHistory> getHistory() {
260
+ return history;
261
+ }
263262
264
- public void setHistory(List<LicenseHistory> history) {
265
- this.history = history;
266
- }
263
+ public void setHistory(List<LicenseHistory> history) {
264
+ this.history = history;
265
+ }
267266
268
- public Date getExpirationDate() {
269
- return expirationDate;
270
- }
267
+ public Date getExpirationDate() {
268
+ return expirationDate;
269
+ }
271270
272
- public void setExpirationDate(Date expirationDate) {
273
- this.expirationDate = expirationDate;
274
- }
271
+ public void setExpirationDate(Date expirationDate) {
272
+ this.expirationDate = expirationDate;
273
+ }
275274
276
- public static class Action {
277
- public static final int CREATE = 1;
278
- public static final int REQUEST = 2;
279
- public static final int ACTIVATION = 3;
280
- public static final int SEND = 4;
281
- public static final int DOWNLOAD = 5;
282
- public static final int CANCEL = 6;
283
- public static final int DELETE = 7;
284
- }
275
+ public static class Action {
276
+ public static final int CREATE = 1;
277
+ public static final int REQUEST = 2;
278
+ public static final int ACTIVATION = 3;
279
+ public static final int SEND = 4;
280
+ public static final int DOWNLOAD = 5;
281
+ public static final int CANCEL = 6;
282
+ public static final int DELETE = 7;
283
+ }
285284
286
- public static class Status {
287
- public static final int CREATED = 1;
288
- public static final int REQUESTED = 2;
289
- public static final int PREACTIVE = 3;
290
- public static final int ACTIVE = 4;
291
- public static final int EXPIRED = 5;
292
- public static final int CANCELED = 6;
293
- public static final int DELETED = 7;
285
+ public static class Status {
286
+ public static final int CREATED = 1;
287
+ public static final int REQUESTED = 2;
288
+ public static final int PREACTIVE = 3;
289
+ public static final int ACTIVE = 4;
290
+ public static final int EXPIRED = 5;
291
+ public static final int CANCELED = 6;
292
+ public static final int DELETED = 7;
294293
295
- private static final Map<Integer, List<Integer>> transitions = Utils.createMap( //
296
- Action.REQUEST, Arrays.asList(CREATED, REQUESTED), //
297
- Action.ACTIVATION, Arrays.asList(REQUESTED, PREACTIVE, EXPIRED), //
298
- Action.SEND, Arrays.asList(ACTIVE, PREACTIVE), //
299
- Action.DOWNLOAD, Arrays.asList(ACTIVE, PREACTIVE), //
300
- Action.CANCEL, Arrays.asList(ACTIVE, PREACTIVE, REQUESTED, EXPIRED), //
301
- Action.DELETE, Arrays.asList(CANCELED, CREATED) //
294
+ private static final Map<Integer, List<Integer>> transitions = Utils.createMap( //
295
+ Action.REQUEST, Arrays.asList(CREATED, REQUESTED), //
296
+ Action.ACTIVATION, Arrays.asList(REQUESTED, PREACTIVE, EXPIRED), //
297
+ Action.SEND, Arrays.asList(ACTIVE, PREACTIVE), //
298
+ Action.DOWNLOAD, Arrays.asList(ACTIVE, PREACTIVE), //
299
+ Action.CANCEL, Arrays.asList(ACTIVE, PREACTIVE, REQUESTED, EXPIRED), //
300
+ Action.DELETE, Arrays.asList(CANCELED, CREATED) //
302301
303
- );
302
+ );
304303
305
- /**
306
- * It checks if a given action is valid for the License, passing the action and the current license status
307
- *
308
- * @param oldStatus
309
- * @param newStatus
310
- * @return
311
- */
312
- public static boolean isActionValid(Integer action, Integer currentStatus) {
313
- List<Integer> validStatuses = transitions.get(currentStatus);
304
+ /**
305
+ * It checks if a given action is valid for the License, passing the
306
+ * action and the current license status
307
+ *
308
+ * @param oldStatus
309
+ * @param newStatus
310
+ * @return
311
+ */
312
+ public static boolean isActionValid(Integer action, Integer currentStatus) {
313
+ List<Integer> validStatuses = transitions.get(currentStatus);
314314
315
- return validStatuses != null && validStatuses.contains(currentStatus);
316
- }
317
- }
315
+ return validStatuses != null && validStatuses.contains(currentStatus);
316
+ }
317
+ }
318318 }