rsanchez
2015-09-24 94c288b4f8d353c44b64e40c0863c7fce6782293
securis/src/main/java/net/curisit/securis/services/LicenseResource.java
....@@ -209,7 +209,7 @@
209209
210210 License existingLicense = License.findActiveLicenseByRequestData(lic.getRequestData(), em);
211211 if (existingLicense != null && existingLicense.getStatus() == LicenseStatus.ACTIVE) {
212
- throw new SeCurisServiceException(ErrorCodes.NO_AVAILABLE_LICENSES, "The pack has not available licenses");
212
+ throw new SeCurisServiceException(ErrorCodes.NO_AVAILABLE_LICENSES, "An active license already exists for the given request data");
213213 }
214214
215215 lic.setStatus(LicenseStatus.ACTIVE);
....@@ -347,9 +347,19 @@
347347 if (checkIfCodeExists(lic.getCode(), em)) {
348348 throw new SeCurisServiceException(ErrorCodes.INVALID_DATA, "The license code is already used in an existing license");
349349 }
350
+ if (lic.getActivationCode() == null) {
351
+ throw new SeCurisServiceException(ErrorCodes.INVALID_DATA, "The activation code is mandatory");
352
+ }
353
+ License existingLic = License.findLicenseByActivationCode(lic.getActivationCode(), em);
354
+ if (existingLic != null) {
355
+ throw new SeCurisServiceException(ErrorCodes.INVALID_DATA, "The activation code is already used in: " + existingLic.getCode());
356
+ }
350357 if (!LicUtils.checkValidLicenseCodeCrc(lic.getCode())) {
351358 throw new SeCurisServiceException(ErrorCodes.INVALID_DATA, "The license code is not valid");
352359 }
360
+ if (!Utils.isValidEmail(lic.getEmail())) {
361
+ throw new SeCurisServiceException(ErrorCodes.INVALID_DATA, "The user email should be a valid email");
362
+ }
353363
354364 Pack pack = null;
355365 if (lic.getPackId() != null) {