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.springframework.beans.factory.annotation.Autowired;
29 import org.springframework.context.annotation.EnableAspectJAutoProxy;
30 import org.springframework.web.bind.annotation.RequestBody;
31 import org.springframework.web.bind.annotation.RequestMapping;
32 import org.springframework.web.bind.annotation.RequestMethod;
33 import org.springframework.web.bind.annotation.RestController;
35 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
37 import org.openecomp.portalapp.controller.EPRestrictedBaseController;
38 import org.openecomp.portalapp.portal.domain.EPApp;
39 import org.openecomp.portalapp.portal.domain.EPUser;
40 import org.openecomp.portalapp.portal.logging.aop.EPAuditLog;
41 import org.openecomp.portalapp.portal.service.AdminRolesService;
42 import org.openecomp.portalapp.portal.service.EPAppService;
43 import org.openecomp.portalapp.portal.service.PersUserAppService;
44 import org.openecomp.portalapp.portal.transport.AppCatalogPersonalization;
45 import org.openecomp.portalapp.portal.transport.FieldsValidator;
46 import org.openecomp.portalapp.portal.utils.EcompPortalUtils;
47 import org.openecomp.portalapp.portal.ecomp.model.AppCatalogItem;
48 import org.openecomp.portalapp.util.EPUserUtils;
51 @org.springframework.context.annotation.Configuration
52 @EnableAspectJAutoProxy
54 public class AppCatalogController extends EPRestrictedBaseController {
55 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AppCatalogController.class);
58 AdminRolesService adminRolesService;
60 EPAppService appService;
62 PersUserAppService persUserAppService;
65 * RESTful service method to fetch all enabled applications, with details
66 * about which are accessible to the current user, selected by the current
69 * @return List of items suitable for display
71 @RequestMapping(value = { "/portalApi/appCatalog" }, method = RequestMethod.GET, produces = "application/json")
72 public List<AppCatalogItem> getAppCatalog(HttpServletRequest request, HttpServletResponse response)
74 EPUser user = EPUserUtils.getUserSession(request);
75 List<AppCatalogItem> appCatalog = null;
78 EcompPortalUtils.setBadPermissions(user, response, "getAppCatalog");
80 if (adminRolesService.isSuperAdmin(user))
81 appCatalog = appService.getAdminAppCatalog(user);
83 appCatalog = appService.getUserAppCatalog(user);
84 EcompPortalUtils.logAndSerializeObject(logger,"/portalApi/getAppCatalog", "GET result =", appCatalog);
86 } catch (Exception e) {
87 logger.error(EELFLoggerDelegate.errorLogger, "Failed in getAppCatalog", e);
88 response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString());
94 * RESTful service to accept a user's action made on the application
98 * @param selectRequest
99 * JSON with data including application ID
101 * @return FieldsValidator
102 * @throws IOException
104 @RequestMapping(value = { "/portalApi/appCatalog" }, method = RequestMethod.PUT, produces = "application/json")
105 public FieldsValidator putAppCatalogSelection(HttpServletRequest request,
106 @RequestBody AppCatalogPersonalization persRequest, HttpServletResponse response) throws IOException {
107 FieldsValidator result = new FieldsValidator();
108 EPApp app = appService.getApp(persRequest.getAppId());
109 EPUser user = EPUserUtils.getUserSession(request);
111 if (app == null || user == null) {
112 EcompPortalUtils.setBadPermissions(user, response, "putAppCatalogSelection");
114 persUserAppService.setPersUserAppValue(user, app, persRequest.getSelect(), persRequest.getPending());
116 } catch (Exception e) {
117 logger.error(EELFLoggerDelegate.errorLogger, "Failed in putAppCatalogSelection", e);
118 response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString());
120 result.httpStatusCode = new Long(HttpServletResponse.SC_OK);