diff options
author | Christopher Lott (cl778h) <clott@research.att.com> | 2017-09-07 08:52:41 -0400 |
---|---|---|
committer | Christopher Lott (cl778h) <clott@research.att.com> | 2017-09-07 08:54:52 -0400 |
commit | 8cd208ebaa33627daf05d8ffff7b28e53a7067d0 (patch) | |
tree | 0b07ec3c6305c46f34eae69d8fb6fa824aaae256 /ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/util/UsageUtils.java | |
parent | b52d4cebc430a083ec1e6881c4f01dfe709ac726 (diff) |
Adjust code for Sonar issues
Made non-functional updates to address static code analysis issues.
Update license header with simple double-quote characters.
Issue: PORTAL-72, PORTAL-90
Change-Id: Ic2c330daea07d721f0e6b350ebf03da97073f7ce
Signed-off-by: Christopher Lott (cl778h) <clott@research.att.com>
Diffstat (limited to 'ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/util/UsageUtils.java')
-rw-r--r-- | ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/util/UsageUtils.java | 94 |
1 files changed, 47 insertions, 47 deletions
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/util/UsageUtils.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/util/UsageUtils.java index faf410fc..569c2b87 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/util/UsageUtils.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/util/UsageUtils.java @@ -6,7 +6,7 @@ * =================================================================== * * Unless otherwise specified, all software contained herein is licensed - * under the Apache License, Version 2.0 (the “License”); + * under the Apache License, Version 2.0 (the "License"); * you may not use this software except in compliance with the License. * You may obtain a copy of the License at * @@ -19,7 +19,7 @@ * limitations under the License. * * Unless otherwise specified, all documentation contained herein is licensed - * under the Creative Commons License, Attribution 4.0 Intl. (the “License”); + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); * you may not use this documentation except in compliance with the License. * You may obtain a copy of the License at * @@ -40,8 +40,9 @@ package org.onap.portalsdk.core.util; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; -import java.util.HashMap; import java.util.Iterator; +import java.util.List; +import java.util.Map; import javax.servlet.http.HttpSession; @@ -49,62 +50,61 @@ import org.onap.portalsdk.core.command.UserRowBean; import org.onap.portalsdk.core.domain.User; public class UsageUtils { + + private UsageUtils() { + // Class has only static methods + } + @SuppressWarnings("rawtypes") - public static ArrayList<UserRowBean> getActiveUsers(HashMap activeUsers) { - ArrayList<UserRowBean> rows = new ArrayList<UserRowBean>(); - SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); + public static List<UserRowBean> getActiveUsers(Map activeUsers) { + ArrayList<UserRowBean> rows = new ArrayList<>(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); + + for (Iterator i = activeUsers.keySet().iterator(); i.hasNext();) { + String sessionId = (String) i.next(); + HttpSession session = (HttpSession) activeUsers.get(sessionId); + User userBean = (User) session.getAttribute("user"); + + // Not all sessions will be valid logins + if (null == userBean) + continue; - for(Iterator i = activeUsers.keySet().iterator(); i.hasNext(); ){ - String sessionId = (String)i.next(); - HttpSession session = (HttpSession)activeUsers.get(sessionId); - User userBean = (User)session.getAttribute("user"); - // - // Not all sessions will be valid logins - // Skip those ones - // - if(null == userBean) - continue; + UserRowBean userRow = new UserRowBean(); + userRow.setFirstName(userBean.getFirstName()); + userRow.setLastName(userBean.getLastName()); + userRow.setEmail(userBean.getEmail()); + userRow.setId(userBean.getId()); + userRow.setSessionId(sessionId); + userRow.setLoginTime(sdf.format(new Date(session.getCreationTime()))); + userRow.setLastLoginTime(sdf.format(userBean.getLastLoginDate())); - UserRowBean userRow = new UserRowBean(); - userRow.setFirstName(userBean.getFirstName()); - userRow.setLastName(userBean.getLastName()); - userRow.setEmail(userBean.getEmail()); - userRow.setId(userBean.getId()); - userRow.setSessionId(sessionId); - userRow.setLoginTime(sdf.format(new Date(session.getCreationTime()))); - userRow.setLastLoginTime(sdf.format(userBean.getLastLoginDate())); + // Calculate the last time and time remaining for these sessions. + int sessionLength = session.getMaxInactiveInterval(); + long now = new java.util.Date().getTime(); + long lastAccessed = (now - session.getLastAccessedTime()) / 1000; + long lengthInactive = now - session.getLastAccessedTime(); + long minutesRemaining = sessionLength - (lengthInactive / 1000); - // - // Calculate the last time and time remaining for these sessions. - // - int sessionLength = session.getMaxInactiveInterval(); - long now = new java.util.Date().getTime(); - long lastAccessed = (now - session.getLastAccessedTime()) / 1000; - long lengthInactive = (now - session.getLastAccessedTime()); - long minutesRemaining = sessionLength - (lengthInactive / 1000); + userRow.setLastAccess((lastAccessed / 60) + ":" + String.format("%02d", lastAccessed % 60)); + userRow.setRemaining((minutesRemaining / 60) + ":" + String.format("%02d", minutesRemaining % 60)); - userRow.setLastAccess((lastAccessed / 60) + ":" + String.format("%02d", (lastAccessed % 60))); - userRow.setRemaining((minutesRemaining / 60) + ":" + String.format("%02d", (minutesRemaining % 60))); + rows.add(userRow); + } - rows.add(userRow); - } - - return rows; + return rows; } - + @SuppressWarnings("rawtypes") - public static ArrayList<UserRowBean> getActiveUsersAfterDelete(HashMap activeUsers, final java.lang.Object data) { - return getActiveUsers(deleteSession(activeUsers,data)); - + public static List<UserRowBean> getActiveUsersAfterDelete(Map activeUsers, final java.lang.Object data) { + return getActiveUsers(deleteSession(activeUsers, data)); } - + @SuppressWarnings("rawtypes") - private static HashMap deleteSession(HashMap activeUsers, Object data) { - String sessionId = ((UserRowBean)data).getSessionId(); - HttpSession session = (HttpSession)activeUsers.get(sessionId); + private static Map deleteSession(Map activeUsers, Object data) { + String sessionId = ((UserRowBean) data).getSessionId(); + HttpSession session = (HttpSession) activeUsers.get(sessionId); session.invalidate(); activeUsers.remove(sessionId); - return activeUsers; } } |