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() {
72 public boolean isRESTfulCall() {
76 @ModelAttribute("menu")
77 public Map<String, Object> messages(HttpServletRequest request) {
78 HttpSession session = null;
79 Map<String, Object> model = new HashMap<String, Object>();
80 session = request.getSession();
81 EPUser user = EPUserUtils.getUserSession(request);
82 if (session != null && user != null) {
83 @SuppressWarnings("unchecked")
84 Set<MenuData> menuResult = (Set<MenuData>) session
85 .getAttribute(SystemProperties.getProperty(SystemProperties.APPLICATION_MENU_ATTRIBUTE_NAME));
87 model = setMenu(menuResult);
88 } catch (Exception e) {
89 logger.error(EELFLoggerDelegate.errorLogger, "messages failed", e);
96 public Map<String, Object> setMenu(Set<MenuData> menuResult) throws Exception {
97 ObjectMapper mapper = new ObjectMapper();
98 List<List<MenuData>> childItemList = new ArrayList<List<MenuData>>();
100 List<MenuData> parentList = new ArrayList<MenuData>();
102 Map<String, Object> model = new HashMap<>();
103 for (MenuData menu : menuResult) {
104 MenuData parentData = new MenuData();
105 parentData.setLabel(menu.getLabel());
106 parentData.setAction(menu.getAction());
107 parentData.setImageSrc(menu.getImageSrc());
108 parentList.add(parentData);
109 List<MenuData> tempList = new ArrayList<MenuData>();
110 for (Object o : menu.getChildMenus()) {
111 MenuData m = (MenuData) o;
112 MenuData data = new MenuData();
113 data.setLabel(m.getLabel());
114 data.setAction(m.getAction());
115 data.setImageSrc(m.getImageSrc());
118 childItemList.add(tempList);
120 model.put("childItemList", mapper.writeValueAsString(childItemList));
121 model.put("parentList", mapper.writeValueAsString(parentList));