X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ecomp-portal-BE-common%2Fsrc%2Fmain%2Fjava%2Forg%2Fopenecomp%2Fportalapp%2Fportal%2Fservice%2FFunctionalMenuServiceImpl.java;h=26f1431eaf51dd31afe2bfeb056711ad6a7003e7;hb=51d83152697da4f2ef2242471ee43f36e6b64300;hp=87143e85f10a8638e6ba287b7ce5c46b0ba6ba2e;hpb=1b29c0944a7eba1c88cfd25c94e4dd7ed0f82dc7;p=portal.git diff --git a/ecomp-portal-BE-common/src/main/java/org/openecomp/portalapp/portal/service/FunctionalMenuServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/openecomp/portalapp/portal/service/FunctionalMenuServiceImpl.java index 87143e85..26f1431e 100644 --- a/ecomp-portal-BE-common/src/main/java/org/openecomp/portalapp/portal/service/FunctionalMenuServiceImpl.java +++ b/ecomp-portal-BE-common/src/main/java/org/openecomp/portalapp/portal/service/FunctionalMenuServiceImpl.java @@ -1,21 +1,39 @@ /*- - * ================================================================================ - * ECOMP Portal - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * ================================================================================ + * + * Unless otherwise specified, all documentation contained herein is licensed + * 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 + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ package org.openecomp.portalapp.portal.service; @@ -35,13 +53,6 @@ import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.criterion.Projections; import org.hibernate.criterion.Restrictions; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.EnableAspectJAutoProxy; -import org.springframework.stereotype.Service; - -import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; -import org.openecomp.portalsdk.core.service.DataAccessService; -import org.openecomp.portalsdk.core.util.SystemProperties; import org.openecomp.portalapp.portal.domain.EPApp; import org.openecomp.portalapp.portal.domain.EPUser; import org.openecomp.portalapp.portal.domain.FunctionalMenuItemWithAppID; @@ -55,6 +66,12 @@ import org.openecomp.portalapp.portal.transport.FunctionalMenuItemWithRoles; import org.openecomp.portalapp.portal.transport.FunctionalMenuRole; import org.openecomp.portalapp.portal.utils.EPCommonSystemProperties; import org.openecomp.portalapp.portal.utils.EcompPortalUtils; +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.openecomp.portalsdk.core.service.DataAccessService; +import org.openecomp.portalsdk.core.util.SystemProperties; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.EnableAspectJAutoProxy; +import org.springframework.stereotype.Service; @Service("functionalMenuService") @org.springframework.context.annotation.Configuration @@ -74,12 +91,13 @@ public class FunctionalMenuServiceImpl implements FunctionalMenuService { @PostConstruct private void init() { try { - ACCOUNT_ADMIN_ROLE_ID = Long.valueOf(SystemProperties.getProperty(EPCommonSystemProperties.ACCOUNT_ADMIN_ROLE_ID)); + ACCOUNT_ADMIN_ROLE_ID = Long + .valueOf(SystemProperties.getProperty(EPCommonSystemProperties.ACCOUNT_ADMIN_ROLE_ID)); RESTRICTED_APP_ROLE_ID = SystemProperties.getProperty(EPCommonSystemProperties.RESTRICTED_APP_ROLE_ID); - } catch(Exception e) { + } catch (Exception e) { } } - + public List getFunctionalMenuItems(EPUser user) { List menuItems = new ArrayList(); return menuItems; @@ -88,39 +106,38 @@ public class FunctionalMenuServiceImpl implements FunctionalMenuService { public List getFunctionalMenuItems() { return getFunctionalMenuItems(false); } - + public List getFunctionalMenuItems(Boolean all) { - // Divide this into 2 queries: one which returns the bottom-level menu items associated with Restricted apps, - // and one that returns all the other menu items. Then we can easily add the boolean flag + // Divide this into 2 queries: one which returns the bottom-level menu items + // associated with Restricted apps, + // and one that returns all the other menu items. Then we can easily add the + // boolean flag // restrictedApp to each FunctionalMenuItem, to be used by the front end. String activeWhereClause = ""; - if (! all) { + if (!all) { activeWhereClause = " AND UPPER(m.active_yn) = 'Y' "; } String sql = "SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id, m.url, m.active_yn, r.app_id " - + "FROM fn_menu_functional m, fn_menu_functional_roles r " - + "WHERE m.menu_id = r.menu_id " - + activeWhereClause //" AND UPPER(m.active_yn) = 'Y' " - + " AND r.role_id != '" + RESTRICTED_APP_ROLE_ID + "' " - + " UNION " - + " SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id, m.url, m.active_yn,-1 app_id " - + " FROM fn_menu_functional m " - + " WHERE m.url='' " - + activeWhereClause; //" AND UPPER(m.active_yn) = 'Y' "; + + "FROM fn_menu_functional m, fn_menu_functional_roles r " + "WHERE m.menu_id = r.menu_id " + + activeWhereClause // " AND UPPER(m.active_yn) = 'Y' " + + " AND r.role_id != '" + RESTRICTED_APP_ROLE_ID + "' " + " UNION " + + " SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id, m.url, m.active_yn,-1 app_id " + + " FROM fn_menu_functional m " + " WHERE m.url='' " + activeWhereClause; // " AND UPPER(m.active_yn) = + // 'Y' "; logQuery(sql); @SuppressWarnings("unchecked") - List menuItemsWithAppIdList = dataAccessService.executeSQLQuery(sql,FunctionalMenuItemWithAppID.class, null); - List menuItems = new ArrayList<>(); + List menuItemsWithAppIdList = dataAccessService.executeSQLQuery(sql, + FunctionalMenuItemWithAppID.class, null); + List menuItems = new ArrayList<>(); menuItems = transformFunctionalMenuItemWithAppIDToFunctionalMenuItem(menuItemsWithAppIdList); for (FunctionalMenuItem menuItem : menuItems) { menuItem.restrictedApp = false; } - + sql = "SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id, m.url, m.active_yn, r.app_id " - + "FROM fn_menu_functional m, fn_menu_functional_roles r " - + "WHERE m.menu_id = r.menu_id " - + activeWhereClause //" AND UPPER(m.active_yn) = 'Y' " + + "FROM fn_menu_functional m, fn_menu_functional_roles r " + "WHERE m.menu_id = r.menu_id " + + activeWhereClause // " AND UPPER(m.active_yn) = 'Y' " + " AND r.role_id = '" + RESTRICTED_APP_ROLE_ID + "' "; logQuery(sql); @SuppressWarnings("unchecked") @@ -129,44 +146,42 @@ public class FunctionalMenuServiceImpl implements FunctionalMenuService { menuItem.restrictedApp = true; menuItems.add(menuItem); } - + return menuItems; } - public List getFunctionalMenuItemsForNotificationTree(Boolean all) { - // Divide this into 2 queries: one which returns the bottom-level menu items associated with Restricted apps, - // and one that returns all the other menu items which are active. Then we can easily add the boolean flag + // Divide this into 2 queries: one which returns the bottom-level menu items + // associated with Restricted apps, + // and one that returns all the other menu items which are active. Then we can + // easily add the boolean flag // restrictedApp to each FunctionalMenuItem, to be used by the front end. String activeWhereClause = ""; - if (! all) { + if (!all) { activeWhereClause = " AND UPPER(m.active_yn) = 'Y' "; } String sql = "SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id, m.url, m.active_yn, r.app_id " - + "FROM fn_menu_functional m, fn_menu_functional_roles r " - + "WHERE m.menu_id = r.menu_id " - + activeWhereClause + " AND UPPER(m.active_yn) = 'Y' " - + " AND r.role_id != '" + RESTRICTED_APP_ROLE_ID + "' " - + " UNION " - + " SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id, m.url, m.active_yn,-1 app_id " - + " FROM fn_menu_functional m " - + " WHERE m.url='' " - + activeWhereClause + " AND UPPER(m.active_yn) = 'Y' "; + + "FROM fn_menu_functional m, fn_menu_functional_roles r " + "WHERE m.menu_id = r.menu_id " + + activeWhereClause + " AND UPPER(m.active_yn) = 'Y' " + " AND r.role_id != '" + RESTRICTED_APP_ROLE_ID + + "' " + " UNION " + + " SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id, m.url, m.active_yn,-1 app_id " + + " FROM fn_menu_functional m " + " WHERE m.url='' " + activeWhereClause + + " AND UPPER(m.active_yn) = 'Y' "; logQuery(sql); @SuppressWarnings("unchecked") - List menuItemsWithAppIdList = dataAccessService.executeSQLQuery(sql,FunctionalMenuItemWithAppID.class, null); - List menuItems = new ArrayList<>(); + List menuItemsWithAppIdList = dataAccessService.executeSQLQuery(sql, + FunctionalMenuItemWithAppID.class, null); + List menuItems = new ArrayList<>(); menuItems = transformFunctionalMenuItemWithAppIDToFunctionalMenuItem(menuItemsWithAppIdList); for (FunctionalMenuItem menuItem : menuItems) { menuItem.restrictedApp = false; } - + sql = "SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id, m.url, m.active_yn, r.app_id " - + "FROM fn_menu_functional m, fn_menu_functional_roles r " - + "WHERE m.menu_id = r.menu_id " - + activeWhereClause + " AND UPPER(m.active_yn) = 'Y' " - + " AND r.role_id = '" + RESTRICTED_APP_ROLE_ID + "' "; + + "FROM fn_menu_functional m, fn_menu_functional_roles r " + "WHERE m.menu_id = r.menu_id " + + activeWhereClause + " AND UPPER(m.active_yn) = 'Y' " + " AND r.role_id = '" + RESTRICTED_APP_ROLE_ID + + "' "; logQuery(sql); @SuppressWarnings("unchecked") List menuItems2 = dataAccessService.executeSQLQuery(sql, FunctionalMenuItem.class, null); @@ -174,77 +189,77 @@ public class FunctionalMenuServiceImpl implements FunctionalMenuService { menuItem.restrictedApp = true; menuItems.add(menuItem); } - + return menuItems; } public List getFunctionalMenuItemsForApp(Integer appId) { String sql = "SELECT DISTINCT m1.menu_id, m1.column_num, m1.text, m1.parent_menu_id, m1.url, m.active_yn " + " FROM fn_menu_functional m, fn_menu_functional m1, fn_menu_functional_ancestors a, fn_menu_functional_roles mr " - + " WHERE " + " mr.app_id='" + appId + "' " + " AND mr.menu_id = m.menu_id " + " AND UPPER(m.active_yn) = 'Y'" - + " AND UPPER(m1.active_yn) ='Y'" + " AND a.menu_id = m.menu_id " + " AND a.ancestor_menu_id = m1.menu_id"; + + " WHERE " + " mr.app_id='" + appId + "' " + " AND mr.menu_id = m.menu_id " + + " AND UPPER(m.active_yn) = 'Y'" + " AND UPPER(m1.active_yn) ='Y'" + " AND a.menu_id = m.menu_id " + + " AND a.ancestor_menu_id = m1.menu_id"; logQuery(sql); logger.debug(EELFLoggerDelegate.debugLogger, "getFunctionalMenuItemsForApp: logged the query"); @SuppressWarnings("unchecked") List menuItems = dataAccessService.executeSQLQuery(sql, FunctionalMenuItem.class, null); - + return menuItems; } + /** * convert List of FunctionalMenuItemWithAppID into List of FunctionalMenuItem * */ - public List transformFunctionalMenuItemWithAppIDToFunctionalMenuItem(List functionalMenuItemWithAppIDList) { + public List transformFunctionalMenuItemWithAppIDToFunctionalMenuItem( + List functionalMenuItemWithAppIDList) { List functionalMenuItemList = new ArrayList(); for (FunctionalMenuItemWithAppID functionalMenuItemWithAppID : functionalMenuItemWithAppIDList) { FunctionalMenuItem menuItem = new FunctionalMenuItem(); - menuItem.menuId=functionalMenuItemWithAppID.menuId; - menuItem.column=functionalMenuItemWithAppID.column; - menuItem.text=functionalMenuItemWithAppID.text; - menuItem.parentMenuId=functionalMenuItemWithAppID.parentMenuId; - menuItem.url=functionalMenuItemWithAppID.url; - menuItem.active_yn=functionalMenuItemWithAppID.active_yn; - menuItem.appid=functionalMenuItemWithAppID.appid; + menuItem.menuId = functionalMenuItemWithAppID.menuId; + menuItem.column = functionalMenuItemWithAppID.column; + menuItem.text = functionalMenuItemWithAppID.text; + menuItem.parentMenuId = functionalMenuItemWithAppID.parentMenuId; + menuItem.url = functionalMenuItemWithAppID.url; + menuItem.active_yn = functionalMenuItemWithAppID.active_yn; + menuItem.appid = functionalMenuItemWithAppID.appid; menuItem.setRoles(functionalMenuItemWithAppID.roles); - menuItem.restrictedApp=functionalMenuItemWithAppID.restrictedApp; + menuItem.restrictedApp = functionalMenuItemWithAppID.restrictedApp; functionalMenuItemList.add(menuItem); } return functionalMenuItemList; } - + public List getFunctionalMenuItemsForUser(String orgUserId) { // m represents the functional menu items that are the leaf nodes // m1 represents the functional menu items for all the nodes - // Divide this into 2 queries: one which returns the bottom-level menu items associated with Restricted apps, - // and one that returns all the other menu items. Then we can easily add the boolean flag + // Divide this into 2 queries: one which returns the bottom-level menu items + // associated with Restricted apps, + // and one that returns all the other menu items. Then we can easily add the + // boolean flag // restrictedApp to each FunctionalMenuItem, to be used by the front end. String sql = "SELECT DISTINCT m1.menu_id, m1.column_num, m1.text, m1.parent_menu_id, m1.url, m.active_yn " + " FROM fn_menu_functional m, fn_menu_functional m1, fn_menu_functional_ancestors a, " - + " fn_menu_functional_roles mr, fn_user u , fn_user_role ur " + " WHERE " + " u.org_user_id='" + orgUserId - + "' " + " AND u.user_id = ur.user_id " + " AND ur.app_id = mr.app_id " + + + " fn_menu_functional_roles mr, fn_user u , fn_user_role ur " + " WHERE " + " u.org_user_id='" + + orgUserId + "' " + " AND u.user_id = ur.user_id " + " AND ur.app_id = mr.app_id " + // " AND ur.role_id = mr.role_id " + " AND (ur.role_id = mr.role_id " + " OR ur.role_id = '" + ACCOUNT_ADMIN_ROLE_ID + "') " + " AND m.menu_id = mr.menu_id " + " AND UPPER(m.active_yn) = 'Y'" + " AND UPPER(m1.active_yn) ='Y' " - + " AND a.menu_id = m.menu_id " + " AND a.ancestor_menu_id = m1.menu_id " - + " UNION " + + " AND a.menu_id = m.menu_id " + " AND a.ancestor_menu_id = m1.menu_id " + " UNION " // the ancestors of the restricted app menu items + " select m1.menu_id, m1.column_num, m1.text, m1.parent_menu_id, m1.url, m1.active_yn " + " FROM fn_menu_functional m, fn_menu_functional_roles mr, fn_menu_functional m1, " - + " fn_menu_functional_ancestors a " - + " where a.menu_id = m.menu_id " - + " AND a.ancestor_menu_id = m1.menu_id " - + " AND m.menu_id != m1.menu_id " - + " AND m.menu_id = mr.menu_id " - + " AND mr.role_id = '" + RESTRICTED_APP_ROLE_ID + "' " + + " fn_menu_functional_ancestors a " + " where a.menu_id = m.menu_id " + + " AND a.ancestor_menu_id = m1.menu_id " + " AND m.menu_id != m1.menu_id " + + " AND m.menu_id = mr.menu_id " + " AND mr.role_id = '" + RESTRICTED_APP_ROLE_ID + "' " + " AND UPPER(m.active_yn) = 'Y'" + " AND UPPER(m1.active_yn) ='Y' " // Add the Favorites menu item - + " UNION " - + " SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id, m.url, m.active_yn " + + " UNION " + " SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id, m.url, m.active_yn " + " FROM fn_menu_functional m " + " WHERE m.text in ('Favorites','Get Access','Contact Us','Support','User Guide','Help')"; - + logQuery(sql); logger.debug(EELFLoggerDelegate.debugLogger, "getFunctionalMenuItemsForUser: logged the query"); @@ -253,12 +268,10 @@ public class FunctionalMenuServiceImpl implements FunctionalMenuService { for (FunctionalMenuItem menuItem : menuItems) { menuItem.restrictedApp = false; } - + sql = " SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id, m.url, m.active_yn " - + " FROM fn_menu_functional m, fn_menu_functional_roles r " - + " WHERE m.menu_id = r.menu_id " - + " AND UPPER(m.active_yn) = 'Y' " - + " AND r.role_id = '" + RESTRICTED_APP_ROLE_ID + "' "; + + " FROM fn_menu_functional m, fn_menu_functional_roles r " + " WHERE m.menu_id = r.menu_id " + + " AND UPPER(m.active_yn) = 'Y' " + " AND r.role_id = '" + RESTRICTED_APP_ROLE_ID + "' "; logQuery(sql); @SuppressWarnings("unchecked") List menuItems2 = dataAccessService.executeSQLQuery(sql, FunctionalMenuItem.class, null); @@ -266,7 +279,7 @@ public class FunctionalMenuServiceImpl implements FunctionalMenuService { menuItem.restrictedApp = true; menuItems.add(menuItem); } - + return menuItems; } @@ -289,12 +302,13 @@ public class FunctionalMenuServiceImpl implements FunctionalMenuService { menuItem.appid = appid; List roles = new ArrayList(); for (FunctionalMenuRole roleItem : roleItems) { - logger.debug(EELFLoggerDelegate.debugLogger, "LR: app_id: " + roleItem.appId + "; role_id: " + roleItem.roleId + "\n"); + logger.debug(EELFLoggerDelegate.debugLogger, + "LR: app_id: " + roleItem.appId + "; role_id: " + roleItem.roleId + "\n"); roles.add(roleItem.roleId); } menuItem.setRoles(roles); } - + return menuItem; } @@ -305,7 +319,7 @@ public class FunctionalMenuServiceImpl implements FunctionalMenuService { @SuppressWarnings("unchecked") List functionalMenuItems = dataAccessService.getList(FunctionalMenuItem.class, " where text = '" + menuItemJson.text + "'", null, null); - + boolean dublicatedName = false; for (FunctionalMenuItem fnMenuItem : functionalMenuItems) { if (menuItemJson.menuId != null && menuItemJson.menuId.equals(fnMenuItem.menuId)) { @@ -322,43 +336,49 @@ public class FunctionalMenuServiceImpl implements FunctionalMenuService { fieldsValidator.addProblematicFieldName("text"); fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_CONFLICT); fieldsValidator.errorCode = new Long(EPCommonSystemProperties.DUBLICATED_FIELD_VALUE_ECOMP_ERROR); - logger.debug(EELFLoggerDelegate.debugLogger, "In menuItemFieldsChecker, Error: we have an duplicate text field"); - } else if (StringUtils.isEmpty(menuItemJson.text) && menuItemJson.menuId == null) { - // text must be non empty for a create. For an edit, can be empty, which means it is a move request. + logger.debug(EELFLoggerDelegate.debugLogger, + "In menuItemFieldsChecker, Error: we have an duplicate text field"); + } else if (StringUtils.isEmpty(menuItemJson.text) && menuItemJson.menuId == null) { + // text must be non empty for a create. For an edit, can be empty, which means + // it is a move request. // a null menuId indicates a create. fieldsValidator.addProblematicFieldName("text"); fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_BAD_REQUEST); - logger.debug(EELFLoggerDelegate.debugLogger, "In menuItemFieldsChecker, Error: we have an empty text field"); + logger.debug(EELFLoggerDelegate.debugLogger, + "In menuItemFieldsChecker, Error: we have an empty text field"); } else { // The url, appid, and roles must either be all filled or all empty. Boolean urlIsEmpty = StringUtils.isEmpty(menuItemJson.url); Boolean rolesIsEmpty = menuItemJson.getRoles() == null || menuItemJson.getRoles().isEmpty(); Boolean appidIsEmpty = menuItemJson.appid == null || menuItemJson.appid == 0; - logger.debug(EELFLoggerDelegate.debugLogger, "LR: menuItemfieldsChecker: urlIsEmpty: " + urlIsEmpty + "; rolesIsEmpty: " + rolesIsEmpty + "; appidIsEmpty: " + appidIsEmpty +"\n"); - if (!((urlIsEmpty && rolesIsEmpty && appidIsEmpty) || (!urlIsEmpty && !rolesIsEmpty && !appidIsEmpty))) - { + logger.debug(EELFLoggerDelegate.debugLogger, "LR: menuItemfieldsChecker: urlIsEmpty: " + urlIsEmpty + + "; rolesIsEmpty: " + rolesIsEmpty + "; appidIsEmpty: " + appidIsEmpty + "\n"); + if (!((urlIsEmpty && rolesIsEmpty && appidIsEmpty) + || (!urlIsEmpty && !rolesIsEmpty && !appidIsEmpty))) { fieldsValidator.addProblematicFieldName("url,roles,appid"); fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_BAD_REQUEST); - logger.debug(EELFLoggerDelegate.debugLogger, "In menuItemFieldsChecker, Error: we don't have: either all 3 fields empty or all 3 fields nonempty"); + logger.debug(EELFLoggerDelegate.debugLogger, + "In menuItemFieldsChecker, Error: we don't have: either all 3 fields empty or all 3 fields nonempty"); } else { - logger.debug(EELFLoggerDelegate.debugLogger, "In menuItemFieldsChecker, Success: either all 3 fields empty or all 3 fields nonempty"); + logger.debug(EELFLoggerDelegate.debugLogger, + "In menuItemFieldsChecker, Success: either all 3 fields empty or all 3 fields nonempty"); } } } catch (Exception e) { - logger.error(EELFLoggerDelegate.errorLogger, "Exception occurred while validating the FunctionalMenuItems. Details: " + EcompPortalUtils.getStackTrace(e)); + logger.error(EELFLoggerDelegate.errorLogger, "menuItemFieldsChecker failed", e); fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } - + return fieldsValidator; } - + // Turn foreign key checks on or off protected void setForeignKeys(Session localSession, Boolean on) { String keyCheck = "0"; if (on) { keyCheck = "1"; } - String sql = "set FOREIGN_KEY_CHECKS="+keyCheck; + String sql = "set FOREIGN_KEY_CHECKS=" + keyCheck; logQuery(sql); Query query = localSession.createSQLQuery(sql); query.executeUpdate(); @@ -380,12 +400,12 @@ public class FunctionalMenuServiceImpl implements FunctionalMenuService { menuItem.parentMenuId = menuItemJson.parentMenuId; menuItem.active_yn = "Y"; localSession = sessionFactory.openSession(); - + // If the app is disabled, deactivate the menu item. if (menuItemJson.appid != null) { Long appidLong = Long.valueOf(menuItemJson.appid); EPApp app = (EPApp) localSession.get(EPApp.class, appidLong); - if (app != null && ! app.getEnabled()) { + if (app != null && !app.getEnabled()) { menuItem.active_yn = "N"; } } @@ -415,20 +435,22 @@ public class FunctionalMenuServiceImpl implements FunctionalMenuService { transaction.commit(); result = true; } catch (Exception e) { - EcompPortalUtils.rollbackTransaction(transaction, - "createFunctionalMenuItem rollback, exception = " + e); - logger.error(EELFLoggerDelegate.errorLogger, EcompPortalUtils.getStackTrace(e)); + logger.error(EELFLoggerDelegate.errorLogger, "createFunctionalMenuItem failed", e); + EcompPortalUtils.rollbackTransaction(transaction, + "createFunctionalMenuItem rollback, exception = " + e.toString()); } finally { EcompPortalUtils.closeLocalSession(localSession, "createFunctionalMenuItem"); } if (result) { } else { - logger.debug(EELFLoggerDelegate.debugLogger, "LR: createFunctionalMenuItem: no result. setting httpStatusCode to " - + HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + logger.debug(EELFLoggerDelegate.debugLogger, + "LR: createFunctionalMenuItem: no result. setting httpStatusCode to " + + HttpServletResponse.SC_INTERNAL_SERVER_ERROR); fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } } else { - logger.error(EELFLoggerDelegate.errorLogger, "FunctionalMenuServiceImpl.createFunctionalMenuItem: bad request"); + logger.error(EELFLoggerDelegate.errorLogger, + "FunctionalMenuServiceImpl.createFunctionalMenuItem: bad request"); } return fieldsValidator; } @@ -461,7 +483,7 @@ public class FunctionalMenuServiceImpl implements FunctionalMenuService { public void deleteFavorites(Long menuId) { dataAccessService.deleteDomainObjects(FavoritesFunctionalMenuItem.class, "menu_id='" + menuId + "'", null); } - + private Boolean parentMenuIdEqual(Integer menuId1, Integer menuId2) { return ((menuId1 == null && menuId2 == null) || (menuId1 != null && menuId1.equals(menuId2))); } @@ -532,8 +554,8 @@ public class FunctionalMenuServiceImpl implements FunctionalMenuService { } // Adjust the children under the new parent. logger.debug(EELFLoggerDelegate.debugLogger, "about to adjust the children under the new parent"); - logger.debug(EELFLoggerDelegate.debugLogger, "get all menu items where menuId!=" + menuId + "; parentMenuId==" + newParentMenuId - + "; column>=" + newColumn); + logger.debug(EELFLoggerDelegate.debugLogger, "get all menu items where menuId!=" + menuId + + "; parentMenuId==" + newParentMenuId + "; column>=" + newColumn); criteria = localSession.createCriteria(FunctionalMenuItem.class); criteria.add(Restrictions.ne("menuId", menuId)); if (newParentMenuId == null) { @@ -568,10 +590,10 @@ public class FunctionalMenuServiceImpl implements FunctionalMenuService { } public FieldsValidator editFunctionalMenuItem(FunctionalMenuItemWithRoles menuItemJson) { - boolean result = false; - Session localSession = null; + boolean result = false; + Session localSession = null; Transaction transaction = null; - Long menuId = menuItemJson.menuId; + Long menuId = menuItemJson.menuId; logger.debug(EELFLoggerDelegate.debugLogger, "LR: editFunctionalMenuItem: test 1"); FieldsValidator fieldsValidator = menuItemFieldsChecker(menuItemJson); @@ -580,7 +602,8 @@ public class FunctionalMenuServiceImpl implements FunctionalMenuService { // in db table. if (menuId == null) { fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_BAD_REQUEST); - logger.error(EELFLoggerDelegate.errorLogger, "FunctionalMenuServiceImpl.editFunctionalMenuItem: bad request"); + logger.error(EELFLoggerDelegate.errorLogger, + "FunctionalMenuServiceImpl.editFunctionalMenuItem: bad request"); } else { // To simplify the code, assume we will have a transaction try { @@ -588,16 +611,19 @@ public class FunctionalMenuServiceImpl implements FunctionalMenuService { transaction = localSession.beginTransaction(); // Get the existing info associated with menuItem from the DB - FunctionalMenuItem menuItem = (FunctionalMenuItem) localSession.get(FunctionalMenuItem.class, menuId); + FunctionalMenuItem menuItem = (FunctionalMenuItem) localSession.get(FunctionalMenuItem.class, + menuId); Integer oldColumn = menuItem.column; Integer oldParentMenuId = menuItem.parentMenuId; Integer newColumn = menuItemJson.column; Integer newParentMenuId = menuItemJson.parentMenuId; - logger.debug(EELFLoggerDelegate.debugLogger, "prev info: column: " + oldColumn + "; parentMenuId: " + oldParentMenuId); + logger.debug(EELFLoggerDelegate.debugLogger, + "prev info: column: " + oldColumn + "; parentMenuId: " + oldParentMenuId); - if (menuItemJson.appid != null && menuItemJson.getRoles() != null && !menuItemJson.getRoles().isEmpty() - && menuItemJson.url != null && !menuItemJson.url.isEmpty() && menuItemJson.text != null + if (menuItemJson.appid != null && menuItemJson.getRoles() != null + && !menuItemJson.getRoles().isEmpty() && menuItemJson.url != null + && !menuItemJson.url.isEmpty() && menuItemJson.text != null && !menuItemJson.text.isEmpty()) { // Scenario: appid, roles, url and text are all non-null. // This menu item is associated with an app. @@ -618,21 +644,21 @@ public class FunctionalMenuServiceImpl implements FunctionalMenuService { menuItem.setRoles(menuItemJson.getRoles()); menuItem.url = menuItemJson.url; menuItem.text = menuItemJson.text; - + // If the app is disabled, deactivate the menu item. Long appidLong = Long.valueOf(menuItemJson.appid); EPApp app = (EPApp) localSession.get(EPApp.class, appidLong); - if (app != null && ! app.getEnabled()) { + if (app != null && !app.getEnabled()) { menuItem.active_yn = "N"; } else { menuItem.active_yn = "Y"; } - localSession.update(menuItem); addRoles(menuItemJson, localSession); - } else if (menuItemJson.appid == null && (menuItemJson.getRoles() == null || menuItemJson.getRoles().isEmpty()) + } else if (menuItemJson.appid == null + && (menuItemJson.getRoles() == null || menuItemJson.getRoles().isEmpty()) && (menuItemJson.url == null || menuItemJson.url.isEmpty()) && menuItemJson.text != null && !menuItemJson.text.isEmpty()) { // Scenario: appid, roles and url are all null; text is @@ -686,25 +712,27 @@ public class FunctionalMenuServiceImpl implements FunctionalMenuService { } transaction.commit(); - logger.debug(EELFLoggerDelegate.debugLogger, "LR: editFunctionalMenuItem: finished committing transaction"); + logger.debug(EELFLoggerDelegate.debugLogger, + "LR: editFunctionalMenuItem: finished committing transaction"); result = true; } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "editFunctionalMenuItem failed", e); EcompPortalUtils.rollbackTransaction(transaction, - "createFunctionalMenuItem rollback, exception = " + e); - logger.error(EELFLoggerDelegate.errorLogger, EcompPortalUtils.getStackTrace(e)); + "createFunctionalMenuItem rollback, exception = " + e.toString()); } finally { EcompPortalUtils.closeLocalSession(localSession, "editFunctionalMenuItem"); } - + if (result) { } else { - logger.debug(EELFLoggerDelegate.debugLogger, "LR: createFunctionalMenuItem: no result. setting httpStatusCode to " - + HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + logger.debug(EELFLoggerDelegate.debugLogger, + "LR: createFunctionalMenuItem: no result. setting httpStatusCode to " + + HttpServletResponse.SC_INTERNAL_SERVER_ERROR); fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } } - } - + } + return fieldsValidator; } @@ -718,7 +746,8 @@ public class FunctionalMenuServiceImpl implements FunctionalMenuService { try { localSession = sessionFactory.openSession(); transaction = localSession.beginTransaction(); - // We must turn off foreign keys before deleting a menu item. Otherwise there will be a + // We must turn off foreign keys before deleting a menu item. Otherwise there + // will be a // constraint violation from the ancestors table. setForeignKeys(localSession, false); deleteRoles(menuId); @@ -730,21 +759,22 @@ public class FunctionalMenuServiceImpl implements FunctionalMenuService { transaction.commit(); result = true; } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "deleteFunctionalMenuItem failed", e); EcompPortalUtils.rollbackTransaction(transaction, - "deleteFunctionalMenuItem rollback, exception = " + e); - logger.error(EELFLoggerDelegate.errorLogger, EcompPortalUtils.getStackTrace(e)); + "deleteFunctionalMenuItem rollback, exception = " + e.toString()); } finally { EcompPortalUtils.closeLocalSession(localSession, "deleteFunctionalMenuItem"); } if (result) { } else { - logger.debug(EELFLoggerDelegate.debugLogger, "LR: deleteFunctionalMenuItem: no result. setting httpStatusCode to " - + HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + logger.debug(EELFLoggerDelegate.debugLogger, + "LR: deleteFunctionalMenuItem: no result. setting httpStatusCode to " + + HttpServletResponse.SC_INTERNAL_SERVER_ERROR); fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } return fieldsValidator; } - + // Regenerate the fn_menu_functional_ancestors table, which is used // by the queries that return the functional menu items. public FieldsValidator regenerateAncestorTable() { @@ -760,7 +790,7 @@ public class FunctionalMenuServiceImpl implements FunctionalMenuService { Query query = localSession.createSQLQuery(sql); query.executeUpdate(); logger.debug(EELFLoggerDelegate.debugLogger, "regenerateAncestorTable: finished query 1"); - + sql = "ALTER TABLE fn_menu_functional_ancestors AUTO_INCREMENT=1"; logQuery(sql); query = localSession.createSQLQuery(sql); @@ -787,9 +817,9 @@ public class FunctionalMenuServiceImpl implements FunctionalMenuService { logger.debug(EELFLoggerDelegate.debugLogger, "regenerateAncestorTable: finished query 3"); transaction.commit(); } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "regenerateAncestorTable failed", e); EcompPortalUtils.rollbackTransaction(transaction, - "regenerateAncestorTable rollback, exception = " + e); - logger.error(EELFLoggerDelegate.errorLogger, EcompPortalUtils.getStackTrace(e)); + "regenerateAncestorTable rollback, exception = " + e.toString()); fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } finally { EcompPortalUtils.closeLocalSession(localSession, "regenerateAncestorTable"); @@ -804,132 +834,139 @@ public class FunctionalMenuServiceImpl implements FunctionalMenuService { public FieldsValidator setFavoriteItem(FavoritesFunctionalMenuItem menuItemJson) { boolean result = false; FieldsValidator fieldsValidator = new FieldsValidator(); - + Session localSession = null; Transaction transaction = null; - + try { - logger.debug(EELFLoggerDelegate.debugLogger, String.format("Before adding favorite for user id:{0} and menu id:{1} ",menuItemJson.userId,menuItemJson.menuId)); + logger.debug(EELFLoggerDelegate.debugLogger, + String.format("Before adding favorite for user id:{0} and menu id:{1} ", menuItemJson.userId, + menuItemJson.menuId)); localSession = sessionFactory.openSession(); transaction = localSession.beginTransaction(); localSession.save(menuItemJson); - transaction.commit(); + transaction.commit(); result = true; - logger.debug(EELFLoggerDelegate.debugLogger, String.format("After adding favorite for user id:{0} and menu id:{1} ",menuItemJson.userId,menuItemJson.menuId)); + logger.debug(EELFLoggerDelegate.debugLogger, + String.format("After adding favorite for user id:{0} and menu id:{1} ", menuItemJson.userId, + menuItemJson.menuId)); } catch (Exception e) { - EcompPortalUtils.rollbackTransaction(transaction,"setFavoriteItem rollback, exception = " + e); - logger.error(EELFLoggerDelegate.errorLogger, EcompPortalUtils.getStackTrace(e)); + logger.error(EELFLoggerDelegate.errorLogger, "setFavoriteItem failed", e); + EcompPortalUtils.rollbackTransaction(transaction, "setFavoriteItem rollback, exception = " + e.toString()); } finally { EcompPortalUtils.closeLocalSession(localSession, "setFavoriteItem"); - } - - if(result) { } - else { + + if (result) { + } else { fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } - + return fieldsValidator; } - - public List getFavoriteItems(Long userId) { + + public List getFavoriteItems(Long userId) { try { logger.debug(EELFLoggerDelegate.debugLogger, "Before getting favorites for user id: " + userId); - - // Divide this into 2 queries: one which returns the favorites items associated with Restricted apps, - // and one that returns all the other favorites items. Then we can easily add the boolean flag - // restrictedApp to each FavoritesFunctionalMenuItemJson, to be used by the front end. + + // Divide this into 2 queries: one which returns the favorites items associated + // with Restricted apps, + // and one that returns all the other favorites items. Then we can easily add + // the boolean flag + // restrictedApp to each FavoritesFunctionalMenuItemJson, to be used by the + // front end. String sql = "SELECT f.user_id,f.menu_id,m.text,m.url " + " FROM fn_menu_favorites f, fn_menu_functional m, fn_menu_functional_roles mr " - + " WHERE f.user_id='" + userId + "' AND f.menu_id = m.menu_id " - + " AND f.menu_id = mr.menu_id " + + " WHERE f.user_id='" + userId + "' AND f.menu_id = m.menu_id " + " AND f.menu_id = mr.menu_id " + " AND mr.role_id = '" + RESTRICTED_APP_ROLE_ID + "' "; @SuppressWarnings("unchecked") - List menuItems = dataAccessService.executeSQLQuery(sql, FavoritesFunctionalMenuItemJson.class, null); + List menuItems = dataAccessService.executeSQLQuery(sql, + FavoritesFunctionalMenuItemJson.class, null); for (FavoritesFunctionalMenuItemJson menuItem : menuItems) { menuItem.restrictedApp = true; } - + sql = "SELECT DISTINCT f.user_id,f.menu_id,m.text,m.url " + " FROM fn_menu_favorites f, fn_menu_functional m, fn_menu_functional_roles mr " - + " WHERE f.user_id='" + userId + "' AND f.menu_id = m.menu_id " - + " AND f.menu_id = mr.menu_id " + + " WHERE f.user_id='" + userId + "' AND f.menu_id = m.menu_id " + " AND f.menu_id = mr.menu_id " + " AND mr.role_id != '" + RESTRICTED_APP_ROLE_ID + "' "; @SuppressWarnings("unchecked") - List menuItems2 = dataAccessService.executeSQLQuery(sql, FavoritesFunctionalMenuItemJson.class, null); + List menuItems2 = dataAccessService.executeSQLQuery(sql, + FavoritesFunctionalMenuItemJson.class, null); for (FavoritesFunctionalMenuItemJson menuItem : menuItems2) { menuItem.restrictedApp = false; menuItems.add(menuItem); } - + return menuItems; } catch (Exception e) { - logger.error(EELFLoggerDelegate.errorLogger, "Exception occurred in FunctionalMenuServiceImpl.getFavoriteItems. Details: " + EcompPortalUtils.getStackTrace(e)); + logger.error(EELFLoggerDelegate.errorLogger, "getFavoriteItems failed", e); List menuItems = new ArrayList(); return menuItems; - } + } } - + public FieldsValidator removeFavoriteItem(Long userId, Long menuId) { boolean result = false; FieldsValidator fieldsValidator = new FieldsValidator(); - + Session localSession = null; Transaction transaction = null; - - try { - + + try { + FavoritesFunctionalMenuItem menuItemJson = new FavoritesFunctionalMenuItem(); menuItemJson.userId = userId; menuItemJson.menuId = menuId; - + localSession = sessionFactory.openSession(); transaction = localSession.beginTransaction(); localSession.delete(menuItemJson); localSession.flush(); - transaction.commit(); + transaction.commit(); result = true; - logger.debug(EELFLoggerDelegate.debugLogger, String.format("After removing favorite for user id: " + userId + "; menu id: " + menuId)); + logger.debug(EELFLoggerDelegate.debugLogger, + String.format("After removing favorite for user id: " + userId + "; menu id: " + menuId)); } catch (Exception e) { - EcompPortalUtils.rollbackTransaction(transaction,"removeFavoriteItem rollback, exception = " + e); - logger.error(EELFLoggerDelegate.errorLogger, EcompPortalUtils.getStackTrace(e)); - } finally { + logger.error(EELFLoggerDelegate.errorLogger, "removeFavoriteItem failed", e); + EcompPortalUtils.rollbackTransaction(transaction, + "removeFavoriteItem rollback, exception = " + e.toString()); + } finally { EcompPortalUtils.closeLocalSession(localSession, "removeFavoriteItem"); - } - - if(result) { } - else { + + if (result) { + } else { fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } - + return fieldsValidator; } - + @Override public void assignHelpURLs(List menuItems) { try { String user_guide_link = SystemProperties.getProperty(EPCommonSystemProperties.USER_GUIDE_URL); - - for(FunctionalMenuItem menuItem: menuItems){ - if(menuItem.text.equalsIgnoreCase("Contact Us")){ + + for (FunctionalMenuItem menuItem : menuItems) { + if (menuItem.text.equalsIgnoreCase("Contact Us")) { menuItem.setUrl("contactUs"); - //menuItem.setRestrictedApp(true); + // menuItem.setRestrictedApp(true); } - if(menuItem.text.equalsIgnoreCase("Get Access")) { + if (menuItem.text.equalsIgnoreCase("Get Access")) { menuItem.setUrl("getAccess"); } - if(menuItem.text.equalsIgnoreCase("User Guide")) { + if (menuItem.text.equalsIgnoreCase("User Guide")) { menuItem.setUrl(user_guide_link); menuItem.setRestrictedApp(true); } } - } catch (Exception e) { - logger.error(EELFLoggerDelegate.errorLogger, "assignHelpURLs process failed. Details: " + EcompPortalUtils.getStackTrace(e)); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "assignHelpURLs process failed", e); } - + } public List getFunctionalMenuRole() { @@ -938,8 +975,9 @@ public class FunctionalMenuServiceImpl implements FunctionalMenuService { logger.debug(EELFLoggerDelegate.debugLogger, "getFunctionalMenuRole: logged the query"); @SuppressWarnings("unchecked") - List functionalMenuRole = dataAccessService.executeSQLQuery(sql, FunctionalMenuRole.class, null); - + List functionalMenuRole = dataAccessService.executeSQLQuery(sql, FunctionalMenuRole.class, + null); + return functionalMenuRole; } @@ -951,13 +989,12 @@ public class FunctionalMenuServiceImpl implements FunctionalMenuService { List userAppRoles = null; try { - userAppRoles = dataAccessService - .executeNamedQuery("getUserApproles", params, null); + userAppRoles = dataAccessService.executeNamedQuery("getUserApproles", params, null); } catch (Exception e) { // TODO Auto-generated catch block logger.error(EELFLoggerDelegate.errorLogger, "getUserAppRolesList failed", e); - } + } return userAppRoles; } - + }