From 071a008cf28e733ca3aaafa57e675fd54a5ea33b Mon Sep 17 00:00:00 2001
From: Roberto Sánchez <roberto.sanchez@curisit.net>
Date: Fri, 19 Sep 2014 09:29:16 +0000
Subject: [PATCH] #396 fix - Fixed more SonarQube issues, new code style applied

---
 securis/src/main/java/net/curisit/securis/services/LicenseResource.java |   65 ++++++++++++++++++++------------
 1 files changed, 41 insertions(+), 24 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 1ef497d..8869c03 100644
--- a/securis/src/main/java/net/curisit/securis/services/LicenseResource.java
+++ b/securis/src/main/java/net/curisit/securis/services/LicenseResource.java
@@ -33,9 +33,9 @@
 import net.curisit.securis.services.exception.SeCurisServiceException;
 import net.curisit.securis.utils.TokenHelper;
 
-import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput;
-import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput;
 
 import com.google.inject.persist.Transactional;
 
@@ -56,7 +56,8 @@
     @Inject
     Provider<EntityManager> emProvider;
 
-    public LicenseResource() {}
+    public LicenseResource() {
+    }
 
     /**
      * 
@@ -65,7 +66,9 @@
     @GET
     @Path("/")
     @Securable
-    @Produces({ MediaType.APPLICATION_JSON })
+    @Produces({
+        MediaType.APPLICATION_JSON
+    })
     public Response index(@QueryParam("packId") Integer packId, @Context BasicSecurityContext bsc) {
         LOG.info("Getting licenses list ");
 
@@ -97,7 +100,9 @@
     @GET
     @Path("/{licId}")
     @Securable
-    @Produces({ MediaType.APPLICATION_JSON })
+    @Produces({
+        MediaType.APPLICATION_JSON
+    })
     public Response get(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
         LOG.info("Getting organization data for id: {}: ", licId);
 
@@ -114,7 +119,9 @@
     @GET
     @Path("/{licId}/download")
     @Securable
-    @Produces({ MediaType.APPLICATION_OCTET_STREAM })
+    @Produces({
+        MediaType.APPLICATION_OCTET_STREAM
+    })
     public Response download(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
 
         EntityManager em = emProvider.get();
@@ -137,7 +144,9 @@
     @Securable
     @Transactional
     @Consumes(MediaType.APPLICATION_JSON)
-    @Produces({ MediaType.APPLICATION_JSON })
+    @Produces({
+        MediaType.APPLICATION_JSON
+    })
     public Response activate(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
 
         EntityManager em = emProvider.get();
@@ -163,7 +172,9 @@
     @Securable
     @Transactional
     @Consumes(MediaType.APPLICATION_JSON)
-    @Produces({ MediaType.APPLICATION_JSON })
+    @Produces({
+        MediaType.APPLICATION_JSON
+    })
     public Response send(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
 
         EntityManager em = emProvider.get();
@@ -183,7 +194,9 @@
     @Securable
     @Transactional
     @Consumes(MediaType.APPLICATION_JSON)
-    @Produces({ MediaType.APPLICATION_JSON })
+    @Produces({
+        MediaType.APPLICATION_JSON
+    })
     public Response cancel(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
 
         EntityManager em = emProvider.get();
@@ -208,7 +221,9 @@
     @Path("/")
     @Consumes(MediaType.APPLICATION_JSON)
     @Securable
-    @Produces({ MediaType.APPLICATION_JSON })
+    @Produces({
+        MediaType.APPLICATION_JSON
+    })
     @Transactional
     public Response create(License lic, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
         LOG.info("Creating new license from create()");
@@ -221,12 +236,10 @@
                 return Response.status(Status.NOT_FOUND)
                         .header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "License's pack not found with ID: " + lic.getPackId()).build();
             } else {
-                if (!bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN)) {
-                    if (!bsc.getOrganizationsIds().contains(pack.getOrganization().getId())) {
-                        LOG.error("License for pack with id {} can not be created by user {}", pack.getId(), bsc.getUserPrincipal());
-                        return Response.status(Status.UNAUTHORIZED)
-                                .header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Unathorized action on pack license").build();
-                    }
+                if (!bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN) && !bsc.getOrganizationsIds().contains(pack.getOrganization().getId())) {
+                    LOG.error("License for pack with id {} can not be created by user {}", pack.getId(), bsc.getUserPrincipal());
+                    return Response.status(Status.UNAUTHORIZED)
+                            .header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Unathorized action on pack license").build();
                 }
             }
         }
@@ -248,7 +261,9 @@
     @Path("/")
     @Consumes(MediaType.MULTIPART_FORM_DATA)
     @Securable
-    @Produces({ MediaType.APPLICATION_JSON })
+    @Produces({
+        MediaType.APPLICATION_JSON
+    })
     @Transactional
     public Response createWithFile(MultipartFormDataInput mpfdi, @Context BasicSecurityContext bsc) throws IOException, SeCurisServiceException {
         License lic = new License();
@@ -268,7 +283,9 @@
     @Securable
     @Transactional
     @Consumes(MediaType.APPLICATION_JSON)
-    @Produces({ MediaType.APPLICATION_JSON })
+    @Produces({
+        MediaType.APPLICATION_JSON
+    })
     public Response modify(License lic, @PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
         LOG.info("Modifying organization with id: {}", licId);
 
@@ -290,7 +307,9 @@
     @Path("/{licId}")
     @Transactional
     @Securable
-    @Produces({ MediaType.APPLICATION_JSON })
+    @Produces({
+        MediaType.APPLICATION_JSON
+    })
     public Response delete(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
         LOG.info("Deleting license with id: {}", licId);
         EntityManager em = emProvider.get();
@@ -317,11 +336,9 @@
             LOG.error("License with id {} not found in DB", licId);
             throw new SeCurisServiceException(Status.NOT_FOUND.getStatusCode(), "License not found for ID: " + licId);
         }
-        if (!bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN)) {
-            if (!bsc.getOrganizationsIds().contains(lic.getPack().getOrganization().getId())) {
-                LOG.error("License with id {} is not accesible by user {}", licId, bsc.getUserPrincipal());
-                throw new SeCurisServiceException(Status.UNAUTHORIZED.getStatusCode(), "Unathorized access to license data");
-            }
+        if (!bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN) && !bsc.getOrganizationsIds().contains(lic.getPack().getOrganization().getId())) {
+            LOG.error("License with id {} is not accesible by user {}", licId, bsc.getUserPrincipal());
+            throw new SeCurisServiceException(Status.UNAUTHORIZED.getStatusCode(), "Unathorized access to license data");
         }
         return lic;
     }

--
Gitblit v1.3.2