2 * ================================================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ================================================================================
20 package org.openecomp.portalapp.uebhandler;
22 import java.util.List;
24 import org.openecomp.portalapp.portal.domain.EPUser;
25 import org.openecomp.portalapp.portal.logging.aop.EPAuditLog;
26 import org.openecomp.portalapp.portal.service.AdminRolesService;
27 import org.openecomp.portalapp.portal.service.FunctionalMenuService;
28 import org.openecomp.portalapp.portal.service.SearchService;
29 import org.openecomp.portalapp.portal.transport.FunctionalMenuItem;
30 import org.openecomp.portalapp.portal.utils.EcompPortalUtils;
31 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
32 import org.openecomp.portalsdk.core.onboarding.ueb.UebException;
33 import org.openecomp.portalsdk.core.onboarding.ueb.UebManager;
34 import org.openecomp.portalsdk.core.onboarding.ueb.UebMsg;
35 import org.openecomp.portalsdk.core.service.DataAccessService;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.context.annotation.EnableAspectJAutoProxy;
38 import org.springframework.scheduling.annotation.Async;
39 import org.springframework.stereotype.Component;
41 import com.google.gson.Gson;
44 @org.springframework.context.annotation.Configuration
45 @EnableAspectJAutoProxy
47 public class FunctionalMenuHandler {
48 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(FunctionalMenuHandler.class);
51 AdminRolesService adminRolesService;
54 FunctionalMenuService functionalMenuService;
57 SearchService searchSvc;
60 DataAccessService dataAccessService;
63 public Boolean getFunctionalMenu(UebMsg requestMsg)
65 UebMsg returnMsg = new UebMsg();
67 if (requestMsg == null)
69 logger.error(EELFLoggerDelegate.errorLogger, "handleMenuRequest received null message");
72 else if (requestMsg.getSourceTopicName() == null)
74 logger.error(EELFLoggerDelegate.errorLogger, "A source topic name is required and not found in this msg:" + requestMsg.toString());
77 else if (requestMsg.getUserId() == null)
79 logger.debug(EELFLoggerDelegate.debugLogger, "Error getting functional menu. A userId is required and not found in this msg: " + requestMsg.toString());
80 returnMsg.putMsgId(requestMsg.getMsgId()); // echo tells requester this is a response
81 returnMsg.putPayload("Error: A userId is required. Call msg.putUserId() with an userId");
85 logger.debug(EELFLoggerDelegate.debugLogger, "Getting functional menu for user = " + requestMsg.getUserId());
86 EPUser user = searchSvc.searchUserByUserId(requestMsg.getUserId());
88 List<FunctionalMenuItem> menuItems = null;
91 logger.debug(EELFLoggerDelegate.debugLogger, "Error getting functional menu. userId not found in directory or is guest: " + requestMsg.toString());
93 else if (adminRolesService.isSuperAdmin(user))
95 logger.debug(EELFLoggerDelegate.debugLogger, "FunctionalMenuHandler: SuperUser, about to call getFunctionalMenuItems()");
96 menuItems = functionalMenuService.getFunctionalMenuItems();
100 logger.debug(EELFLoggerDelegate.debugLogger, "getMenuItemsForAuthUser: about to call getFunctionalMenuItemsForUser()");
101 menuItems = functionalMenuService.getFunctionalMenuItemsForUser(requestMsg.getUserId());
104 if ( menuItems != null )
106 String functionalMenuJsonString = new Gson().toJson(menuItems);
107 logger.debug(EELFLoggerDelegate.debugLogger, "returning functional menu : " + functionalMenuJsonString);
108 returnMsg.putMsgId(requestMsg.getMsgId()); // echo tells requester this is a response
109 returnMsg.putPayload(functionalMenuJsonString);
111 returnMsg.putMsgId(requestMsg.getMsgId()); // echo tells requester this is a response
112 returnMsg.putPayload("Error: Not found for userId = " + requestMsg.getUserId());
117 UebManager.getInstance().publishReplyEP(returnMsg, requestMsg.getSourceTopicName());
118 } catch (UebException e) {
119 logger.error(EELFLoggerDelegate.errorLogger, "UebException occurred while responding to the Ueb message, Details:" + EcompPortalUtils.getStackTrace(e));
120 } catch (Exception e) {
121 logger.error(EELFLoggerDelegate.errorLogger, "Exception occurred while responding to the Ueb message, Details:" + EcompPortalUtils.getStackTrace(e));