2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 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.controller.core;
40 import static com.att.eelf.configuration.Configuration.MDC_KEY_REQUEST_ID;
42 import javax.servlet.http.HttpServletRequest;
43 import javax.servlet.http.HttpServletResponse;
44 import javax.servlet.http.HttpSession;
46 import org.json.JSONArray;
47 import org.json.JSONObject;
48 import org.onap.portalsdk.core.controller.RestrictedBaseController;
49 import org.onap.portalsdk.core.domain.App;
50 import org.onap.portalsdk.core.domain.User;
51 import org.onap.portalsdk.core.logging.aspect.AuditLog;
52 import org.onap.portalsdk.core.logging.format.AlarmSeverityEnum;
53 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
54 import org.onap.portalsdk.core.onboarding.rest.FavoritesClient;
55 import org.onap.portalsdk.core.onboarding.util.CipherUtil;
56 import org.onap.portalsdk.core.service.AppService;
57 import org.onap.portalsdk.core.util.SystemProperties;
59 import org.springframework.beans.factory.annotation.Autowired;
60 import org.springframework.context.annotation.EnableAspectJAutoProxy;
61 import org.springframework.stereotype.Controller;
62 import org.springframework.web.bind.annotation.RequestMapping;
63 import org.springframework.web.bind.annotation.RequestMethod;
67 @org.springframework.context.annotation.Configuration
68 @EnableAspectJAutoProxy
70 public class FavoritesController extends RestrictedBaseController {
72 private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(FavoritesController.class);
75 private AppService appService;
78 * Makes the REST API call to Portal Back-end and retrieves Favorite menu items
79 * for the currently logged in user.
84 @RequestMapping(value = { "/get_favorites" }, method = RequestMethod.GET)
85 public void getFavorites(HttpServletRequest request, HttpServletResponse response) {
87 String requestId = "";
88 String appUserName = "";
89 String decryptedPwd = null;
92 HttpSession session = request.getSession();
93 User user = (User) session.getAttribute(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME));
94 if (user == null || user.getId() == null) {
95 logger.error(EELFLoggerDelegate.errorLogger,
96 "Http request did not contain user info, cannot retrieve favorites.");
97 response.setContentType("application/json");
98 JSONArray jsonResponse = new JSONArray();
99 JSONObject error = new JSONObject();
100 error.put("error", "Http request did not contain user info, cannot retrieve favorites.");
101 jsonResponse.put(error);
102 response.getWriter().write(jsonResponse.toString());
104 logger.debug(EELFLoggerDelegate.debugLogger,
105 "Retrieving Favorites for the user '" + MDC.get(SystemProperties.MDC_LOGIN_ID) + "'.");
107 App app = appService.getDefaultApp();
109 appName = app.getName();
110 appUserName = app.getUsername();
112 decryptedPwd = CipherUtil.decryptPKC(app.getAppPassword(),
113 SystemProperties.getProperty(SystemProperties.Decryption_Key));
114 } catch (Exception e) {
115 logger.error(EELFLoggerDelegate.errorLogger,
116 "FavoritesController.getFavorites failed while decrypting password", e);
119 logger.error(EELFLoggerDelegate.errorLogger,
120 "Unable to locate the app information from the database.");
121 appName = SystemProperties.SDK_NAME;
123 requestId = MDC.get(MDC_KEY_REQUEST_ID);
125 String jsonResponse = FavoritesClient.getFavorites(MDC.get(SystemProperties.MDC_LOGIN_ID), appName,
126 requestId, appUserName, decryptedPwd);
128 logger.debug(EELFLoggerDelegate.debugLogger, "FavoritesMenu response: {}", jsonResponse);
129 response.setContentType("application/json");
130 response.getWriter().write(jsonResponse);
132 } catch (Exception e) {
133 logger.error(EELFLoggerDelegate.errorLogger,
134 "FavoritesController.getFavorites failed", e);