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.RequestMapping;
63 import org.springframework.web.bind.annotation.RequestMethod;
64 import org.springframework.web.bind.annotation.RestController;
67 @org.springframework.context.annotation.Configuration
68 @EnableAspectJAutoProxy
70 public class AppCatalogController extends EPRestrictedBaseController {
72 private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AppCatalogController.class);
75 private AdminRolesService adminRolesService;
77 private EPAppService appService;
79 private PersUserAppService persUserAppService;
82 * RESTful service method to fetch all enabled applications, with details
83 * about which are accessible to the current user, selected by the current
90 * @throws IOException If sendError fails
91 * @return List of items suitable for display
93 @RequestMapping(value = { "/portalApi/appCatalog" }, method = RequestMethod.GET, produces = "application/json")
94 public List<AppCatalogItem> getAppCatalog(HttpServletRequest request, HttpServletResponse response)
96 EPUser user = EPUserUtils.getUserSession(request);
97 List<AppCatalogItem> appCatalog = null;
100 EcompPortalUtils.setBadPermissions(user, response, "getAppCatalog");
102 if (adminRolesService.isSuperAdmin(user))
103 appCatalog = appService.getAdminAppCatalog(user);
105 appCatalog = appService.getUserAppCatalog(user);
106 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/getAppCatalog", "GET result =", appCatalog);
108 } catch (Exception e) {
109 logger.error(EELFLoggerDelegate.errorLogger, "getAppCatalog failed", e);
110 response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString());
116 * RESTful service to accept a user's action made on the application
122 * JSON with data including application ID
124 * HttpServletResponse
125 * @return FieldsValidator
126 * @throws IOException If sendError fails
128 @RequestMapping(value = { "/portalApi/appCatalog" }, method = RequestMethod.PUT, produces = "application/json")
129 public FieldsValidator putAppCatalogSelection(HttpServletRequest request,
130 @RequestBody AppCatalogPersonalization persRequest, HttpServletResponse response) throws IOException {
131 FieldsValidator result = new FieldsValidator();
132 EPApp app = appService.getApp(persRequest.getAppId());
133 EPUser user = EPUserUtils.getUserSession(request);
135 if (app == null || user == null) {
136 EcompPortalUtils.setBadPermissions(user, response, "putAppCatalogSelection");
138 persUserAppService.setPersUserAppValue(user, app, persRequest.getSelect(), persRequest.getPending());
140 } catch (Exception e) {
141 logger.error(EELFLoggerDelegate.errorLogger, "putAppCatalogSelection failed", e);
142 response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString());
144 result.httpStatusCode = new Long(HttpServletResponse.SC_OK);