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/ApplicationResource.java |  195 ++++++++++++++++++++++++------------------------
 1 files changed, 98 insertions(+), 97 deletions(-)

diff --git a/securis/src/main/java/net/curisit/securis/services/ApplicationResource.java b/securis/src/main/java/net/curisit/securis/services/ApplicationResource.java
index 1c1d860..1e7230d 100644
--- a/securis/src/main/java/net/curisit/securis/services/ApplicationResource.java
+++ b/securis/src/main/java/net/curisit/securis/services/ApplicationResource.java
@@ -33,124 +33,125 @@
 import com.google.inject.persist.Transactional;
 
 /**
- * Application resource, this service will provide methods to create, modify and delete applications
+ * Application resource, this service will provide methods to create, modify and
+ * delete applications
  * 
  * @author roberto <roberto.sanchez@curisit.net>
  */
 @Path("/application")
 public class ApplicationResource {
 
-	@Inject
-	TokenHelper tokenHelper;
+    @Inject
+    TokenHelper tokenHelper;
 
-	@Inject
-	Provider<EntityManager> emProvider;
+    @Inject
+    Provider<EntityManager> emProvider;
 
-	private static final Logger LOG = LogManager.getLogger(ApplicationResource.class);
+    private static final Logger LOG = LogManager.getLogger(ApplicationResource.class);
 
-	public ApplicationResource() {
-	}
+    public ApplicationResource() {}
 
-	/**
-	 * 
-	 * @return the server version in format majorVersion.minorVersion
-	 */
-	@GET
-	@Path("/")
-	@Produces(
-		{ MediaType.APPLICATION_JSON })
-	public Response index() {
-		LOG.info("Getting applications list ");
+    /**
+     * 
+     * @return the server version in format majorVersion.minorVersion
+     */
+    @GET
+    @Path("/")
+    @Produces({ MediaType.APPLICATION_JSON })
+    public Response index() {
+        LOG.info("Getting applications list ");
 
-		EntityManager em = emProvider.get();
-		TypedQuery<Application> q = em.createNamedQuery("list-applications", Application.class);
-		List<Application> list = q.getResultList();
+        EntityManager em = emProvider.get();
+        TypedQuery<Application> q = em.createNamedQuery("list-applications", Application.class);
+        List<Application> list = q.getResultList();
 
-		return Response.ok(list).build();
-	}
+        return Response.ok(list).build();
+    }
 
-	/**
-	 * 
-	 * @return the server version in format majorVersion.minorVersion
-	 */
-	@GET
-	@Path("/{appid}")
-	@Produces(
-		{ MediaType.APPLICATION_JSON })
-	public Response get(@PathParam("appid") String appid, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
-		LOG.info("Getting application data for id: {}: ", appid);
-		if (appid == null || appid.equals("")) {
-			LOG.error("Application ID is mandatory");
-			return Response.status(Status.NOT_FOUND).build();
-		}
+    /**
+     * 
+     * @return the server version in format majorVersion.minorVersion
+     */
+    @GET
+    @Path("/{appid}")
+    @Produces({ MediaType.APPLICATION_JSON })
+    public Response get(@PathParam("appid") String appid, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
+        LOG.info("Getting application data for id: {}: ", appid);
+        if (appid == null || "".equals(appid)) {
+            LOG.error("Application ID is mandatory");
+            return Response.status(Status.NOT_FOUND).build();
+        }
 
-		EntityManager em = emProvider.get();
-		Application app = em.find(Application.class, Integer.parseInt(appid));
-		if (app == null) {
-			LOG.error("Application with id {} not found in DB", appid);
+        EntityManager em = emProvider.get();
+        Application app = em.find(Application.class, Integer.parseInt(appid));
+        if (app == null) {
+            LOG.error("Application with id {} not found in DB", appid);
 
-			return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Application not found with ID: " + appid).build();
-		}
-		return Response.ok(app).build();
-	}
+            return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Application not found with ID: " + appid)
+                    .build();
+        }
+        return Response.ok(app).build();
+    }
 
-	@POST
-	@Path("/")
-	@Consumes(MediaType.APPLICATION_JSON)
-	@Produces(
-		{ MediaType.APPLICATION_JSON })
-	@Transactional
-	public Response create(Application app, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
-		LOG.info("Creating new application");
-		EntityManager em = emProvider.get();
-		app.setCreationTimestamp(new Date());
-		em.persist(app);
+    @POST
+    @Path("/")
+    @Consumes(MediaType.APPLICATION_JSON)
+    @Produces({ MediaType.APPLICATION_JSON })
+    @Transactional
+    public Response create(Application app, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
+        LOG.info("Creating new application");
+        EntityManager em = emProvider.get();
+        app.setCreationTimestamp(new Date());
+        em.persist(app);
 
-		return Response.ok(app).build();
-	}
+        return Response.ok(app).build();
+    }
 
-	@PUT
-	@POST
-	@Path("/{appid}")
-	@Transactional
-	@Consumes(MediaType.APPLICATION_JSON)
-	@Produces(
-		{ MediaType.APPLICATION_JSON })
-	public Response modify(Application app, @PathParam("appid") String appid, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
-		LOG.info("Modifying application with id: {}", appid);
-		EntityManager em = emProvider.get();
-		Application currentapp = em.find(Application.class, Integer.parseInt(appid));
-		if (currentapp == null) {
-			LOG.error("Application with id {} not found in DB", appid);
-			return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Application not found with ID: " + appid).build();
-		}
-		currentapp.setName(app.getName());
-		currentapp.setDescription(app.getDescription());
-		em.persist(currentapp);
+    @PUT
+    @POST
+    @Path("/{appid}")
+    @Transactional
+    @Consumes(MediaType.APPLICATION_JSON)
+    @Produces({ MediaType.APPLICATION_JSON })
+    public Response modify(Application app, @PathParam("appid") String appid, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
+        LOG.info("Modifying application with id: {}", appid);
+        EntityManager em = emProvider.get();
+        Application currentapp = em.find(Application.class, Integer.parseInt(appid));
+        if (currentapp == null) {
+            LOG.error("Application with id {} not found in DB", appid);
+            return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Application not found with ID: " + appid)
+                    .build();
+        }
+        currentapp.setName(app.getName());
+        currentapp.setDescription(app.getDescription());
+        em.persist(currentapp);
 
-		return Response.ok(currentapp).build();
-	}
+        return Response.ok(currentapp).build();
+    }
 
-	@DELETE
-	@Path("/{appid}")
-	@Transactional
-	@Produces(
-		{ MediaType.APPLICATION_JSON })
-	public Response delete(@PathParam("appid") String appid, @Context HttpServletRequest request) {
-		LOG.info("Deleting app with id: {}", appid);
-		EntityManager em = emProvider.get();
-		Application app = em.find(Application.class, Integer.parseInt(appid));
-		if (app == null) {
-			LOG.error("Application with id {} can not be deleted, It was not found in DB", appid);
-			return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Application not found with ID: " + appid).build();
-		}
+    @DELETE
+    @Path("/{appid}")
+    @Transactional
+    @Produces({ MediaType.APPLICATION_JSON })
+    public Response delete(@PathParam("appid") String appid, @Context HttpServletRequest request) {
+        LOG.info("Deleting app with id: {}", appid);
+        EntityManager em = emProvider.get();
+        Application app = em.find(Application.class, Integer.parseInt(appid));
+        if (app == null) {
+            LOG.error("Application with id {} can not be deleted, It was not found in DB", appid);
+            return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Application not found with ID: " + appid)
+                    .build();
+        }
 
-		if (app.getLicenseTypes() != null && app.getLicenseTypes().size() > 0) {
-			return Response.status(Status.FORBIDDEN).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Application can not be deleted becasue has assigned one or more License types, ID: " + appid).build();
-		}
+        if (app.getLicenseTypes() != null && app.getLicenseTypes().size() > 0) {
+            return Response
+                    .status(Status.FORBIDDEN)
+                    .header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER,
+                            "Application can not be deleted becasue has assigned one or more License types, ID: " + appid).build();
+        }
 
-		em.remove(app);
-		return Response.ok(Utils.createMap("success", true, "id", appid)).build();
-	}
+        em.remove(app);
+        return Response.ok(Utils.createMap("success", true, "id", appid)).build();
+    }
 
 }

--
Gitblit v1.3.2