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.controller;
40 import java.util.ArrayList;
41 import java.util.HashMap;
42 import java.util.List;
46 import javax.servlet.http.HttpServletRequest;
47 import javax.servlet.http.HttpSession;
49 import org.openecomp.portalapp.portal.domain.EPUser;
50 import org.openecomp.portalapp.util.EPUserUtils;
51 import org.openecomp.portalsdk.core.controller.FusionBaseController;
52 import org.openecomp.portalsdk.core.domain.MenuData;
53 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
54 import org.openecomp.portalsdk.core.util.SystemProperties;
55 import org.springframework.stereotype.Controller;
56 import org.springframework.web.bind.annotation.ModelAttribute;
58 import com.fasterxml.jackson.databind.ObjectMapper;
61 public abstract class EPFusionBaseController extends FusionBaseController {
63 private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(EPFusionBaseController.class);
66 public boolean isAccessible() {
70 public boolean isRESTfulCall() {
74 @ModelAttribute("menu")
75 public Map<String, Object> messages(HttpServletRequest request) {
76 HttpSession session = null;
77 Map<String, Object> model = new HashMap<String, Object>();
78 session = request.getSession();
79 EPUser user = EPUserUtils.getUserSession(request);
80 if (session != null && user != null) {
81 @SuppressWarnings("unchecked")
82 Set<MenuData> menuResult = (Set<MenuData>) session
83 .getAttribute(SystemProperties.getProperty(SystemProperties.APPLICATION_MENU_ATTRIBUTE_NAME));
85 model = setMenu(menuResult);
86 } catch (Exception e) {
87 logger.error(EELFLoggerDelegate.errorLogger, "messages failed", e);
94 public Map<String, Object> setMenu(Set<MenuData> menuResult) throws Exception {
95 ObjectMapper mapper = new ObjectMapper();
96 List<List<MenuData>> childItemList = new ArrayList<List<MenuData>>();
98 List<MenuData> parentList = new ArrayList<MenuData>();
100 Map<String, Object> model = new HashMap<String, Object>();
101 for (MenuData menu : menuResult) {
102 MenuData parentData = new MenuData();
103 parentData.setLabel(menu.getLabel());
104 parentData.setAction(menu.getAction());
105 parentData.setImageSrc(menu.getImageSrc());
106 parentList.add(parentData);
107 List<MenuData> tempList = new ArrayList<MenuData>();
108 for (Object o : menu.getChildMenus()) {
109 MenuData m = (MenuData) o;
110 MenuData data = new MenuData();
111 data.setLabel(m.getLabel());
112 data.setAction(m.getAction());
113 data.setImageSrc(m.getImageSrc());
116 childItemList.add(tempList);
118 model.put("childItemList", mapper.writeValueAsString(childItemList));
119 model.put("parentList", mapper.writeValueAsString(parentList));