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.GetMapping;
87 import org.springframework.web.bind.annotation.PostMapping;
88 import org.springframework.web.bind.annotation.PutMapping;
89 import org.springframework.web.bind.annotation.DeleteMapping;
90 import org.springframework.web.bind.annotation.RequestParam;
91 import org.springframework.web.bind.annotation.RestController;
94 * Supports menus at the top of the Portal app landing page.
98 @EnableAspectJAutoProxy
100 public class FunctionalMenuController extends EPRestrictedBaseController {
102 private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(FunctionalMenuController.class);
103 private final DataValidator dataValidator = new DataValidator();
106 private AdminRolesService adminRolesService;
108 private FunctionalMenuService functionalMenuService;
110 private SharedContextService sharedContextService;
112 private SearchService searchService;
115 * RESTful service method to fetch all the FunctionalMenuItems.
120 * HttpServletResponse
121 * @return List of FunctionalMenuItem objects
123 @GetMapping(value = { "/portalApi/functionalMenu" }, produces = "application/json")
124 public List<FunctionalMenuItem> getMenuItems(HttpServletRequest request, HttpServletResponse response) {
125 // TODO: should only the superuser be allowed to use this API?
126 List<FunctionalMenuItem> menuItems = null;
128 menuItems = functionalMenuService.getFunctionalMenuItems();
129 functionalMenuService.assignHelpURLs(menuItems);
130 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/functionalMenu", "result =", menuItems);
131 } catch (Exception e) {
132 logger.error(EELFLoggerDelegate.errorLogger, "getMenuItems failed", e);
138 * RESTful service method to get ONAP Portal Title.
143 * HttpServletResponse
144 * @return PortalRestResponse of ONAP portal title
146 @GetMapping(value = { "/portalApi/ecompTitle" }, produces = "application/json")
147 public PortalRestResponse<String> getECOMPTitle(HttpServletRequest request, HttpServletResponse response) {
148 PortalRestResponse<String> portalRestResponse = null;
150 String ecompTitle = SystemProperties.getProperty(SystemProperties.APP_DISPLAY_NAME);
151 portalRestResponse = new PortalRestResponse<String>(PortalRestStatusEnum.OK, "success", ecompTitle);
152 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/ecompTitle", "result =", ecompTitle);
153 } catch (Exception e) {
154 portalRestResponse = new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), null);
155 logger.error(EELFLoggerDelegate.errorLogger, "getEcompTitle failed", e);
157 return portalRestResponse;
161 * RESTful service method to fetch all the FunctionalMenuItems, both active and
162 * inactive, for the EditFunctionalMenu feature. Can only be accessed by the
168 * HttpServletResponse
169 * @return List of FunctionalMenuItem objects
171 @GetMapping(value = {
172 "/portalApi/functionalMenuForEditing" }, produces = "application/json")
173 public List<FunctionalMenuItem> getMenuItemsForEditing(HttpServletRequest request, HttpServletResponse response) {
174 // TODO: should only the superuser be allowed to use this API?
175 EPUser user = EPUserUtils.getUserSession(request);
176 List<FunctionalMenuItem> menuItems = null;
178 if (!adminRolesService.isSuperAdmin(user)) {
179 EcompPortalUtils.setBadPermissions(user, response, "getFunctionalMenuItemDetails");
181 menuItems = functionalMenuService.getFunctionalMenuItems(true);
183 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/functionalMenuForEditing", "result =",
185 } catch (Exception e) {
186 logger.error(EELFLoggerDelegate.errorLogger, "getMenuItemsForEditing failed", e);
192 * RESTful service method to fetch all the FunctionalMenuItems, active , for the
193 * Functional menu in notification Tree feature.
198 * HttpServletResponse
199 * @return List of FunctionalMenuItem objects
201 @GetMapping(value = {
202 "/portalApi/functionalMenuForNotificationTree" }, produces = "application/json")
203 public List<FunctionalMenuItem> getMenuItemsForNotifications(HttpServletRequest request,
204 HttpServletResponse response) {
205 // TODO: should only the superuser be allowed to use this API?
206 // EPUser user = EPUserUtils.getUserSession(request);
207 List<FunctionalMenuItem> menuItems = null;
209 menuItems = functionalMenuService.getFunctionalMenuItemsForNotificationTree(true);
210 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/functionalMenuForNotificationTree", "result =",
212 } catch (Exception e) {
213 logger.error(EELFLoggerDelegate.errorLogger, "getMenuItemsForNotifications failed", e);
219 * RESTful service method to fetch all FunctionalMenuItems associated with an
226 * @return List of FunctionalMenuItem objects
228 @GetMapping(value = {
229 "/portalApi/functionalMenuForApp/{appId}" }, produces = "application/json")
230 public List<FunctionalMenuItem> getMenuItemsForApp(HttpServletRequest request,
231 @PathVariable("appId") Integer appId) {
232 // TODO: should only the superuser be allowed to use this API?
233 List<FunctionalMenuItem> menuItems = null;
235 menuItems = functionalMenuService.getFunctionalMenuItemsForApp(appId);
236 functionalMenuService.assignHelpURLs(menuItems);
237 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/functionalMenuForApp/" + appId, "result =",
239 } catch (Exception e) {
240 logger.error(EELFLoggerDelegate.errorLogger, "getMenuItemsForApp failed", e);
246 * RESTful service method to fetch all FunctionalMenuItems associated with the
247 * applications and roles that a user has access to.
253 * @return List of FunctionalMenuItem objects
255 @GetMapping(value = {
256 "/portalApi/functionalMenuForUser/{orgUserId}" }, produces = "application/json")
257 public List<FunctionalMenuItem> getMenuItemsForUser(HttpServletRequest request,
258 @PathVariable("orgUserId") String orgUserId) {
259 // TODO: should only the superuser be allowed to use this API?
260 List<FunctionalMenuItem> menuItems = null;
262 menuItems = functionalMenuService.getFunctionalMenuItemsForUser(orgUserId);
263 functionalMenuService.assignHelpURLs(menuItems);
264 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/functionalMenuForUser/" + orgUserId, "result =",
266 } catch (Exception e) {
267 logger.error(EELFLoggerDelegate.errorLogger, "getMenuItemsForUser failed", e);
274 * RESTful service method to fetch all FunctionalMenuItems associated with the
275 * applications and roles that the authenticated user has access to.
280 * HttpServletResponse
281 * @return List of FunctionalMenuItem objects
283 @GetMapping(value = {
284 "/portalApi/functionalMenuForAuthUser" }, produces = "application/json")
285 public List<FunctionalMenuItem> getMenuItemsForAuthUser(HttpServletRequest request, HttpServletResponse response) {
287 EPUser user = EPUserUtils.getUserSession(request);
288 List<FunctionalMenuItem> menuItems = null;
291 EcompPortalUtils.setBadPermissions(user, response, "getMenuItemsForAuthUser");
292 } else if (adminRolesService.isSuperAdmin(user)) {
293 menuItems = functionalMenuService.getFunctionalMenuItems();
295 // calculate the menu items
296 String orgUserId = user.getOrgUserId();
297 menuItems = functionalMenuService.getFunctionalMenuItemsForUser(orgUserId);
298 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/functionalMenuForUser/" + orgUserId,
299 "result =", menuItems);
301 functionalMenuService.assignHelpURLs(menuItems);
302 } catch (Exception e) {
303 logger.error(EELFLoggerDelegate.errorLogger, "getMenuItemsForAuthUser failed", e);
309 * RESTful service method to fetch the details for a functional menu item.
310 * Requirement: you must be the ONAP portal super admin user.
315 * HttpServletResponse
318 * @return FunctionalMenuItem object
320 @GetMapping(value = {
321 "/portalApi/functionalMenuItemDetails/{menuId}" }, produces = "application/json")
322 public FunctionalMenuItem getFunctionalMenuItemDetails(HttpServletRequest request,
323 @PathVariable("menuId") Long menuId, HttpServletResponse response) {
324 // TODO: return FunctionalMenuItemJson
325 // TODO: modify FunctionalMenuItem to not include the transient fields
326 FunctionalMenuItem menuItem = null;
328 EPUser user = EPUserUtils.getUserSession(request);
329 if (!adminRolesService.isSuperAdmin(user)) {
330 EcompPortalUtils.setBadPermissions(user, response, "getFunctionalMenuItemDetails");
332 menuItem = functionalMenuService.getFunctionalMenuItemDetails(menuId);
333 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/functionalMenuItemDetails/" + menuId,
334 "result =", menuItem);
336 } catch (Exception e) {
337 logger.error(EELFLoggerDelegate.errorLogger, "getFunctionalMenuItemDetails failed", e);
344 * RESTful service method to create a new menu item.
346 * Requirement: you must be the ONAP portal super admin user.
351 * HttpServletResponse
352 * @param menuItemJson
353 * FunctionalMenuItemWithRoles
354 * @return FieldsValidator
356 @PostMapping(value = { "/portalApi/functionalMenuItem" })
357 public FieldsValidator createFunctionalMenuItem(HttpServletRequest request,
358 @RequestBody FunctionalMenuItemWithRoles menuItemJson, HttpServletResponse response) {
359 EPUser user = EPUserUtils.getUserSession(request);
360 FieldsValidator fieldsValidator = null;
362 if(!dataValidator.isValid(menuItemJson)){
363 fieldsValidator = new FieldsValidator();
364 logger.warn(EELFLoggerDelegate.debugLogger,"FunctionalMenuController.createFunctionalMenuItem not valid object");
365 fieldsValidator.httpStatusCode = (long)HttpServletResponse.SC_NOT_ACCEPTABLE;
366 return fieldsValidator;
369 if (!adminRolesService.isSuperAdmin(user)) {
370 logger.debug(EELFLoggerDelegate.debugLogger,
371 "FunctionalMenuController.createFunctionalMenuItem bad permissions");
372 EcompPortalUtils.setBadPermissions(user, response, "createFunctionalMenuItem");
374 fieldsValidator = functionalMenuService.createFunctionalMenuItem(menuItemJson);
375 response.setStatus(fieldsValidator.httpStatusCode.intValue());
376 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/functionalMenuItem", "POST result =",
377 response.getStatus());
380 return fieldsValidator;
384 * RESTful service method to update an existing menu item
386 * Requirement: you must be the ONAP portal super admin user.
391 * HttpServletResponse
392 * @param menuItemJson
393 * FunctionalMenuItemWithRoles
394 * @return FieldsValidator
396 @PutMapping(value = { "/portalApi/functionalMenuItem" })
397 public FieldsValidator editFunctionalMenuItem(HttpServletRequest request,
398 @RequestBody FunctionalMenuItemWithRoles menuItemJson, HttpServletResponse response) {
399 EPUser user = EPUserUtils.getUserSession(request);
400 FieldsValidator fieldsValidator = null;
402 if(!dataValidator.isValid(menuItemJson)){
403 fieldsValidator = new FieldsValidator();
404 logger.warn(EELFLoggerDelegate.debugLogger,"FunctionalMenuController.createFunctionalMenuItem not valid object");
405 fieldsValidator.httpStatusCode = (long)HttpServletResponse.SC_NOT_ACCEPTABLE;
406 return fieldsValidator;
409 if (!adminRolesService.isSuperAdmin(user)) {
410 EcompPortalUtils.setBadPermissions(user, response, "editFunctionalMenuItem");
412 fieldsValidator = functionalMenuService.editFunctionalMenuItem(menuItemJson);
413 response.setStatus(fieldsValidator.httpStatusCode.intValue());
414 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/functionalMenuItem", "PUT result =",
415 response.getStatus());
418 return fieldsValidator;
422 * RESTful service method to delete a menu item
427 * HttpServletResponse
430 * @return FieldsValidator
432 @DeleteMapping(value = { "/portalApi/functionalMenuItem/{menuId}" })
433 public FieldsValidator deleteFunctionalMenuItem(HttpServletRequest request, @PathVariable("menuId") Long menuId,
434 HttpServletResponse response) {
435 EPUser user = EPUserUtils.getUserSession(request);
436 FieldsValidator fieldsValidator = null;
437 if (!adminRolesService.isSuperAdmin(user)) {
438 EcompPortalUtils.setBadPermissions(user, response, "deleteFunctionalMenuItem");
440 fieldsValidator = functionalMenuService.deleteFunctionalMenuItem(menuId);
441 response.setStatus(fieldsValidator.httpStatusCode.intValue());
442 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/functionalMenuItem", "DELETE result =",
443 response.getStatus());
446 return fieldsValidator;
450 * RESTful service to regenerate table
455 * HttpServletResponse
456 * @return FieldsValidator
458 @GetMapping(value = { "/portalApi/regenerateFunctionalMenuAncestors" })
459 public FieldsValidator regenerateAncestorTable(HttpServletRequest request, HttpServletResponse response) {
460 // TODO: should only the superuser be allowed to use this API?
461 EPUser user = EPUserUtils.getUserSession(request);
462 FieldsValidator fieldsValidator = null;
464 if (!adminRolesService.isSuperAdmin(user)) {
465 EcompPortalUtils.setBadPermissions(user, response, "deleteFunctionalMenuItem");
467 fieldsValidator = functionalMenuService.regenerateAncestorTable();
468 response.setStatus(fieldsValidator.httpStatusCode.intValue());
469 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/regenerateAncestorTable", "GET result =",
470 response.getStatus());
473 return fieldsValidator;
477 * RESful service to set a favorite item.
482 * HttpServletResponse
483 * @param menuItemJson
484 * FunctionalMenuItemWithRoles
485 * @return FieldsValidator
487 @PostMapping(value = { "/portalApi/setFavoriteItem" })
488 public FieldsValidator addFavoriteItem(HttpServletRequest request,
489 @RequestBody FavoritesFunctionalMenuItem menuItemJson, HttpServletResponse response) {
490 EPUser user = EPUserUtils.getUserSession(request);
491 FieldsValidator fieldsValidator = null;
492 menuItemJson.userId = user.getId();
493 fieldsValidator = functionalMenuService.setFavoriteItem(menuItemJson);
494 response.setStatus(fieldsValidator.httpStatusCode.intValue());
495 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/setFavoriteItem", "Post result =",
496 response.getStatus());
498 return fieldsValidator;
502 * RESTful service to get favorites for the current user as identified in the
508 * HttpServletResponse
509 * @return List of FavoritesFunctionalMenuItemJson
511 @GetMapping(value = {
512 "/portalApi/getFavoriteItems" }, produces = "application/json")
513 public List<FavoritesFunctionalMenuItemJson> getFavoritesForUser(HttpServletRequest request,
514 HttpServletResponse response) {
515 EPUser user = EPUserUtils.getUserSession(request);
516 List<FavoritesFunctionalMenuItemJson> favorites = functionalMenuService.getFavoriteItems(user.getId());
517 FieldsValidator fieldsValidator = new FieldsValidator();
518 response.setStatus(fieldsValidator.httpStatusCode.intValue());
519 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/getFavoriteItems", "GET result =",
520 response.getStatus());
525 * RESTful service to delete a favorite menu item for the current user as
526 * identified in the session.
531 * HttpServletResponse
534 * @return FieldsValidator
536 @DeleteMapping(value = { "/portalApi/removeFavoriteItem/{menuId}" })
537 public FieldsValidator deleteFavoriteItem(HttpServletRequest request, @PathVariable("menuId") Long menuId,
538 HttpServletResponse response) {
539 EPUser user = EPUserUtils.getUserSession(request);
540 FieldsValidator fieldsValidator = null;
541 Long userId = user.getId();
542 fieldsValidator = functionalMenuService.removeFavoriteItem(userId, menuId);
543 response.setStatus(fieldsValidator.httpStatusCode.intValue());
544 EcompPortalUtils.logAndSerializeObject(logger, "/deleteFavoriteItem", "DELETE result =", response.getStatus());
546 return fieldsValidator;
550 * RESTful service to get user information: user's first and last names, org
551 * user ID, email and last-login. (Actually has nothing to do with the real
552 * functional menu.) First attempts to get the information from the Tomcat
553 * session (i.e., the CSP cookie); if that fails, calls the shared context
554 * service to read the information from the database. Gives back what it found,
555 * any of which may be null, as a JSON collection.
560 * HttpServletResponse
561 * @return JSON collection of key-value pairs shown below.
563 @GetMapping(value = {
564 "/portalApi/functionalMenuStaticInfo" }, produces = "application/json")
565 public String getFunctionalMenuStaticInfo(HttpServletRequest request, HttpServletResponse response) {
567 // Get user details from session
568 logger.debug(EELFLoggerDelegate.debugLogger, "getFunctionalMenuStaticInfo: getting user info");
569 String fnMenuStaticResponse = null;
571 String orgUserIdStr = null;
572 String firstNameStr = null;
573 String lastNameStr = null;
574 String emailStr = null;
575 String lastLogin = null;
576 EPUser user = EPUserUtils.getUserSession(request);
577 firstNameStr = user.getFirstName();
578 lastNameStr = user.getLastName();
579 orgUserIdStr = user.getOrgUserId();
580 emailStr = user.getEmail();
581 if (emailStr == null || emailStr.equals("")) {
582 EPUser userResult = searchService.searchUserByUserId(orgUserIdStr);
583 emailStr = userResult.getEmail();
585 SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss Z a");
586 Date lastLoginDate = user.getLastLoginDate();
587 if (lastLoginDate == null) {
588 // should never happen
589 logger.error(EELFLoggerDelegate.errorLogger, "getFunctionalMenuStaticInfo: no last login in session");
590 lastLogin = "no last login available";
592 lastLogin = sdf.format(lastLoginDate);
595 // If any item is missing from session, try the Shared Context
597 SharedContext orgUserIdSC = null;
598 SharedContext firstNameSC = null;
599 SharedContext lastNameSC = null;
600 SharedContext emailSC = null;
601 String sessionId = request.getSession().getId();
602 if (firstNameStr == null)
603 firstNameSC = sharedContextService.getSharedContext(sessionId,
604 EPCommonSystemProperties.USER_FIRST_NAME);
605 if (lastNameStr == null)
606 lastNameSC = sharedContextService.getSharedContext(sessionId, EPCommonSystemProperties.USER_LAST_NAME);
607 if (emailStr == null)
608 emailSC = sharedContextService.getSharedContext(sessionId, EPCommonSystemProperties.USER_EMAIL);
609 if (orgUserIdStr == null)
610 orgUserIdSC = sharedContextService.getSharedContext(sessionId,
611 EPCommonSystemProperties.USER_ORG_USERID);
613 // Build the response
614 Map<String, String> map = new HashMap<String, String>();
616 firstNameStr != null ? firstNameStr : (firstNameSC != null ? firstNameSC.getCvalue() : null));
618 lastNameStr != null ? lastNameStr : (lastNameSC != null ? lastNameSC.getCvalue() : null));
619 map.put("email", emailStr != null ? emailStr : (emailSC != null ? emailSC.getCvalue() : null));
621 orgUserIdStr != null ? orgUserIdStr : (orgUserIdSC != null ? orgUserIdSC.getCvalue() : null));
622 map.put("last_login", lastLogin);
623 JSONObject j = new JSONObject(map);
624 fnMenuStaticResponse = j.toString();
625 // Be chatty in the log
626 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/functionalMenuStaticInfo", "GET result =",
627 fnMenuStaticResponse);
628 } catch (Exception e) {
629 // Should never happen.
630 logger.error(EELFLoggerDelegate.errorLogger, "getFunctionalMenuStaticInfo failed", e);
631 // Return a real error?
632 // fnMenuStaticResponse = "{ \"status\": \"error\", \"message\": \""
633 // + e.toString() + "\" }";
634 // But the angular controller expects null on error.
636 return fnMenuStaticResponse;
639 private Comparator<BusinessCardApplicationRole> getUserAppRolesComparator = new Comparator<BusinessCardApplicationRole>() {
640 public int compare(BusinessCardApplicationRole o1, BusinessCardApplicationRole o2) {
641 return o1.getAppName().compareTo(o2.getAppName());
651 * @return List<BusinessCardApplicationRolesList>
652 * @throws IOException
655 @GetMapping(value = {
656 "/portalApi/userApplicationRoles" }, produces = "application/json")
657 public List<BusinessCardApplicationRolesList> getAppList(HttpServletRequest request, HttpServletResponse response,
658 @RequestParam("userId") String userId) throws IOException {
660 List<BusinessCardApplicationRolesList> AppRoles = null;
662 if(!UserUtils.getUserSession(request).getOrgUserId().equalsIgnoreCase(userId)) {
663 logger.error(EELFLoggerDelegate.errorLogger, "Not authorized to view roles of others ");
664 response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
665 response.getWriter().flush();
670 List<BusinessCardApplicationRole> userAppRoleList = functionalMenuService.getUserAppRolesList(userId);
672 Collections.sort(userAppRoleList, getUserAppRolesComparator);
673 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/userApplicationRoles", "result =",
676 AppRoles = new ArrayList<BusinessCardApplicationRolesList>();
677 for (BusinessCardApplicationRole userAppRole : userAppRoleList) {
678 boolean found = false;
679 List<String> roles = null;
681 for (BusinessCardApplicationRolesList app : AppRoles) {
682 if (app.getAppName().equals(userAppRole.getAppName())) {
683 roles = app.getRoleNames();
684 roles.add(userAppRole.getRoleName());
685 app.setRoleNames(roles);
692 roles = new ArrayList<String>();
693 roles.add(userAppRole.getRoleName());
694 AppRoles.add(new BusinessCardApplicationRolesList(userAppRole.getAppName(), roles));
697 Collections.sort(roles);
699 } catch (Exception e) {
700 logger.error(EELFLoggerDelegate.errorLogger, "getAppList failed", e);