rsanchez
2015-09-24 94c288b4f8d353c44b64e40c0863c7fce6782293
securis/src/main/java/net/curisit/securis/db/License.java
....@@ -54,6 +54,7 @@
5454 @JsonIgnoreProperties(ignoreUnknown = true)
5555 @NamedQueries({
5656 @NamedQuery(name = "license-by-code", query = "SELECT l FROM License l where l.code = :code"),
57
+ @NamedQuery(name = "license-by-activation-code", query = "SELECT l FROM License l where l.activationCode = :activationCode"),
5758 @NamedQuery(name = "last-code-suffix-used-in-pack", query = "SELECT max(l.codeSuffix) FROM License l where l.pack.id = :packId"),
5859 @NamedQuery(name = "list-licenses-by-pack", query = "SELECT l FROM License l where l.pack.id = :packId"),
5960 @NamedQuery(name = "list-licenses-by-req-data", query = "SELECT l FROM License l where l.reqDataHash = :hash"),
....@@ -72,6 +73,10 @@
7273 private int id;
7374
7475 private String code;
76
+
77
+ @Column(name = "activation_code")
78
+ @JsonProperty("activation_code")
79
+ private String activationCode;
7580
7681 @Column(name = "code_suffix")
7782 @JsonProperty("code_suffix")
....@@ -397,6 +402,26 @@
397402 }
398403 }
399404
405
+ /**
406
+ * Return licenses with status: REquested, ACtive, Pre-Active for a given
407
+ * request data
408
+ *
409
+ * @param requestData
410
+ * @param em
411
+ * @return
412
+ * @throws SeCurisServiceException
413
+ */
414
+ public static License findLicenseByActivationCode(String activationCode, EntityManager em) throws SeCurisServiceException {
415
+ TypedQuery<License> query = em.createNamedQuery("license-by-activation-code", License.class);
416
+ query.setParameter("activationCode", activationCode);
417
+ try {
418
+ return query.getSingleResult();
419
+ } catch (NoResultException e) {
420
+ // There is no license for request data
421
+ return null;
422
+ }
423
+ }
424
+
400425 public static License findActiveLicenseByRequestData(String requestData, EntityManager em) throws SeCurisServiceException {
401426 TypedQuery<License> query = em.createNamedQuery("list-active-licenses-by-req-data", License.class);
402427 query.setParameter("hash", BlockedRequest.generateHash(requestData));
....@@ -435,4 +460,12 @@
435460 this.codeSuffix = codeSuffix;
436461 }
437462
463
+ public String getActivationCode() {
464
+ return activationCode;
465
+ }
466
+
467
+ public void setActivationCode(String activationCode) {
468
+ this.activationCode = activationCode;
469
+ }
470
+
438471 }