2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 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.openecomp.portalapp.uebhandler;
40 import java.util.List;
42 import org.openecomp.portalapp.portal.domain.EPUser;
43 import org.openecomp.portalapp.portal.logging.aop.EPAuditLog;
44 import org.openecomp.portalapp.portal.service.AdminRolesService;
45 import org.openecomp.portalapp.portal.service.FunctionalMenuService;
46 import org.openecomp.portalapp.portal.service.SearchService;
47 import org.openecomp.portalapp.portal.transport.FunctionalMenuItem;
48 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
49 import org.openecomp.portalsdk.core.onboarding.ueb.UebException;
50 import org.openecomp.portalsdk.core.onboarding.ueb.UebManager;
51 import org.openecomp.portalsdk.core.onboarding.ueb.UebMsg;
52 import org.openecomp.portalsdk.core.service.DataAccessService;
53 import org.springframework.beans.factory.annotation.Autowired;
54 import org.springframework.context.annotation.EnableAspectJAutoProxy;
55 import org.springframework.scheduling.annotation.Async;
56 import org.springframework.stereotype.Component;
58 import com.google.gson.Gson;
61 @org.springframework.context.annotation.Configuration
62 @EnableAspectJAutoProxy
64 public class FunctionalMenuHandler {
65 private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(FunctionalMenuHandler.class);
68 private AdminRolesService adminRolesService;
71 private FunctionalMenuService functionalMenuService;
74 private SearchService searchSvc;
77 public Boolean getFunctionalMenu(UebMsg requestMsg) {
78 UebMsg returnMsg = new UebMsg();
80 if (requestMsg == null) {
81 logger.error(EELFLoggerDelegate.errorLogger, "handleMenuRequest received null message");
83 } else if (requestMsg.getSourceTopicName() == null) {
84 logger.error(EELFLoggerDelegate.errorLogger,
85 "A source topic name is required and not found in this msg:" + requestMsg.toString());
87 } else if (requestMsg.getUserId() == null) {
88 logger.debug(EELFLoggerDelegate.debugLogger,
89 "Error getting functional menu. A userId is required and not found in this msg: "
90 + requestMsg.toString());
91 returnMsg.putMsgId(requestMsg.getMsgId()); // echo tells requester this is a response
92 returnMsg.putPayload("Error: A userId is required. Call msg.putUserId() with an userId");
94 logger.debug(EELFLoggerDelegate.debugLogger,
95 "Getting functional menu for user = " + requestMsg.getUserId());
96 EPUser user = searchSvc.searchUserByUserId(requestMsg.getUserId());
98 List<FunctionalMenuItem> menuItems = null;
100 logger.debug(EELFLoggerDelegate.debugLogger,
101 "Error getting functional menu. userId not found in directory or is guest: "
102 + requestMsg.toString());
103 } else if (adminRolesService.isSuperAdmin(user)) {
104 logger.debug(EELFLoggerDelegate.debugLogger,
105 "FunctionalMenuHandler: SuperUser, about to call getFunctionalMenuItems()");
106 menuItems = functionalMenuService.getFunctionalMenuItems();
108 logger.debug(EELFLoggerDelegate.debugLogger,
109 "getMenuItemsForAuthUser: about to call getFunctionalMenuItemsForUser()");
110 menuItems = functionalMenuService.getFunctionalMenuItemsForUser(requestMsg.getUserId());
113 if (menuItems != null) {
114 String functionalMenuJsonString = new Gson().toJson(menuItems);
115 logger.debug(EELFLoggerDelegate.debugLogger, "returning functional menu : " + functionalMenuJsonString);
116 returnMsg.putMsgId(requestMsg.getMsgId()); // echo tells requester this is a response
117 returnMsg.putPayload(functionalMenuJsonString);
119 returnMsg.putMsgId(requestMsg.getMsgId()); // echo tells requester this is a response
120 returnMsg.putPayload("Error: Not found for userId = " + requestMsg.getUserId());
125 UebManager.getInstance().publishReplyEP(returnMsg, requestMsg.getSourceTopicName());
126 } catch (UebException e) {
127 logger.error(EELFLoggerDelegate.errorLogger,
128 "getFunctionalMenu failed to publish reply", e);
129 } catch (Exception e) {
130 logger.error(EELFLoggerDelegate.errorLogger,
131 "getFunctionalMenu failed", e);