From 8d5386be38db25a2a41c3bf6c876adee21ca26cc Mon Sep 17 00:00:00 2001
From: Roberto Sánchez <roberto.sanchez@curisit.net>
Date: Fri, 19 Sep 2014 08:26:02 +0000
Subject: [PATCH] #396 fix - Fixed more SonarQube issues

---
 securis/src/main/java/net/curisit/securis/services/LicenseTypeResource.java |  243 ++++++++++++++++++++++++------------------------
 1 files changed, 120 insertions(+), 123 deletions(-)

diff --git a/securis/src/main/java/net/curisit/securis/services/LicenseTypeResource.java b/securis/src/main/java/net/curisit/securis/services/LicenseTypeResource.java
index 9218b96..1906c3b 100644
--- a/securis/src/main/java/net/curisit/securis/services/LicenseTypeResource.java
+++ b/securis/src/main/java/net/curisit/securis/services/LicenseTypeResource.java
@@ -35,152 +35,149 @@
 import com.google.inject.persist.Transactional;
 
 /**
- * LicenseType resource, this service will provide methods to create, modify and delete license types
+ * LicenseType resource, this service will provide methods to create, modify and
+ * delete license types
  * 
  * @author roberto <roberto.sanchez@curisit.net>
  */
 @Path("/licensetype")
 public class LicenseTypeResource {
 
-	private static final Logger LOG = LogManager.getLogger(LicenseTypeResource.class);
+    private static final Logger LOG = LogManager.getLogger(LicenseTypeResource.class);
 
-	@Inject
-	TokenHelper tokenHelper;
+    @Inject
+    TokenHelper tokenHelper;
 
-	@Inject
-	Provider<EntityManager> emProvider;
+    @Inject
+    Provider<EntityManager> emProvider;
 
-	public LicenseTypeResource() {
-	}
+    public LicenseTypeResource() {}
 
-	/**
-	 * 
-	 * @return the server version in format majorVersion.minorVersion
-	 */
-	@GET
-	@Path("/")
-	@Produces(
-		{ MediaType.APPLICATION_JSON })
-	public Response index() {
-		LOG.info("Getting license types list ");
+    /**
+     * 
+     * @return the server version in format majorVersion.minorVersion
+     */
+    @GET
+    @Path("/")
+    @Produces({ MediaType.APPLICATION_JSON })
+    public Response index() {
+        LOG.info("Getting license types list ");
 
-		EntityManager em = emProvider.get();
-		TypedQuery<LicenseType> q = em.createNamedQuery("list-license_types", LicenseType.class);
-		List<LicenseType> list = q.getResultList();
+        EntityManager em = emProvider.get();
+        TypedQuery<LicenseType> q = em.createNamedQuery("list-license_types", LicenseType.class);
+        List<LicenseType> list = q.getResultList();
 
-		return Response.ok(list).build();
-	}
+        return Response.ok(list).build();
+    }
 
-	/**
-	 * 
-	 * @return the server version in format majorVersion.minorVersion
-	 */
-	@GET
-	@Path("/{ltid}")
-	@Produces(
-		{ MediaType.APPLICATION_JSON })
-	public Response get(@PathParam("ltid") String ltid, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
-		LOG.info("Getting license type data for id: {}: ", ltid);
-		if (ltid == null || ltid.equals("")) {
-			LOG.error("LicenseType ID is mandatory");
-			return Response.status(Status.NOT_FOUND).build();
-		}
+    /**
+     * 
+     * @return the server version in format majorVersion.minorVersion
+     */
+    @GET
+    @Path("/{ltid}")
+    @Produces({ MediaType.APPLICATION_JSON })
+    public Response get(@PathParam("ltid") String ltid, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
+        LOG.info("Getting license type data for id: {}: ", ltid);
+        if (ltid == null || "".equals(ltid)) {
+            LOG.error("LicenseType ID is mandatory");
+            return Response.status(Status.NOT_FOUND).build();
+        }
 
-		EntityManager em = emProvider.get();
-		LicenseType lt = em.find(LicenseType.class, Integer.parseInt(ltid));
-		if (lt == null) {
-			LOG.error("LicenseType with id {} not found in DB", ltid);
-			return Response.status(Status.NOT_FOUND).build();
-		}
-		return Response.ok(lt).build();
-	}
+        EntityManager em = emProvider.get();
+        LicenseType lt = em.find(LicenseType.class, Integer.parseInt(ltid));
+        if (lt == null) {
+            LOG.error("LicenseType with id {} not found in DB", ltid);
+            return Response.status(Status.NOT_FOUND).build();
+        }
+        return Response.ok(lt).build();
+    }
 
-	@POST
-	@Path("/")
-	@Consumes(MediaType.APPLICATION_JSON)
-	@Produces(
-		{ MediaType.APPLICATION_JSON })
-	@Transactional
-	public Response create(LicenseType lt, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
-		LOG.info("Creating new license type");
-		EntityManager em = emProvider.get();
+    @POST
+    @Path("/")
+    @Consumes(MediaType.APPLICATION_JSON)
+    @Produces({ MediaType.APPLICATION_JSON })
+    @Transactional
+    public Response create(LicenseType lt, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
+        LOG.info("Creating new license type");
+        EntityManager em = emProvider.get();
 
-		try {
-			setApplication(lt, lt.getApplicationId(), em);
-		} catch (SeCurisException e) {
-			return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, e.getMessage()).build();
-		}
-		
-		if (lt.getApplicationId() == null) {
-			LOG.error("Application is missing for current license type data");
-			return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Application is missing for current license type data").build();
-		}
+        try {
+            setApplication(lt, lt.getApplicationId(), em);
+        } catch (SeCurisException e) {
+            return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, e.getMessage()).build();
+        }
 
-		lt.setCreationTimestamp(new Date());
-		em.persist(lt);
+        if (lt.getApplicationId() == null) {
+            LOG.error("Application is missing for current license type data");
+            return Response.status(Status.NOT_FOUND)
+                    .header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Application is missing for current license type data").build();
+        }
 
-		return Response.ok(lt).build();
-	}
+        lt.setCreationTimestamp(new Date());
+        em.persist(lt);
 
-	@PUT
-	@POST
-	@Path("/{ltid}")
-	@Transactional
-	@Consumes(MediaType.APPLICATION_JSON)
-	@Produces(
-		{ MediaType.APPLICATION_JSON })
-	public Response modify(LicenseType lt, @PathParam("ltid") String ltid, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
-		LOG.info("Modifying license type with id: {}", ltid);
-		EntityManager em = emProvider.get();
-		LicenseType currentlt = em.find(LicenseType.class, Integer.parseInt(ltid));
-		if (currentlt == null) {
-			LOG.error("LicenseType with id {} not found in DB", ltid);
-			return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "License type not found with ID: " + ltid).build();
-		}
+        return Response.ok(lt).build();
+    }
 
-		try {
-			setApplication(currentlt, lt.getApplicationId(), em);
-		} catch (SeCurisException e) {
-			return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, e.getMessage()).build();
-		}
-		
-		currentlt.setCode(lt.getCode());
-		currentlt.setName(lt.getName());
-		currentlt.setDescription(lt.getDescription());
-		em.persist(currentlt);
+    @PUT
+    @POST
+    @Path("/{ltid}")
+    @Transactional
+    @Consumes(MediaType.APPLICATION_JSON)
+    @Produces({ MediaType.APPLICATION_JSON })
+    public Response modify(LicenseType lt, @PathParam("ltid") String ltid, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
+        LOG.info("Modifying license type with id: {}", ltid);
+        EntityManager em = emProvider.get();
+        LicenseType currentlt = em.find(LicenseType.class, Integer.parseInt(ltid));
+        if (currentlt == null) {
+            LOG.error("LicenseType with id {} not found in DB", ltid);
+            return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "License type not found with ID: " + ltid)
+                    .build();
+        }
 
-		return Response.ok(currentlt).build();
-	}
+        try {
+            setApplication(currentlt, lt.getApplicationId(), em);
+        } catch (SeCurisException e) {
+            return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, e.getMessage()).build();
+        }
 
-	private void setApplication(LicenseType licType, Integer applicationId, EntityManager em) throws SeCurisException {
-		Application app = null;
-		if (applicationId != null) {
-			app = em.find(Application.class, applicationId);
-			if (app == null) {
-				LOG.error("LicenseType application with id {} not found in DB", applicationId);
-				
-				throw new SecurityException("License type's app not found with ID: " + applicationId);
-			}
-		}
-		licType.setApplication(app);		
-	}
+        currentlt.setCode(lt.getCode());
+        currentlt.setName(lt.getName());
+        currentlt.setDescription(lt.getDescription());
+        em.persist(currentlt);
 
-	@DELETE
-	@Path("/{ltid}")
-	@Transactional
-	@Produces(
-		{ MediaType.APPLICATION_JSON })
-	public Response delete(@PathParam("ltid") String ltid, @Context HttpServletRequest request) {
-		LOG.info("Deleting app with id: {}", ltid);
-		EntityManager em = emProvider.get();
-		LicenseType app = em.find(LicenseType.class, Integer.parseInt(ltid));
-		if (app == null) {
-			LOG.error("LicenseType with id {} can not be deleted, It was not found in DB", ltid);
-			return Response.status(Status.NOT_FOUND).build();
-		}
+        return Response.ok(currentlt).build();
+    }
 
-		em.remove(app);
-		return Response.ok(Utils.createMap("success", true, "id", ltid)).build();
-	}
+    private void setApplication(LicenseType licType, Integer applicationId, EntityManager em) throws SeCurisException {
+        Application app = null;
+        if (applicationId != null) {
+            app = em.find(Application.class, applicationId);
+            if (app == null) {
+                LOG.error("LicenseType application with id {} not found in DB", applicationId);
+
+                throw new SecurityException("License type's app not found with ID: " + applicationId);
+            }
+        }
+        licType.setApplication(app);
+    }
+
+    @DELETE
+    @Path("/{ltid}")
+    @Transactional
+    @Produces({ MediaType.APPLICATION_JSON })
+    public Response delete(@PathParam("ltid") String ltid, @Context HttpServletRequest request) {
+        LOG.info("Deleting app with id: {}", ltid);
+        EntityManager em = emProvider.get();
+        LicenseType app = em.find(LicenseType.class, Integer.parseInt(ltid));
+        if (app == null) {
+            LOG.error("LicenseType with id {} can not be deleted, It was not found in DB", ltid);
+            return Response.status(Status.NOT_FOUND).build();
+        }
+
+        em.remove(app);
+        return Response.ok(Utils.createMap("success", true, "id", ltid)).build();
+    }
 
 }

--
Gitblit v1.3.2