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) --- .../org/onap/portalsdk/core/menu/MenuBuilder.java | 168 ++++++++++----------- .../onap/portalsdk/core/menu/MenuProperties.java | 152 +++++++++---------- 2 files changed, 152 insertions(+), 168 deletions(-) (limited to 'ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/menu') diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/menu/MenuBuilder.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/menu/MenuBuilder.java index ac1e9396..9bd8f44d 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/menu/MenuBuilder.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/menu/MenuBuilder.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 * @@ -54,128 +54,118 @@ import org.springframework.beans.factory.annotation.Autowired; @SuppressWarnings("rawtypes") public class MenuBuilder implements FusionObject { - @Autowired - private DataAccessService dataAccessService; + @Autowired + private DataAccessService dataAccessService; - public MenuBuilder() { - } + @SuppressWarnings("unchecked") + public Set getMenu(String menuSetName, DataAccessService dataAccessService) { - @SuppressWarnings("unchecked") - public Set getMenu(String menuSetName, DataAccessService dataAccessService) { + Set menu = null; - Set menu = null; - MenuData root = null; + HashMap params = new HashMap(); - HashMap params = new HashMap(); + params.put("menu_set_cd", menuSetName); - params.put("menu_set_cd", menuSetName); + // execute a query of the latest configuration of the FN_MENU table for the + // given menu_set_cd. + List menuItems = dataAccessService + .executeNamedQuery(SystemProperties.getProperty(SystemProperties.MENU_QUERY_NAME), params, null); - // execute a query of the latest configuration of the FN_MENU table for the given menu_set_cd. - List menuItems = dataAccessService.executeNamedQuery(SystemProperties.getProperty(SystemProperties.MENU_QUERY_NAME), params, null); + Iterator i = menuItems.iterator(); + if (i.hasNext()) { + MenuData root = (MenuData) i.next(); + menu = root.getChildMenus(); + } - Iterator i = menuItems.iterator(); - if (i.hasNext()) { - root = (MenuData)i.next(); - menu = root.getChildMenus(); - } - - return menu; - } - - @SuppressWarnings("unchecked") - public Set getMenu(String menuSetName) { + return menu; + } - Set menu = null; - MenuData root = null; + @SuppressWarnings("unchecked") + public Set getMenu(String menuSetName) { - HashMap params = new HashMap(); + Set menu = null; - params.put("menu_set_cd", menuSetName); + HashMap params = new HashMap(); - // execute a query of the latest configuration of the FN_MENU table for the given menu_set_cd. - List menuItems = getDataAccessService().executeNamedQuery(SystemProperties.getProperty(SystemProperties.MENU_QUERY_NAME), params, null); + params.put("menu_set_cd", menuSetName); - Iterator i = menuItems.iterator(); - if (i.hasNext()) { - root = (MenuData)i.next(); - menu = root.getChildMenus(); - } + // execute a query of the latest configuration of the FN_MENU table for the + // given menu_set_cd. + List menuItems = getDataAccessService() + .executeNamedQuery(SystemProperties.getProperty(SystemProperties.MENU_QUERY_NAME), params, null); - return menu; - } + Iterator i = menuItems.iterator(); + if (i.hasNext()) { + MenuData root = (MenuData) i.next(); + menu = root.getChildMenus(); + } - public static Set filterMenu(Set menus, HttpServletRequest request) { - Iterator j = menus.iterator(); + return menu; + } - while (j.hasNext()) { - MenuData menuItem = (MenuData)j.next(); + public static Set filterMenu(Set menus, HttpServletRequest request) { + Iterator j = menus.iterator(); - if (!UserUtils.isAccessible(request, menuItem.getFunctionCd())) { - // remove the menu if the user doesn't have access to it - j.remove(); - } - else { - // if an accessible menu has a child menu, let's filter that recursively + while (j.hasNext()) { + MenuData menuItem = (MenuData) j.next(); - Set childMenus = menuItem.getChildMenus(); - if (childMenus != null && childMenus.size() > 0) { - filterMenu(childMenus, request); - } + if (!UserUtils.isAccessible(request, menuItem.getFunctionCd())) { + // remove the menu if the user doesn't have access to it + j.remove(); + } else { + // if an accessible menu has a child menu, let's filter that recursively - } - } + Set childMenus = menuItem.getChildMenus(); + if (childMenus != null && ! childMenus.isEmpty()) { + filterMenu(childMenus, request); + } - return menus; - } + } + } - - public static String getUrlHtml(MenuData menuData) { - String html = ""; + return menus; + } - if (menuData.getExternalUrl() != null && menuData.getExternalUrl().length() > 0) { - html = menuData.getExternalUrl(); - } - else if (menuData.getServlet() != null && menuData.getServlet().length() > 0) { - html = "/" + menuData.getServlet(); - } - else if (menuData.getAction() != null && menuData.getAction().length() > 0) { - html = "/" + menuData.getAction(); - } + public static String getUrlHtml(MenuData menuData) { + String html = ""; - return html; - } + if (menuData.getExternalUrl() != null && menuData.getExternalUrl().length() > 0) { + html = menuData.getExternalUrl(); + } else if (menuData.getServlet() != null && menuData.getServlet().length() > 0) { + html = "/" + menuData.getServlet(); + } else if (menuData.getAction() != null && menuData.getAction().length() > 0) { + html = "/" + menuData.getAction(); + } + return html; + } - public static String getTargetHtml(MenuData menuData) { - String html = ""; + public static String getTargetHtml(MenuData menuData) { + String html = ""; - if (menuData.getTarget() != null && menuData.getTarget().length() > 0) { - html = "target=\"" + menuData.getTarget() + "\""; - } + if (menuData.getTarget() != null && menuData.getTarget().length() > 0) { + html = "target=\"" + menuData.getTarget() + "\""; + } - return html; - } + return html; + } + public static String getQueryStringHtml(MenuData menuData) { + String html = ""; - public static String getQueryStringHtml(MenuData menuData) { - String html = ""; + if (menuData.getQueryString() != null && menuData.getQueryString().length() > 0) { + html = "?" + menuData.getQueryString(); + } - if (menuData.getQueryString() != null && menuData.getQueryString().length() > 0) { - html = "?" + menuData.getQueryString(); - } + return html; + } - return html; - } - - public DataAccessService getDataAccessService() { + public DataAccessService getDataAccessService() { return dataAccessService; } - public void setDataAccessService(DataAccessService dataAccessService) { this.dataAccessService = dataAccessService; } } - - diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/menu/MenuProperties.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/menu/MenuProperties.java index 18f3f83e..67ea3bf6 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/menu/MenuProperties.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/menu/MenuProperties.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 * @@ -45,88 +45,82 @@ import javax.servlet.ServletContext; import org.onap.portalsdk.core.util.SystemProperties; - /* MenuProperties contains a list of constants used during the creation, privilege screening, and rendering of the application menu. */ public class MenuProperties { - private MenuProperties() { - // cannot instantiate - } - - @SuppressWarnings("rawtypes") - private static HashMap menuProperties = new HashMap(); - - // keys used to reference values in the menu.properties file - public static final String WIDTH = "width"; - public static final String LEFT_POSITION = "left_position"; - public static final String TOP_POSITION = "top_position"; - public static final String FONT_COLOR = "font_color"; - public static final String MOUSEOVER_FONT_COLOR = "mouseover_font_color"; - public static final String BACKGROUND_COLOR = "background_color"; - public static final String MOUSEOVER_BACKGROUND_COLOR = "mouseover_background_color"; - public static final String BORDER_COLOR = "border_color"; - public static final String SEPARATOR_COLOR = "separator_color"; - public static final String IMAGE_SRC = "image_src"; - public static final String IMAGE_SRC_LEFT = "image_src_left"; - public static final String IMAGE_SRC_OVER = "image_src_over"; - public static final String IMAGE_SRC_LEFT_OVER = "image_src_left_over"; - public static final String EVALUATE_UPON_TREE_SHOW = "evaluate_upon_tree_show"; - public static final String EVALUATE_UPON_TREE_HIDE = "evaluate_upon_tree_hide"; - public static final String TOP_IS_PERMANENT = "top_is_permanent"; - public static final String TOP_IS_HORIZONTAL = "top_is_horizontal"; - public static final String TREE_IS_HORIZONTAL = "tree_is_horizontal"; - public static final String POSITION_UNDER = "position_under"; - public static final String TOP_MORE_IMAGES_VISIBLE = "top_more_images_visible"; - public static final String TREE_MORE_IMAGES_VISIBLE = "tree_more_images_visible"; - public static final String RIGHT_TO_LEFT = "right_to_left"; - public static final String DISPLAY_ON_CLICK = "display_on_click"; - public static final String TOP_IS_VARIABLE_WIDTH = "top_is_variable_width"; - public static final String TREE_IS_VARIABLE_WIDTH = "tree_is_variable_width"; - public static final String TOP_KEEP_IN_WINDOW_X = "top_keep_in_window_x"; - public static final String TOP_KEEP_IN_WINDOW_Y = "top_keep_in_window_y"; - public static final String MENU_ID_ADMIN = "menu_id_admin"; - public static final String MENU_ID_LOGOUT = "menu_id_logout"; - public static final String MENU_FRAME = "menu_frame"; - public static final String MAIN_FRAME = "main_frame"; - public static final String NESTED_MAIN_FRAME = "nested_main_frame"; - public static final String ROLE_FUNCTIONS_TAG = "role_functions_tag"; - - public static final String MAX_DISPLAYABLE_ADMIN_MENU_SORT_ORDER = "max_displayable_admin_menu_sort_order"; - public static final String MENU_PROPERTIES_FILENAME_KEY = "menu_properties_filename"; - public static final String DEFAULT_SERVLET_NAME = "dispatcher"; - public static final String DEFAULT_TARGET = "_self"; - - public static final String TOP_MENU_CLASS = "top_menu_class"; - public static final String TOP_MENU_LINK_CLASS = "top_menu_link_class"; - - public static final String ON_MOUSE_OUT_TRAILER = "on_mouse_out_trailer"; - public static final String ON_MOUSE_OVER_TRAILER = "on_mouse_over_trailer"; - public static final String ON_CLICK_TRAILER = "on_click_trailer"; - - public static final String MENU_ID_PREFIX = "menu_id_prefix"; - - - @SuppressWarnings("unchecked") - public static void loadFromFile(ServletContext servletContext, String filename, String menuSetName) throws IOException { - Properties p = new Properties(); - - if (filename == null) { - filename = SystemProperties.getProperty(SystemProperties.APPLICATION_MENU_PROPERTIES_NAME); - } - - p.load(servletContext.getResourceAsStream(SystemProperties.getProperty(SystemProperties.MENU_PROPERTIES_FILE_LOCATION) + filename)); - menuProperties.put(menuSetName, p); - } // loadMenuProperties - - public static String getProperty(String key) { - return getProperty(key, SystemProperties.getProperty(SystemProperties.APPLICATION_MENU_SET_NAME)); - } - public static String getProperty(String key, String menuSetName) { - Properties p = (Properties)menuProperties.get(menuSetName); - return p.getProperty(key); - } + // keys used to reference values in the menu.properties file + public static final String WIDTH = "width"; + public static final String LEFT_POSITION = "left_position"; + public static final String TOP_POSITION = "top_position"; + public static final String FONT_COLOR = "font_color"; + public static final String MOUSEOVER_FONT_COLOR = "mouseover_font_color"; + public static final String BACKGROUND_COLOR = "background_color"; + public static final String MOUSEOVER_BACKGROUND_COLOR = "mouseover_background_color"; + public static final String BORDER_COLOR = "border_color"; + public static final String SEPARATOR_COLOR = "separator_color"; + public static final String IMAGE_SRC = "image_src"; + public static final String IMAGE_SRC_LEFT = "image_src_left"; + public static final String IMAGE_SRC_OVER = "image_src_over"; + public static final String IMAGE_SRC_LEFT_OVER = "image_src_left_over"; + public static final String EVALUATE_UPON_TREE_SHOW = "evaluate_upon_tree_show"; + public static final String EVALUATE_UPON_TREE_HIDE = "evaluate_upon_tree_hide"; + public static final String TOP_IS_PERMANENT = "top_is_permanent"; + public static final String TOP_IS_HORIZONTAL = "top_is_horizontal"; + public static final String TREE_IS_HORIZONTAL = "tree_is_horizontal"; + public static final String POSITION_UNDER = "position_under"; + public static final String TOP_MORE_IMAGES_VISIBLE = "top_more_images_visible"; + public static final String TREE_MORE_IMAGES_VISIBLE = "tree_more_images_visible"; + public static final String RIGHT_TO_LEFT = "right_to_left"; + public static final String DISPLAY_ON_CLICK = "display_on_click"; + public static final String TOP_IS_VARIABLE_WIDTH = "top_is_variable_width"; + public static final String TREE_IS_VARIABLE_WIDTH = "tree_is_variable_width"; + public static final String TOP_KEEP_IN_WINDOW_X = "top_keep_in_window_x"; + public static final String TOP_KEEP_IN_WINDOW_Y = "top_keep_in_window_y"; + public static final String MENU_ID_ADMIN = "menu_id_admin"; + public static final String MENU_ID_LOGOUT = "menu_id_logout"; + public static final String MENU_FRAME = "menu_frame"; + public static final String MAIN_FRAME = "main_frame"; + public static final String NESTED_MAIN_FRAME = "nested_main_frame"; + public static final String ROLE_FUNCTIONS_TAG = "role_functions_tag"; + public static final String MAX_DISPLAYABLE_ADMIN_MENU_SORT_ORDER = "max_displayable_admin_menu_sort_order"; + public static final String MENU_PROPERTIES_FILENAME_KEY = "menu_properties_filename"; + public static final String DEFAULT_SERVLET_NAME = "dispatcher"; + public static final String DEFAULT_TARGET = "_self"; + public static final String TOP_MENU_CLASS = "top_menu_class"; + public static final String TOP_MENU_LINK_CLASS = "top_menu_link_class"; + public static final String ON_MOUSE_OUT_TRAILER = "on_mouse_out_trailer"; + public static final String ON_MOUSE_OVER_TRAILER = "on_mouse_over_trailer"; + public static final String ON_CLICK_TRAILER = "on_click_trailer"; + public static final String MENU_ID_PREFIX = "menu_id_prefix"; + + @SuppressWarnings("rawtypes") + private static HashMap menuProperties = new HashMap(); + + private MenuProperties() { + // cannot instantiate + } + + @SuppressWarnings("unchecked") + public static void loadFromFile(ServletContext servletContext, String filename, String menuSetName) + throws IOException { + if (filename == null) + filename = SystemProperties.getProperty(SystemProperties.APPLICATION_MENU_PROPERTIES_NAME); + Properties p = new Properties(); + p.load(servletContext.getResourceAsStream( + SystemProperties.getProperty(SystemProperties.MENU_PROPERTIES_FILE_LOCATION) + filename)); + menuProperties.put(menuSetName, p); + } + + public static String getProperty(String key) { + return getProperty(key, SystemProperties.getProperty(SystemProperties.APPLICATION_MENU_SET_NAME)); + } + + public static String getProperty(String key, String menuSetName) { + Properties p = (Properties) menuProperties.get(menuSetName); + return p.getProperty(key); + } } -- cgit 1.2.3-korg