summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-app-common/src
diff options
context:
space:
mode:
authorburdziak <olaf.burdziakowski@nokia.com>2019-03-19 10:06:38 +0100
committerburdziak <olaf.burdziakowski@nokia.com>2019-03-19 10:06:38 +0100
commit8aeb2a96617cfa470d3a6935915fb57bf8658ccc (patch)
treebcbe31ae50baefda6d358a75d43e6de6aee8c6ae /ecomp-sdk/epsdk-app-common/src
parent1ded3bb69c5e91cd879d83e13d2b3295710cdb4f (diff)
Fix sonar issues in UsageListController
Change-Id: Id7bc48db31e9b8eb7a6fed1d8edcfdc34f60c655 Issue-ID: PORTAL-523 Signed-off-by: burdziak <olaf.burdziakowski@nokia.com>
Diffstat (limited to 'ecomp-sdk/epsdk-app-common/src')
-rw-r--r--ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/UsageListController.java77
1 files changed, 29 insertions, 48 deletions
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<UserRowBean> 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<UserRowBean> 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<UserRowBean> 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<UserRowBean> 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);
}