From 8aeb2a96617cfa470d3a6935915fb57bf8658ccc Mon Sep 17 00:00:00 2001 From: burdziak Date: Tue, 19 Mar 2019 10:06:38 +0100 Subject: Fix sonar issues in UsageListController Change-Id: Id7bc48db31e9b8eb7a6fed1d8edcfdc34f60c655 Issue-ID: PORTAL-523 Signed-off-by: burdziak --- .../controller/core/UsageListController.java | 77 ++++++++-------------- 1 file changed, 29 insertions(+), 48 deletions(-) (limited to 'ecomp-sdk/epsdk-app-common') diff --git a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/UsageListController.java b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/UsageListController.java index 681702bf..04c1f2bc 100644 --- a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/UsageListController.java +++ b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/UsageListController.java @@ -65,6 +65,31 @@ public class UsageListController extends RestrictedBaseController { private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(UsageListController.class); + private void addUsers2jsonArray(JSONArray ja,HashMap activeUsers,String httpSessionId) + { + List rows = UsageUtils.getActiveUsers(activeUsers); + for (UserRowBean userRowBean : rows) + ja.put(userRowBean2json(userRowBean,httpSessionId)); + } + + private JSONObject userRowBean2json(UserRowBean userRowBean,String httpSessionId) + { + JSONObject jo = new JSONObject(); + jo.put("id", userRowBean.getId()); + jo.put("lastName", userRowBean.getLastName()); + jo.put("email", userRowBean.getEmail()); + jo.put("lastAccess", userRowBean.getLastAccess()); + jo.put("remaining", userRowBean.getRemaining()); + jo.put("sessionId", userRowBean.getSessionId()); + if (!httpSessionId.equals(userRowBean.getSessionId())) { + jo.put("delete", "yes"); + } else { + jo.put("delete", "no"); + } + + return jo; + } + @SuppressWarnings({ "unchecked", "rawtypes" }) @RequestMapping(value = { "/usage_list" }, method = RequestMethod.GET) public ModelAndView usageList(HttpServletRequest request) { @@ -76,24 +101,10 @@ public class UsageListController extends RestrictedBaseController { activeUsers.put(httpSession.getId(), httpSession); httpSession.getServletContext().setAttribute("activeUsers", activeUsers); } - List rows = UsageUtils.getActiveUsers(activeUsers); + JSONArray ja = new JSONArray(); try { - for (UserRowBean userRowBean : rows) { - JSONObject jo = new JSONObject(); - jo.put("id", userRowBean.getId()); - jo.put("lastName", userRowBean.getLastName()); - jo.put("email", userRowBean.getEmail()); - jo.put("lastAccess", userRowBean.getLastAccess()); - jo.put("remaining", userRowBean.getRemaining()); - jo.put("sessionId", userRowBean.getSessionId()); - if (!(httpSession.getId().equals(userRowBean.getSessionId()))) { - jo.put("delete", "yes"); - } else { - jo.put("delete", "no"); - } - ja.put(jo); - } + addUsers2jsonArray(ja,activeUsers,httpSession.getId()); } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "usageList failed", e); } @@ -113,24 +124,9 @@ public class UsageListController extends RestrictedBaseController { activeUsers.put(httpSession.getId(), httpSession); httpSession.getServletContext().setAttribute("activeUsers", activeUsers); } - List rows = UsageUtils.getActiveUsers(activeUsers); JSONArray ja = new JSONArray(); try { - for (UserRowBean userRowBean : rows) { - JSONObject jo = new JSONObject(); - jo.put("id", userRowBean.getId()); - jo.put("lastName", userRowBean.getLastName()); - jo.put("email", userRowBean.getEmail()); - jo.put("lastAccess", userRowBean.getLastAccess()); - jo.put("remaining", userRowBean.getRemaining()); - jo.put("sessionId", userRowBean.getSessionId()); - if (!(httpSession.getId().equals(userRowBean.getSessionId()))) { - jo.put("delete", "yes"); - } else { - jo.put("delete", "no"); - } - ja.put(jo); - } + addUsers2jsonArray(ja,activeUsers,httpSession.getId()); } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "getUsageList failed", e); } @@ -154,24 +150,9 @@ public class UsageListController extends RestrictedBaseController { UsageUtils.getActiveUsersAfterDelete(activeUsers, data); HttpSession httpSession = request.getSession(); - List rows = UsageUtils.getActiveUsers(activeUsers); JSONArray ja = new JSONArray(); try { - for (UserRowBean userRowBean : rows) { - JSONObject jo = new JSONObject(); - jo.put("id", userRowBean.getId()); - jo.put("lastName", userRowBean.getLastName()); - jo.put("email", userRowBean.getEmail()); - jo.put("lastAccess", userRowBean.getLastAccess()); - jo.put("remaining", userRowBean.getRemaining()); - jo.put("sessionId", userRowBean.getSessionId()); - if (!(httpSession.getId().equals(userRowBean.getSessionId()))) { - jo.put("delete", "yes"); - } else { - jo.put("delete", "no"); - } - ja.put(jo); - } + addUsers2jsonArray(ja,activeUsers,httpSession.getId()); } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "removeSession failed", e); } -- cgit 1.2.3-korg