From 9baa053329dcb227c32f74a446d59c067e5ac821 Mon Sep 17 00:00:00 2001 From: burdziak Date: Tue, 19 Mar 2019 10:53:47 +0100 Subject: Fix sonar issues in BroadcastListController Change-Id: If213a08c9cdc6d35e510e1abf70ac08186e06d6a Issue-ID: PORTAL-523 Signed-off-by: burdziak --- .../controller/sample/BroadcastListController.java | 25 ++++++++++++---------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'ecomp-sdk/epsdk-app-common') diff --git a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/BroadcastListController.java b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/BroadcastListController.java index 8b740d0b..c9c666fb 100644 --- a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/BroadcastListController.java +++ b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/BroadcastListController.java @@ -37,6 +37,7 @@ */ package org.onap.portalapp.controller.sample; +import java.io.IOException; import java.io.PrintWriter; import java.util.HashMap; import java.util.Map; @@ -65,6 +66,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; public class BroadcastListController extends RestrictedBaseController { private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(BroadcastListController.class); + private static final String UTF8 = "UTF-8"; + @Autowired private BroadcastService broadcastService; @@ -78,7 +81,7 @@ public class BroadcastListController extends RestrictedBaseController { @RequestMapping(value = { "/get_broadcast_list" }, method = RequestMethod.GET) public void getBroadcast(HttpServletRequest request, HttpServletResponse response) { - Map model = new HashMap(); + Map model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); try { model.put("model", broadcastService.getBcModel(request)); @@ -94,7 +97,7 @@ public class BroadcastListController extends RestrictedBaseController { } @RequestMapping(value = { "/broadcast_list/remove" }, method = RequestMethod.POST) - public ModelAndView remove(HttpServletRequest request, HttpServletResponse response) throws Exception { + public ModelAndView remove(HttpServletRequest request, HttpServletResponse response) throws IOException { try { @@ -106,9 +109,9 @@ public class BroadcastListController extends RestrictedBaseController { broadcastService.removeBroadcastMessage(broadcastMessage); - response.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(UTF8); response.setContentType("application / json"); - request.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding(UTF8); PrintWriter out = response.getWriter(); String responseString = mapper.writeValueAsString(broadcastMessage); @@ -118,8 +121,8 @@ public class BroadcastListController extends RestrictedBaseController { return null; } catch (Exception e) { - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(UTF8); + request.setCharacterEncoding(UTF8); PrintWriter out = response.getWriter(); out.write("An error occurred while removing the BroadcastMessage in the remove ()"); logger.error(EELFLoggerDelegate.errorLogger, "remove() failed", e); @@ -129,7 +132,7 @@ public class BroadcastListController extends RestrictedBaseController { } @RequestMapping(value = { "/broadcast_list/toggleActive" }, method = RequestMethod.POST) - public ModelAndView toggleActive(HttpServletRequest request, HttpServletResponse response) throws Exception { + public ModelAndView toggleActive(HttpServletRequest request, HttpServletResponse response) throws IOException { try { @@ -141,9 +144,9 @@ public class BroadcastListController extends RestrictedBaseController { broadcastService.saveBroadcastMessage(broadcastMessage); - response.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(UTF8); response.setContentType("application / json"); - request.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding(UTF8); PrintWriter out = response.getWriter(); String responseString = mapper.writeValueAsString(broadcastMessage); @@ -153,8 +156,8 @@ public class BroadcastListController extends RestrictedBaseController { return null; } catch (Exception e) { - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(UTF8); + request.setCharacterEncoding(UTF8); PrintWriter out = response.getWriter(); out.write("An error occurred while saving the BroadcastMessage in the toggleActive () "); logger.error(EELFLoggerDelegate.errorLogger, "toggleActive() failed", e); -- cgit 1.2.3-korg