From 94c288b4f8d353c44b64e40c0863c7fce6782293 Mon Sep 17 00:00:00 2001
From: rsanchez <rsanchez@curisit.net>
Date: Thu, 24 Sep 2015 17:26:14 +0000
Subject: [PATCH] #2756 fix - chnaged API to allow activation by code and other UI changes

---
 securis/src/main/java/net/curisit/securis/services/LicenseResource.java |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/securis/src/main/java/net/curisit/securis/services/LicenseResource.java b/securis/src/main/java/net/curisit/securis/services/LicenseResource.java
index 3abb26f..fc57a2f 100644
--- a/securis/src/main/java/net/curisit/securis/services/LicenseResource.java
+++ b/securis/src/main/java/net/curisit/securis/services/LicenseResource.java
@@ -209,7 +209,7 @@
 
         License existingLicense = License.findActiveLicenseByRequestData(lic.getRequestData(), em);
         if (existingLicense != null && existingLicense.getStatus() == LicenseStatus.ACTIVE) {
-            throw new SeCurisServiceException(ErrorCodes.NO_AVAILABLE_LICENSES, "The pack has not available licenses");
+            throw new SeCurisServiceException(ErrorCodes.NO_AVAILABLE_LICENSES, "An active license already exists for the given request data");
         }
 
         lic.setStatus(LicenseStatus.ACTIVE);
@@ -347,9 +347,19 @@
         if (checkIfCodeExists(lic.getCode(), em)) {
             throw new SeCurisServiceException(ErrorCodes.INVALID_DATA, "The license code is already used in an existing license");
         }
+        if (lic.getActivationCode() == null) {
+            throw new SeCurisServiceException(ErrorCodes.INVALID_DATA, "The activation code is mandatory");
+        }
+        License existingLic = License.findLicenseByActivationCode(lic.getActivationCode(), em);
+        if (existingLic != null) {
+            throw new SeCurisServiceException(ErrorCodes.INVALID_DATA, "The activation code is already used in: " + existingLic.getCode());
+        }
         if (!LicUtils.checkValidLicenseCodeCrc(lic.getCode())) {
             throw new SeCurisServiceException(ErrorCodes.INVALID_DATA, "The license code is not valid");
         }
+        if (!Utils.isValidEmail(lic.getEmail())) {
+            throw new SeCurisServiceException(ErrorCodes.INVALID_DATA, "The user email should be a valid email");
+        }
 
         Pack pack = null;
         if (lic.getPackId() != null) {

--
Gitblit v1.3.2