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.portal.service;
40 import java.util.Collection;
41 import java.util.Comparator;
42 import java.util.LinkedHashMap;
45 import java.util.SortedSet;
46 import java.util.TreeSet;
48 import org.json.JSONArray;
49 import org.json.JSONObject;
50 import org.springframework.beans.factory.annotation.Autowired;
51 import org.springframework.context.annotation.EnableAspectJAutoProxy;
52 import org.springframework.stereotype.Service;
53 import org.springframework.transaction.annotation.Transactional;
55 import org.openecomp.portalsdk.core.domain.MenuData;
56 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
57 import org.openecomp.portalapp.portal.domain.EPUser;
58 import org.openecomp.portalapp.portal.domain.UserRoles;
59 //import org.openecomp.portalapp.portal.domain.Menu;
60 import org.openecomp.portalapp.portal.logging.aop.EPMetricsLog;
62 @Service("leftMenuService")
64 @org.springframework.context.annotation.Configuration
65 @EnableAspectJAutoProxy
68 public class EPLeftMenuServiceImpl implements EPLeftMenuService {
70 private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(EPLeftMenuServiceImpl.class);
73 private EPAppService appService;
79 * org.openecomp.portalapp.portal.service.EPLeftMenuService#getLeftMenuItems
83 public String getLeftMenuItems(EPUser user, Set<MenuData> fullMenuSet, Set<String> roleFunctionSet) {
84 final Map<String, JSONObject> defaultNavMap = new LinkedHashMap<String, JSONObject>();
86 resetNavMap(defaultNavMap);
88 loadDefaultNavMap(defaultNavMap);
90 // Handle Account Administrator in a special way; soon this will
91 // be revised as Account Administrator may become obsolete
94 UserRoles uRoles = appService.getUserProfileNormalizedForLeftMenu(user);
95 if (uRoles.getRoles().contains("Account Administrator"))
96 loadAccAdminNavMap(defaultNavMap);
98 } catch (Exception e) {
99 logger.error(EELFLoggerDelegate.errorLogger,
100 "getLeftMenuItems: failed to get roles for user " + user.getOrgUserId(), e);
103 loadNavMapByRole(defaultNavMap, fullMenuSet);
105 return convertToSideBarModel(defaultNavMap);
111 * @param defaultNavMap
113 private void resetNavMap(Map<String, JSONObject> defaultNavMap) {
114 defaultNavMap.clear();
119 * @param defaultNavMap
122 private void loadNavMapByRole(Map<String, JSONObject> defaultNavMap, Set<MenuData> fullMenuSet) {
124 class SortOrderComparator implements Comparator<MenuData> {
126 public int compare(MenuData e1, MenuData e2) {
127 return e1.getSortOrder().compareTo(e2.getSortOrder());
131 SortedSet<MenuData> sortMenuSet = new TreeSet<MenuData>(new SortOrderComparator());
132 for (MenuData mn : fullMenuSet) {
136 for (MenuData mn : sortMenuSet) {
137 JSONObject navItemsDetails = new JSONObject();
138 navItemsDetails.put("name", mn.getLabel());
139 navItemsDetails.put("state", mn.getAction());
140 navItemsDetails.put("imageSrc", mn.getImageSrc());
141 defaultNavMap.put(mn.getAction(), navItemsDetails);
147 * @param defaultNavMap
150 private String convertToSideBarModel(Map<String, JSONObject> defaultNavMap) {
151 JSONObject sidebarModel = new JSONObject();
152 JSONArray navItems = new JSONArray();
153 Collection<JSONObject> jsonObjs = defaultNavMap.values();
155 for (JSONObject navItemsDetail : jsonObjs)
156 navItems.put(navItemsDetail);
158 sidebarModel.put("label", "ECOMP portal");
159 sidebarModel.put("navItems", navItems);
160 return sidebarModel.toString();
164 * Loads default entries for regular user.
166 * @param defaultNavMap
168 private void loadDefaultNavMap(Map<String, JSONObject> defaultNavMap) {
170 JSONObject navItemsDetails1 = new JSONObject();
171 navItemsDetails1.put("name", "Home");
172 navItemsDetails1.put("state", "root.applicationsHome");
173 navItemsDetails1.put("imageSrc", "icon-building-home");
174 defaultNavMap.put("root.applicationsHome", navItemsDetails1);
176 JSONObject navItemsDetails2 = new JSONObject();
177 navItemsDetails2.put("name", "Application Catalog");
178 navItemsDetails2.put("state", "root.appCatalog");
179 navItemsDetails2.put("imageSrc", "icon-apps-marketplace");
180 defaultNavMap.put("root.appCatalog", navItemsDetails2);
182 JSONObject navItemsDetails3 = new JSONObject();
183 navItemsDetails3.put("name", "Widget Catalog");
184 navItemsDetails3.put("state", "root.widgetCatalog");
185 navItemsDetails3.put("imageSrc", "icon-apps-marketplace");
186 defaultNavMap.put("root.widgetCatalog", navItemsDetails3);
191 * Loads default entries for application administrator.
193 * @param defaultNavMap
195 private void loadAccAdminNavMap(Map<String, JSONObject> defaultNavMap) {
197 JSONObject navItemsDetails1 = new JSONObject();
198 navItemsDetails1.put("name", "Users");
199 navItemsDetails1.put("state", "root.users");
200 navItemsDetails1.put("imageSrc", "icon-user");
201 defaultNavMap.put("root.users", navItemsDetails1);
203 // No more widget onboarding like this:
205 // JSONObject navItemsDetails2 = new JSONObject();
206 // navItemsDetails2.put("name", "Widget Onboarding");
207 // navItemsDetails2.put("state", "root.widgetOnboarding");
208 // navItemsDetails2.put("imageSrc", "icon-add-widget");
209 // defaultNavMap.put("root.widgetOnboarding", navItemsDetails2);