2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
7 * Modifications Copyright © 2018 IBM.
8 * ===================================================================
10 * Unless otherwise specified, all software contained herein is licensed
11 * under the Apache License, Version 2.0 (the "License");
12 * you may not use this software except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * Unless otherwise specified, all documentation contained herein is licensed
24 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
25 * you may not use this documentation except in compliance with the License.
26 * You may obtain a copy of the License at
28 * https://creativecommons.org/licenses/by/4.0/
30 * Unless required by applicable law or agreed to in writing, documentation
31 * distributed under the License is distributed on an "AS IS" BASIS,
32 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33 * See the License for the specific language governing permissions and
34 * limitations under the License.
36 * ============LICENSE_END============================================
40 package org.onap.portalapp.controller;
42 import java.util.ArrayList;
43 import java.util.HashMap;
44 import java.util.List;
48 import javax.servlet.http.HttpServletRequest;
49 import javax.servlet.http.HttpSession;
51 import org.onap.portalapp.portal.domain.EPUser;
52 import org.onap.portalapp.util.EPUserUtils;
53 import org.onap.portalsdk.core.controller.FusionBaseController;
54 import org.onap.portalsdk.core.domain.MenuData;
55 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
56 import org.onap.portalsdk.core.util.SystemProperties;
57 import org.springframework.stereotype.Controller;
58 import org.springframework.web.bind.annotation.ModelAttribute;
60 import com.fasterxml.jackson.databind.ObjectMapper;
63 public abstract class EPFusionBaseController extends FusionBaseController {
65 private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(EPFusionBaseController.class);
68 public boolean isAccessible() {
73 public boolean isRESTfulCall() {
77 @ModelAttribute("menu")
78 public Map<String, Object> messages(HttpServletRequest request) {
79 HttpSession session = null;
80 Map<String, Object> model = new HashMap<>();
81 session = request.getSession();
82 EPUser user = EPUserUtils.getUserSession(request);
83 if (session != null && user != null) {
84 @SuppressWarnings("unchecked")
85 Set<MenuData> menuResult = (Set<MenuData>) session
86 .getAttribute(SystemProperties.getProperty(SystemProperties.APPLICATION_MENU_ATTRIBUTE_NAME));
88 model = setMenu(menuResult);
89 } catch (Exception e) {
90 logger.error(EELFLoggerDelegate.errorLogger, "messages failed", e);
98 public Map<String, Object> setMenu(Set<MenuData> menuResult) throws Exception {
99 ObjectMapper mapper = new ObjectMapper();
100 List<List<MenuData>> childItemList = new ArrayList<>();
102 List<MenuData> parentList = new ArrayList<>();
104 Map<String, Object> model = new HashMap<>();
105 for (MenuData menu : menuResult) {
106 MenuData parentData = new MenuData();
107 parentData.setLabel(menu.getLabel());
108 parentData.setAction(menu.getAction());
109 parentData.setImageSrc(menu.getImageSrc());
110 parentList.add(parentData);
111 List<MenuData> tempList = new ArrayList<>();
112 for (Object o : menu.getChildMenus()) {
113 MenuData m = (MenuData) o;
114 MenuData data = new MenuData();
115 data.setLabel(m.getLabel());
116 data.setAction(m.getAction());
117 data.setImageSrc(m.getImageSrc());
120 childItemList.add(tempList);
122 model.put("childItemList", mapper.writeValueAsString(childItemList));
123 model.put("parentList", mapper.writeValueAsString(parentList));