summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManoop Talasila <talasila@research.att.com>2019-04-11 13:50:27 +0000
committerGerrit Code Review <gerrit@onap.org>2019-04-11 13:50:27 +0000
commit6679a89d4ec39baa658506080bc2e0680a1971e5 (patch)
tree06d595ff12929bcc9632c73b0f7e2a919788f2a9
parenteaac4b655353df40c0fd56c90a2a9a9dfe0e1a6b (diff)
parent8aeb2a96617cfa470d3a6935915fb57bf8658ccc (diff)
Merge "Fix sonar issues in UsageListController"
-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);
}