nexus site path corrected
[portal.git] / ecomp-portal-BE / src / main / java / org / openecomp / portalapp / uebhandler / FunctionalMenuHandler.java
1 /*-
2  * ================================================================================
3  * eCOMP Portal
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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  * ================================================================================
19  */
20 package org.openecomp.portalapp.uebhandler;
21
22 import java.util.List;
23
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;
40
41 import com.google.gson.Gson;
42
43 @Component
44 @org.springframework.context.annotation.Configuration
45 @EnableAspectJAutoProxy
46 @EPAuditLog
47 public class FunctionalMenuHandler { 
48         EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(FunctionalMenuHandler.class);
49         
50         @Autowired
51         AdminRolesService adminRolesService;
52         
53         @Autowired
54         FunctionalMenuService functionalMenuService;
55         
56         @Autowired
57         SearchService searchSvc;
58         
59         @Autowired 
60         DataAccessService dataAccessService;
61
62         @Async
63         public Boolean getFunctionalMenu(UebMsg requestMsg)
64         {
65                 UebMsg returnMsg = new UebMsg();
66                 
67                 if (requestMsg == null)
68                 {
69                         logger.error(EELFLoggerDelegate.errorLogger, "handleMenuRequest received null message");
70                         return false;
71                 }
72                 else if (requestMsg.getSourceTopicName() == null)
73                 {
74                         logger.error(EELFLoggerDelegate.errorLogger, "A source topic name is required and not found in this msg:" + requestMsg.toString());
75                         return false;
76                 }
77                 else if (requestMsg.getUserId() == null)
78                 {
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");
82                 }
83                 else
84                 {
85                         logger.debug(EELFLoggerDelegate.debugLogger, "Getting functional menu for user = " + requestMsg.getUserId());
86                         EPUser user = searchSvc.searchUserByUserId(requestMsg.getUserId());
87                         
88                         List<FunctionalMenuItem> menuItems = null;
89                         if (user == null) 
90                         {
91                                 logger.debug(EELFLoggerDelegate.debugLogger, "Error getting functional menu.  userId not found in directory or is guest: " + requestMsg.toString());
92                         } 
93                 else if (adminRolesService.isSuperAdmin(user)) 
94                 {  
95                                 logger.debug(EELFLoggerDelegate.debugLogger, "FunctionalMenuHandler: SuperUser, about to call getFunctionalMenuItems()");
96                                 menuItems = functionalMenuService.getFunctionalMenuItems();
97                         } 
98                 else 
99                         {
100                                 logger.debug(EELFLoggerDelegate.debugLogger, "getMenuItemsForAuthUser: about to call getFunctionalMenuItemsForUser()");
101                                 menuItems = functionalMenuService.getFunctionalMenuItemsForUser(requestMsg.getUserId());
102                         }
103                     
104                         if ( menuItems != null )
105                     {
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);
110                         } else {
111                                 returnMsg.putMsgId(requestMsg.getMsgId());  // echo tells requester this is a response
112                                 returnMsg.putPayload("Error: Not found for userId = " + requestMsg.getUserId());
113                         }
114                 }
115             
116                 try {
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));
122             }
123         
124         return true;
125         }
126 }