2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
7 * Modification Copyright © 2020 IBM.
8 * ===================================================================
10 * Unless otherwise specified, all software contained herein is licensed
11 * under the Apache License, Version 2.0 (the "License");
12 * you may not use this software except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * Unless otherwise specified, all documentation contained herein is licensed
24 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
25 * you may not use this documentation except in compliance with the License.
26 * You may obtain a copy of the License at
28 * https://creativecommons.org/licenses/by/4.0/
30 * Unless required by applicable law or agreed to in writing, documentation
31 * distributed under the License is distributed on an "AS IS" BASIS,
32 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33 * See the License for the specific language governing permissions and
34 * limitations under the License.
36 * ============LICENSE_END============================================
40 package org.onap.portalapp.portal.controller;
42 import java.io.IOException;
43 import java.text.SimpleDateFormat;
44 import java.util.ArrayList;
45 import java.util.Collections;
46 import java.util.Comparator;
47 import java.util.Date;
48 import java.util.HashMap;
49 import java.util.List;
52 import javax.servlet.http.HttpServletRequest;
53 import javax.servlet.http.HttpServletResponse;
54 import javax.ws.rs.core.Response;
56 import org.json.JSONObject;
57 import org.onap.portalapp.controller.EPRestrictedBaseController;
58 import org.onap.portalapp.portal.domain.EPUser;
59 import org.onap.portalapp.portal.domain.SharedContext;
60 import org.onap.portalapp.portal.ecomp.model.PortalRestResponse;
61 import org.onap.portalapp.portal.ecomp.model.PortalRestStatusEnum;
62 import org.onap.portalapp.portal.logging.aop.EPAuditLog;
63 import org.onap.portalapp.portal.service.AdminRolesService;
64 import org.onap.portalapp.portal.service.FunctionalMenuService;
65 import org.onap.portalapp.portal.service.SearchService;
66 import org.onap.portalapp.portal.service.SharedContextService;
67 import org.onap.portalapp.portal.transport.BusinessCardApplicationRole;
68 import org.onap.portalapp.portal.transport.BusinessCardApplicationRolesList;
69 import org.onap.portalapp.portal.transport.FavoritesFunctionalMenuItem;
70 import org.onap.portalapp.portal.transport.FavoritesFunctionalMenuItemJson;
71 import org.onap.portalapp.portal.transport.FieldsValidator;
72 import org.onap.portalapp.portal.transport.FunctionalMenuItem;
73 import org.onap.portalapp.portal.transport.FunctionalMenuItemWithRoles;
74 import org.onap.portalapp.portal.utils.EPCommonSystemProperties;
75 import org.onap.portalapp.portal.utils.EcompPortalUtils;
76 import org.onap.portalapp.util.EPUserUtils;
77 import org.onap.portalapp.validation.DataValidator;
78 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
79 import org.onap.portalsdk.core.util.SystemProperties;
80 import org.onap.portalsdk.core.web.support.UserUtils;
81 import org.springframework.beans.factory.annotation.Autowired;
82 import org.springframework.context.annotation.Configuration;
83 import org.springframework.context.annotation.EnableAspectJAutoProxy;
84 import org.springframework.web.bind.annotation.PathVariable;
85 import org.springframework.web.bind.annotation.RequestBody;
86 import org.springframework.web.bind.annotation.RequestMapping;
87 import org.springframework.web.bind.annotation.GetMapping;
88 import org.springframework.web.bind.annotation.PostMapping;
89 import org.springframework.web.bind.annotation.PutMapping;
90 import org.springframework.web.bind.annotation.DeleteMapping;
91 import org.springframework.web.bind.annotation.RequestMethod;
92 import org.springframework.web.bind.annotation.RequestParam;
93 import org.springframework.web.bind.annotation.RestController;
96 * Supports menus at the top of the Portal app landing page.
100 @EnableAspectJAutoProxy
102 public class FunctionalMenuController extends EPRestrictedBaseController {
104 private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(FunctionalMenuController.class);
105 private final DataValidator dataValidator = new DataValidator();
108 private AdminRolesService adminRolesService;
110 private FunctionalMenuService functionalMenuService;
112 private SharedContextService sharedContextService;
114 private SearchService searchService;
117 * RESTful service method to fetch all the FunctionalMenuItems.
122 * HttpServletResponse
123 * @return List of FunctionalMenuItem objects
125 @GetMapping(value = { "/portalApi/functionalMenu" }, produces = "application/json")
126 public List<FunctionalMenuItem> getMenuItems(HttpServletRequest request, HttpServletResponse response) {
127 // TODO: should only the superuser be allowed to use this API?
128 List<FunctionalMenuItem> menuItems = null;
130 menuItems = functionalMenuService.getFunctionalMenuItems();
131 functionalMenuService.assignHelpURLs(menuItems);
132 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/functionalMenu", "result =", menuItems);
133 } catch (Exception e) {
134 logger.error(EELFLoggerDelegate.errorLogger, "getMenuItems failed", e);
140 * RESTful service method to get ONAP Portal Title.
145 * HttpServletResponse
146 * @return PortalRestResponse of ONAP portal title
148 @GetMapping(value = { "/portalApi/ecompTitle" }, produces = "application/json")
149 public PortalRestResponse<String> getECOMPTitle(HttpServletRequest request, HttpServletResponse response) {
150 PortalRestResponse<String> portalRestResponse = null;
152 String ecompTitle = SystemProperties.getProperty(SystemProperties.APP_DISPLAY_NAME);
153 portalRestResponse = new PortalRestResponse<String>(PortalRestStatusEnum.OK, "success", ecompTitle);
154 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/ecompTitle", "result =", ecompTitle);
155 } catch (Exception e) {
156 portalRestResponse = new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), null);
157 logger.error(EELFLoggerDelegate.errorLogger, "getEcompTitle failed", e);
159 return portalRestResponse;
163 * RESTful service method to fetch all the FunctionalMenuItems, both active and
164 * inactive, for the EditFunctionalMenu feature. Can only be accessed by the
170 * HttpServletResponse
171 * @return List of FunctionalMenuItem objects
173 @GetMapping(value = {
174 "/portalApi/functionalMenuForEditing" }, produces = "application/json")
175 public List<FunctionalMenuItem> getMenuItemsForEditing(HttpServletRequest request, HttpServletResponse response) {
176 // TODO: should only the superuser be allowed to use this API?
177 EPUser user = EPUserUtils.getUserSession(request);
178 List<FunctionalMenuItem> menuItems = null;
180 if (!adminRolesService.isSuperAdmin(user)) {
181 EcompPortalUtils.setBadPermissions(user, response, "getFunctionalMenuItemDetails");
183 menuItems = functionalMenuService.getFunctionalMenuItems(true);
185 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/functionalMenuForEditing", "result =",
187 } catch (Exception e) {
188 logger.error(EELFLoggerDelegate.errorLogger, "getMenuItemsForEditing failed", e);
194 * RESTful service method to fetch all the FunctionalMenuItems, active , for the
195 * Functional menu in notification Tree feature.
200 * HttpServletResponse
201 * @return List of FunctionalMenuItem objects
203 @GetMapping(value = {
204 "/portalApi/functionalMenuForNotificationTree" }, produces = "application/json")
205 public List<FunctionalMenuItem> getMenuItemsForNotifications(HttpServletRequest request,
206 HttpServletResponse response) {
207 // TODO: should only the superuser be allowed to use this API?
208 // EPUser user = EPUserUtils.getUserSession(request);
209 List<FunctionalMenuItem> menuItems = null;
211 menuItems = functionalMenuService.getFunctionalMenuItemsForNotificationTree(true);
212 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/functionalMenuForNotificationTree", "result =",
214 } catch (Exception e) {
215 logger.error(EELFLoggerDelegate.errorLogger, "getMenuItemsForNotifications failed", e);
221 * RESTful service method to fetch all FunctionalMenuItems associated with an
228 * @return List of FunctionalMenuItem objects
230 @GetMapping(value = {
231 "/portalApi/functionalMenuForApp/{appId}" }, produces = "application/json")
232 public List<FunctionalMenuItem> getMenuItemsForApp(HttpServletRequest request,
233 @PathVariable("appId") Integer appId) {
234 // TODO: should only the superuser be allowed to use this API?
235 List<FunctionalMenuItem> menuItems = null;
237 menuItems = functionalMenuService.getFunctionalMenuItemsForApp(appId);
238 functionalMenuService.assignHelpURLs(menuItems);
239 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/functionalMenuForApp/" + appId, "result =",
241 } catch (Exception e) {
242 logger.error(EELFLoggerDelegate.errorLogger, "getMenuItemsForApp failed", e);
248 * RESTful service method to fetch all FunctionalMenuItems associated with the
249 * applications and roles that a user has access to.
255 * @return List of FunctionalMenuItem objects
257 @GetMapping(value = {
258 "/portalApi/functionalMenuForUser/{orgUserId}" }, produces = "application/json")
259 public List<FunctionalMenuItem> getMenuItemsForUser(HttpServletRequest request,
260 @PathVariable("orgUserId") String orgUserId) {
261 // TODO: should only the superuser be allowed to use this API?
262 List<FunctionalMenuItem> menuItems = null;
264 menuItems = functionalMenuService.getFunctionalMenuItemsForUser(orgUserId);
265 functionalMenuService.assignHelpURLs(menuItems);
266 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/functionalMenuForUser/" + orgUserId, "result =",
268 } catch (Exception e) {
269 logger.error(EELFLoggerDelegate.errorLogger, "getMenuItemsForUser failed", e);
276 * RESTful service method to fetch all FunctionalMenuItems associated with the
277 * applications and roles that the authenticated user has access to.
282 * HttpServletResponse
283 * @return List of FunctionalMenuItem objects
285 @GetMapping(value = {
286 "/portalApi/functionalMenuForAuthUser" }, produces = "application/json")
287 public List<FunctionalMenuItem> getMenuItemsForAuthUser(HttpServletRequest request, HttpServletResponse response) {
289 EPUser user = EPUserUtils.getUserSession(request);
290 List<FunctionalMenuItem> menuItems = null;
293 EcompPortalUtils.setBadPermissions(user, response, "getMenuItemsForAuthUser");
294 } else if (adminRolesService.isSuperAdmin(user)) {
295 menuItems = functionalMenuService.getFunctionalMenuItems();
297 // calculate the menu items
298 String orgUserId = user.getOrgUserId();
299 menuItems = functionalMenuService.getFunctionalMenuItemsForUser(orgUserId);
300 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/functionalMenuForUser/" + orgUserId,
301 "result =", menuItems);
303 functionalMenuService.assignHelpURLs(menuItems);
304 } catch (Exception e) {
305 logger.error(EELFLoggerDelegate.errorLogger, "getMenuItemsForAuthUser failed", e);
311 * RESTful service method to fetch the details for a functional menu item.
312 * Requirement: you must be the ONAP portal super admin user.
317 * HttpServletResponse
320 * @return FunctionalMenuItem object
322 @GetMapping(value = {
323 "/portalApi/functionalMenuItemDetails/{menuId}" }, produces = "application/json")
324 public FunctionalMenuItem getFunctionalMenuItemDetails(HttpServletRequest request,
325 @PathVariable("menuId") Long menuId, HttpServletResponse response) {
326 // TODO: return FunctionalMenuItemJson
327 // TODO: modify FunctionalMenuItem to not include the transient fields
328 FunctionalMenuItem menuItem = null;
330 EPUser user = EPUserUtils.getUserSession(request);
331 if (!adminRolesService.isSuperAdmin(user)) {
332 EcompPortalUtils.setBadPermissions(user, response, "getFunctionalMenuItemDetails");
334 menuItem = functionalMenuService.getFunctionalMenuItemDetails(menuId);
335 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/functionalMenuItemDetails/" + menuId,
336 "result =", menuItem);
338 } catch (Exception e) {
339 logger.error(EELFLoggerDelegate.errorLogger, "getFunctionalMenuItemDetails failed", e);
346 * RESTful service method to create a new menu item.
348 * Requirement: you must be the ONAP portal super admin user.
353 * HttpServletResponse
354 * @param menuItemJson
355 * FunctionalMenuItemWithRoles
356 * @return FieldsValidator
358 @PostMapping(value = { "/portalApi/functionalMenuItem" })
359 public FieldsValidator createFunctionalMenuItem(HttpServletRequest request,
360 @RequestBody FunctionalMenuItemWithRoles menuItemJson, HttpServletResponse response) {
361 EPUser user = EPUserUtils.getUserSession(request);
362 FieldsValidator fieldsValidator = null;
364 if(!dataValidator.isValid(menuItemJson)){
365 fieldsValidator = new FieldsValidator();
366 logger.warn(EELFLoggerDelegate.debugLogger,"FunctionalMenuController.createFunctionalMenuItem not valid object");
367 fieldsValidator.httpStatusCode = (long)HttpServletResponse.SC_NOT_ACCEPTABLE;
368 return fieldsValidator;
371 if (!adminRolesService.isSuperAdmin(user)) {
372 logger.debug(EELFLoggerDelegate.debugLogger,
373 "FunctionalMenuController.createFunctionalMenuItem bad permissions");
374 EcompPortalUtils.setBadPermissions(user, response, "createFunctionalMenuItem");
376 fieldsValidator = functionalMenuService.createFunctionalMenuItem(menuItemJson);
377 response.setStatus(fieldsValidator.httpStatusCode.intValue());
378 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/functionalMenuItem", "POST result =",
379 response.getStatus());
382 return fieldsValidator;
386 * RESTful service method to update an existing menu item
388 * Requirement: you must be the ONAP portal super admin user.
393 * HttpServletResponse
394 * @param menuItemJson
395 * FunctionalMenuItemWithRoles
396 * @return FieldsValidator
398 @PutMapping(value = { "/portalApi/functionalMenuItem" })
399 public FieldsValidator editFunctionalMenuItem(HttpServletRequest request,
400 @RequestBody FunctionalMenuItemWithRoles menuItemJson, HttpServletResponse response) {
401 EPUser user = EPUserUtils.getUserSession(request);
402 FieldsValidator fieldsValidator = null;
404 if(!dataValidator.isValid(menuItemJson)){
405 fieldsValidator = new FieldsValidator();
406 logger.warn(EELFLoggerDelegate.debugLogger,"FunctionalMenuController.createFunctionalMenuItem not valid object");
407 fieldsValidator.httpStatusCode = (long)HttpServletResponse.SC_NOT_ACCEPTABLE;
408 return fieldsValidator;
411 if (!adminRolesService.isSuperAdmin(user)) {
412 EcompPortalUtils.setBadPermissions(user, response, "editFunctionalMenuItem");
414 fieldsValidator = functionalMenuService.editFunctionalMenuItem(menuItemJson);
415 response.setStatus(fieldsValidator.httpStatusCode.intValue());
416 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/functionalMenuItem", "PUT result =",
417 response.getStatus());
420 return fieldsValidator;
424 * RESTful service method to delete a menu item
429 * HttpServletResponse
432 * @return FieldsValidator
434 @DeleteMapping(value = { "/portalApi/functionalMenuItem/{menuId}" })
435 public FieldsValidator deleteFunctionalMenuItem(HttpServletRequest request, @PathVariable("menuId") Long menuId,
436 HttpServletResponse response) {
437 EPUser user = EPUserUtils.getUserSession(request);
438 FieldsValidator fieldsValidator = null;
439 if (!adminRolesService.isSuperAdmin(user)) {
440 EcompPortalUtils.setBadPermissions(user, response, "deleteFunctionalMenuItem");
442 fieldsValidator = functionalMenuService.deleteFunctionalMenuItem(menuId);
443 response.setStatus(fieldsValidator.httpStatusCode.intValue());
444 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/functionalMenuItem", "DELETE result =",
445 response.getStatus());
448 return fieldsValidator;
452 * RESTful service to regenerate table
457 * HttpServletResponse
458 * @return FieldsValidator
460 @GetMapping(value = { "/portalApi/regenerateFunctionalMenuAncestors" })
461 public FieldsValidator regenerateAncestorTable(HttpServletRequest request, HttpServletResponse response) {
462 // TODO: should only the superuser be allowed to use this API?
463 EPUser user = EPUserUtils.getUserSession(request);
464 FieldsValidator fieldsValidator = null;
466 if (!adminRolesService.isSuperAdmin(user)) {
467 EcompPortalUtils.setBadPermissions(user, response, "deleteFunctionalMenuItem");
469 fieldsValidator = functionalMenuService.regenerateAncestorTable();
470 response.setStatus(fieldsValidator.httpStatusCode.intValue());
471 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/regenerateAncestorTable", "GET result =",
472 response.getStatus());
475 return fieldsValidator;
479 * RESful service to set a favorite item.
484 * HttpServletResponse
485 * @param menuItemJson
486 * FunctionalMenuItemWithRoles
487 * @return FieldsValidator
489 @PostMapping(value = { "/portalApi/setFavoriteItem" })
490 public FieldsValidator addFavoriteItem(HttpServletRequest request,
491 @RequestBody FavoritesFunctionalMenuItem menuItemJson, HttpServletResponse response) {
492 EPUser user = EPUserUtils.getUserSession(request);
493 FieldsValidator fieldsValidator = null;
494 menuItemJson.userId = user.getId();
495 fieldsValidator = functionalMenuService.setFavoriteItem(menuItemJson);
496 response.setStatus(fieldsValidator.httpStatusCode.intValue());
497 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/setFavoriteItem", "Post result =",
498 response.getStatus());
500 return fieldsValidator;
504 * RESTful service to get favorites for the current user as identified in the
510 * HttpServletResponse
511 * @return List of FavoritesFunctionalMenuItemJson
513 @GetMapping(value = {
514 "/portalApi/getFavoriteItems" }, produces = "application/json")
515 public List<FavoritesFunctionalMenuItemJson> getFavoritesForUser(HttpServletRequest request,
516 HttpServletResponse response) {
517 EPUser user = EPUserUtils.getUserSession(request);
518 List<FavoritesFunctionalMenuItemJson> favorites = functionalMenuService.getFavoriteItems(user.getId());
519 FieldsValidator fieldsValidator = new FieldsValidator();
520 response.setStatus(fieldsValidator.httpStatusCode.intValue());
521 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/getFavoriteItems", "GET result =",
522 response.getStatus());
527 * RESTful service to delete a favorite menu item for the current user as
528 * identified in the session.
533 * HttpServletResponse
536 * @return FieldsValidator
538 @DeleteMapping(value = { "/portalApi/removeFavoriteItem/{menuId}" })
539 public FieldsValidator deleteFavoriteItem(HttpServletRequest request, @PathVariable("menuId") Long menuId,
540 HttpServletResponse response) {
541 EPUser user = EPUserUtils.getUserSession(request);
542 FieldsValidator fieldsValidator = null;
543 Long userId = user.getId();
544 fieldsValidator = functionalMenuService.removeFavoriteItem(userId, menuId);
545 response.setStatus(fieldsValidator.httpStatusCode.intValue());
546 EcompPortalUtils.logAndSerializeObject(logger, "/deleteFavoriteItem", "DELETE result =", response.getStatus());
548 return fieldsValidator;
552 * RESTful service to get user information: user's first and last names, org
553 * user ID, email and last-login. (Actually has nothing to do with the real
554 * functional menu.) First attempts to get the information from the Tomcat
555 * session (i.e., the CSP cookie); if that fails, calls the shared context
556 * service to read the information from the database. Gives back what it found,
557 * any of which may be null, as a JSON collection.
562 * HttpServletResponse
563 * @return JSON collection of key-value pairs shown below.
565 @GetMapping(value = {
566 "/portalApi/functionalMenuStaticInfo" }, produces = "application/json")
567 public String getFunctionalMenuStaticInfo(HttpServletRequest request, HttpServletResponse response) {
569 // Get user details from session
570 logger.debug(EELFLoggerDelegate.debugLogger, "getFunctionalMenuStaticInfo: getting user info");
571 String fnMenuStaticResponse = null;
573 String orgUserIdStr = null;
574 String firstNameStr = null;
575 String lastNameStr = null;
576 String emailStr = null;
577 String lastLogin = null;
578 EPUser user = EPUserUtils.getUserSession(request);
579 firstNameStr = user.getFirstName();
580 lastNameStr = user.getLastName();
581 orgUserIdStr = user.getOrgUserId();
582 emailStr = user.getEmail();
583 if (emailStr == null || emailStr.equals("")) {
584 EPUser userResult = searchService.searchUserByUserId(orgUserIdStr);
585 emailStr = userResult.getEmail();
587 SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss Z a");
588 Date lastLoginDate = user.getLastLoginDate();
589 if (lastLoginDate == null) {
590 // should never happen
591 logger.error(EELFLoggerDelegate.errorLogger, "getFunctionalMenuStaticInfo: no last login in session");
592 lastLogin = "no last login available";
594 lastLogin = sdf.format(lastLoginDate);
597 // If any item is missing from session, try the Shared Context
599 SharedContext orgUserIdSC = null;
600 SharedContext firstNameSC = null;
601 SharedContext lastNameSC = null;
602 SharedContext emailSC = null;
603 String sessionId = request.getSession().getId();
604 if (firstNameStr == null)
605 firstNameSC = sharedContextService.getSharedContext(sessionId,
606 EPCommonSystemProperties.USER_FIRST_NAME);
607 if (lastNameStr == null)
608 lastNameSC = sharedContextService.getSharedContext(sessionId, EPCommonSystemProperties.USER_LAST_NAME);
609 if (emailStr == null)
610 emailSC = sharedContextService.getSharedContext(sessionId, EPCommonSystemProperties.USER_EMAIL);
611 if (orgUserIdStr == null)
612 orgUserIdSC = sharedContextService.getSharedContext(sessionId,
613 EPCommonSystemProperties.USER_ORG_USERID);
615 // Build the response
616 Map<String, String> map = new HashMap<String, String>();
618 firstNameStr != null ? firstNameStr : (firstNameSC != null ? firstNameSC.getCvalue() : null));
620 lastNameStr != null ? lastNameStr : (lastNameSC != null ? lastNameSC.getCvalue() : null));
621 map.put("email", emailStr != null ? emailStr : (emailSC != null ? emailSC.getCvalue() : null));
623 orgUserIdStr != null ? orgUserIdStr : (orgUserIdSC != null ? orgUserIdSC.getCvalue() : null));
624 map.put("last_login", lastLogin);
625 JSONObject j = new JSONObject(map);
626 fnMenuStaticResponse = j.toString();
627 // Be chatty in the log
628 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/functionalMenuStaticInfo", "GET result =",
629 fnMenuStaticResponse);
630 } catch (Exception e) {
631 // Should never happen.
632 logger.error(EELFLoggerDelegate.errorLogger, "getFunctionalMenuStaticInfo failed", e);
633 // Return a real error?
634 // fnMenuStaticResponse = "{ \"status\": \"error\", \"message\": \""
635 // + e.toString() + "\" }";
636 // But the angular controller expects null on error.
638 return fnMenuStaticResponse;
641 private Comparator<BusinessCardApplicationRole> getUserAppRolesComparator = new Comparator<BusinessCardApplicationRole>() {
642 public int compare(BusinessCardApplicationRole o1, BusinessCardApplicationRole o2) {
643 return o1.getAppName().compareTo(o2.getAppName());
653 * @return List<BusinessCardApplicationRolesList>
654 * @throws IOException
657 @GetMapping(value = {
658 "/portalApi/userApplicationRoles" }, produces = "application/json")
659 public List<BusinessCardApplicationRolesList> getAppList(HttpServletRequest request, HttpServletResponse response,
660 @RequestParam("userId") String userId) throws IOException {
662 List<BusinessCardApplicationRolesList> AppRoles = null;
664 if(!UserUtils.getUserSession(request).getOrgUserId().equalsIgnoreCase(userId)) {
665 logger.error(EELFLoggerDelegate.errorLogger, "Not authorized to view roles of others ");
666 response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
667 response.getWriter().flush();
672 List<BusinessCardApplicationRole> userAppRoleList = functionalMenuService.getUserAppRolesList(userId);
674 Collections.sort(userAppRoleList, getUserAppRolesComparator);
675 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/userApplicationRoles", "result =",
678 AppRoles = new ArrayList<BusinessCardApplicationRolesList>();
679 for (BusinessCardApplicationRole userAppRole : userAppRoleList) {
680 boolean found = false;
681 List<String> roles = null;
683 for (BusinessCardApplicationRolesList app : AppRoles) {
684 if (app.getAppName().equals(userAppRole.getAppName())) {
685 roles = app.getRoleNames();
686 roles.add(userAppRole.getRoleName());
687 app.setRoleNames(roles);
694 roles = new ArrayList<String>();
695 roles.add(userAppRole.getRoleName());
696 AppRoles.add(new BusinessCardApplicationRolesList(userAppRole.getAppName(), roles));
699 Collections.sort(roles);
701 } catch (Exception e) {
702 logger.error(EELFLoggerDelegate.errorLogger, "getAppList failed", e);