Roberto Sánchez
2014-09-18 52ce72b22ef8d92a1f35b4993bcddaaa66d67350
securis/src/main/java/net/curisit/securis/services/LicenseResource.java
....@@ -47,7 +47,7 @@
4747 @Path("/license")
4848 public class LicenseResource {
4949
50
- private static final Logger log = LogManager.getLogger(LicenseResource.class);
50
+ private static final Logger LOG = LogManager.getLogger(LicenseResource.class);
5151
5252 @Inject
5353 TokenHelper tokenHelper;
....@@ -68,7 +68,7 @@
6868 @Produces(
6969 { MediaType.APPLICATION_JSON })
7070 public Response index(@QueryParam("packId") Integer packId, @Context BasicSecurityContext bsc) {
71
- log.info("Getting licenses list ");
71
+ LOG.info("Getting licenses list ");
7272
7373 EntityManager em = emProvider.get();
7474
....@@ -77,7 +77,7 @@
7777 if (pack == null)
7878 return Response.ok().build();
7979 if (!bsc.getOrganizationsIds().contains(pack.getOrganization().getId())) {
80
- log.error("Pack with id {} not accesible by user {}", pack, bsc.getUserPrincipal());
80
+ LOG.error("Pack with id {} not accesible by user {}", pack, bsc.getUserPrincipal());
8181 return Response.status(Status.UNAUTHORIZED).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Unathorized access to pack licenses").build();
8282 }
8383 }
....@@ -99,7 +99,7 @@
9999 @Produces(
100100 { MediaType.APPLICATION_JSON })
101101 public Response get(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
102
- log.info("Getting organization data for id: {}: ", licId);
102
+ LOG.info("Getting organization data for id: {}: ", licId);
103103
104104 EntityManager em = emProvider.get();
105105 License lic = getCurrentLicense(licId, bsc, em);
....@@ -122,11 +122,11 @@
122122 License lic = getCurrentLicense(licId, bsc, em);
123123
124124 if (lic.getLicenseData() == null) {
125
- log.error("License with id {} has not license file generated", licId, bsc.getUserPrincipal());
125
+ 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 }
128128 if (License.Status.isActionValid(License.Action.DOWNLOAD, lic.getStatus())) {
129
- log.error("License with id {} is not active, so It can not downloaded", licId, bsc.getUserPrincipal());
129
+ 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 }
132132 return Response.ok(lic.getLicenseData()).build();
....@@ -146,7 +146,7 @@
146146 License lic = getCurrentLicense(licId, bsc, em);
147147
148148 if (License.Status.isActionValid(License.Action.ACTIVATION, lic.getStatus())) {
149
- log.error("License with id {} can not be activated from current license status", licId);
149
+ LOG.error("License with id {} can not be activated from current license status", licId);
150150 throw new SeCurisServiceException(Status.FORBIDDEN.getStatusCode(), "License with id " + licId + " can not be activated from the current license status");
151151 }
152152
....@@ -193,7 +193,7 @@
193193 License lic = getCurrentLicense(licId, bsc, em);
194194
195195 if (License.Status.isActionValid(License.Action.CANCEL, lic.getStatus())) {
196
- log.error("License with id {} can not be canceled from current license status", licId);
196
+ LOG.error("License with id {} can not be canceled from current license status", licId);
197197 throw new SeCurisServiceException(Status.FORBIDDEN.getStatusCode(), "License with id " + licId + " can not be canceled from the current license status");
198198 }
199199
....@@ -214,18 +214,18 @@
214214 { MediaType.APPLICATION_JSON })
215215 @Transactional
216216 public Response create(License lic, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
217
- log.info("Creating new license from create()");
217
+ LOG.info("Creating new license from create()");
218218 EntityManager em = emProvider.get();
219219 Pack pack = null;
220220 if (lic.getPackId() != null) {
221221 pack = em.find(Pack.class, lic.getPackId());
222222 if (pack == null) {
223
- log.error("License pack with id {} not found in DB", lic.getPackId());
223
+ LOG.error("License pack with id {} not found in DB", lic.getPackId());
224224 return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "License's pack not found with ID: " + lic.getPackId()).build();
225225 } else {
226226 if (!bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN)) {
227227 if (!bsc.getOrganizationsIds().contains(pack.getOrganization().getId())) {
228
- log.error("License for pack with id {} can not be created by user {}", pack.getId(), bsc.getUserPrincipal());
228
+ LOG.error("License for pack with id {} can not be created by user {}", pack.getId(), bsc.getUserPrincipal());
229229 return Response.status(Status.UNAUTHORIZED).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Unathorized action on pack license").build();
230230 }
231231 }
....@@ -273,7 +273,7 @@
273273 @Produces(
274274 { MediaType.APPLICATION_JSON })
275275 public Response modify(License lic, @PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
276
- log.info("Modifying organization with id: {}", licId);
276
+ LOG.info("Modifying organization with id: {}", licId);
277277
278278 EntityManager em = emProvider.get();
279279
....@@ -296,12 +296,12 @@
296296 @Produces(
297297 { MediaType.APPLICATION_JSON })
298298 public Response delete(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
299
- log.info("Deleting license with id: {}", licId);
299
+ LOG.info("Deleting license with id: {}", licId);
300300 EntityManager em = emProvider.get();
301301 License lic = getCurrentLicense(licId, bsc, em);
302302
303303 if (lic.getStatus() != License.Status.CANCELED || lic.getStatus() != License.Status.CREATED) {
304
- log.error("License {} can not be deleted with status {}", lic.getCode(), lic.getStatus());
304
+ LOG.error("License {} can not be deleted with status {}", lic.getCode(), lic.getStatus());
305305 return Response.status(Status.FORBIDDEN).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "License can not be deleted in current status").build();
306306 }
307307
....@@ -311,18 +311,18 @@
311311
312312 private License getCurrentLicense(Integer licId, BasicSecurityContext bsc, EntityManager em) throws SeCurisServiceException {
313313 if (licId == null || licId.equals("")) {
314
- log.error("License ID is mandatory");
314
+ LOG.error("License ID is mandatory");
315315 throw new SeCurisServiceException(Status.NOT_FOUND.getStatusCode(), "Missing license ID");
316316 }
317317
318318 License lic = em.find(License.class, licId);
319319 if (lic == null) {
320
- log.error("License with id {} not found in DB", licId);
320
+ LOG.error("License with id {} not found in DB", licId);
321321 throw new SeCurisServiceException(Status.NOT_FOUND.getStatusCode(), "License not found for ID: " + licId);
322322 }
323323 if (!bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN)) {
324324 if (!bsc.getOrganizationsIds().contains(lic.getPack().getOrganization().getId())) {
325
- log.error("License with id {} is not accesible by user {}", licId, bsc.getUserPrincipal());
325
+ LOG.error("License with id {} is not accesible by user {}", licId, bsc.getUserPrincipal());
326326 throw new SeCurisServiceException(Status.UNAUTHORIZED.getStatusCode(), "Unathorized access to license data");
327327 }
328328 }