2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the "License");
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
38 package org.onap.portalapp.portal.controller;
40 import java.io.IOException;
41 import java.text.SimpleDateFormat;
42 import java.util.ArrayList;
43 import java.util.Collections;
44 import java.util.Comparator;
45 import java.util.Date;
46 import java.util.HashMap;
47 import java.util.List;
50 import javax.servlet.http.HttpServletRequest;
51 import javax.servlet.http.HttpServletResponse;
52 import javax.ws.rs.core.Response;
54 import org.json.JSONObject;
55 import org.onap.portalapp.controller.EPRestrictedBaseController;
56 import org.onap.portalapp.portal.domain.EPUser;
57 import org.onap.portalapp.portal.domain.SharedContext;
58 import org.onap.portalapp.portal.ecomp.model.PortalRestResponse;
59 import org.onap.portalapp.portal.ecomp.model.PortalRestStatusEnum;
60 import org.onap.portalapp.portal.logging.aop.EPAuditLog;
61 import org.onap.portalapp.portal.service.AdminRolesService;
62 import org.onap.portalapp.portal.service.FunctionalMenuService;
63 import org.onap.portalapp.portal.service.SearchService;
64 import org.onap.portalapp.portal.service.SharedContextService;
65 import org.onap.portalapp.portal.transport.BusinessCardApplicationRole;
66 import org.onap.portalapp.portal.transport.BusinessCardApplicationRolesList;
67 import org.onap.portalapp.portal.transport.FavoritesFunctionalMenuItem;
68 import org.onap.portalapp.portal.transport.FavoritesFunctionalMenuItemJson;
69 import org.onap.portalapp.portal.transport.FieldsValidator;
70 import org.onap.portalapp.portal.transport.FunctionalMenuItem;
71 import org.onap.portalapp.portal.transport.FunctionalMenuItemWithRoles;
72 import org.onap.portalapp.portal.utils.EPCommonSystemProperties;
73 import org.onap.portalapp.portal.utils.EcompPortalUtils;
74 import org.onap.portalapp.util.EPUserUtils;
75 import org.onap.portalapp.validation.DataValidator;
76 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
77 import org.onap.portalsdk.core.util.SystemProperties;
78 import org.onap.portalsdk.core.web.support.UserUtils;
79 import org.springframework.beans.factory.annotation.Autowired;
80 import org.springframework.context.annotation.Configuration;
81 import org.springframework.context.annotation.EnableAspectJAutoProxy;
82 import org.springframework.web.bind.annotation.PathVariable;
83 import org.springframework.web.bind.annotation.RequestBody;
84 import org.springframework.web.bind.annotation.RequestMapping;
85 import org.springframework.web.bind.annotation.RequestMethod;
86 import org.springframework.web.bind.annotation.RequestParam;
87 import org.springframework.web.bind.annotation.RestController;
90 * Supports menus at the top of the Portal app landing page.
94 @EnableAspectJAutoProxy
96 public class FunctionalMenuController extends EPRestrictedBaseController {
98 private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(FunctionalMenuController.class);
99 private final DataValidator dataValidator = new DataValidator();
102 private AdminRolesService adminRolesService;
104 private FunctionalMenuService functionalMenuService;
106 private SharedContextService sharedContextService;
108 private SearchService searchService;
111 * RESTful service method to fetch all the FunctionalMenuItems.
116 * HttpServletResponse
117 * @return List of FunctionalMenuItem objects
119 @RequestMapping(value = { "/portalApi/functionalMenu" }, method = RequestMethod.GET, produces = "application/json")
120 public List<FunctionalMenuItem> getMenuItems(HttpServletRequest request, HttpServletResponse response) {
121 // TODO: should only the superuser be allowed to use this API?
122 List<FunctionalMenuItem> menuItems = null;
124 menuItems = functionalMenuService.getFunctionalMenuItems();
125 functionalMenuService.assignHelpURLs(menuItems);
126 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/functionalMenu", "result =", menuItems);
127 } catch (Exception e) {
128 logger.error(EELFLoggerDelegate.errorLogger, "getMenuItems failed", e);
134 * RESTful service method to get ONAP Portal Title.
139 * HttpServletResponse
140 * @return PortalRestResponse of ONAP portal title
142 @RequestMapping(value = { "/portalApi/ecompTitle" }, method = RequestMethod.GET, produces = "application/json")
143 public PortalRestResponse<String> getECOMPTitle(HttpServletRequest request, HttpServletResponse response) {
144 PortalRestResponse<String> portalRestResponse = null;
146 String ecompTitle = SystemProperties.getProperty(SystemProperties.APP_DISPLAY_NAME);
147 portalRestResponse = new PortalRestResponse<String>(PortalRestStatusEnum.OK, "success", ecompTitle);
148 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/ecompTitle", "result =", ecompTitle);
149 } catch (Exception e) {
150 portalRestResponse = new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), null);
151 logger.error(EELFLoggerDelegate.errorLogger, "getEcompTitle failed", e);
153 return portalRestResponse;
157 * RESTful service method to fetch all the FunctionalMenuItems, both active and
158 * inactive, for the EditFunctionalMenu feature. Can only be accessed by the
164 * HttpServletResponse
165 * @return List of FunctionalMenuItem objects
167 @RequestMapping(value = {
168 "/portalApi/functionalMenuForEditing" }, method = RequestMethod.GET, produces = "application/json")
169 public List<FunctionalMenuItem> getMenuItemsForEditing(HttpServletRequest request, HttpServletResponse response) {
170 // TODO: should only the superuser be allowed to use this API?
171 EPUser user = EPUserUtils.getUserSession(request);
172 List<FunctionalMenuItem> menuItems = null;
174 if (!adminRolesService.isSuperAdmin(user)) {
175 EcompPortalUtils.setBadPermissions(user, response, "getFunctionalMenuItemDetails");
177 menuItems = functionalMenuService.getFunctionalMenuItems(true);
179 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/functionalMenuForEditing", "result =",
181 } catch (Exception e) {
182 logger.error(EELFLoggerDelegate.errorLogger, "getMenuItemsForEditing failed", e);
188 * RESTful service method to fetch all the FunctionalMenuItems, active , for the
189 * Functional menu in notification Tree feature.
194 * HttpServletResponse
195 * @return List of FunctionalMenuItem objects
197 @RequestMapping(value = {
198 "/portalApi/functionalMenuForNotificationTree" }, method = RequestMethod.GET, produces = "application/json")
199 public List<FunctionalMenuItem> getMenuItemsForNotifications(HttpServletRequest request,
200 HttpServletResponse response) {
201 // TODO: should only the superuser be allowed to use this API?
202 // EPUser user = EPUserUtils.getUserSession(request);
203 List<FunctionalMenuItem> menuItems = null;
205 menuItems = functionalMenuService.getFunctionalMenuItemsForNotificationTree(true);
206 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/functionalMenuForNotificationTree", "result =",
208 } catch (Exception e) {
209 logger.error(EELFLoggerDelegate.errorLogger, "getMenuItemsForNotifications failed", e);
215 * RESTful service method to fetch all FunctionalMenuItems associated with an
222 * @return List of FunctionalMenuItem objects
224 @RequestMapping(value = {
225 "/portalApi/functionalMenuForApp/{appId}" }, method = RequestMethod.GET, produces = "application/json")
226 public List<FunctionalMenuItem> getMenuItemsForApp(HttpServletRequest request,
227 @PathVariable("appId") Integer appId) {
228 // TODO: should only the superuser be allowed to use this API?
229 List<FunctionalMenuItem> menuItems = null;
231 menuItems = functionalMenuService.getFunctionalMenuItemsForApp(appId);
232 functionalMenuService.assignHelpURLs(menuItems);
233 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/functionalMenuForApp/" + appId, "result =",
235 } catch (Exception e) {
236 logger.error(EELFLoggerDelegate.errorLogger, "getMenuItemsForApp failed", e);
242 * RESTful service method to fetch all FunctionalMenuItems associated with the
243 * applications and roles that a user has access to.
249 * @return List of FunctionalMenuItem objects
251 @RequestMapping(value = {
252 "/portalApi/functionalMenuForUser/{orgUserId}" }, method = RequestMethod.GET, produces = "application/json")
253 public List<FunctionalMenuItem> getMenuItemsForUser(HttpServletRequest request,
254 @PathVariable("orgUserId") String orgUserId) {
255 // TODO: should only the superuser be allowed to use this API?
256 List<FunctionalMenuItem> menuItems = null;
258 menuItems = functionalMenuService.getFunctionalMenuItemsForUser(orgUserId);
259 functionalMenuService.assignHelpURLs(menuItems);
260 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/functionalMenuForUser/" + orgUserId, "result =",
262 } catch (Exception e) {
263 logger.error(EELFLoggerDelegate.errorLogger, "getMenuItemsForUser failed", e);
270 * RESTful service method to fetch all FunctionalMenuItems associated with the
271 * applications and roles that the authenticated user has access to.
276 * HttpServletResponse
277 * @return List of FunctionalMenuItem objects
279 @RequestMapping(value = {
280 "/portalApi/functionalMenuForAuthUser" }, method = RequestMethod.GET, produces = "application/json")
281 public List<FunctionalMenuItem> getMenuItemsForAuthUser(HttpServletRequest request, HttpServletResponse response) {
283 EPUser user = EPUserUtils.getUserSession(request);
284 List<FunctionalMenuItem> menuItems = null;
287 EcompPortalUtils.setBadPermissions(user, response, "getMenuItemsForAuthUser");
288 } else if (adminRolesService.isSuperAdmin(user)) {
289 menuItems = functionalMenuService.getFunctionalMenuItems();
291 // calculate the menu items
292 String orgUserId = user.getOrgUserId();
293 menuItems = functionalMenuService.getFunctionalMenuItemsForUser(orgUserId);
294 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/functionalMenuForUser/" + orgUserId,
295 "result =", menuItems);
297 functionalMenuService.assignHelpURLs(menuItems);
298 } catch (Exception e) {
299 logger.error(EELFLoggerDelegate.errorLogger, "getMenuItemsForAuthUser failed", e);
305 * RESTful service method to fetch the details for a functional menu item.
306 * Requirement: you must be the ONAP portal super admin user.
311 * HttpServletResponse
314 * @return FunctionalMenuItem object
316 @RequestMapping(value = {
317 "/portalApi/functionalMenuItemDetails/{menuId}" }, method = RequestMethod.GET, produces = "application/json")
318 public FunctionalMenuItem getFunctionalMenuItemDetails(HttpServletRequest request,
319 @PathVariable("menuId") Long menuId, HttpServletResponse response) {
320 // TODO: return FunctionalMenuItemJson
321 // TODO: modify FunctionalMenuItem to not include the transient fields
322 FunctionalMenuItem menuItem = null;
324 EPUser user = EPUserUtils.getUserSession(request);
325 if (!adminRolesService.isSuperAdmin(user)) {
326 EcompPortalUtils.setBadPermissions(user, response, "getFunctionalMenuItemDetails");
328 menuItem = functionalMenuService.getFunctionalMenuItemDetails(menuId);
329 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/functionalMenuItemDetails/" + menuId,
330 "result =", menuItem);
332 } catch (Exception e) {
333 logger.error(EELFLoggerDelegate.errorLogger, "getFunctionalMenuItemDetails failed", e);
340 * RESTful service method to create a new menu item.
342 * Requirement: you must be the ONAP portal super admin user.
347 * HttpServletResponse
348 * @param menuItemJson
349 * FunctionalMenuItemWithRoles
350 * @return FieldsValidator
352 @RequestMapping(value = { "/portalApi/functionalMenuItem" }, method = RequestMethod.POST)
353 public FieldsValidator createFunctionalMenuItem(HttpServletRequest request,
354 @RequestBody FunctionalMenuItemWithRoles menuItemJson, HttpServletResponse response) {
355 EPUser user = EPUserUtils.getUserSession(request);
356 FieldsValidator fieldsValidator = null;
358 if(!dataValidator.isValid(menuItemJson)){
359 fieldsValidator = new FieldsValidator();
360 logger.warn(EELFLoggerDelegate.debugLogger,"FunctionalMenuController.createFunctionalMenuItem not valid object");
361 fieldsValidator.httpStatusCode = (long)HttpServletResponse.SC_NOT_ACCEPTABLE;
362 return fieldsValidator;
365 if (!adminRolesService.isSuperAdmin(user)) {
366 logger.debug(EELFLoggerDelegate.debugLogger,
367 "FunctionalMenuController.createFunctionalMenuItem bad permissions");
368 EcompPortalUtils.setBadPermissions(user, response, "createFunctionalMenuItem");
370 fieldsValidator = functionalMenuService.createFunctionalMenuItem(menuItemJson);
371 response.setStatus(fieldsValidator.httpStatusCode.intValue());
372 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/functionalMenuItem", "POST result =",
373 response.getStatus());
376 return fieldsValidator;
380 * RESTful service method to update an existing menu item
382 * Requirement: you must be the ONAP portal super admin user.
387 * HttpServletResponse
388 * @param menuItemJson
389 * FunctionalMenuItemWithRoles
390 * @return FieldsValidator
392 @RequestMapping(value = { "/portalApi/functionalMenuItem" }, method = RequestMethod.PUT)
393 public FieldsValidator editFunctionalMenuItem(HttpServletRequest request,
394 @RequestBody FunctionalMenuItemWithRoles menuItemJson, HttpServletResponse response) {
395 EPUser user = EPUserUtils.getUserSession(request);
396 FieldsValidator fieldsValidator = null;
398 if(!dataValidator.isValid(menuItemJson)){
399 fieldsValidator = new FieldsValidator();
400 logger.warn(EELFLoggerDelegate.debugLogger,"FunctionalMenuController.createFunctionalMenuItem not valid object");
401 fieldsValidator.httpStatusCode = (long)HttpServletResponse.SC_NOT_ACCEPTABLE;
402 return fieldsValidator;
405 if (!adminRolesService.isSuperAdmin(user)) {
406 EcompPortalUtils.setBadPermissions(user, response, "editFunctionalMenuItem");
408 fieldsValidator = functionalMenuService.editFunctionalMenuItem(menuItemJson);
409 response.setStatus(fieldsValidator.httpStatusCode.intValue());
410 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/functionalMenuItem", "PUT result =",
411 response.getStatus());
414 return fieldsValidator;
418 * RESTful service method to delete a menu item
423 * HttpServletResponse
426 * @return FieldsValidator
428 @RequestMapping(value = { "/portalApi/functionalMenuItem/{menuId}" }, method = RequestMethod.DELETE)
429 public FieldsValidator deleteFunctionalMenuItem(HttpServletRequest request, @PathVariable("menuId") Long menuId,
430 HttpServletResponse response) {
431 EPUser user = EPUserUtils.getUserSession(request);
432 FieldsValidator fieldsValidator = null;
433 if (!adminRolesService.isSuperAdmin(user)) {
434 EcompPortalUtils.setBadPermissions(user, response, "deleteFunctionalMenuItem");
436 fieldsValidator = functionalMenuService.deleteFunctionalMenuItem(menuId);
437 response.setStatus(fieldsValidator.httpStatusCode.intValue());
438 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/functionalMenuItem", "DELETE result =",
439 response.getStatus());
442 return fieldsValidator;
446 * RESTful service to regenerate table
451 * HttpServletResponse
452 * @return FieldsValidator
454 @RequestMapping(value = { "/portalApi/regenerateFunctionalMenuAncestors" }, method = RequestMethod.GET)
455 public FieldsValidator regenerateAncestorTable(HttpServletRequest request, HttpServletResponse response) {
456 // TODO: should only the superuser be allowed to use this API?
457 EPUser user = EPUserUtils.getUserSession(request);
458 FieldsValidator fieldsValidator = null;
460 if (!adminRolesService.isSuperAdmin(user)) {
461 EcompPortalUtils.setBadPermissions(user, response, "deleteFunctionalMenuItem");
463 fieldsValidator = functionalMenuService.regenerateAncestorTable();
464 response.setStatus(fieldsValidator.httpStatusCode.intValue());
465 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/regenerateAncestorTable", "GET result =",
466 response.getStatus());
469 return fieldsValidator;
473 * RESful service to set a favorite item.
478 * HttpServletResponse
479 * @param menuItemJson
480 * FunctionalMenuItemWithRoles
481 * @return FieldsValidator
483 @RequestMapping(value = { "/portalApi/setFavoriteItem" }, method = RequestMethod.POST)
484 public FieldsValidator addFavoriteItem(HttpServletRequest request,
485 @RequestBody FavoritesFunctionalMenuItem menuItemJson, HttpServletResponse response) {
486 EPUser user = EPUserUtils.getUserSession(request);
487 FieldsValidator fieldsValidator = null;
488 menuItemJson.userId = user.getId();
489 fieldsValidator = functionalMenuService.setFavoriteItem(menuItemJson);
490 response.setStatus(fieldsValidator.httpStatusCode.intValue());
491 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/setFavoriteItem", "Post result =",
492 response.getStatus());
494 return fieldsValidator;
498 * RESTful service to get favorites for the current user as identified in the
504 * HttpServletResponse
505 * @return List of FavoritesFunctionalMenuItemJson
507 @RequestMapping(value = {
508 "/portalApi/getFavoriteItems" }, method = RequestMethod.GET, produces = "application/json")
509 public List<FavoritesFunctionalMenuItemJson> getFavoritesForUser(HttpServletRequest request,
510 HttpServletResponse response) {
511 EPUser user = EPUserUtils.getUserSession(request);
512 List<FavoritesFunctionalMenuItemJson> favorites = functionalMenuService.getFavoriteItems(user.getId());
513 FieldsValidator fieldsValidator = new FieldsValidator();
514 response.setStatus(fieldsValidator.httpStatusCode.intValue());
515 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/getFavoriteItems", "GET result =",
516 response.getStatus());
521 * RESTful service to delete a favorite menu item for the current user as
522 * identified in the session.
527 * HttpServletResponse
530 * @return FieldsValidator
532 @RequestMapping(value = { "/portalApi/removeFavoriteItem/{menuId}" }, method = RequestMethod.DELETE)
533 public FieldsValidator deleteFavoriteItem(HttpServletRequest request, @PathVariable("menuId") Long menuId,
534 HttpServletResponse response) {
535 EPUser user = EPUserUtils.getUserSession(request);
536 FieldsValidator fieldsValidator = null;
537 Long userId = user.getId();
538 fieldsValidator = functionalMenuService.removeFavoriteItem(userId, menuId);
539 response.setStatus(fieldsValidator.httpStatusCode.intValue());
540 EcompPortalUtils.logAndSerializeObject(logger, "/deleteFavoriteItem", "DELETE result =", response.getStatus());
542 return fieldsValidator;
546 * RESTful service to get user information: user's first and last names, org
547 * user ID, email and last-login. (Actually has nothing to do with the real
548 * functional menu.) First attempts to get the information from the Tomcat
549 * session (i.e., the CSP cookie); if that fails, calls the shared context
550 * service to read the information from the database. Gives back what it found,
551 * any of which may be null, as a JSON collection.
556 * HttpServletResponse
557 * @return JSON collection of key-value pairs shown below.
559 @RequestMapping(value = {
560 "/portalApi/functionalMenuStaticInfo" }, method = RequestMethod.GET, produces = "application/json")
561 public String getFunctionalMenuStaticInfo(HttpServletRequest request, HttpServletResponse response) {
563 // Get user details from session
564 logger.debug(EELFLoggerDelegate.debugLogger, "getFunctionalMenuStaticInfo: getting user info");
565 String fnMenuStaticResponse = null;
567 String orgUserIdStr = null, firstNameStr = null, lastNameStr = null, emailStr = null, lastLogin = null;
568 EPUser user = EPUserUtils.getUserSession(request);
569 firstNameStr = user.getFirstName();
570 lastNameStr = user.getLastName();
571 orgUserIdStr = user.getOrgUserId();
572 emailStr = user.getEmail();
573 if (emailStr == null || emailStr.equals("")) {
574 EPUser userResult = searchService.searchUserByUserId(orgUserIdStr);
575 emailStr = userResult.getEmail();
577 SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss Z a");
578 Date lastLoginDate = user.getLastLoginDate();
579 if (lastLoginDate == null) {
580 // should never happen
581 logger.error(EELFLoggerDelegate.errorLogger, "getFunctionalMenuStaticInfo: no last login in session");
582 lastLogin = "no last login available";
584 lastLogin = sdf.format(lastLoginDate);
587 // If any item is missing from session, try the Shared Context
589 SharedContext orgUserIdSC = null, firstNameSC = null, lastNameSC = null, emailSC = null;
590 String sessionId = request.getSession().getId();
591 if (firstNameStr == null)
592 firstNameSC = sharedContextService.getSharedContext(sessionId,
593 EPCommonSystemProperties.USER_FIRST_NAME);
594 if (lastNameStr == null)
595 lastNameSC = sharedContextService.getSharedContext(sessionId, EPCommonSystemProperties.USER_LAST_NAME);
596 if (emailStr == null)
597 emailSC = sharedContextService.getSharedContext(sessionId, EPCommonSystemProperties.USER_EMAIL);
598 if (orgUserIdStr == null)
599 orgUserIdSC = sharedContextService.getSharedContext(sessionId,
600 EPCommonSystemProperties.USER_ORG_USERID);
602 // Build the response
603 Map<String, String> map = new HashMap<String, String>();
605 firstNameStr != null ? firstNameStr : (firstNameSC != null ? firstNameSC.getCvalue() : null));
607 lastNameStr != null ? lastNameStr : (lastNameSC != null ? lastNameSC.getCvalue() : null));
608 map.put("email", emailStr != null ? emailStr : (emailSC != null ? emailSC.getCvalue() : null));
610 orgUserIdStr != null ? orgUserIdStr : (orgUserIdSC != null ? orgUserIdSC.getCvalue() : null));
611 map.put("last_login", lastLogin);
612 JSONObject j = new JSONObject(map);
613 fnMenuStaticResponse = j.toString();
614 // Be chatty in the log
615 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/functionalMenuStaticInfo", "GET result =",
616 fnMenuStaticResponse);
617 } catch (Exception e) {
618 // Should never happen.
619 logger.error(EELFLoggerDelegate.errorLogger, "getFunctionalMenuStaticInfo failed", e);
620 // Return a real error?
621 // fnMenuStaticResponse = "{ \"status\": \"error\", \"message\": \""
622 // + e.toString() + "\" }";
623 // But the angular controller expects null on error.
625 return fnMenuStaticResponse;
628 private Comparator<BusinessCardApplicationRole> getUserAppRolesComparator = new Comparator<BusinessCardApplicationRole>() {
629 public int compare(BusinessCardApplicationRole o1, BusinessCardApplicationRole o2) {
630 return o1.getAppName().compareTo(o2.getAppName());
640 * @return List<BusinessCardApplicationRolesList>
641 * @throws IOException
644 @RequestMapping(value = {
645 "/portalApi/userApplicationRoles" }, method = RequestMethod.GET, produces = "application/json")
646 public List<BusinessCardApplicationRolesList> getAppList(HttpServletRequest request, HttpServletResponse response,
647 @RequestParam("userId") String userId) throws IOException {
649 List<BusinessCardApplicationRolesList> AppRoles = null;
651 if(!UserUtils.getUserSession(request).getOrgUserId().equalsIgnoreCase(userId)) {
652 logger.error(EELFLoggerDelegate.errorLogger, "Not authorized to view roles of others ");
653 response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
654 response.getWriter().flush();
659 List<BusinessCardApplicationRole> userAppRoleList = functionalMenuService.getUserAppRolesList(userId);
661 Collections.sort(userAppRoleList, getUserAppRolesComparator);
662 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/userApplicationRoles", "result =",
665 AppRoles = new ArrayList<BusinessCardApplicationRolesList>();
666 for (BusinessCardApplicationRole userAppRole : userAppRoleList) {
667 boolean found = false;
668 List<String> roles = null;
670 for (BusinessCardApplicationRolesList app : AppRoles) {
671 if (app.getAppName().equals(userAppRole.getAppName())) {
672 roles = app.getRoleNames();
673 roles.add(userAppRole.getRoleName());
674 app.setRoleNames(roles);
681 roles = new ArrayList<String>();
682 roles.add(userAppRole.getRoleName());
683 AppRoles.add(new BusinessCardApplicationRolesList(userAppRole.getAppName(), roles));
686 Collections.sort(roles);
688 } catch (Exception e) {
689 logger.error(EELFLoggerDelegate.errorLogger, "getAppList failed", e);