2 * ================================================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ================================================================================
20 package org.openecomp.portalapp.controller;
22 import java.util.ArrayList;
23 import java.util.HashMap;
24 import java.util.List;
28 import javax.servlet.http.HttpServletRequest;
29 import javax.servlet.http.HttpSession;
31 import org.openecomp.portalapp.portal.domain.EPUser;
32 import org.openecomp.portalapp.portal.utils.EcompPortalUtils;
33 import org.openecomp.portalapp.util.EPUserUtils;
34 import org.openecomp.portalsdk.core.controller.FusionBaseController;
35 import org.openecomp.portalsdk.core.domain.MenuData;
36 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
37 import org.openecomp.portalsdk.core.util.SystemProperties;
38 import org.springframework.stereotype.Controller;
39 import org.springframework.web.bind.annotation.ModelAttribute;
41 import com.fasterxml.jackson.databind.ObjectMapper;
44 public abstract class EPFusionBaseController extends FusionBaseController {
45 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(EPFusionBaseController.class);
50 public boolean isAccessible() {
54 public boolean isRESTfulCall() {
58 @ModelAttribute("menu")
59 public Map<String, Object> messages(HttpServletRequest request) {
60 HttpSession session = null;
61 Map<String, Object> model = new HashMap<String, Object>();
62 session = request.getSession();
63 EPUser user = EPUserUtils.getUserSession(request);
64 if (session != null && user != null) {
65 @SuppressWarnings("unchecked")
66 Set<MenuData> menuResult = (Set<MenuData>) session
67 .getAttribute(SystemProperties.getProperty(SystemProperties.APPLICATION_MENU_ATTRIBUTE_NAME));
69 model = setMenu(menuResult);
70 } catch (Exception e) {
71 logger.error(EELFLoggerDelegate.errorLogger, EcompPortalUtils.getStackTrace(e));
78 public Map<String, Object> setMenu(Set<MenuData> menuResult) throws Exception {
79 ObjectMapper mapper = new ObjectMapper();
80 List<List<MenuData>> childItemList = new ArrayList<List<MenuData>>();
82 List<MenuData> parentList = new ArrayList<MenuData>();
84 Map<String, Object> model = new HashMap<String, Object>();
85 for (MenuData menu : menuResult) {
86 MenuData parentData = new MenuData();
87 parentData.setLabel(menu.getLabel());
88 parentData.setAction(menu.getAction());
89 parentData.setImageSrc(menu.getImageSrc());
90 parentList.add(parentData);
91 List<MenuData> tempList = new ArrayList<MenuData>();
92 for (Object o : menu.getChildMenus()) {
93 MenuData m = (MenuData) o;
94 MenuData data = new MenuData();
95 data.setLabel(m.getLabel());
96 data.setAction(m.getAction());
97 data.setImageSrc(m.getImageSrc());
100 childItemList.add(tempList);
102 model.put("childItemList", childItemList != null ? mapper.writeValueAsString(childItemList) : "");
103 model.put("parentList", parentList != null ? mapper.writeValueAsString(parentList) : "");