Roberto Sánchez
2014-02-05 8e6db5714c3884cc74c3230abf7b20589ccd1552
securis/src/main/java/net/curisit/securis/services/LicenseResource.java
....@@ -125,7 +125,7 @@
125125 log.error("License with id {} has not license file generated", licId, bsc.getUserPrincipal());
126126 throw new SeCurisServiceException(Status.FORBIDDEN.getStatusCode(), "License has not contain data to generate license file");
127127 }
128
- if (lic.getStatus() != License.Status.ACTIVE) {
128
+ if (License.Status.isActionValid(License.Action.DOWNLOAD, lic.getStatus())) {
129129 log.error("License with id {} is not active, so It can not downloaded", licId, bsc.getUserPrincipal());
130130 throw new SeCurisServiceException(Status.FORBIDDEN.getStatusCode(), "License is not active, so It can not be downloaded");
131131 }
....@@ -145,11 +145,15 @@
145145 EntityManager em = emProvider.get();
146146 License lic = getCurrentLicense(licId, bsc, em);
147147
148
- User user = getUser(bsc.getUserPrincipal().getName(), em);
148
+ if (License.Status.isActionValid(License.Action.ACTIVATION, lic.getStatus())) {
149
+ log.error("License with id {} can not be activated from current license status", licId);
150
+ throw new SeCurisServiceException(Status.FORBIDDEN.getStatusCode(), "License with id " + licId + " can not be activated from the current license status");
151
+ }
149152
150153 lic.setStatus(License.Status.ACTIVE);
151154 lic.setModificationTimestamp(new Date());
152155 em.persist(lic);
156
+ User user = getUser(bsc.getUserPrincipal().getName(), em);
153157 em.persist(createLicenseHistoryAction(lic, user, LicenseHistory.Actions.ACTIVATE));
154158 return Response.ok(lic).build();
155159 }
....@@ -188,11 +192,16 @@
188192 EntityManager em = emProvider.get();
189193 License lic = getCurrentLicense(licId, bsc, em);
190194
191
- User user = getUser(bsc.getUserPrincipal().getName(), em);
195
+ if (License.Status.isActionValid(License.Action.CANCEL, lic.getStatus())) {
196
+ log.error("License with id {} can not be canceled from current license status", licId);
197
+ throw new SeCurisServiceException(Status.FORBIDDEN.getStatusCode(), "License with id " + licId + " can not be canceled from the current license status");
198
+ }
192199
193200 lic.setStatus(License.Status.CANCELED);
194201 lic.setModificationTimestamp(new Date());
195202 em.persist(lic);
203
+
204
+ User user = getUser(bsc.getUserPrincipal().getName(), em);
196205 em.persist(createLicenseHistoryAction(lic, user, LicenseHistory.Actions.CANCEL));
197206 return Response.ok(lic).build();
198207 }