2 * ================================================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ================================================================================
\r
20 package org.openecomp.portalapp.portal.service;
\r
22 import java.util.ArrayList;
\r
23 import java.util.HashMap;
\r
24 import java.util.List;
\r
25 import java.util.Map;
\r
27 import javax.annotation.PostConstruct;
\r
28 import javax.servlet.http.HttpServletResponse;
\r
30 import org.apache.commons.lang3.StringUtils;
\r
31 import org.hibernate.Criteria;
\r
32 import org.hibernate.Query;
\r
33 import org.hibernate.Session;
\r
34 import org.hibernate.SessionFactory;
\r
35 import org.hibernate.Transaction;
\r
36 import org.hibernate.criterion.Projections;
\r
37 import org.hibernate.criterion.Restrictions;
\r
38 import org.springframework.beans.factory.annotation.Autowired;
\r
39 import org.springframework.context.annotation.EnableAspectJAutoProxy;
\r
40 import org.springframework.stereotype.Service;
\r
42 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
\r
43 import org.openecomp.portalsdk.core.service.DataAccessService;
\r
44 import org.openecomp.portalsdk.core.util.SystemProperties;
\r
45 import org.openecomp.portalapp.portal.domain.EPApp;
\r
46 import org.openecomp.portalapp.portal.domain.EPUser;
\r
47 import org.openecomp.portalapp.portal.domain.FunctionalMenuItemWithAppID;
\r
48 import org.openecomp.portalapp.portal.logging.aop.EPMetricsLog;
\r
49 import org.openecomp.portalapp.portal.transport.BusinessCardApplicationRole;
\r
50 import org.openecomp.portalapp.portal.transport.FavoritesFunctionalMenuItem;
\r
51 import org.openecomp.portalapp.portal.transport.FavoritesFunctionalMenuItemJson;
\r
52 import org.openecomp.portalapp.portal.transport.FieldsValidator;
\r
53 import org.openecomp.portalapp.portal.transport.FunctionalMenuItem;
\r
54 import org.openecomp.portalapp.portal.transport.FunctionalMenuItemWithRoles;
\r
55 import org.openecomp.portalapp.portal.transport.FunctionalMenuRole;
\r
56 import org.openecomp.portalapp.portal.utils.EPCommonSystemProperties;
\r
57 import org.openecomp.portalapp.portal.utils.EcompPortalUtils;
\r
59 @Service("functionalMenuService")
\r
60 @org.springframework.context.annotation.Configuration
\r
61 @EnableAspectJAutoProxy
\r
63 public class FunctionalMenuServiceImpl implements FunctionalMenuService {
\r
64 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(FunctionalMenuServiceImpl.class);
\r
66 private Long ACCOUNT_ADMIN_ROLE_ID = 999L;
\r
67 private String RESTRICTED_APP_ROLE_ID = "900";
\r
70 private DataAccessService dataAccessService;
\r
72 private SessionFactory sessionFactory;
\r
75 private void init() {
\r
77 ACCOUNT_ADMIN_ROLE_ID = Long.valueOf(SystemProperties.getProperty(EPCommonSystemProperties.ACCOUNT_ADMIN_ROLE_ID));
\r
78 RESTRICTED_APP_ROLE_ID = SystemProperties.getProperty(EPCommonSystemProperties.RESTRICTED_APP_ROLE_ID);
\r
79 } catch(Exception e) {
\r
83 public List<FunctionalMenuItem> getFunctionalMenuItems(EPUser user) {
\r
84 List<FunctionalMenuItem> menuItems = new ArrayList<FunctionalMenuItem>();
\r
88 public List<FunctionalMenuItem> getFunctionalMenuItems() {
\r
89 return getFunctionalMenuItems(false);
\r
92 public List<FunctionalMenuItem> getFunctionalMenuItems(Boolean all) {
\r
93 // Divide this into 2 queries: one which returns the bottom-level menu items associated with Restricted apps,
\r
94 // and one that returns all the other menu items. Then we can easily add the boolean flag
\r
95 // restrictedApp to each FunctionalMenuItem, to be used by the front end.
\r
96 String activeWhereClause = "";
\r
98 activeWhereClause = " AND UPPER(m.active_yn) = 'Y' ";
\r
100 String sql = "SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id, m.url, m.active_yn, r.app_id "
\r
101 + "FROM fn_menu_functional m, fn_menu_functional_roles r "
\r
102 + "WHERE m.menu_id = r.menu_id "
\r
103 + activeWhereClause //" AND UPPER(m.active_yn) = 'Y' "
\r
104 + " AND r.role_id != '" + RESTRICTED_APP_ROLE_ID + "' "
\r
106 + " SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id, m.url, m.active_yn,-1 app_id "
\r
107 + " FROM fn_menu_functional m "
\r
108 + " WHERE m.url='' "
\r
109 + activeWhereClause; //" AND UPPER(m.active_yn) = 'Y' ";
\r
112 @SuppressWarnings("unchecked")
\r
113 List<FunctionalMenuItemWithAppID> menuItemsWithAppIdList = dataAccessService.executeSQLQuery(sql,FunctionalMenuItemWithAppID.class, null);
\r
114 List<FunctionalMenuItem> menuItems = new ArrayList<>();
\r
115 menuItems = transformFunctionalMenuItemWithAppIDToFunctionalMenuItem(menuItemsWithAppIdList);
\r
116 for (FunctionalMenuItem menuItem : menuItems) {
\r
117 menuItem.restrictedApp = false;
\r
120 sql = "SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id, m.url, m.active_yn, r.app_id "
\r
121 + "FROM fn_menu_functional m, fn_menu_functional_roles r "
\r
122 + "WHERE m.menu_id = r.menu_id "
\r
123 + activeWhereClause //" AND UPPER(m.active_yn) = 'Y' "
\r
124 + " AND r.role_id = '" + RESTRICTED_APP_ROLE_ID + "' ";
\r
126 @SuppressWarnings("unchecked")
\r
127 List<FunctionalMenuItem> menuItems2 = dataAccessService.executeSQLQuery(sql, FunctionalMenuItem.class, null);
\r
128 for (FunctionalMenuItem menuItem : menuItems2) {
\r
129 menuItem.restrictedApp = true;
\r
130 menuItems.add(menuItem);
\r
137 public List<FunctionalMenuItem> getFunctionalMenuItemsForNotificationTree(Boolean all) {
\r
138 // Divide this into 2 queries: one which returns the bottom-level menu items associated with Restricted apps,
\r
139 // and one that returns all the other menu items which are active. Then we can easily add the boolean flag
\r
140 // restrictedApp to each FunctionalMenuItem, to be used by the front end.
\r
141 String activeWhereClause = "";
\r
143 activeWhereClause = " AND UPPER(m.active_yn) = 'Y' ";
\r
145 String sql = "SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id, m.url, m.active_yn, r.app_id "
\r
146 + "FROM fn_menu_functional m, fn_menu_functional_roles r "
\r
147 + "WHERE m.menu_id = r.menu_id "
\r
148 + activeWhereClause + " AND UPPER(m.active_yn) = 'Y' "
\r
149 + " AND r.role_id != '" + RESTRICTED_APP_ROLE_ID + "' "
\r
151 + " SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id, m.url, m.active_yn,-1 app_id "
\r
152 + " FROM fn_menu_functional m "
\r
153 + " WHERE m.url='' "
\r
154 + activeWhereClause + " AND UPPER(m.active_yn) = 'Y' ";
\r
157 @SuppressWarnings("unchecked")
\r
158 List<FunctionalMenuItemWithAppID> menuItemsWithAppIdList = dataAccessService.executeSQLQuery(sql,FunctionalMenuItemWithAppID.class, null);
\r
159 List<FunctionalMenuItem> menuItems = new ArrayList<>();
\r
160 menuItems = transformFunctionalMenuItemWithAppIDToFunctionalMenuItem(menuItemsWithAppIdList);
\r
161 for (FunctionalMenuItem menuItem : menuItems) {
\r
162 menuItem.restrictedApp = false;
\r
165 sql = "SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id, m.url, m.active_yn, r.app_id "
\r
166 + "FROM fn_menu_functional m, fn_menu_functional_roles r "
\r
167 + "WHERE m.menu_id = r.menu_id "
\r
168 + activeWhereClause + " AND UPPER(m.active_yn) = 'Y' "
\r
169 + " AND r.role_id = '" + RESTRICTED_APP_ROLE_ID + "' ";
\r
171 @SuppressWarnings("unchecked")
\r
172 List<FunctionalMenuItem> menuItems2 = dataAccessService.executeSQLQuery(sql, FunctionalMenuItem.class, null);
\r
173 for (FunctionalMenuItem menuItem : menuItems2) {
\r
174 menuItem.restrictedApp = true;
\r
175 menuItems.add(menuItem);
\r
181 public List<FunctionalMenuItem> getFunctionalMenuItemsForApp(Integer appId) {
\r
182 String sql = "SELECT DISTINCT m1.menu_id, m1.column_num, m1.text, m1.parent_menu_id, m1.url, m.active_yn "
\r
183 + " FROM fn_menu_functional m, fn_menu_functional m1, fn_menu_functional_ancestors a, fn_menu_functional_roles mr "
\r
184 + " WHERE " + " mr.app_id='" + appId + "' " + " AND mr.menu_id = m.menu_id " + " AND UPPER(m.active_yn) = 'Y'"
\r
185 + " AND UPPER(m1.active_yn) ='Y'" + " AND a.menu_id = m.menu_id " + " AND a.ancestor_menu_id = m1.menu_id";
\r
187 logger.debug(EELFLoggerDelegate.debugLogger, "getFunctionalMenuItemsForApp: logged the query");
\r
189 @SuppressWarnings("unchecked")
\r
190 List<FunctionalMenuItem> menuItems = dataAccessService.executeSQLQuery(sql, FunctionalMenuItem.class, null);
\r
195 * convert List of FunctionalMenuItemWithAppID into List of FunctionalMenuItem
\r
198 public List<FunctionalMenuItem> transformFunctionalMenuItemWithAppIDToFunctionalMenuItem(List<FunctionalMenuItemWithAppID> functionalMenuItemWithAppIDList) {
\r
199 List<FunctionalMenuItem> functionalMenuItemList = new ArrayList<FunctionalMenuItem>();
\r
200 for (FunctionalMenuItemWithAppID functionalMenuItemWithAppID : functionalMenuItemWithAppIDList) {
\r
201 FunctionalMenuItem menuItem = new FunctionalMenuItem();
\r
202 menuItem.menuId=functionalMenuItemWithAppID.menuId;
\r
203 menuItem.column=functionalMenuItemWithAppID.column;
\r
204 menuItem.text=functionalMenuItemWithAppID.text;
\r
205 menuItem.parentMenuId=functionalMenuItemWithAppID.parentMenuId;
\r
206 menuItem.url=functionalMenuItemWithAppID.url;
\r
207 menuItem.active_yn=functionalMenuItemWithAppID.active_yn;
\r
208 menuItem.appid=functionalMenuItemWithAppID.appid;
\r
209 menuItem.setRoles(functionalMenuItemWithAppID.roles);
\r
210 menuItem.restrictedApp=functionalMenuItemWithAppID.restrictedApp;
\r
211 functionalMenuItemList.add(menuItem);
\r
213 return functionalMenuItemList;
\r
216 public List<FunctionalMenuItem> getFunctionalMenuItemsForUser(String orgUserId) {
\r
217 // m represents the functional menu items that are the leaf nodes
\r
218 // m1 represents the functional menu items for all the nodes
\r
220 // Divide this into 2 queries: one which returns the bottom-level menu items associated with Restricted apps,
\r
221 // and one that returns all the other menu items. Then we can easily add the boolean flag
\r
222 // restrictedApp to each FunctionalMenuItem, to be used by the front end.
\r
223 String sql = "SELECT DISTINCT m1.menu_id, m1.column_num, m1.text, m1.parent_menu_id, m1.url, m.active_yn "
\r
224 + " FROM fn_menu_functional m, fn_menu_functional m1, fn_menu_functional_ancestors a, "
\r
225 + " fn_menu_functional_roles mr, fn_user u , fn_user_role ur " + " WHERE " + " u.org_user_id='" + orgUserId
\r
226 + "' " + " AND u.user_id = ur.user_id " + " AND ur.app_id = mr.app_id " +
\r
227 // " AND ur.role_id = mr.role_id " +
\r
228 " AND (ur.role_id = mr.role_id " + " OR ur.role_id = '" + ACCOUNT_ADMIN_ROLE_ID + "') "
\r
229 + " AND m.menu_id = mr.menu_id " + " AND UPPER(m.active_yn) = 'Y'" + " AND UPPER(m1.active_yn) ='Y' "
\r
230 + " AND a.menu_id = m.menu_id " + " AND a.ancestor_menu_id = m1.menu_id "
\r
232 // the ancestors of the restricted app menu items
\r
233 + " select m1.menu_id, m1.column_num, m1.text, m1.parent_menu_id, m1.url, m1.active_yn "
\r
234 + " FROM fn_menu_functional m, fn_menu_functional_roles mr, fn_menu_functional m1, "
\r
235 + " fn_menu_functional_ancestors a "
\r
236 + " where a.menu_id = m.menu_id "
\r
237 + " AND a.ancestor_menu_id = m1.menu_id "
\r
238 + " AND m.menu_id != m1.menu_id "
\r
239 + " AND m.menu_id = mr.menu_id "
\r
240 + " AND mr.role_id = '" + RESTRICTED_APP_ROLE_ID + "' "
\r
241 + " AND UPPER(m.active_yn) = 'Y'" + " AND UPPER(m1.active_yn) ='Y' "
\r
242 // Add the Favorites menu item
\r
244 + " SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id, m.url, m.active_yn "
\r
245 + " FROM fn_menu_functional m "
\r
246 + " WHERE m.text in ('Favorites','Get Access','Contact Us','Support','User Guide','Help')";
\r
249 logger.debug(EELFLoggerDelegate.debugLogger, "getFunctionalMenuItemsForUser: logged the query");
\r
251 @SuppressWarnings("unchecked")
\r
252 List<FunctionalMenuItem> menuItems = dataAccessService.executeSQLQuery(sql, FunctionalMenuItem.class, null);
\r
253 for (FunctionalMenuItem menuItem : menuItems) {
\r
254 menuItem.restrictedApp = false;
\r
257 sql = " SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id, m.url, m.active_yn "
\r
258 + " FROM fn_menu_functional m, fn_menu_functional_roles r "
\r
259 + " WHERE m.menu_id = r.menu_id "
\r
260 + " AND UPPER(m.active_yn) = 'Y' "
\r
261 + " AND r.role_id = '" + RESTRICTED_APP_ROLE_ID + "' ";
\r
263 @SuppressWarnings("unchecked")
\r
264 List<FunctionalMenuItem> menuItems2 = dataAccessService.executeSQLQuery(sql, FunctionalMenuItem.class, null);
\r
265 for (FunctionalMenuItem menuItem : menuItems2) {
\r
266 menuItem.restrictedApp = true;
\r
267 menuItems.add(menuItem);
\r
273 public FunctionalMenuItem getFunctionalMenuItemDetails(Integer menuid) {
\r
274 // First, fill in the fields that apply to all menu items
\r
276 String sql = "SELECT * FROM fn_menu_functional WHERE menu_id = '" + menuid + "'";
\r
278 @SuppressWarnings("unchecked")
\r
279 List<FunctionalMenuItem> menuItems = dataAccessService.executeSQLQuery(sql, FunctionalMenuItem.class, null);
\r
280 FunctionalMenuItem menuItem = (menuItems == null || menuItems.isEmpty() ? null : menuItems.get(0));
\r
281 // If it is a bottom-level menu item, must fill in the appid and the
\r
283 sql = "SELECT * FROM fn_menu_functional_roles WHERE menu_id = '" + menuid + "'";
\r
285 @SuppressWarnings("unchecked")
\r
286 List<FunctionalMenuRole> roleItems = dataAccessService.executeSQLQuery(sql, FunctionalMenuRole.class, null);
\r
287 if (roleItems.size() > 0) {
\r
288 Integer appid = roleItems.get(0).appId;
\r
289 menuItem.appid = appid;
\r
290 List<Integer> roles = new ArrayList<Integer>();
\r
291 for (FunctionalMenuRole roleItem : roleItems) {
\r
292 logger.debug(EELFLoggerDelegate.debugLogger, "LR: app_id: " + roleItem.appId + "; role_id: " + roleItem.roleId + "\n");
\r
293 roles.add(roleItem.roleId);
\r
295 menuItem.setRoles(roles);
\r
301 private FieldsValidator menuItemFieldsChecker(FunctionalMenuItemWithRoles menuItemJson) {
\r
302 FieldsValidator fieldsValidator = new FieldsValidator();
\r
304 // TODO: validate all the fields
\r
305 @SuppressWarnings("unchecked")
\r
306 List<FunctionalMenuItem> functionalMenuItems = dataAccessService.getList(FunctionalMenuItem.class,
\r
307 " where text = '" + menuItemJson.text + "'", null, null);
\r
309 boolean dublicatedName = false;
\r
310 for (FunctionalMenuItem fnMenuItem : functionalMenuItems) {
\r
311 if (menuItemJson.menuId != null && menuItemJson.menuId.equals(fnMenuItem.menuId)) {
\r
312 // FunctionalMenuItem should not be compared with itself
\r
316 if (!dublicatedName && fnMenuItem.text.equalsIgnoreCase(menuItemJson.text)) {
\r
317 dublicatedName = true;
\r
321 if (dublicatedName) {
\r
322 fieldsValidator.addProblematicFieldName("text");
\r
323 fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_CONFLICT);
\r
324 fieldsValidator.errorCode = new Long(EPCommonSystemProperties.DUBLICATED_FIELD_VALUE_ECOMP_ERROR);
\r
325 logger.debug(EELFLoggerDelegate.debugLogger, "In menuItemFieldsChecker, Error: we have an duplicate text field");
\r
326 } else if (StringUtils.isEmpty(menuItemJson.text) && menuItemJson.menuId == null) {
\r
327 // text must be non empty for a create. For an edit, can be empty, which means it is a move request.
\r
328 // a null menuId indicates a create.
\r
329 fieldsValidator.addProblematicFieldName("text");
\r
330 fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_BAD_REQUEST);
\r
331 logger.debug(EELFLoggerDelegate.debugLogger, "In menuItemFieldsChecker, Error: we have an empty text field");
\r
333 // The url, appid, and roles must either be all filled or all empty.
\r
334 Boolean urlIsEmpty = StringUtils.isEmpty(menuItemJson.url);
\r
335 Boolean rolesIsEmpty = menuItemJson.getRoles() == null || menuItemJson.getRoles().isEmpty();
\r
336 Boolean appidIsEmpty = menuItemJson.appid == null || menuItemJson.appid == 0;
\r
337 logger.debug(EELFLoggerDelegate.debugLogger, "LR: menuItemfieldsChecker: urlIsEmpty: " + urlIsEmpty + "; rolesIsEmpty: " + rolesIsEmpty + "; appidIsEmpty: " + appidIsEmpty +"\n");
\r
338 if (!((urlIsEmpty && rolesIsEmpty && appidIsEmpty) || (!urlIsEmpty && !rolesIsEmpty && !appidIsEmpty)))
\r
340 fieldsValidator.addProblematicFieldName("url,roles,appid");
\r
341 fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_BAD_REQUEST);
\r
342 logger.debug(EELFLoggerDelegate.debugLogger, "In menuItemFieldsChecker, Error: we don't have: either all 3 fields empty or all 3 fields nonempty");
\r
344 logger.debug(EELFLoggerDelegate.debugLogger, "In menuItemFieldsChecker, Success: either all 3 fields empty or all 3 fields nonempty");
\r
347 } catch (Exception e) {
\r
348 logger.error(EELFLoggerDelegate.errorLogger, "Exception occurred while validating the FunctionalMenuItems. Details: " + EcompPortalUtils.getStackTrace(e));
\r
349 fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
\r
352 return fieldsValidator;
\r
355 // Turn foreign key checks on or off
\r
356 protected void setForeignKeys(Session localSession, Boolean on) {
\r
357 String keyCheck = "0";
\r
361 String sql = "set FOREIGN_KEY_CHECKS="+keyCheck;
\r
363 Query query = localSession.createSQLQuery(sql);
\r
364 query.executeUpdate();
\r
367 public FieldsValidator createFunctionalMenuItem(FunctionalMenuItemWithRoles menuItemJson) {
\r
368 FieldsValidator fieldsValidator = menuItemFieldsChecker(menuItemJson);
\r
369 if (fieldsValidator.httpStatusCode.intValue() == HttpServletResponse.SC_OK) {
\r
370 logger.debug(EELFLoggerDelegate.debugLogger, "LR: createFunctionalMenuItem: test 1");
\r
371 boolean result = false;
\r
372 Session localSession = null;
\r
373 Transaction transaction = null;
\r
375 FunctionalMenuItem menuItem = new FunctionalMenuItem();
\r
376 menuItem.appid = menuItemJson.appid;
\r
377 menuItem.setRoles(menuItemJson.getRoles());
\r
378 menuItem.url = menuItemJson.url;
\r
379 menuItem.text = menuItemJson.text;
\r
380 menuItem.parentMenuId = menuItemJson.parentMenuId;
\r
381 menuItem.active_yn = "Y";
\r
382 localSession = sessionFactory.openSession();
\r
384 // If the app is disabled, deactivate the menu item.
\r
385 if (menuItemJson.appid != null) {
\r
386 Long appidLong = Long.valueOf(menuItemJson.appid);
\r
387 EPApp app = (EPApp) localSession.get(EPApp.class, appidLong);
\r
388 if (app != null && ! app.getEnabled()) {
\r
389 menuItem.active_yn = "N";
\r
393 // Set the column number to 1 higher than the highest column
\r
394 // number under this parent.
\r
395 Criteria criteria = localSession.createCriteria(FunctionalMenuItem.class);
\r
396 criteria.setProjection(Projections.max("column"));
\r
397 criteria.add(Restrictions.eq("parentMenuId", menuItem.parentMenuId));
\r
398 Integer maxColumn = (Integer) criteria.uniqueResult();
\r
399 if (maxColumn == null) {
\r
402 menuItem.column = maxColumn + 1;
\r
403 logger.debug(EELFLoggerDelegate.debugLogger, "about to create menu item: " + menuItem.toString());
\r
405 transaction = localSession.beginTransaction();
\r
406 // localSession.saveOrUpdate(newMenuItem);
\r
407 localSession.save(menuItem);
\r
408 Long menuid = menuItem.menuId;
\r
409 menuItemJson.menuId = menuid;
\r
410 logger.debug(EELFLoggerDelegate.debugLogger, "after saving menu object, new id: " + menuid);
\r
412 // Next, save all the roles
\r
414 addRoles(menuItemJson, localSession);
\r
415 transaction.commit();
\r
417 } catch (Exception e) {
\r
418 EcompPortalUtils.rollbackTransaction(transaction,
\r
419 "createFunctionalMenuItem rollback, exception = " + e);
\r
420 logger.error(EELFLoggerDelegate.errorLogger, EcompPortalUtils.getStackTrace(e));
\r
422 EcompPortalUtils.closeLocalSession(localSession, "createFunctionalMenuItem");
\r
426 logger.debug(EELFLoggerDelegate.debugLogger, "LR: createFunctionalMenuItem: no result. setting httpStatusCode to "
\r
427 + HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
\r
428 fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
\r
431 logger.error(EELFLoggerDelegate.errorLogger, "FunctionalMenuServiceImpl.createFunctionalMenuItem: bad request");
\r
433 return fieldsValidator;
\r
436 /* Add all the roles in the menu item to the database */
\r
437 public void addRoles(FunctionalMenuItemWithRoles menuItemJson, Session localSession) {
\r
438 logger.debug(EELFLoggerDelegate.debugLogger, "entering addRoles.");
\r
439 List<Integer> roles = menuItemJson.getRoles();
\r
440 if (roles != null && roles.size() > 0) {
\r
441 Integer appid = menuItemJson.appid;
\r
442 Long menuid = menuItemJson.menuId;
\r
443 for (Integer roleid : roles) {
\r
444 logger.debug(EELFLoggerDelegate.debugLogger, "about to create record for role: " + roleid);
\r
445 FunctionalMenuRole role = new FunctionalMenuRole();
\r
446 role.appId = appid;
\r
447 role.menuId = menuid;
\r
448 role.roleId = roleid;
\r
449 localSession.save(role);
\r
450 logger.debug(EELFLoggerDelegate.debugLogger, "after saving role menu object, new id: " + role.id);
\r
455 /* Delete all the roles associated with the menu item from the database */
\r
456 public void deleteRoles(Long menuId) {
\r
457 dataAccessService.deleteDomainObjects(FunctionalMenuRole.class, "menu_id='" + menuId + "'", null);
\r
460 /* Delete all favorites associated with the menu item from the database */
\r
461 public void deleteFavorites(Long menuId) {
\r
462 dataAccessService.deleteDomainObjects(FavoritesFunctionalMenuItem.class, "menu_id='" + menuId + "'", null);
\r
465 private Boolean parentMenuIdEqual(Integer menuId1, Integer menuId2) {
\r
466 return ((menuId1 == null && menuId2 == null) || (menuId1 != null && menuId1.equals(menuId2)));
\r
469 private void updateColumnForSiblings(Session localSession, Long menuId, Integer oldParentMenuId,
\r
470 Integer newParentMenuId, Integer oldColumn, Integer newColumn) {
\r
471 logger.debug(EELFLoggerDelegate.debugLogger, "entering updateColumnForSiblings");
\r
472 Criteria criteria = localSession.createCriteria(FunctionalMenuItem.class);
\r
473 criteria.add(Restrictions.ne("menuId", menuId));
\r
474 if (parentMenuIdEqual(oldParentMenuId, newParentMenuId)) {
\r
475 logger.debug(EELFLoggerDelegate.debugLogger, "moving under the same parent");
\r
476 // We are moving to a new position under the same parent
\r
477 if (newParentMenuId == null) {
\r
478 logger.debug(EELFLoggerDelegate.debugLogger, "newParentMenuId is null, so using isNull");
\r
479 criteria.add(Restrictions.isNull("parentMenuId"));
\r
481 logger.debug(EELFLoggerDelegate.debugLogger, "newParentMenuId is NOT null, so using eq");
\r
482 criteria.add(Restrictions.eq("parentMenuId", newParentMenuId));
\r
484 if (oldColumn > newColumn) {
\r
485 logger.debug(EELFLoggerDelegate.debugLogger, "moving to a lower column under the same parent");
\r
486 // We are moving to a lower column under the same parent
\r
487 criteria.add(Restrictions.ge("column", newColumn));
\r
488 criteria.add(Restrictions.lt("column", oldColumn));
\r
489 @SuppressWarnings("unchecked")
\r
490 List<FunctionalMenuItem> menuItems = criteria.list();
\r
491 for (FunctionalMenuItem menuItem : menuItems) {
\r
492 menuItem.column += 1;
\r
493 localSession.save(menuItem);
\r
495 } else if (oldColumn < newColumn) {
\r
496 logger.debug(EELFLoggerDelegate.debugLogger, "moving to a higher column under the same parent");
\r
497 // We are moving to a higher column under the same parent
\r
498 criteria.add(Restrictions.gt("column", oldColumn));
\r
499 criteria.add(Restrictions.le("column", newColumn));
\r
500 @SuppressWarnings("unchecked")
\r
501 List<FunctionalMenuItem> menuItems = criteria.list();
\r
502 for (FunctionalMenuItem menuItem : menuItems) {
\r
503 menuItem.column -= 1;
\r
504 localSession.save(menuItem);
\r
507 // No info has changed
\r
508 logger.debug(EELFLoggerDelegate.debugLogger, "no info has changed, so we are not moving");
\r
511 logger.debug(EELFLoggerDelegate.debugLogger, "moving under a new parent");
\r
512 // We are moving under a new parent.
\r
514 // Adjust the children under the old parent
\r
515 logger.debug(EELFLoggerDelegate.debugLogger, "about to adjust the children under the old parent");
\r
517 // If the parentId is null, must check for its children differently
\r
518 if (oldParentMenuId == null) {
\r
519 logger.debug(EELFLoggerDelegate.debugLogger, "oldParentMenuId is null, so using isNull");
\r
520 criteria.add(Restrictions.isNull("parentMenuId"));
\r
522 logger.debug(EELFLoggerDelegate.debugLogger, "oldParentMenuId is NOT null, so using eq");
\r
523 criteria.add(Restrictions.eq("parentMenuId", oldParentMenuId));
\r
526 criteria.add(Restrictions.gt("column", oldColumn));
\r
527 @SuppressWarnings("unchecked")
\r
528 List<FunctionalMenuItem> menuItems1 = criteria.list();
\r
529 for (FunctionalMenuItem menuItem : menuItems1) {
\r
530 menuItem.column -= 1;
\r
531 localSession.save(menuItem);
\r
533 // Adjust the children under the new parent.
\r
534 logger.debug(EELFLoggerDelegate.debugLogger, "about to adjust the children under the new parent");
\r
535 logger.debug(EELFLoggerDelegate.debugLogger, "get all menu items where menuId!=" + menuId + "; parentMenuId==" + newParentMenuId
\r
536 + "; column>=" + newColumn);
\r
537 criteria = localSession.createCriteria(FunctionalMenuItem.class);
\r
538 criteria.add(Restrictions.ne("menuId", menuId));
\r
539 if (newParentMenuId == null) {
\r
540 logger.debug(EELFLoggerDelegate.debugLogger, "newParentMenuId is null, so using isNull");
\r
541 criteria.add(Restrictions.isNull("parentMenuId"));
\r
543 logger.debug(EELFLoggerDelegate.debugLogger, "newParentMenuId is NOT null, so using eq");
\r
544 criteria.add(Restrictions.eq("parentMenuId", newParentMenuId));
\r
547 criteria.add(Restrictions.ge("column", newColumn));
\r
548 @SuppressWarnings("unchecked")
\r
549 List<FunctionalMenuItem> menuItems2 = criteria.list();
\r
550 if (menuItems2 != null) {
\r
551 logger.debug(EELFLoggerDelegate.debugLogger, "found " + menuItems2.size() + " menu items");
\r
553 logger.debug(EELFLoggerDelegate.debugLogger, "found null menu items");
\r
555 for (FunctionalMenuItem menuItem : menuItems2) {
\r
556 menuItem.column += 1;
\r
557 localSession.save(menuItem);
\r
560 logger.debug(EELFLoggerDelegate.debugLogger, "done with updateColumnForSiblings");
\r
563 public void removeAppInfo(Session localSession, Long menuId) {
\r
564 // Remove the url, role, and app info from a menu item
\r
565 FunctionalMenuItem menuItem = (FunctionalMenuItem) localSession.get(FunctionalMenuItem.class, menuId);
\r
567 deleteRoles(menuId);
\r
570 public FieldsValidator editFunctionalMenuItem(FunctionalMenuItemWithRoles menuItemJson) {
\r
571 boolean result = false;
\r
572 Session localSession = null;
\r
573 Transaction transaction = null;
\r
574 Long menuId = menuItemJson.menuId;
\r
576 logger.debug(EELFLoggerDelegate.debugLogger, "LR: editFunctionalMenuItem: test 1");
\r
577 FieldsValidator fieldsValidator = menuItemFieldsChecker(menuItemJson);
\r
578 if (fieldsValidator.httpStatusCode.intValue() == HttpServletResponse.SC_OK) {
\r
579 // TODO: make sure menuId is here. And, it might not already exist
\r
581 if (menuId == null) {
\r
582 fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_BAD_REQUEST);
\r
583 logger.error(EELFLoggerDelegate.errorLogger, "FunctionalMenuServiceImpl.editFunctionalMenuItem: bad request");
\r
585 // To simplify the code, assume we will have a transaction
\r
587 localSession = sessionFactory.openSession();
\r
588 transaction = localSession.beginTransaction();
\r
590 // Get the existing info associated with menuItem from the DB
\r
591 FunctionalMenuItem menuItem = (FunctionalMenuItem) localSession.get(FunctionalMenuItem.class, menuId);
\r
592 Integer oldColumn = menuItem.column;
\r
593 Integer oldParentMenuId = menuItem.parentMenuId;
\r
594 Integer newColumn = menuItemJson.column;
\r
595 Integer newParentMenuId = menuItemJson.parentMenuId;
\r
597 logger.debug(EELFLoggerDelegate.debugLogger, "prev info: column: " + oldColumn + "; parentMenuId: " + oldParentMenuId);
\r
599 if (menuItemJson.appid != null && menuItemJson.getRoles() != null && !menuItemJson.getRoles().isEmpty()
\r
600 && menuItemJson.url != null && !menuItemJson.url.isEmpty() && menuItemJson.text != null
\r
601 && !menuItemJson.text.isEmpty()) {
\r
602 // Scenario: appid, roles, url and text are all non-null.
\r
603 // This menu item is associated with an app.
\r
604 // (Note: this should only occur for a bottom-level menu
\r
605 // item with no children.)
\r
606 // 1) Remove all the records from fn_menu_functional_role
\r
607 // for this menuId.
\r
608 // 2) Add records to the fn_menu_function_role table for the
\r
609 // appId and each roleId
\r
610 // 3) Update the url and text for this menu item.
\r
612 // Because of foreign key constraints, delete the roles,
\r
613 // then update the menuItem then add the roles.
\r
614 deleteRoles(menuId);
\r
615 // Assumption: this is not a Move, so don't change the
\r
616 // parentMenuId and column.
\r
617 menuItem.appid = menuItemJson.appid;
\r
618 menuItem.setRoles(menuItemJson.getRoles());
\r
619 menuItem.url = menuItemJson.url;
\r
620 menuItem.text = menuItemJson.text;
\r
622 // If the app is disabled, deactivate the menu item.
\r
623 Long appidLong = Long.valueOf(menuItemJson.appid);
\r
624 EPApp app = (EPApp) localSession.get(EPApp.class, appidLong);
\r
625 if (app != null && ! app.getEnabled()) {
\r
626 menuItem.active_yn = "N";
\r
628 menuItem.active_yn = "Y";
\r
632 localSession.update(menuItem);
\r
633 addRoles(menuItemJson, localSession);
\r
635 } else if (menuItemJson.appid == null && (menuItemJson.getRoles() == null || menuItemJson.getRoles().isEmpty())
\r
636 && (menuItemJson.url == null || menuItemJson.url.isEmpty()) && menuItemJson.text != null
\r
637 && !menuItemJson.text.isEmpty()) {
\r
638 // Scenario: appid, roles and url are all null; text is
\r
640 // This menu item is NOT associated with an app.
\r
641 // 1) Remove all the records from fn_menu_functional_role
\r
643 // (in case it was previously associated with an app).
\r
644 // 2) Update the text for this menu item.
\r
645 // 3) Set the url to ""
\r
646 deleteRoles(menuId);
\r
647 // Assumption: this is not a Move, so don't change the
\r
648 // parentMenuId and column.
\r
649 menuItem.text = menuItemJson.text;
\r
651 menuItem.active_yn = "Y";
\r
652 localSession.update(menuItem);
\r
654 } else if (newColumn != null) {
\r
655 // This is a "move" request.
\r
656 // Menu item has been moved to a different position under
\r
657 // the same parent, or under a new parent.
\r
658 logger.debug(EELFLoggerDelegate.debugLogger, "Doing a move operation.");
\r
659 if (parentMenuIdEqual(oldParentMenuId, newParentMenuId)) {
\r
660 // The parent is the same. We have just changed the
\r
662 logger.debug(EELFLoggerDelegate.debugLogger, "moving under the same parent");
\r
663 menuItem.column = newColumn;
\r
664 localSession.update(menuItem);
\r
666 logger.debug(EELFLoggerDelegate.debugLogger, "moving under a different parent");
\r
667 menuItem.parentMenuId = newParentMenuId;
\r
668 menuItem.column = newColumn;
\r
669 localSession.update(menuItem);
\r
670 // If we are moving under a new parent, must delete any
\r
671 // app/role info from
\r
672 // the new parent, since it is no longer a leaf menu
\r
673 // item and cannot have app info
\r
674 // associated with it. The front end will have warned
\r
675 // the user and gotten confirmation.
\r
676 if (menuItemJson.parentMenuId != null) {
\r
677 Long parentMenuIdLong = new Long(menuItemJson.parentMenuId);
\r
678 removeAppInfo(localSession, parentMenuIdLong);
\r
679 // deleteRoles(parentMenuIdLong);
\r
682 // must update the column for all old and new sibling menu
\r
684 updateColumnForSiblings(localSession, menuId, oldParentMenuId, newParentMenuId, oldColumn,
\r
688 transaction.commit();
\r
689 logger.debug(EELFLoggerDelegate.debugLogger, "LR: editFunctionalMenuItem: finished committing transaction");
\r
691 } catch (Exception e) {
\r
692 EcompPortalUtils.rollbackTransaction(transaction,
\r
693 "createFunctionalMenuItem rollback, exception = " + e);
\r
694 logger.error(EELFLoggerDelegate.errorLogger, EcompPortalUtils.getStackTrace(e));
\r
696 EcompPortalUtils.closeLocalSession(localSession, "editFunctionalMenuItem");
\r
701 logger.debug(EELFLoggerDelegate.debugLogger, "LR: createFunctionalMenuItem: no result. setting httpStatusCode to "
\r
702 + HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
\r
703 fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
\r
708 return fieldsValidator;
\r
711 public FieldsValidator deleteFunctionalMenuItem(Long menuId) {
\r
712 FieldsValidator fieldsValidator = new FieldsValidator();
\r
713 logger.debug(EELFLoggerDelegate.debugLogger, "LR: deleteFunctionalMenuItem: test 1");
\r
714 boolean result = false;
\r
715 Session localSession = null;
\r
716 Transaction transaction = null;
\r
719 localSession = sessionFactory.openSession();
\r
720 transaction = localSession.beginTransaction();
\r
721 // We must turn off foreign keys before deleting a menu item. Otherwise there will be a
\r
722 // constraint violation from the ancestors table.
\r
723 setForeignKeys(localSession, false);
\r
724 deleteRoles(menuId);
\r
725 logger.debug(EELFLoggerDelegate.debugLogger, "deleteFunctionalMenuItem: after deleting roles");
\r
726 deleteFavorites(menuId);
\r
727 logger.debug(EELFLoggerDelegate.debugLogger, "deleteFunctionalMenuItem: after deleting favorites");
\r
728 localSession.delete(localSession.get(FunctionalMenuItem.class, menuId));
\r
729 logger.debug(EELFLoggerDelegate.debugLogger, "deleteFunctionalMenuItem: about to commit");
\r
730 transaction.commit();
\r
732 } catch (Exception e) {
\r
733 EcompPortalUtils.rollbackTransaction(transaction,
\r
734 "deleteFunctionalMenuItem rollback, exception = " + e);
\r
735 logger.error(EELFLoggerDelegate.errorLogger, EcompPortalUtils.getStackTrace(e));
\r
737 EcompPortalUtils.closeLocalSession(localSession, "deleteFunctionalMenuItem");
\r
741 logger.debug(EELFLoggerDelegate.debugLogger, "LR: deleteFunctionalMenuItem: no result. setting httpStatusCode to "
\r
742 + HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
\r
743 fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
\r
745 return fieldsValidator;
\r
748 // Regenerate the fn_menu_functional_ancestors table, which is used
\r
749 // by the queries that return the functional menu items.
\r
750 public FieldsValidator regenerateAncestorTable() {
\r
751 FieldsValidator fieldsValidator = new FieldsValidator();
\r
752 Session localSession = null;
\r
753 Transaction transaction = null;
\r
756 localSession = sessionFactory.openSession();
\r
757 transaction = localSession.beginTransaction();
\r
758 String sql = "DELETE FROM fn_menu_functional_ancestors";
\r
760 Query query = localSession.createSQLQuery(sql);
\r
761 query.executeUpdate();
\r
762 logger.debug(EELFLoggerDelegate.debugLogger, "regenerateAncestorTable: finished query 1");
\r
764 sql = "ALTER TABLE fn_menu_functional_ancestors AUTO_INCREMENT=1";
\r
766 query = localSession.createSQLQuery(sql);
\r
767 query.executeUpdate();
\r
768 logger.debug(EELFLoggerDelegate.debugLogger, "regenerateAncestorTable: reset AUTO_INCREMENT to 1");
\r
771 sql = "INSERT INTO fn_menu_functional_ancestors(menu_id, ancestor_menu_id, depth) "
\r
772 + "SELECT m.menu_id, m.menu_id, " + depth + " FROM fn_menu_functional m";
\r
774 query = localSession.createSQLQuery(sql);
\r
775 query.executeUpdate();
\r
776 logger.debug(EELFLoggerDelegate.debugLogger, "regenerateAncestorTable: finished query 2");
\r
777 for (depth = 0; depth < 3; depth++) {
\r
778 int depthPlusOne = depth + 1;
\r
779 sql = "INSERT INTO fn_menu_functional_ancestors(menu_id, ancestor_menu_id, depth) "
\r
780 + " SELECT a.menu_id, m.parent_menu_id, " + depthPlusOne
\r
781 + " FROM fn_menu_functional m, fn_menu_functional_ancestors a " + " WHERE a.depth='" + depth
\r
782 + "' AND " + " a.ancestor_menu_id = m.menu_id AND " + " m.parent_menu_id != '-1'";
\r
784 query = localSession.createSQLQuery(sql);
\r
785 query.executeUpdate();
\r
787 logger.debug(EELFLoggerDelegate.debugLogger, "regenerateAncestorTable: finished query 3");
\r
788 transaction.commit();
\r
789 } catch (Exception e) {
\r
790 EcompPortalUtils.rollbackTransaction(transaction,
\r
791 "regenerateAncestorTable rollback, exception = " + e);
\r
792 logger.error(EELFLoggerDelegate.errorLogger, EcompPortalUtils.getStackTrace(e));
\r
793 fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
\r
795 EcompPortalUtils.closeLocalSession(localSession, "regenerateAncestorTable");
\r
797 return fieldsValidator;
\r
800 private void logQuery(String sql) {
\r
801 logger.debug(EELFLoggerDelegate.debugLogger, "Executing query: " + sql);
\r
804 public FieldsValidator setFavoriteItem(FavoritesFunctionalMenuItem menuItemJson) {
\r
805 boolean result = false;
\r
806 FieldsValidator fieldsValidator = new FieldsValidator();
\r
808 Session localSession = null;
\r
809 Transaction transaction = null;
\r
812 logger.debug(EELFLoggerDelegate.debugLogger, String.format("Before adding favorite for user id:{0} and menu id:{1} ",menuItemJson.userId,menuItemJson.menuId));
\r
813 localSession = sessionFactory.openSession();
\r
814 transaction = localSession.beginTransaction();
\r
815 localSession.save(menuItemJson);
\r
816 transaction.commit();
\r
818 logger.debug(EELFLoggerDelegate.debugLogger, String.format("After adding favorite for user id:{0} and menu id:{1} ",menuItemJson.userId,menuItemJson.menuId));
\r
819 } catch (Exception e) {
\r
820 EcompPortalUtils.rollbackTransaction(transaction,"setFavoriteItem rollback, exception = " + e);
\r
821 logger.error(EELFLoggerDelegate.errorLogger, EcompPortalUtils.getStackTrace(e));
\r
823 EcompPortalUtils.closeLocalSession(localSession, "setFavoriteItem");
\r
829 fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
\r
832 return fieldsValidator;
\r
835 public List<FavoritesFunctionalMenuItemJson> getFavoriteItems(Long userId) {
\r
837 logger.debug(EELFLoggerDelegate.debugLogger, "Before getting favorites for user id: " + userId);
\r
839 // Divide this into 2 queries: one which returns the favorites items associated with Restricted apps,
\r
840 // and one that returns all the other favorites items. Then we can easily add the boolean flag
\r
841 // restrictedApp to each FavoritesFunctionalMenuItemJson, to be used by the front end.
\r
843 String sql = "SELECT f.user_id,f.menu_id,m.text,m.url "
\r
844 + " FROM fn_menu_favorites f, fn_menu_functional m, fn_menu_functional_roles mr "
\r
845 + " WHERE f.user_id='" + userId + "' AND f.menu_id = m.menu_id "
\r
846 + " AND f.menu_id = mr.menu_id "
\r
847 + " AND mr.role_id = '" + RESTRICTED_APP_ROLE_ID + "' ";
\r
849 @SuppressWarnings("unchecked")
\r
850 List<FavoritesFunctionalMenuItemJson> menuItems = dataAccessService.executeSQLQuery(sql, FavoritesFunctionalMenuItemJson.class, null);
\r
851 for (FavoritesFunctionalMenuItemJson menuItem : menuItems) {
\r
852 menuItem.restrictedApp = true;
\r
855 sql = "SELECT DISTINCT f.user_id,f.menu_id,m.text,m.url "
\r
856 + " FROM fn_menu_favorites f, fn_menu_functional m, fn_menu_functional_roles mr "
\r
857 + " WHERE f.user_id='" + userId + "' AND f.menu_id = m.menu_id "
\r
858 + " AND f.menu_id = mr.menu_id "
\r
859 + " AND mr.role_id != '" + RESTRICTED_APP_ROLE_ID + "' ";
\r
860 @SuppressWarnings("unchecked")
\r
861 List<FavoritesFunctionalMenuItemJson> menuItems2 = dataAccessService.executeSQLQuery(sql, FavoritesFunctionalMenuItemJson.class, null);
\r
862 for (FavoritesFunctionalMenuItemJson menuItem : menuItems2) {
\r
863 menuItem.restrictedApp = false;
\r
864 menuItems.add(menuItem);
\r
868 } catch (Exception e) {
\r
869 logger.error(EELFLoggerDelegate.errorLogger, "Exception occurred in FunctionalMenuServiceImpl.getFavoriteItems. Details: " + EcompPortalUtils.getStackTrace(e));
\r
870 List<FavoritesFunctionalMenuItemJson> menuItems = new ArrayList<FavoritesFunctionalMenuItemJson>();
\r
875 public FieldsValidator removeFavoriteItem(Long userId, Long menuId) {
\r
876 boolean result = false;
\r
877 FieldsValidator fieldsValidator = new FieldsValidator();
\r
879 Session localSession = null;
\r
880 Transaction transaction = null;
\r
884 FavoritesFunctionalMenuItem menuItemJson = new FavoritesFunctionalMenuItem();
\r
885 menuItemJson.userId = userId;
\r
886 menuItemJson.menuId = menuId;
\r
888 localSession = sessionFactory.openSession();
\r
889 transaction = localSession.beginTransaction();
\r
890 localSession.delete(menuItemJson);
\r
891 localSession.flush();
\r
892 transaction.commit();
\r
894 logger.debug(EELFLoggerDelegate.debugLogger, String.format("After removing favorite for user id: " + userId + "; menu id: " + menuId));
\r
895 } catch (Exception e) {
\r
896 EcompPortalUtils.rollbackTransaction(transaction,"removeFavoriteItem rollback, exception = " + e);
\r
897 logger.error(EELFLoggerDelegate.errorLogger, EcompPortalUtils.getStackTrace(e));
\r
899 EcompPortalUtils.closeLocalSession(localSession, "removeFavoriteItem");
\r
905 fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
\r
908 return fieldsValidator;
\r
912 public void assignHelpURLs(List<FunctionalMenuItem> menuItems) {
\r
914 String user_guide_link = SystemProperties.getProperty(EPCommonSystemProperties.USER_GUIDE_URL);
\r
916 for(FunctionalMenuItem menuItem: menuItems){
\r
917 if(menuItem.text.equalsIgnoreCase("Contact Us")){
\r
918 menuItem.setUrl("contactUs");
\r
919 //menuItem.setRestrictedApp(true);
\r
921 if(menuItem.text.equalsIgnoreCase("Get Access")) {
\r
922 menuItem.setUrl("getAccess");
\r
924 if(menuItem.text.equalsIgnoreCase("User Guide")) {
\r
925 menuItem.setUrl(user_guide_link);
\r
926 menuItem.setRestrictedApp(true);
\r
929 } catch (Exception e) {
\r
930 logger.error(EELFLoggerDelegate.errorLogger, "assignHelpURLs process failed. Details: " + EcompPortalUtils.getStackTrace(e));
\r
935 public List<FunctionalMenuRole> getFunctionalMenuRole() {
\r
936 String sql = "SELECT * from fn_menu_functional_roles";
\r
938 logger.debug(EELFLoggerDelegate.debugLogger, "getFunctionalMenuRole: logged the query");
\r
940 @SuppressWarnings("unchecked")
\r
941 List<FunctionalMenuRole> functionalMenuRole = dataAccessService.executeSQLQuery(sql, FunctionalMenuRole.class, null);
\r
943 return functionalMenuRole;
\r
946 @SuppressWarnings("unchecked")
\r
948 public List<BusinessCardApplicationRole> getUserAppRolesList(String userId) {
\r
949 Map<String, String> params = new HashMap<>();
\r
950 params.put("userId", userId);
\r
952 List<BusinessCardApplicationRole> userAppRoles = null;
\r
954 userAppRoles = dataAccessService
\r
955 .executeNamedQuery("getUserApproles", params, null);
\r
956 } catch (Exception e) {
\r
957 // TODO Auto-generated catch block
\r
958 logger.error(EELFLoggerDelegate.errorLogger, "getUserAppRolesList failed", e);
\r
960 return userAppRoles;
\r