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.portal.service;
40 import java.util.Collection;
41 import java.util.Comparator;
42 import java.util.LinkedHashMap;
43 import java.util.List;
46 import java.util.SortedSet;
47 import java.util.TreeSet;
49 import org.json.JSONArray;
50 import org.json.JSONObject;
51 import org.onap.portalapp.portal.domain.CentralizedApp;
52 import org.onap.portalapp.portal.domain.EPUser;
53 import org.onap.portalapp.portal.logging.aop.EPMetricsLog;
54 import org.onap.portalsdk.core.domain.MenuData;
55 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
56 import org.springframework.beans.factory.annotation.Autowired;
57 import org.springframework.context.annotation.EnableAspectJAutoProxy;
58 import org.springframework.stereotype.Service;
59 import org.springframework.transaction.annotation.Transactional;
61 @Service("leftMenuService")
63 @org.springframework.context.annotation.Configuration
64 @EnableAspectJAutoProxy
67 public class EPLeftMenuServiceImpl implements EPLeftMenuService {
69 private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(EPLeftMenuServiceImpl.class);
73 private ExternalAccessRolesService externalAccessRolesService;
78 * org.onap.portalapp.portal.service.EPLeftMenuService#getLeftMenuItems
82 public String getLeftMenuItems(EPUser user, Set<MenuData> fullMenuSet, Set<String> roleFunctionSet) {
83 final Map<String, JSONObject> defaultNavMap = new LinkedHashMap<String, JSONObject>();
84 resetNavMap(defaultNavMap);
85 loadDefaultNavMap(defaultNavMap);
86 loadNavMapByRole(defaultNavMap, fullMenuSet , user);
87 return convertToSideBarModel(defaultNavMap);
93 * @param defaultNavMap
95 private void resetNavMap(Map<String, JSONObject> defaultNavMap) {
96 defaultNavMap.clear();
101 * @param defaultNavMap
104 private void loadNavMapByRole(Map<String, JSONObject> defaultNavMap, Set<MenuData> fullMenuSet , EPUser user) {
106 class SortOrderComparator implements Comparator<MenuData> {
108 public int compare(MenuData e1, MenuData e2) {
109 return e1.getSortOrder().compareTo(e2.getSortOrder());
113 SortedSet<MenuData> sortMenuSet = new TreeSet<MenuData>(new SortOrderComparator());
114 for (MenuData mn : fullMenuSet) {
118 // Remove Roles from left menu if user doesnt have admin access on
119 // centralized application
120 List<CentralizedApp> applicationsList = null;
121 applicationsList = externalAccessRolesService.getCentralizedAppsOfUser(user.getOrgUserId());
122 if (applicationsList.size() == 0)
123 sortMenuSet.removeIf(x -> x.getLabel().contains("Roles"));
125 for (MenuData mn : sortMenuSet) {
126 JSONObject navItemsDetails = new JSONObject();
127 navItemsDetails.put("name", mn.getLabel());
128 navItemsDetails.put("state", mn.getAction());
129 navItemsDetails.put("imageSrc", mn.getImageSrc());
130 defaultNavMap.put(mn.getAction(), navItemsDetails);
136 * @param defaultNavMap
139 private String convertToSideBarModel(Map<String, JSONObject> defaultNavMap) {
140 JSONObject sidebarModel = new JSONObject();
141 JSONArray navItems = new JSONArray();
142 Collection<JSONObject> jsonObjs = defaultNavMap.values();
144 for (JSONObject navItemsDetail : jsonObjs)
145 navItems.put(navItemsDetail);
147 sidebarModel.put("label", "ECOMP portal");
148 sidebarModel.put("navItems", navItems);
149 return sidebarModel.toString();
153 * Loads default entries for regular user.
155 * @param defaultNavMap
157 private void loadDefaultNavMap(Map<String, JSONObject> defaultNavMap) {
159 JSONObject navItemsDetails1 = new JSONObject();
160 navItemsDetails1.put("name", "Home");
161 navItemsDetails1.put("state", "root.applicationsHome");
162 navItemsDetails1.put("imageSrc", "icon-building-home");
163 defaultNavMap.put("root.applicationsHome", navItemsDetails1);
165 JSONObject navItemsDetails2 = new JSONObject();
166 navItemsDetails2.put("name", "Application Catalog");
167 navItemsDetails2.put("state", "root.appCatalog");
168 navItemsDetails2.put("imageSrc", "icon-apps-marketplace");
169 defaultNavMap.put("root.appCatalog", navItemsDetails2);
171 JSONObject navItemsDetails3 = new JSONObject();
172 navItemsDetails3.put("name", "Widget Catalog");
173 navItemsDetails3.put("state", "root.widgetCatalog");
174 navItemsDetails3.put("imageSrc", "icon-apps-marketplace");
175 defaultNavMap.put("root.widgetCatalog", navItemsDetails3);