2 * ================================================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ================================================================================
20 package org.openecomp.portalapp.portal.controller;
22 import java.io.IOException;
23 import java.util.List;
25 import javax.servlet.http.HttpServletRequest;
26 import javax.servlet.http.HttpServletResponse;
28 import org.openecomp.portalapp.controller.EPRestrictedBaseController;
29 import org.openecomp.portalapp.portal.domain.EPApp;
30 import org.openecomp.portalapp.portal.domain.EPUser;
31 import org.openecomp.portalapp.portal.ecomp.model.AppCatalogItem;
32 import org.openecomp.portalapp.portal.logging.aop.EPAuditLog;
33 import org.openecomp.portalapp.portal.service.AdminRolesService;
34 import org.openecomp.portalapp.portal.service.EPAppService;
35 import org.openecomp.portalapp.portal.service.PersUserAppService;
36 import org.openecomp.portalapp.portal.transport.AppCatalogPersonalization;
37 import org.openecomp.portalapp.portal.transport.FieldsValidator;
38 import org.openecomp.portalapp.portal.utils.EcompPortalUtils;
39 import org.openecomp.portalapp.util.EPUserUtils;
40 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
41 import org.springframework.beans.factory.annotation.Autowired;
42 import org.springframework.context.annotation.EnableAspectJAutoProxy;
43 import org.springframework.web.bind.annotation.RequestBody;
44 import org.springframework.web.bind.annotation.RequestMapping;
45 import org.springframework.web.bind.annotation.RequestMethod;
46 import org.springframework.web.bind.annotation.RestController;
49 @org.springframework.context.annotation.Configuration
50 @EnableAspectJAutoProxy
52 public class AppCatalogController extends EPRestrictedBaseController {
54 private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AppCatalogController.class);
57 private AdminRolesService adminRolesService;
59 private EPAppService appService;
61 private PersUserAppService persUserAppService;
64 * RESTful service method to fetch all enabled applications, with details
65 * about which are accessible to the current user, selected by the current
72 * @throws IOException If sendError fails
73 * @return List of items suitable for display
75 @RequestMapping(value = { "/portalApi/appCatalog" }, method = RequestMethod.GET, produces = "application/json")
76 public List<AppCatalogItem> getAppCatalog(HttpServletRequest request, HttpServletResponse response)
78 EPUser user = EPUserUtils.getUserSession(request);
79 List<AppCatalogItem> appCatalog = null;
82 EcompPortalUtils.setBadPermissions(user, response, "getAppCatalog");
84 if (adminRolesService.isSuperAdmin(user))
85 appCatalog = appService.getAdminAppCatalog(user);
87 appCatalog = appService.getUserAppCatalog(user);
88 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/getAppCatalog", "GET result =", appCatalog);
90 } catch (Exception e) {
91 logger.error(EELFLoggerDelegate.errorLogger, "getAppCatalog failed", e);
92 response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString());
98 * RESTful service to accept a user's action made on the application
104 * JSON with data including application ID
106 * HttpServletResponse
107 * @return FieldsValidator
108 * @throws IOException If sendError fails
110 @RequestMapping(value = { "/portalApi/appCatalog" }, method = RequestMethod.PUT, produces = "application/json")
111 public FieldsValidator putAppCatalogSelection(HttpServletRequest request,
112 @RequestBody AppCatalogPersonalization persRequest, HttpServletResponse response) throws IOException {
113 FieldsValidator result = new FieldsValidator();
114 EPApp app = appService.getApp(persRequest.getAppId());
115 EPUser user = EPUserUtils.getUserSession(request);
117 if (app == null || user == null) {
118 EcompPortalUtils.setBadPermissions(user, response, "putAppCatalogSelection");
120 persUserAppService.setPersUserAppValue(user, app, persRequest.getSelect(), persRequest.getPending());
122 } catch (Exception e) {
123 logger.error(EELFLoggerDelegate.errorLogger, "putAppCatalogSelection failed", e);
124 response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString());
126 result.httpStatusCode = new Long(HttpServletResponse.SC_OK);