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.logic.EELFLoggerDelegate;
53 import org.onap.portalsdk.core.onboarding.rest.FavoritesClient;
54 import org.onap.portalsdk.core.onboarding.util.CipherUtil;
55 import org.onap.portalsdk.core.service.AppService;
56 import org.onap.portalsdk.core.util.SystemProperties;
58 import org.springframework.beans.factory.annotation.Autowired;
59 import org.springframework.context.annotation.EnableAspectJAutoProxy;
60 import org.springframework.stereotype.Controller;
61 import org.springframework.web.bind.annotation.RequestMapping;
62 import org.springframework.web.bind.annotation.RequestMethod;
66 @org.springframework.context.annotation.Configuration
67 @EnableAspectJAutoProxy
69 public class FavoritesController extends RestrictedBaseController {
71 private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(FavoritesController.class);
74 private AppService appService;
77 * Makes the REST API call to Portal Back-end and retrieves Favorite menu items
78 * for the currently logged in user.
83 @RequestMapping(value = { "/get_favorites" }, method = RequestMethod.GET)
84 public void getFavorites(HttpServletRequest request, HttpServletResponse response) {
86 String requestId = "";
87 String appUserName = "";
88 String decryptedPwd = null;
91 HttpSession session = request.getSession();
92 User user = (User) session.getAttribute(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME));
93 if (user == null || user.getId() == null) {
94 logger.error(EELFLoggerDelegate.errorLogger,
95 "Http request did not contain user info, cannot retrieve favorites.");
96 response.setContentType("application/json");
97 JSONArray jsonResponse = new JSONArray();
98 JSONObject error = new JSONObject();
99 error.put("error", "Http request did not contain user info, cannot retrieve favorites.");
100 jsonResponse.put(error);
101 response.getWriter().write(jsonResponse.toString());
103 logger.debug(EELFLoggerDelegate.debugLogger,
104 "Retrieving Favorites for the user '" + MDC.get(SystemProperties.MDC_LOGIN_ID) + "'.");
106 App app = appService.getDefaultApp();
108 appName = app.getName();
109 appUserName = app.getUsername();
111 decryptedPwd = CipherUtil.decryptPKC(app.getAppPassword(),
112 SystemProperties.getProperty(SystemProperties.Decryption_Key));
113 } catch (Exception e) {
114 logger.error(EELFLoggerDelegate.errorLogger,
115 "FavoritesController.getFavorites failed while decrypting password", e);
118 logger.error(EELFLoggerDelegate.errorLogger,
119 "Unable to locate the app information from the database.");
120 appName = SystemProperties.SDK_NAME;
122 requestId = MDC.get(MDC_KEY_REQUEST_ID);
124 String jsonResponse = FavoritesClient.getFavorites(MDC.get(SystemProperties.MDC_LOGIN_ID), appName,
125 requestId, appUserName, decryptedPwd);
127 logger.debug(EELFLoggerDelegate.debugLogger, "FavoritesMenu response: {}", jsonResponse);
128 response.setContentType("application/json");
129 response.getWriter().write(jsonResponse);
131 } catch (Exception e) {
132 logger.error(EELFLoggerDelegate.errorLogger,
133 "FavoritesController.getFavorites failed", e);