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.uebhandler;
40 import java.util.List;
42 import org.onap.portalapp.portal.domain.EPUser;
43 import org.onap.portalapp.portal.logging.aop.EPAuditLog;
44 import org.onap.portalapp.portal.service.AdminRolesService;
45 import org.onap.portalapp.portal.service.FunctionalMenuService;
46 import org.onap.portalapp.portal.service.SearchService;
47 import org.onap.portalapp.portal.transport.FunctionalMenuItem;
48 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
49 import org.onap.portalsdk.core.onboarding.ueb.UebException;
50 import org.onap.portalsdk.core.onboarding.ueb.UebManager;
51 import org.onap.portalsdk.core.onboarding.ueb.UebMsg;
52 import org.springframework.beans.factory.annotation.Autowired;
53 import org.springframework.context.annotation.EnableAspectJAutoProxy;
54 import org.springframework.scheduling.annotation.Async;
55 import org.springframework.stereotype.Component;
57 import com.google.gson.Gson;
60 @org.springframework.context.annotation.Configuration
61 @EnableAspectJAutoProxy
63 public class FunctionalMenuHandler {
64 private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(FunctionalMenuHandler.class);
67 private AdminRolesService adminRolesService;
70 private FunctionalMenuService functionalMenuService;
73 private SearchService searchSvc;
76 public Boolean getFunctionalMenu(UebMsg requestMsg) {
77 UebMsg returnMsg = new UebMsg();
79 if (requestMsg == null) {
80 logger.error(EELFLoggerDelegate.errorLogger, "handleMenuRequest received null message");
82 } else if (requestMsg.getSourceTopicName() == null) {
83 logger.error(EELFLoggerDelegate.errorLogger,
84 "A source topic name is required and not found in this msg:" + requestMsg.toString());
86 } else if (requestMsg.getUserId() == null) {
87 logger.debug(EELFLoggerDelegate.debugLogger,
88 "Error getting functional menu. A userId is required and not found in this msg: "
89 + requestMsg.toString());
90 returnMsg.putMsgId(requestMsg.getMsgId()); // echo tells requester this is a response
91 returnMsg.putPayload("Error: A userId is required. Call msg.putUserId() with an userId");
93 logger.debug(EELFLoggerDelegate.debugLogger,
94 "Getting functional menu for user = " + requestMsg.getUserId());
95 EPUser user = searchSvc.searchUserByUserId(requestMsg.getUserId());
97 List<FunctionalMenuItem> menuItems = null;
99 logger.debug(EELFLoggerDelegate.debugLogger,
100 "Error getting functional menu. userId not found in directory or is guest: "
101 + requestMsg.toString());
102 } else if (adminRolesService.isSuperAdmin(user)) {
103 logger.debug(EELFLoggerDelegate.debugLogger,
104 "FunctionalMenuHandler: SuperUser, about to call getFunctionalMenuItems()");
105 menuItems = functionalMenuService.getFunctionalMenuItems();
107 logger.debug(EELFLoggerDelegate.debugLogger,
108 "getMenuItemsForAuthUser: about to call getFunctionalMenuItemsForUser()");
109 menuItems = functionalMenuService.getFunctionalMenuItemsForUser(requestMsg.getUserId());
112 if (menuItems != null) {
113 String functionalMenuJsonString = new Gson().toJson(menuItems);
114 logger.debug(EELFLoggerDelegate.debugLogger, "returning functional menu : " + functionalMenuJsonString);
115 returnMsg.putMsgId(requestMsg.getMsgId()); // echo tells requester this is a response
116 returnMsg.putPayload(functionalMenuJsonString);
118 returnMsg.putMsgId(requestMsg.getMsgId()); // echo tells requester this is a response
119 returnMsg.putPayload("Error: Not found for userId = " + requestMsg.getUserId());
124 UebManager.getInstance().publishReplyEP(returnMsg, requestMsg.getSourceTopicName());
125 } catch (UebException e) {
126 logger.error(EELFLoggerDelegate.errorLogger, "getFunctionalMenu failed on UEB exception", e);
127 } catch (Exception e) {
128 logger.error(EELFLoggerDelegate.errorLogger, "getFunctionalMenu failed", e);