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.EPRestrictedBaseController;
47 import org.onap.portalapp.portal.domain.EPApp;
48 import org.onap.portalapp.portal.domain.EPUser;
49 import org.onap.portalapp.portal.ecomp.model.AppCatalogItem;
50 import org.onap.portalapp.portal.logging.aop.EPAuditLog;
51 import org.onap.portalapp.portal.service.AdminRolesService;
52 import org.onap.portalapp.portal.service.EPAppService;
53 import org.onap.portalapp.portal.service.PersUserAppService;
54 import org.onap.portalapp.portal.transport.AppCatalogPersonalization;
55 import org.onap.portalapp.portal.transport.FieldsValidator;
56 import org.onap.portalapp.portal.utils.EcompPortalUtils;
57 import org.onap.portalapp.util.EPUserUtils;
58 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
59 import org.springframework.beans.factory.annotation.Autowired;
60 import org.springframework.context.annotation.EnableAspectJAutoProxy;
61 import org.springframework.web.bind.annotation.RequestBody;
62 import org.springframework.web.bind.annotation.RestController;
63 import org.springframework.web.bind.annotation.GetMapping;
64 import org.springframework.web.bind.annotation.PutMapping;
68 @org.springframework.context.annotation.Configuration
69 @EnableAspectJAutoProxy
71 public class AppCatalogController extends EPRestrictedBaseController {
73 private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AppCatalogController.class);
76 private AdminRolesService adminRolesService;
78 private EPAppService appService;
80 private PersUserAppService persUserAppService;
83 * RESTful service method to fetch all enabled applications, with details
84 * about which are accessible to the current user, selected by the current
91 * @throws IOException If sendError fails
92 * @return List of items suitable for display
94 @GetMapping(value = { "/portalApi/appCatalog" }, produces = "application/json")
95 public List<AppCatalogItem> getAppCatalog(HttpServletRequest request, HttpServletResponse response)
97 EPUser user = EPUserUtils.getUserSession(request);
98 List<AppCatalogItem> appCatalog = null;
101 EcompPortalUtils.setBadPermissions(user, response, "getAppCatalog");
103 if (adminRolesService.isSuperAdmin(user))
104 appCatalog = appService.getAdminAppCatalog(user);
106 appCatalog = appService.getUserAppCatalog(user);
107 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/getAppCatalog", "GET result =", appCatalog);
109 } catch (Exception e) {
110 logger.error(EELFLoggerDelegate.errorLogger, "getAppCatalog failed", e);
111 response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString());
117 * RESTful service to accept a user's action made on the application
123 * JSON with data including application ID
125 * HttpServletResponse
126 * @return FieldsValidator
127 * @throws IOException If sendError fails
129 @PutMapping(value = { "/portalApi/appCatalog" }, produces = "application/json")
130 public FieldsValidator putAppCatalogSelection(HttpServletRequest request,
131 @RequestBody AppCatalogPersonalization persRequest, HttpServletResponse response) throws IOException {
132 FieldsValidator result = new FieldsValidator();
133 EPApp app = appService.getApp(persRequest.getAppId());
134 EPUser user = EPUserUtils.getUserSession(request);
136 if (app == null || user == null) {
137 EcompPortalUtils.setBadPermissions(user, response, "putAppCatalogSelection");
139 persUserAppService.setPersUserAppValue(user, app, persRequest.getSelect(), persRequest.getPending());
141 } catch (Exception e) {
142 logger.error(EELFLoggerDelegate.errorLogger, "putAppCatalogSelection failed", e);
143 response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString());
145 result.httpStatusCode = new Long(HttpServletResponse.SC_OK);