From 8cd208ebaa33627daf05d8ffff7b28e53a7067d0 Mon Sep 17 00:00:00 2001 From: "Christopher Lott (cl778h)" Date: Thu, 7 Sep 2017 08:52:41 -0400 Subject: 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) --- .../onap/portalsdk/core/web/support/AppUtils.java | 278 +++++++++------------ .../core/web/support/ControllerProperties.java | 38 +-- .../core/web/support/FeedbackMessage.java | 88 +++---- .../portalsdk/core/web/support/JsonMessage.java | 32 ++- .../portalsdk/core/web/support/MessagesList.java | 105 ++++---- .../onap/portalsdk/core/web/support/UserUtils.java | 64 ++--- 6 files changed, 279 insertions(+), 326 deletions(-) (limited to 'ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/web/support') diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/web/support/AppUtils.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/web/support/AppUtils.java index f6655399..135fb4cf 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/web/support/AppUtils.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/web/support/AppUtils.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 * @@ -37,19 +37,8 @@ */ package org.onap.portalsdk.core.web.support; -import java.io.File; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.Date; -import java.util.Enumeration; -import java.util.Hashtable; import java.util.Iterator; import java.util.List; -import java.util.Map; -import java.util.Vector; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; @@ -59,112 +48,99 @@ import org.hibernate.Session; import org.onap.portalsdk.core.exception.SessionExpiredException; import org.onap.portalsdk.core.objectcache.AbstractCacheManager; import org.onap.portalsdk.core.service.DataAccessService; -import org.onap.portalsdk.core.util.SystemProperties; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.io.FileSystemResource; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.StringUtils; - public class AppUtils { - - - - private static DataAccessService dataAccessService; - - private static AbstractCacheManager cacheManager; - private static boolean applicationLocked; + private static DataAccessService dataAccessService; + + private static AbstractCacheManager cacheManager; + + private static boolean applicationLocked; - private static Hashtable feedback = new Hashtable(); - - private static DataSource datasource; + private static DataSource datasource; - public static DataSource getDatasource() { + public static DataSource getDatasource() { return datasource; } - - @Autowired + + public AppUtils() { + super(); + } + + @Autowired public void setDatasource(DataSource datasource) { AppUtils.datasource = datasource; } - - public AppUtils() { - } - - public static HttpSession getSession(HttpServletRequest request) { - HttpSession session = null; - if (request != null) { - session = request.getSession(false); - if (session == null) { - throw new SessionExpiredException(); - } - } else { - throw new SessionExpiredException(); - } - return session; - } - - public static List getLookupList(String dbTable, String dbValueCol, String dbLabelCol, String dbFilter, String dbOrderBy) { - return getLookupList(dbTable, dbValueCol, dbLabelCol, dbFilter, dbOrderBy, null); - } // getLookupList - - public static List getLookupList(String dbTable, String dbValueCol, String dbLabelCol, String dbFilter, String dbOrderBy, Session session) { - String cacheKey = dbTable + "|" + dbValueCol + "|" + dbLabelCol + "|" + dbFilter + "|" + dbOrderBy; - List list = getLookupListFromCache(cacheKey); - if (list == null) { - list = getDataAccessService().getLookupList(dbTable, dbValueCol, dbLabelCol, dbFilter, dbOrderBy, null); - if (list != null) { - addLookupListToCache(cacheKey, list); - } - } // if - return list; - } // getLookupList - - private static List getLookupListFromCache(String key) { - return (List)getObjectFromCache(key); - } // getLookupListFromCache - - public static Object getObjectFromCache(String key) { - if (isCacheManagerAvailable()) { - return getCacheManager().getObject(key); - } else { - return null; - } - } // getObjectFromCache - - private static void addLookupListToCache(String key, List list) { - addObjectToCache(key, list); - } // addLookupListToCache - - public static void addObjectToCache(String key, Object o) { - if (isCacheManagerAvailable()) { - getCacheManager().putObject(key, o); - } - } // addObjectToCache - - @Autowired - public void setCacheManager(AbstractCacheManager cacheManager) { + + public static HttpSession getSession(HttpServletRequest request) { + if (request != null) { + HttpSession session = request.getSession(false); + if (session == null) + throw new SessionExpiredException(); + else + return session; + } else { + throw new SessionExpiredException(); + } + } + + public static List getLookupList(String dbTable, String dbValueCol, String dbLabelCol, String dbFilter, + String dbOrderBy) { + return getLookupList(dbTable, dbValueCol, dbLabelCol, dbFilter, dbOrderBy, null); + } // getLookupList + + public static List getLookupList(String dbTable, String dbValueCol, String dbLabelCol, String dbFilter, + String dbOrderBy, Session session) { + String cacheKey = dbTable + "|" + dbValueCol + "|" + dbLabelCol + "|" + dbFilter + "|" + dbOrderBy; + List list = getLookupListFromCache(cacheKey); + if (list == null) { + list = getDataAccessService().getLookupList(dbTable, dbValueCol, dbLabelCol, dbFilter, dbOrderBy, null); + if (list != null) { + addLookupListToCache(cacheKey, list); + } + } // if + return list; + } // getLookupList + + private static List getLookupListFromCache(String key) { + return (List) getObjectFromCache(key); + } // getLookupListFromCache + + public static Object getObjectFromCache(String key) { + if (isCacheManagerAvailable()) { + return getCacheManager().getObject(key); + } else { + return null; + } + } // getObjectFromCache + + private static void addLookupListToCache(String key, List list) { + addObjectToCache(key, list); + } // addLookupListToCache + + public static void addObjectToCache(String key, Object o) { + if (isCacheManagerAvailable()) { + getCacheManager().putObject(key, o); + } + } // addObjectToCache + + @Autowired + public void setCacheManager(AbstractCacheManager cacheManager) { this.cacheManager = cacheManager; } public static AbstractCacheManager getCacheManager() { - return cacheManager; - } - - public static boolean isCacheManagerAvailable() { - return (getCacheManager() != null); - } - - public void setFeedback(Hashtable feedback) { - this.feedback = feedback; - } - - public static boolean isApplicationLocked() { - return applicationLocked; - } + return cacheManager; + } + + public static boolean isCacheManagerAvailable() { + return getCacheManager() != null; + } + + public static boolean isApplicationLocked() { + return applicationLocked; + } public static DataAccessService getDataAccessService() { return dataAccessService; @@ -176,56 +152,50 @@ public class AppUtils { } public static void setApplicationLocked(boolean locked) { - applicationLocked = locked; - } - - public static String getLookupValueByLabel(String label, String dbTable, String dbValueCol, String dbLabelCol) { - if (label == null || label.equals("")) { - return ""; - } - - List lstResult = getLookupListNoCache(dbTable, dbValueCol, dbLabelCol, dbLabelCol + "='" + label.replaceAll("'", "''") + "'", ""); - if (lstResult == null) { - return ""; - } - if (lstResult.size() > 0) { - return ((org.onap.portalsdk.core.domain.Lookup)lstResult.toArray()[0]).getValue(); - } else { - return ""; - } - } - - public static String getLookupValueByLabel(String label, List lookupList) { - Iterator i = null; - - if (label == null || label.equalsIgnoreCase("")) { - return ""; - } - - if (lookupList == null || lookupList.size() == 0) { - return ""; - } - - i = lookupList.iterator(); - while (i.hasNext()) { - org.onap.portalsdk.core.domain.Lookup lookup = (org.onap.portalsdk.core.domain.Lookup)i.next(); - - if (lookup.getLabel().equals(label)) { - return lookup.getValue(); - } - } - - return ""; -} - public static List getLookupListNoCache(String dbTable, String dbValueCol, String dbLabelCol, String dbFilter, String dbOrderBy) { - return getLookupListNoCache(dbTable, dbValueCol, dbLabelCol, dbFilter, dbOrderBy, null); - } // getLookupListNoCache + applicationLocked = locked; + } + public static String getLookupValueByLabel(String label, String dbTable, String dbValueCol, String dbLabelCol) { + if (label == null || label.equals("")) { + return ""; + } + + List lstResult = getLookupListNoCache(dbTable, dbValueCol, dbLabelCol, + dbLabelCol + "='" + label.replaceAll("'", "''") + "'", ""); + if (lstResult == null) { + return ""; + } + if (!lstResult.isEmpty()) { + return ((org.onap.portalsdk.core.domain.Lookup) lstResult.toArray()[0]).getValue(); + } else { + return ""; + } + } - public static List getLookupListNoCache(String dbTable, String dbValueCol, String dbLabelCol, String dbFilter, String dbOrderBy, Session session) { - return getDataAccessService().getLookupList(dbTable, dbValueCol, dbLabelCol, dbFilter, dbOrderBy, null); - } // getLookupListNoCache - - + public static String getLookupValueByLabel(String label, List lookupList) { + if (label == null || "".equals(label)) + return ""; + if (lookupList == null || lookupList.size() == 0) + return ""; + + Iterator i = lookupList.iterator(); + while (i.hasNext()) { + org.onap.portalsdk.core.domain.Lookup lookup = (org.onap.portalsdk.core.domain.Lookup) i.next(); + if (lookup.getLabel().equals(label)) { + return lookup.getValue(); + } + } + return ""; + } + + public static List getLookupListNoCache(String dbTable, String dbValueCol, String dbLabelCol, String dbFilter, + String dbOrderBy) { + return getLookupListNoCache(dbTable, dbValueCol, dbLabelCol, dbFilter, dbOrderBy, null); + } -} // AppUtils + public static List getLookupListNoCache(String dbTable, String dbValueCol, String dbLabelCol, String dbFilter, + String dbOrderBy, Session session) { + return getDataAccessService().getLookupList(dbTable, dbValueCol, dbLabelCol, dbFilter, dbOrderBy, null); + } + +} diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/web/support/ControllerProperties.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/web/support/ControllerProperties.java index c1c2f24a..31b810db 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/web/support/ControllerProperties.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/web/support/ControllerProperties.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 * @@ -39,21 +39,21 @@ package org.onap.portalsdk.core.web.support; public interface ControllerProperties { - static final String TASK_GET = "get"; - static final String TASK_DELETE = "delete"; - static final String TASK_SAVE = "save"; - static final String TASK_PROCESS = "process"; - static final String TASK_TOGGLE_ACTIVE = "toggleActive"; - static final String TASK_DOWNLOAD = "download"; - static final String TASK_POPUP = "popup"; - static final String TASK_LOOKUP = "lookup"; - static final String TASK_ADD_ROW = "addRow"; - static final String TASK_APPROVE = "approve"; - static final String TASK_REJECT = "reject"; - static final String TASK_RESET = "reset"; - static final String TASK_ASSIGN = "assign"; - static final String TASK_CUT = "cut"; - static final String TASK_COPY = "copy"; - static final String TASK_PASTE = "paste"; - static final String TASK_SELECT = "select"; + static final String TASK_GET = "get"; + static final String TASK_DELETE = "delete"; + static final String TASK_SAVE = "save"; + static final String TASK_PROCESS = "process"; + static final String TASK_TOGGLE_ACTIVE = "toggleActive"; + static final String TASK_DOWNLOAD = "download"; + static final String TASK_POPUP = "popup"; + static final String TASK_LOOKUP = "lookup"; + static final String TASK_ADD_ROW = "addRow"; + static final String TASK_APPROVE = "approve"; + static final String TASK_REJECT = "reject"; + static final String TASK_RESET = "reset"; + static final String TASK_ASSIGN = "assign"; + static final String TASK_CUT = "cut"; + static final String TASK_COPY = "copy"; + static final String TASK_PASTE = "paste"; + static final String TASK_SELECT = "select"; } diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/web/support/FeedbackMessage.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/web/support/FeedbackMessage.java index e2dadb50..013d153b 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/web/support/FeedbackMessage.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/web/support/FeedbackMessage.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 * @@ -39,60 +39,60 @@ package org.onap.portalsdk.core.web.support; public class FeedbackMessage { - private String message; - private int messageType; - private boolean keyed; + private String message; + private int messageType; + private boolean keyed; - public static final int MESSAGE_TYPE_ERROR = 10; - public static final int MESSAGE_TYPE_WARNING = 20; - public static final int MESSAGE_TYPE_INFO = 30; - public static final int MESSAGE_TYPE_SUCCESS = 40; + public static final int MESSAGE_TYPE_ERROR = 10; + public static final int MESSAGE_TYPE_WARNING = 20; + public static final int MESSAGE_TYPE_INFO = 30; + public static final int MESSAGE_TYPE_SUCCESS = 40; - public static final String DEFAULT_MESSAGE_SUCCESS = "Update successful."; - public static final String DEFAULT_MESSAGE_ERROR = "An error occurred while processing the request: "; + public static final String DEFAULT_MESSAGE_SUCCESS = "Update successful."; + public static final String DEFAULT_MESSAGE_ERROR = "An error occurred while processing the request: "; - public static final String DEFAULT_MESSAGE_SYSTEM_ADMINISTRATOR = "If the problem persists, please contact your Administrator."; + public static final String DEFAULT_MESSAGE_SYSTEM_ADMINISTRATOR = "If the problem persists, please contact your Administrator."; - public FeedbackMessage() { - } + public FeedbackMessage() { + this(null); + } - public FeedbackMessage(String message) { - this(message, MESSAGE_TYPE_ERROR); - } + public FeedbackMessage(String message) { + this(message, MESSAGE_TYPE_ERROR); + } - public FeedbackMessage(String message, int messageType) { - this(message, messageType, false); - } + public FeedbackMessage(String message, int messageType) { + this(message, messageType, false); + } - public FeedbackMessage(String message, int messageType, boolean keyed) { - this.message = message; - this.messageType = messageType; - this.keyed = keyed; - } + public FeedbackMessage(String message, int messageType, boolean keyed) { + this.message = message; + this.messageType = messageType; + this.keyed = keyed; + } - public String getMessage() { - return message; - } + public String getMessage() { + return message; + } - public int getMessageType() { - return messageType; - } + public int getMessageType() { + return messageType; + } - public boolean isKeyed() { - return keyed; - } + public boolean isKeyed() { + return keyed; + } - public void setMessage(String message) { - this.message = message; - } + public void setMessage(String message) { + this.message = message; + } - public void setMessageType(int messageType) { - this.messageType = messageType; - } - - public void setKeyed(boolean keyed) { - this.keyed = keyed; - } + public void setMessageType(int messageType) { + this.messageType = messageType; + } + public void setKeyed(boolean keyed) { + this.keyed = keyed; + } } diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/web/support/JsonMessage.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/web/support/JsonMessage.java index 9b7a65ca..ce4cab3a 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/web/support/JsonMessage.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/web/support/JsonMessage.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,6 +40,7 @@ package org.onap.portalsdk.core.web.support; import java.io.PrintWriter; import java.io.StringWriter; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.onboarding.crossapi.PortalAPIResponse; import com.fasterxml.jackson.core.JsonProcessingException; @@ -47,26 +48,30 @@ import com.fasterxml.jackson.databind.ObjectMapper; public class JsonMessage { + private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(JsonMessage.class); + private String data; private String data2; private String data3; + public JsonMessage(String data) { super(); this.data = data; } - public JsonMessage(String data,String data2) { + + public JsonMessage(String data, String data2) { super(); this.data = data; this.data2 = data2; } - public JsonMessage(String data,String data2,String data3) { + public JsonMessage(String data, String data2, String data3) { super(); this.data = data; this.data2 = data2; this.data3 = data3; } - + public String getData() { return data; } @@ -74,20 +79,23 @@ public class JsonMessage { public void setData(String data) { this.data = data; } + public String getData2() { return data2; } + public void setData2(String data2) { this.data2 = data2; } + public String getData3() { return data3; } + public void setData3(String data3) { this.data3 = data3; } - - + /** * Builds JSON object with status + message response body. * @@ -107,15 +115,16 @@ public class JsonMessage { try { json = new ObjectMapper().writeValueAsString(response); } catch (JsonProcessingException ex) { - // Truly should never, ever happen + // Truly should never happen + logger.error(EELFLoggerDelegate.errorLogger, "buildJsonResponse failed", ex); json = "{ \"status\": \"error\",\"message\":\"" + ex.toString() + "\" }"; } return json; } /** - * Builds JSON object with status of error and message containing stack - * trace for the specified throwable. + * Builds JSON object with status of error and message containing stack trace + * for the specified throwable. * * @param t * Throwable with stack trace to use as message @@ -131,6 +140,5 @@ public class JsonMessage { t.printStackTrace(pw); return buildJsonResponse(false, sw.toString()); } - - + } diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/web/support/MessagesList.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/web/support/MessagesList.java index a3ab7896..a1d3e276 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/web/support/MessagesList.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/web/support/MessagesList.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 * @@ -37,74 +37,73 @@ */ package org.onap.portalsdk.core.web.support; -import java.util.*; +import java.util.ArrayList; +import java.util.List; public class MessagesList { - private boolean successMessageDisplayed = true; - private boolean includeCauseInCustomExceptions = false; + private boolean successMessageDisplayed = true; + private boolean includeCauseInCustomExceptions = false; - private List successMessages; - private List exceptionMessages; + private List successMessages; + private List exceptionMessages; - public MessagesList() { - setExceptionMessages(new ArrayList()); - setSuccessMessages(new ArrayList()); - } + public MessagesList() { + setExceptionMessages(new ArrayList()); + setSuccessMessages(new ArrayList()); + } - public MessagesList(boolean displaySuccess) { - this(); - setSuccessMessageDisplayed(displaySuccess); - } + public MessagesList(boolean displaySuccess) { + this(); + setSuccessMessageDisplayed(displaySuccess); + } - public List getExceptionMessages() { - return exceptionMessages; - } + public List getExceptionMessages() { + return exceptionMessages; + } - public List getSuccessMessages() { - return successMessages; - } + public List getSuccessMessages() { + return successMessages; + } - public boolean isSuccessMessageDisplayed() { - return successMessageDisplayed; - } + public boolean isSuccessMessageDisplayed() { + return successMessageDisplayed; + } - public boolean isIncludeCauseInCustomExceptions() { - return includeCauseInCustomExceptions; - } + public boolean isIncludeCauseInCustomExceptions() { + return includeCauseInCustomExceptions; + } + public void setExceptionMessages(List exceptionMessages) { + this.exceptionMessages = exceptionMessages; + } - public void setExceptionMessages(List exceptionMessages) { - this.exceptionMessages = exceptionMessages; - } + public void setSuccessMessages(List successMessages) { + this.successMessages = successMessages; + } - public void setSuccessMessages(List successMessages) { - this.successMessages = successMessages; - } + public void setSuccessMessageDisplayed(boolean successMessageDisplayed) { + this.successMessageDisplayed = successMessageDisplayed; + } - public void setSuccessMessageDisplayed(boolean successMessageDisplayed) { - this.successMessageDisplayed = successMessageDisplayed; - } + public void setIncludeCauseInCustomExceptions(boolean includeCauseInCustomExceptions) { + this.includeCauseInCustomExceptions = includeCauseInCustomExceptions; + } - public void setIncludeCauseInCustomExceptions(boolean includeCauseInCustomExceptions) { - this.includeCauseInCustomExceptions = includeCauseInCustomExceptions; - } + public void addSuccessMessage(FeedbackMessage message) { + getSuccessMessages().add(message); + } + public void addExceptionMessage(FeedbackMessage message) { + getExceptionMessages().add(message); + } - public void addSuccessMessage(FeedbackMessage message) { - getSuccessMessages().add(message); - } + public boolean hasExceptionMessages() { + return !getExceptionMessages().isEmpty(); + } - public void addExceptionMessage(FeedbackMessage message) { - getExceptionMessages().add(message); - } - - public boolean hasExceptionMessages() { - return!getExceptionMessages().isEmpty(); - } - - public boolean hasSuccessMessages() { - return!getSuccessMessages().isEmpty(); - } + public boolean hasSuccessMessages() { + return !getSuccessMessages().isEmpty(); + } } diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/web/support/UserUtils.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/web/support/UserUtils.java index 98e437d9..5395521b 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/web/support/UserUtils.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/web/support/UserUtils.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 * @@ -44,6 +44,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.TreeSet; import java.util.UUID; @@ -61,9 +62,7 @@ import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.menu.MenuBuilder; import org.onap.portalsdk.core.restful.domain.EcompRole; import org.onap.portalsdk.core.restful.domain.EcompUser; -import org.onap.portalsdk.core.service.DataAccessService; import org.onap.portalsdk.core.util.SystemProperties; -import org.springframework.beans.factory.annotation.Autowired; @SuppressWarnings("rawtypes") public class UserUtils { @@ -72,10 +71,8 @@ public class UserUtils { public static final String KEY_USER_ROLES_CACHE = "userRoles"; - private static DataAccessService dataAccessService; - public static void setUserSession(HttpServletRequest request, User user, Set applicationMenuData, - Set businessDirectMenuData, String loginMethod , List roleFunctionList) { + Set businessDirectMenuData, String loginMethod, List roleFunctionList) { HttpSession session = request.getSession(true); UserUtils.clearUserSession(request); // let's clear the current user @@ -97,7 +94,7 @@ public class UserUtils { try { licenseVarificationFlag = (Integer) context.getAttribute("licenseVerification"); } catch (Exception e) { - logger.error(EELFLoggerDelegate.debugLogger, "Error while get license varification " + e.getMessage()); + logger.error(EELFLoggerDelegate.errorLogger, "setUserSession failed on license verification", e); } String displayName = ""; if (SystemProperties.getProperty(SystemProperties.APP_DISPLAY_NAME) != null) @@ -146,14 +143,12 @@ public class UserUtils { @SuppressWarnings("unchecked") public static Set getRoleFunctions(HttpServletRequest request) { - HashSet roleFunctions = null; -// HashSet rolefun = null; HttpSession session = request.getSession(); - roleFunctions = (HashSet) session + HashSet roleFunctions = (HashSet) session .getAttribute(SystemProperties.getProperty(SystemProperties.ROLE_FUNCTIONS_ATTRIBUTE_NAME)); if (roleFunctions == null) { - HashMap roles = getRoles(request); + Map roles = getRoles(request); roleFunctions = new HashSet(); Iterator i = roles.keySet().iterator(); @@ -175,12 +170,10 @@ public class UserUtils { return roleFunctions; } - public static HashMap getRoles(HttpServletRequest request) { - HashMap roles = null; - + public static Map getRoles(HttpServletRequest request) { // HttpSession session = request.getSession(); HttpSession session = AppUtils.getSession(request); - roles = (HashMap) session.getAttribute(SystemProperties.getProperty(SystemProperties.ROLES_ATTRIBUTE_NAME)); + Map roles = (Map) session.getAttribute(SystemProperties.getProperty(SystemProperties.ROLES_ATTRIBUTE_NAME)); // if roles are not already cached, let's grab them from the user // session @@ -208,7 +201,7 @@ public class UserUtils { } @SuppressWarnings("unchecked") - public static HashMap getAllUserRoles(User user) { + public static Map getAllUserRoles(User user) { HashMap roles = new HashMap(); Iterator i = user.getRoles().iterator(); @@ -228,9 +221,9 @@ public class UserUtils { } @SuppressWarnings("unchecked") - private static void addChildRoles(Role role, HashMap roles) { + private static void addChildRoles(Role role, Map roles) { Set childRoles = role.getChildRoles(); - if (childRoles != null && childRoles.size() > 0) { + if (childRoles != null && !childRoles.isEmpty()) { Iterator j = childRoles.iterator(); while (j.hasNext()) { Role childRole = (Role) j.next(); @@ -243,8 +236,6 @@ public class UserUtils { } - - public static boolean hasRole(HttpServletRequest request, String roleKey) { return getRoles(request).keySet().contains(new Long(roleKey)); } @@ -268,27 +259,15 @@ public class UserUtils { .getAttribute(SystemProperties.getProperty(SystemProperties.LOGIN_METHOD_ATTRIBUTE_NAME)); } - public static DataAccessService getDataAccessService() { - return dataAccessService; - } - - @Autowired - public void setDataAccessService(DataAccessService dataAccessService) { - UserUtils.dataAccessService = dataAccessService; - } - public static int getUserId(HttpServletRequest request) { return getUserIdAsLong(request).intValue(); } public static Long getUserIdAsLong(HttpServletRequest request) { Long userId = new Long(SystemProperties.getProperty(SystemProperties.APPLICATION_USER_ID)); - - if (request != null) { - if (getUserSession(request) != null) { + if (request != null && getUserSession(request) != null) userId = getUserSession(request).getId(); - } - } + return userId; } @@ -313,8 +292,7 @@ public class UserUtils { } /** - * Gets the full URL of the request by joining the request and any query - * string. + * Gets the full URL of the request by joining the request and any query string. * * @param request * @return Full URL of the request including query parameters @@ -334,8 +312,8 @@ public class UserUtils { } /** - * Gets or generates a request ID by searching for header X-ECOMP-RequestID. - * If not found, generates a new random UUID. + * Gets or generates a request ID by searching for header X-ECOMP-RequestID. If + * not found, generates a new random UUID. * * @param request * @return Request ID for the specified request @@ -346,7 +324,7 @@ public class UserUtils { String requestId = ""; try { while (headerNames.hasMoreElements()) { - String headerName = (String) headerNames.nextElement(); + String headerName = headerNames.nextElement(); if (logger.isTraceEnabled()) logger.trace(EELFLoggerDelegate.debugLogger, "getRequestId: header {} = {}", headerName, request.getHeader(headerName)); @@ -386,7 +364,7 @@ public class UserUtils { userJson.setOrgId(user.getOrgId()); userJson.setPhone(user.getPhone()); userJson.setOrgUserId(user.getOrgUserId()); - Set ecompRoles = new TreeSet(); + Set ecompRoles = new TreeSet<>(); for (Role role : user.getRoles()) { ecompRoles.add(convertToEcompRole(role)); } @@ -408,6 +386,4 @@ public class UserUtils { return ecompRole; } - } - - +} -- cgit 1.2.3-korg