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============================================
 
  36  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
 
  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;
 
  53 import org.json.JSONObject;
 
  54 import org.onap.portalapp.controller.EPRestrictedBaseController;
 
  55 import org.onap.portalapp.portal.domain.EPUser;
 
  56 import org.onap.portalapp.portal.domain.SharedContext;
 
  57 import org.onap.portalapp.portal.ecomp.model.PortalRestResponse;
 
  58 import org.onap.portalapp.portal.ecomp.model.PortalRestStatusEnum;
 
  59 import org.onap.portalapp.portal.logging.aop.EPAuditLog;
 
  60 import org.onap.portalapp.portal.service.AdminRolesService;
 
  61 import org.onap.portalapp.portal.service.FunctionalMenuService;
 
  62 import org.onap.portalapp.portal.service.SearchService;
 
  63 import org.onap.portalapp.portal.service.SharedContextService;
 
  64 import org.onap.portalapp.portal.transport.BusinessCardApplicationRole;
 
  65 import org.onap.portalapp.portal.transport.BusinessCardApplicationRolesList;
 
  66 import org.onap.portalapp.portal.transport.FavoritesFunctionalMenuItem;
 
  67 import org.onap.portalapp.portal.transport.FavoritesFunctionalMenuItemJson;
 
  68 import org.onap.portalapp.portal.transport.FieldsValidator;
 
  69 import org.onap.portalapp.portal.transport.FunctionalMenuItem;
 
  70 import org.onap.portalapp.portal.transport.FunctionalMenuItemWithRoles;
 
  71 import org.onap.portalapp.portal.utils.EPCommonSystemProperties;
 
  72 import org.onap.portalapp.portal.utils.EcompPortalUtils;
 
  73 import org.onap.portalapp.util.EPUserUtils;
 
  74 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
 
  75 import org.onap.portalsdk.core.util.SystemProperties;
 
  76 import org.springframework.beans.factory.annotation.Autowired;
 
  77 import org.springframework.context.annotation.EnableAspectJAutoProxy;
 
  78 import org.springframework.web.bind.annotation.PathVariable;
 
  79 import org.springframework.web.bind.annotation.RequestBody;
 
  80 import org.springframework.web.bind.annotation.RequestMapping;
 
  81 import org.springframework.web.bind.annotation.RequestMethod;
 
  82 import org.springframework.web.bind.annotation.RequestParam;
 
  83 import org.springframework.web.bind.annotation.RestController;
 
  86  * Supports menus at the top of the Portal app landing page.
 
  89 @org.springframework.context.annotation.Configuration
 
  90 @EnableAspectJAutoProxy
 
  92 public class FunctionalMenuController extends EPRestrictedBaseController {
 
  94         private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(FunctionalMenuController.class);
 
  97         private AdminRolesService adminRolesService;
 
  99         private FunctionalMenuService functionalMenuService;
 
 101         private SharedContextService sharedContextService;
 
 103         private SearchService searchService;
 
 106          * RESTful service method to fetch all the FunctionalMenuItems.
 
 111          *            HttpServletResponse
 
 112          * @return List of FunctionalMenuItem objects
 
 114         @RequestMapping(value = { "/portalApi/functionalMenu" }, method = RequestMethod.GET, produces = "application/json")
 
 115         public List<FunctionalMenuItem> getMenuItems(HttpServletRequest request, HttpServletResponse response) {
 
 116                 // TODO: should only the superuser be allowed to use this API?
 
 117                 List<FunctionalMenuItem> menuItems = null;
 
 119                         menuItems = functionalMenuService.getFunctionalMenuItems();
 
 120                         functionalMenuService.assignHelpURLs(menuItems);
 
 121                         EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/functionalMenu", "result =", menuItems);
 
 122                 } catch (Exception e) {
 
 123                         logger.error(EELFLoggerDelegate.errorLogger, "getMenuItems failed", e);
 
 129          * RESTful service method to get ECOMP Portal Title.
 
 134          *            HttpServletResponse
 
 135          * @return PortalRestResponse of ECOMP portal title
 
 137         @RequestMapping(value = { "/portalApi/ecompTitle" }, method = RequestMethod.GET, produces = "application/json")
 
 138         public PortalRestResponse<String> getECOMPTitle(HttpServletRequest request, HttpServletResponse response) {
 
 139                 PortalRestResponse<String> portalRestResponse = null;
 
 141                         String ecompTitle = SystemProperties.getProperty(SystemProperties.APP_DISPLAY_NAME);
 
 142                         portalRestResponse = new PortalRestResponse<String>(PortalRestStatusEnum.OK, "success", ecompTitle);
 
 143                         EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/ecompTitle", "result =", ecompTitle);
 
 144                 } catch (Exception e) {
 
 145                         portalRestResponse = new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), null);
 
 146                         logger.error(EELFLoggerDelegate.errorLogger, "getEcompTitle failed", e);
 
 148                 return portalRestResponse;
 
 152          * RESTful service method to fetch all the FunctionalMenuItems, both active and
 
 153          * inactive, for the EditFunctionalMenu feature. Can only be accessed by the
 
 159          *            HttpServletResponse
 
 160          * @return List of FunctionalMenuItem objects
 
 162         @RequestMapping(value = {
 
 163                         "/portalApi/functionalMenuForEditing" }, method = RequestMethod.GET, produces = "application/json")
 
 164         public List<FunctionalMenuItem> getMenuItemsForEditing(HttpServletRequest request, HttpServletResponse response) {
 
 165                 // TODO: should only the superuser be allowed to use this API?
 
 166                 EPUser user = EPUserUtils.getUserSession(request);
 
 167                 List<FunctionalMenuItem> menuItems = null;
 
 169                         if (!adminRolesService.isSuperAdmin(user)) {
 
 170                                 EcompPortalUtils.setBadPermissions(user, response, "getFunctionalMenuItemDetails");
 
 172                                 menuItems = functionalMenuService.getFunctionalMenuItems(true);
 
 174                         EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/functionalMenuForEditing", "result =",
 
 176                 } catch (Exception e) {
 
 177                         logger.error(EELFLoggerDelegate.errorLogger, "getMenuItemsForEditing failed", e);
 
 183          * RESTful service method to fetch all the FunctionalMenuItems, active , for the
 
 184          * Functional menu in notification Tree feature.
 
 189          *            HttpServletResponse
 
 190          * @return List of FunctionalMenuItem objects
 
 192         @RequestMapping(value = {
 
 193                         "/portalApi/functionalMenuForNotificationTree" }, method = RequestMethod.GET, produces = "application/json")
 
 194         public List<FunctionalMenuItem> getMenuItemsForNotifications(HttpServletRequest request,
 
 195                         HttpServletResponse response) {
 
 196                 // TODO: should only the superuser be allowed to use this API?
 
 197                 // EPUser user = EPUserUtils.getUserSession(request);
 
 198                 List<FunctionalMenuItem> menuItems = null;
 
 200                         menuItems = functionalMenuService.getFunctionalMenuItemsForNotificationTree(true);
 
 201                         EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/functionalMenuForNotificationTree", "result =",
 
 203                 } catch (Exception e) {
 
 204                         logger.error(EELFLoggerDelegate.errorLogger, "getMenuItemsForNotifications failed", e);
 
 210          * RESTful service method to fetch all FunctionalMenuItems associated with an
 
 217          * @return List of FunctionalMenuItem objects
 
 219         @RequestMapping(value = {
 
 220                         "/portalApi/functionalMenuForApp/{appId}" }, method = RequestMethod.GET, produces = "application/json")
 
 221         public List<FunctionalMenuItem> getMenuItemsForApp(HttpServletRequest request,
 
 222                         @PathVariable("appId") Integer appId) {
 
 223                 // TODO: should only the superuser be allowed to use this API?
 
 224                 List<FunctionalMenuItem> menuItems = null;
 
 226                         menuItems = functionalMenuService.getFunctionalMenuItemsForApp(appId);
 
 227                         functionalMenuService.assignHelpURLs(menuItems);
 
 228                         EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/functionalMenuForApp/" + appId, "result =",
 
 230                 } catch (Exception e) {
 
 231                         logger.error(EELFLoggerDelegate.errorLogger, "getMenuItemsForApp failed", e);
 
 237          * RESTful service method to fetch all FunctionalMenuItems associated with the
 
 238          * applications and roles that a user has access to.
 
 244          * @return List of FunctionalMenuItem objects
 
 246         @RequestMapping(value = {
 
 247                         "/portalApi/functionalMenuForUser/{orgUserId}" }, method = RequestMethod.GET, produces = "application/json")
 
 248         public List<FunctionalMenuItem> getMenuItemsForUser(HttpServletRequest request,
 
 249                         @PathVariable("orgUserId") String orgUserId) {
 
 250                 // TODO: should only the superuser be allowed to use this API?
 
 251                 List<FunctionalMenuItem> menuItems = null;
 
 253                         menuItems = functionalMenuService.getFunctionalMenuItemsForUser(orgUserId);
 
 254                         functionalMenuService.assignHelpURLs(menuItems);
 
 255                         EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/functionalMenuForUser/" + orgUserId, "result =",
 
 257                 } catch (Exception e) {
 
 258                         logger.error(EELFLoggerDelegate.errorLogger, "getMenuItemsForUser failed", e);
 
 265          * RESTful service method to fetch all FunctionalMenuItems associated with the
 
 266          * applications and roles that the authenticated user has access to.
 
 271          *            HttpServletResponse
 
 272          * @return List of FunctionalMenuItem objects
 
 274         @RequestMapping(value = {
 
 275                         "/portalApi/functionalMenuForAuthUser" }, method = RequestMethod.GET, produces = "application/json")
 
 276         public List<FunctionalMenuItem> getMenuItemsForAuthUser(HttpServletRequest request, HttpServletResponse response) {
 
 278                 EPUser user = EPUserUtils.getUserSession(request);
 
 279                 List<FunctionalMenuItem> menuItems = null;
 
 282                                 EcompPortalUtils.setBadPermissions(user, response, "getMenuItemsForAuthUser");
 
 283                         } else if (adminRolesService.isSuperAdmin(user)) {
 
 284                                 menuItems = functionalMenuService.getFunctionalMenuItems();
 
 286                                 // calculate the menu items
 
 287                                 String orgUserId = user.getOrgUserId();
 
 288                                 menuItems = functionalMenuService.getFunctionalMenuItemsForUser(orgUserId);
 
 289                                 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/functionalMenuForUser/" + orgUserId,
 
 290                                                 "result =", menuItems);
 
 292                         functionalMenuService.assignHelpURLs(menuItems);
 
 293                 } catch (Exception e) {
 
 294                         logger.error(EELFLoggerDelegate.errorLogger, "getMenuItemsForAuthUser failed", e);
 
 300          * RESTful service method to fetch the details for a functional menu item.
 
 301          * Requirement: you must be the Ecomp portal super admin user.
 
 306          *            HttpServletResponse
 
 309          * @return FunctionalMenuItem object
 
 311         @RequestMapping(value = {
 
 312                         "/portalApi/functionalMenuItemDetails/{menuId}" }, method = RequestMethod.GET, produces = "application/json")
 
 313         public FunctionalMenuItem getFunctionalMenuItemDetails(HttpServletRequest request,
 
 314                         @PathVariable("menuId") Long menuId, HttpServletResponse response) {
 
 315                 // TODO: return FunctionalMenuItemJson
 
 316                 // TODO: modify FunctionalMenuItem to not include the transient fields
 
 317                 FunctionalMenuItem menuItem = null;
 
 319                         EPUser user = EPUserUtils.getUserSession(request);
 
 320                         if (!adminRolesService.isSuperAdmin(user)) {
 
 321                                 EcompPortalUtils.setBadPermissions(user, response, "getFunctionalMenuItemDetails");
 
 323                                 menuItem = functionalMenuService.getFunctionalMenuItemDetails(menuId);
 
 324                                 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/functionalMenuItemDetails/" + menuId,
 
 325                                                 "result =", menuItem);
 
 327                 } catch (Exception e) {
 
 328                         logger.error(EELFLoggerDelegate.errorLogger, "getFunctionalMenuItemDetails failed", e);
 
 335          * RESTful service method to create a new menu item.
 
 337          * Requirement: you must be the Ecomp portal super admin user.
 
 342          *            HttpServletResponse
 
 343          * @param menuItemJson
 
 344          *            FunctionalMenuItemWithRoles
 
 345          * @return FieldsValidator
 
 347         @RequestMapping(value = { "/portalApi/functionalMenuItem" }, method = RequestMethod.POST)
 
 348         public FieldsValidator createFunctionalMenuItem(HttpServletRequest request,
 
 349                         @RequestBody FunctionalMenuItemWithRoles menuItemJson, HttpServletResponse response) {
 
 350                 EPUser user = EPUserUtils.getUserSession(request);
 
 351                 FieldsValidator fieldsValidator = null;
 
 352                 if (!adminRolesService.isSuperAdmin(user)) {
 
 353                         logger.debug(EELFLoggerDelegate.debugLogger,
 
 354                                         "FunctionalMenuController.createFunctionalMenuItem bad permissions");
 
 355                         EcompPortalUtils.setBadPermissions(user, response, "createFunctionalMenuItem");
 
 357                         fieldsValidator = functionalMenuService.createFunctionalMenuItem(menuItemJson);
 
 358                         response.setStatus(fieldsValidator.httpStatusCode.intValue());
 
 359                         EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/functionalMenuItem", "POST result =",
 
 360                                         response.getStatus());
 
 363                 return fieldsValidator;
 
 367          * RESTful service method to update an existing menu item
 
 369          * Requirement: you must be the Ecomp portal super admin user.
 
 374          *            HttpServletResponse
 
 375          * @param menuItemJson
 
 376          *            FunctionalMenuItemWithRoles
 
 377          * @return FieldsValidator
 
 379         @RequestMapping(value = { "/portalApi/functionalMenuItem" }, method = RequestMethod.PUT)
 
 380         public FieldsValidator editFunctionalMenuItem(HttpServletRequest request,
 
 381                         @RequestBody FunctionalMenuItemWithRoles menuItemJson, HttpServletResponse response) {
 
 382                 EPUser user = EPUserUtils.getUserSession(request);
 
 383                 FieldsValidator fieldsValidator = null;
 
 384                 if (!adminRolesService.isSuperAdmin(user)) {
 
 385                         EcompPortalUtils.setBadPermissions(user, response, "editFunctionalMenuItem");
 
 387                         fieldsValidator = functionalMenuService.editFunctionalMenuItem(menuItemJson);
 
 388                         response.setStatus(fieldsValidator.httpStatusCode.intValue());
 
 389                         EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/functionalMenuItem", "PUT result =",
 
 390                                         response.getStatus());
 
 393                 return fieldsValidator;
 
 397          * RESTful service method to delete a menu item
 
 402          *            HttpServletResponse
 
 405          * @return FieldsValidator
 
 407         @RequestMapping(value = { "/portalApi/functionalMenuItem/{menuId}" }, method = RequestMethod.DELETE)
 
 408         public FieldsValidator deleteFunctionalMenuItem(HttpServletRequest request, @PathVariable("menuId") Long menuId,
 
 409                         HttpServletResponse response) {
 
 410                 EPUser user = EPUserUtils.getUserSession(request);
 
 411                 FieldsValidator fieldsValidator = null;
 
 412                 if (!adminRolesService.isSuperAdmin(user)) {
 
 413                         EcompPortalUtils.setBadPermissions(user, response, "deleteFunctionalMenuItem");
 
 415                         fieldsValidator = functionalMenuService.deleteFunctionalMenuItem(menuId);
 
 416                         response.setStatus(fieldsValidator.httpStatusCode.intValue());
 
 417                         EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/functionalMenuItem", "DELETE result =",
 
 418                                         response.getStatus());
 
 421                 return fieldsValidator;
 
 425          * RESTful service to regenerate table
 
 430          *            HttpServletResponse
 
 431          * @return FieldsValidator
 
 433         @RequestMapping(value = { "/portalApi/regenerateFunctionalMenuAncestors" }, method = RequestMethod.GET)
 
 434         public FieldsValidator regenerateAncestorTable(HttpServletRequest request, HttpServletResponse response) {
 
 435                 // TODO: should only the superuser be allowed to use this API?
 
 436                 EPUser user = EPUserUtils.getUserSession(request);
 
 437                 FieldsValidator fieldsValidator = null;
 
 439                 if (!adminRolesService.isSuperAdmin(user)) {
 
 440                         EcompPortalUtils.setBadPermissions(user, response, "deleteFunctionalMenuItem");
 
 442                         fieldsValidator = functionalMenuService.regenerateAncestorTable();
 
 443                         response.setStatus(fieldsValidator.httpStatusCode.intValue());
 
 444                         EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/regenerateAncestorTable", "GET result =",
 
 445                                         response.getStatus());
 
 448                 return fieldsValidator;
 
 452          * RESful service to set a favorite item.
 
 457          *            HttpServletResponse
 
 458          * @param menuItemJson
 
 459          *            FunctionalMenuItemWithRoles
 
 460          * @return FieldsValidator
 
 462         @RequestMapping(value = { "/portalApi/setFavoriteItem" }, method = RequestMethod.POST)
 
 463         public FieldsValidator addFavoriteItem(HttpServletRequest request,
 
 464                         @RequestBody FavoritesFunctionalMenuItem menuItemJson, HttpServletResponse response) {
 
 465                 EPUser user = EPUserUtils.getUserSession(request);
 
 466                 FieldsValidator fieldsValidator = null;
 
 467                 menuItemJson.userId = user.getId();
 
 468                 fieldsValidator = functionalMenuService.setFavoriteItem(menuItemJson);
 
 469                 response.setStatus(fieldsValidator.httpStatusCode.intValue());
 
 470                 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/setFavoriteItem", "Post result =",
 
 471                                 response.getStatus());
 
 473                 return fieldsValidator;
 
 477          * RESTful service to get favorites for the current user as identified in the
 
 483          *            HttpServletResponse
 
 484          * @return List of FavoritesFunctionalMenuItemJson
 
 486         @RequestMapping(value = {
 
 487                         "/portalApi/getFavoriteItems" }, method = RequestMethod.GET, produces = "application/json")
 
 488         public List<FavoritesFunctionalMenuItemJson> getFavoritesForUser(HttpServletRequest request,
 
 489                         HttpServletResponse response) {
 
 490                 EPUser user = EPUserUtils.getUserSession(request);
 
 491                 List<FavoritesFunctionalMenuItemJson> favorites = functionalMenuService.getFavoriteItems(user.getId());
 
 492                 FieldsValidator fieldsValidator = new FieldsValidator();
 
 493                 response.setStatus(fieldsValidator.httpStatusCode.intValue());
 
 494                 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/getFavoriteItems", "GET result =",
 
 495                                 response.getStatus());
 
 500          * RESTful service to delete a favorite menu item for the current user as
 
 501          * identified in the session.
 
 506          *            HttpServletResponse
 
 509          * @return FieldsValidator
 
 511         @RequestMapping(value = { "/portalApi/removeFavoriteItem/{menuId}" }, method = RequestMethod.DELETE)
 
 512         public FieldsValidator deleteFavoriteItem(HttpServletRequest request, @PathVariable("menuId") Long menuId,
 
 513                         HttpServletResponse response) {
 
 514                 EPUser user = EPUserUtils.getUserSession(request);
 
 515                 FieldsValidator fieldsValidator = null;
 
 516                 Long userId = user.getId();
 
 517                 fieldsValidator = functionalMenuService.removeFavoriteItem(userId, menuId);
 
 518                 response.setStatus(fieldsValidator.httpStatusCode.intValue());
 
 519                 EcompPortalUtils.logAndSerializeObject(logger, "/deleteFavoriteItem", "DELETE result =", response.getStatus());
 
 521                 return fieldsValidator;
 
 525          * RESTful service to get user information: user's first and last names, org
 
 526          * user ID, email and last-login. (Actually has nothing to do with the real
 
 527          * functional menu.) First attempts to get the information from the Tomcat
 
 528          * session (i.e., the CSP cookie); if that fails, calls the shared context
 
 529          * service to read the information from the database. Gives back what it found,
 
 530          * any of which may be null, as a JSON collection.
 
 535          *            HttpServletResponse
 
 536          * @return JSON collection of key-value pairs shown below.
 
 538         @RequestMapping(value = {
 
 539                         "/portalApi/functionalMenuStaticInfo" }, method = RequestMethod.GET, produces = "application/json")
 
 540         public String getFunctionalMenuStaticInfo(HttpServletRequest request, HttpServletResponse response) {
 
 542                 // Get user details from session
 
 543                 logger.debug(EELFLoggerDelegate.debugLogger, "getFunctionalMenuStaticInfo: getting user info");
 
 544                 String fnMenuStaticResponse = null;
 
 546                         String orgUserIdStr = null, firstNameStr = null, lastNameStr = null, emailStr = null, lastLogin = null;
 
 547                         EPUser user = EPUserUtils.getUserSession(request);
 
 548                         firstNameStr = user.getFirstName();
 
 549                         lastNameStr = user.getLastName();
 
 550                         orgUserIdStr = user.getOrgUserId();
 
 551                         emailStr = user.getEmail();
 
 552                         if (emailStr == null || emailStr.equals("")) {
 
 553                                 EPUser userResult = searchService.searchUserByUserId(orgUserIdStr);
 
 554                                 emailStr = userResult.getEmail();
 
 556                         SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss Z a");
 
 557                         Date lastLoginDate = user.getLastLoginDate();
 
 558                         if (lastLoginDate == null) {
 
 559                                 // should never happen
 
 560                                 logger.error(EELFLoggerDelegate.errorLogger, "getFunctionalMenuStaticInfo: no last login in session");
 
 561                                 lastLogin = "no last login available";
 
 563                                 lastLogin = sdf.format(lastLoginDate);
 
 566                         // If any item is missing from session, try the Shared Context
 
 568                         SharedContext orgUserIdSC = null, firstNameSC = null, lastNameSC = null, emailSC = null;
 
 569                         String sessionId = request.getSession().getId();
 
 570                         if (firstNameStr == null)
 
 571                                 firstNameSC = sharedContextService.getSharedContext(sessionId,
 
 572                                                 EPCommonSystemProperties.USER_FIRST_NAME);
 
 573                         if (lastNameStr == null)
 
 574                                 lastNameSC = sharedContextService.getSharedContext(sessionId, EPCommonSystemProperties.USER_LAST_NAME);
 
 575                         if (emailStr == null)
 
 576                                 emailSC = sharedContextService.getSharedContext(sessionId, EPCommonSystemProperties.USER_EMAIL);
 
 577                         if (orgUserIdStr == null)
 
 578                                 orgUserIdSC = sharedContextService.getSharedContext(sessionId,
 
 579                                                 EPCommonSystemProperties.USER_ORG_USERID);
 
 581                         // Build the response
 
 582                         Map<String, String> map = new HashMap<String, String>();
 
 584                                         firstNameStr != null ? firstNameStr : (firstNameSC != null ? firstNameSC.getCvalue() : null));
 
 586                                         lastNameStr != null ? lastNameStr : (lastNameSC != null ? lastNameSC.getCvalue() : null));
 
 587                         map.put("email", emailStr != null ? emailStr : (emailSC != null ? emailSC.getCvalue() : null));
 
 589                                         orgUserIdStr != null ? orgUserIdStr : (orgUserIdSC != null ? orgUserIdSC.getCvalue() : null));
 
 590                         map.put("last_login", lastLogin);
 
 591                         JSONObject j = new JSONObject(map);
 
 592                         fnMenuStaticResponse = j.toString();
 
 593                         // Be chatty in the log
 
 594                         EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/functionalMenuStaticInfo", "GET result =",
 
 595                                         fnMenuStaticResponse);
 
 596                 } catch (Exception e) {
 
 597                         // Should never happen.
 
 598                         logger.error(EELFLoggerDelegate.errorLogger, "getFunctionalMenuStaticInfo failed", e);
 
 599                         // Return a real error?
 
 600                         // fnMenuStaticResponse = "{ \"status\": \"error\", \"message\": \""
 
 601                         // + e.toString() + "\" }";
 
 602                         // But the angular controller expects null on error.
 
 604                 return fnMenuStaticResponse;
 
 607         private Comparator<BusinessCardApplicationRole> getUserAppRolesComparator = new Comparator<BusinessCardApplicationRole>() {
 
 608                 public int compare(BusinessCardApplicationRole o1, BusinessCardApplicationRole o2) {
 
 609                         return o1.getAppName().compareTo(o2.getAppName());
 
 619          * @return List<BusinessCardApplicationRolesList>
 
 620          * @throws IOException
 
 623         @RequestMapping(value = {
 
 624                         "/portalApi/userApplicationRoles" }, method = RequestMethod.GET, produces = "application/json")
 
 625         public List<BusinessCardApplicationRolesList> getAppList(HttpServletRequest request,
 
 626                         @RequestParam("userId") String userId) throws IOException {
 
 628                 List<BusinessCardApplicationRolesList> AppRoles = null;
 
 630                         List<BusinessCardApplicationRole> userAppRoleList = functionalMenuService.getUserAppRolesList(userId);
 
 632                         Collections.sort(userAppRoleList, getUserAppRolesComparator);
 
 633                         EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/userApplicationRoles", "result =",
 
 636                         AppRoles = new ArrayList<BusinessCardApplicationRolesList>();
 
 637                         for (BusinessCardApplicationRole userAppRole : userAppRoleList) {
 
 638                                 boolean found = false;
 
 639                                 List<String> roles = null;
 
 641                                 for (BusinessCardApplicationRolesList app : AppRoles) {
 
 642                                         if (app.getAppName().equals(userAppRole.getAppName())) {
 
 643                                                 roles = app.getRoleNames();
 
 644                                                 roles.add(userAppRole.getRoleName());
 
 645                                                 app.setRoleNames(roles);
 
 652                                         roles = new ArrayList<String>();
 
 653                                         roles.add(userAppRole.getRoleName());
 
 654                                         AppRoles.add(new BusinessCardApplicationRolesList(userAppRole.getAppName(), roles));
 
 657                                 Collections.sort(roles);
 
 659                 } catch (Exception e) {
 
 660                         logger.error(EELFLoggerDelegate.errorLogger, "getAppList failed", e);