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.RequestMethod;
67 import org.springframework.web.bind.annotation.RestController;
70 @RequestMapping(PortalConstants.REST_AUX_API)
71 @org.springframework.context.annotation.Configuration
72 @EnableAspectJAutoProxy
74 public class ExternalAppsRestfulController extends EPRestrictedRESTfulBaseController {
76 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ExternalAppsRestfulController.class);
79 FunctionalMenuService functionalMenuService;
82 EPLoginService epLoginService;
85 AdminRolesService adminRolesService;
87 @RequestMapping(value={"/getFavorites"}, method = RequestMethod.GET,produces = "application/json")
88 public List<FavoritesFunctionalMenuItemJson> getFavoritesForUser(HttpServletRequest request, HttpServletResponse response) throws Exception {
90 String userAgent = "";
91 List<FavoritesFunctionalMenuItemJson> favorites = null;
93 loginId = request.getHeader(EPSystemProperties.MDC_LOGIN_ID);
94 userAgent = MDC.get(EPSystemProperties.PARTNER_NAME);
96 EPUser epUser = epLoginService.findUserWithoutPwd(loginId);
97 logger.info(EELFLoggerDelegate.errorLogger, "getFavorites request was received from " + userAgent + " for the user " + loginId + ".");
98 if (epUser==null || epUser.getId()==null) {
99 logger.error(EELFLoggerDelegate.errorLogger, "No User record found for the LoginId '" + loginId + "' in the database.");
100 throw new Exception("Received null for Login-Id.");
102 favorites = functionalMenuService.getFavoriteItems(epUser.getId());
103 FieldsValidator fieldsValidator = new FieldsValidator();
104 response.setStatus(fieldsValidator.httpStatusCode.intValue());
106 EcompPortalUtils.logAndSerializeObject("/auxapi/getFavorites", "result = ", favorites);
112 @RequestMapping(value={"/functionalMenuItemsForUser"}, method = RequestMethod.GET,produces = "application/json")
113 public List<FunctionalMenuItem> getFunctionalMenuItemsForUser(HttpServletRequest request, HttpServletResponse response) throws Exception {
115 String userAgent = "";
116 List<FunctionalMenuItem> fnMenuItems = null;
118 loginId = request.getHeader("LoginId");
119 userAgent = MDC.get(EPSystemProperties.PARTNER_NAME);
121 EPUser epUser = epLoginService.findUserWithoutPwd(loginId);
122 logger.info(EELFLoggerDelegate.errorLogger, "getFunctionalMenuItemsForUser request was received from " + userAgent + " for the user " + loginId + ".");
123 if (epUser==null || epUser.getId()==null) {
124 logger.error(EELFLoggerDelegate.errorLogger, "No User record found for the LoginId '" + loginId + "' in the database.");
125 throw new Exception("Received null for Login-Id.");
126 } else if (adminRolesService.isSuperAdmin(epUser)) {
127 logger.debug(EELFLoggerDelegate.debugLogger, "FunctionalMenuHandler: SuperUser, about to call getFunctionalMenuItems()");
128 fnMenuItems = functionalMenuService.getFunctionalMenuItems();
131 logger.debug(EELFLoggerDelegate.debugLogger, "getMenuItemsForAuthUser: about to call getFunctionalMenuItemsForUser()");
132 fnMenuItems = functionalMenuService.getFunctionalMenuItemsForUser(epUser.getOrgUserId());
135 FieldsValidator fieldsValidator = new FieldsValidator();
136 response.setStatus(fieldsValidator.httpStatusCode.intValue());
138 EcompPortalUtils.logAndSerializeObject("/auxapi/functionalMenuItemsForUser", "result = ", fnMenuItems);
143 @ExceptionHandler(Exception.class)
144 protected void handleBadRequests(Exception e, HttpServletResponse response) throws IOException {
145 logger.warn(EELFLoggerDelegate.errorLogger, "Handling bad request", e);
146 response.sendError(HttpStatus.BAD_REQUEST.value(), e.getMessage());