rsanchez
2014-11-18 b33557d3faf3e45eff3d3e19f4a1549ffe907b4c
securis/src/main/java/net/curisit/securis/services/LicenseResource.java
....@@ -165,7 +165,7 @@
165165 LOG.error("License with id {} has not license file generated", licId, bsc.getUserPrincipal());
166166 throw new SeCurisServiceException(Status.FORBIDDEN.getStatusCode(), "License has not contain data to generate license file");
167167 }
168
- if (License.Status.isActionValid(License.Action.DOWNLOAD, lic.getStatus())) {
168
+ if (!License.Status.isActionValid(License.Action.DOWNLOAD, lic.getStatus())) {
169169 LOG.error("License with id {} is not active, so It can not downloaded", licId, bsc.getUserPrincipal());
170170 throw new SeCurisServiceException(ErrorCodes.WRONG_STATUS, "License is not active, so It can not be downloaded");
171171 }
....@@ -198,7 +198,7 @@
198198 EntityManager em = emProvider.get();
199199 License lic = getCurrentLicense(licId, bsc, em);
200200
201
- if (License.Status.isActionValid(License.Action.ACTIVATION, lic.getStatus())) {
201
+ if (!License.Status.isActionValid(License.Action.ACTIVATION, lic.getStatus())) {
202202 LOG.error("License with id {} can not be activated from current license status", licId);
203203 throw new SeCurisServiceException(Status.FORBIDDEN.getStatusCode(), "License with id " + licId
204204 + " can not be activated from the current license status");
....@@ -250,10 +250,14 @@
250250 throw new SeCurisServiceException(Status.NOT_FOUND.getStatusCode(), "There is no license file available");
251251 }
252252
253
+ if (lic.getFullName() == null) {
254
+ throw new SeCurisServiceException(Status.NOT_FOUND.getStatusCode(), "Please add an user name in license data to send it the license file");
255
+ }
256
+
253257 User user = userHelper.getUser(bsc.getUserPrincipal().getName(), em);
254258 try {
255259 String subject = MessageFormat.format(Params.get(Params.KEYS.EMAIL_LIC_DEFAULT_SUBJECT), lic.getPack().getAppName());
256
- String email_tpl = IOUtils.toString(this.getClass().getResourceAsStream("/lic_email_template.en"));
260
+ String email_tpl = IOUtils.toString(this.getClass().getResourceAsStream("/lic_email.template.en"));
257261 String body = MessageFormat.format(email_tpl, lic.getFullName(), app.getName());
258262 licFile = licenseHelper.createTemporaryLicenseFile(lic, app.getLicenseFilename());
259263
....@@ -264,11 +268,12 @@
264268 } finally {
265269 if (licFile != null) {
266270 licFile.delete();
271
+ licFile.getParentFile().delete();
267272 }
268273 }
269274
270275 lic.setModificationTimestamp(new Date());
271
- em.persist(lic);
276
+ em.merge(lic);
272277 em.persist(licenseHelper.createLicenseHistoryAction(lic, user, LicenseHistory.Actions.SEND, "Email sent to: " + lic.getEmail()));
273278 return Response.ok(lic).build();
274279 }
....@@ -296,7 +301,7 @@
296301 EntityManager em = emProvider.get();
297302 License lic = getCurrentLicense(licId, bsc, em);
298303
299
- if (License.Status.isActionValid(License.Action.CANCEL, lic.getStatus())) {
304
+ if (!License.Status.isActionValid(License.Action.CANCEL, lic.getStatus())) {
300305 LOG.error("License with id {} can not be canceled from current license status", licId);
301306 throw new SeCurisServiceException(Status.FORBIDDEN.getStatusCode(), "License with id " + licId
302307 + " can not be canceled from the current license status");
....@@ -499,7 +504,7 @@
499504 EntityManager em = emProvider.get();
500505 License lic = getCurrentLicense(licId, bsc, em);
501506
502
- if (License.Status.isActionValid(License.Action.DELETE, lic.getStatus())) {
507
+ if (!License.Status.isActionValid(License.Action.DELETE, lic.getStatus())) {
503508 LOG.error("License {} can not be deleted with status {}", lic.getCode(), lic.getStatus());
504509 throw new SeCurisServiceException(ErrorCodes.WRONG_STATUS, "License can not be deleted in current status: " + lic.getStatus().name());
505510 }