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.controller;
40 import java.io.IOException;
41 import java.util.List;
43 import javax.servlet.http.HttpServletRequest;
44 import javax.servlet.http.HttpServletResponse;
46 import org.onap.portalapp.controller.EPRestrictedRESTfulBaseController;
47 import org.onap.portalapp.portal.controller.ExternalAppsRestfulController;
48 import org.onap.portalapp.portal.domain.EPUser;
49 import org.onap.portalapp.portal.logging.aop.EPAuditLog;
50 import org.onap.portalapp.portal.service.AdminRolesService;
51 import org.onap.portalapp.portal.service.EPLoginService;
52 import org.onap.portalapp.portal.service.FunctionalMenuService;
53 import org.onap.portalapp.portal.transport.FavoritesFunctionalMenuItemJson;
54 import org.onap.portalapp.portal.transport.FieldsValidator;
55 import org.onap.portalapp.portal.transport.FunctionalMenuItem;
56 import org.onap.portalapp.portal.utils.EPSystemProperties;
57 import org.onap.portalapp.portal.utils.EcompPortalUtils;
58 import org.onap.portalapp.portal.utils.PortalConstants;
59 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
61 import org.springframework.beans.factory.annotation.Autowired;
62 import org.springframework.context.annotation.EnableAspectJAutoProxy;
63 import org.springframework.http.HttpStatus;
64 import org.springframework.web.bind.annotation.ExceptionHandler;
65 import org.springframework.web.bind.annotation.RequestMapping;
66 import org.springframework.web.bind.annotation.GetMapping;
67 import org.springframework.web.bind.annotation.RequestMethod;
68 import org.springframework.web.bind.annotation.RestController;
71 @RequestMapping(PortalConstants.REST_AUX_API)
72 @org.springframework.context.annotation.Configuration
73 @EnableAspectJAutoProxy
75 public class ExternalAppsRestfulController extends EPRestrictedRESTfulBaseController {
77 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ExternalAppsRestfulController.class);
80 FunctionalMenuService functionalMenuService;
83 EPLoginService epLoginService;
86 AdminRolesService adminRolesService;
88 @GetMapping(value={"/getFavorites"}, produces = "application/json")
89 public List<FavoritesFunctionalMenuItemJson> getFavoritesForUser(HttpServletRequest request, HttpServletResponse response) throws Exception {
91 String userAgent = "";
92 List<FavoritesFunctionalMenuItemJson> favorites = null;
94 loginId = request.getHeader(EPSystemProperties.MDC_LOGIN_ID);
95 userAgent = MDC.get(EPSystemProperties.PARTNER_NAME);
97 EPUser epUser = epLoginService.findUserWithoutPwd(loginId);
98 logger.info(EELFLoggerDelegate.errorLogger, "getFavorites request was received from " + userAgent + " for the user " + loginId + ".");
99 if (epUser==null || epUser.getId()==null) {
100 logger.error(EELFLoggerDelegate.errorLogger, "No User record found for the LoginId '" + loginId + "' in the database.");
101 throw new Exception("Received null for Login-Id.");
103 favorites = functionalMenuService.getFavoriteItems(epUser.getId());
104 FieldsValidator fieldsValidator = new FieldsValidator();
105 response.setStatus(fieldsValidator.httpStatusCode.intValue());
107 EcompPortalUtils.logAndSerializeObject("/auxapi/getFavorites", "result = ", favorites);
113 @GetMapping(value={"/functionalMenuItemsForUser"}, produces = "application/json")
114 public List<FunctionalMenuItem> getFunctionalMenuItemsForUser(HttpServletRequest request, HttpServletResponse response) throws Exception {
116 String userAgent = "";
117 List<FunctionalMenuItem> fnMenuItems = null;
119 loginId = request.getHeader("LoginId");
120 userAgent = MDC.get(EPSystemProperties.PARTNER_NAME);
122 EPUser epUser = epLoginService.findUserWithoutPwd(loginId);
123 logger.info(EELFLoggerDelegate.errorLogger, "getFunctionalMenuItemsForUser request was received from " + userAgent + " for the user " + loginId + ".");
124 if (epUser==null || epUser.getId()==null) {
125 logger.error(EELFLoggerDelegate.errorLogger, "No User record found for the LoginId '" + loginId + "' in the database.");
126 throw new Exception("Received null for Login-Id.");
127 } else if (adminRolesService.isSuperAdmin(epUser)) {
128 logger.debug(EELFLoggerDelegate.debugLogger, "FunctionalMenuHandler: SuperUser, about to call getFunctionalMenuItems()");
129 fnMenuItems = functionalMenuService.getFunctionalMenuItems();
132 logger.debug(EELFLoggerDelegate.debugLogger, "getMenuItemsForAuthUser: about to call getFunctionalMenuItemsForUser()");
133 fnMenuItems = functionalMenuService.getFunctionalMenuItemsForUser(epUser.getOrgUserId());
136 FieldsValidator fieldsValidator = new FieldsValidator();
137 response.setStatus(fieldsValidator.httpStatusCode.intValue());
139 EcompPortalUtils.logAndSerializeObject("/auxapi/functionalMenuItemsForUser", "result = ", fnMenuItems);
144 @ExceptionHandler(Exception.class)
145 protected void handleBadRequests(Exception e, HttpServletResponse response) throws IOException {
146 logger.warn(EELFLoggerDelegate.errorLogger, "Handling bad request", e);
147 response.sendError(HttpStatus.BAD_REQUEST.value(), e.getMessage());