[PORTAL-7] Rebase
[portal.git] / ecomp-portal-BE-common / src / main / java / org / openecomp / portalapp / portal / controller / GetAccessController.java
1 /*-
2  * ================================================================================
3  * ECOMP Portal
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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  * ================================================================================
19  */
20 package org.openecomp.portalapp.portal.controller;
21
22 import java.io.IOException;
23 import java.util.Collections;
24 import java.util.Comparator;
25 import java.util.List;
26
27 import javax.servlet.http.HttpServletRequest;
28
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.context.annotation.EnableAspectJAutoProxy;
31 import org.springframework.web.bind.annotation.RequestMapping;
32 import org.springframework.web.bind.annotation.RequestMethod;
33 import org.springframework.web.bind.annotation.RestController;
34
35 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
36 import org.openecomp.portalapp.controller.EPUnRestrictedBaseController;
37 import org.openecomp.portalapp.portal.domain.EPUser;
38 import org.openecomp.portalapp.portal.domain.GetAccessResult;
39 import org.openecomp.portalapp.portal.logging.aop.EPAuditLog;
40 import org.openecomp.portalapp.portal.service.GetAccessService;
41 import org.openecomp.portalapp.portal.utils.EcompPortalUtils;
42 import org.openecomp.portalapp.util.EPUserUtils;
43
44 @RestController
45 @org.springframework.context.annotation.Configuration
46 @EnableAspectJAutoProxy
47 @EPAuditLog
48 public class GetAccessController extends EPUnRestrictedBaseController {
49
50         EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(GetAccessController.class);
51
52         @Autowired
53         GetAccessService getAccessService;
54
55         /**
56          * Sorts the list by ECOMP function name.
57          */
58         private Comparator<GetAccessResult> getAccessComparator = new Comparator<GetAccessResult>() {
59                 public int compare(GetAccessResult o1, GetAccessResult o2) {
60                         return o1.getAppName().compareTo(o2.getAppName());
61                 }
62         };
63         
64         @RequestMapping(value = { "/portalApi/getAppList" }, method = RequestMethod.GET, produces = "application/json")
65         public List<GetAccessResult> getAppList(HttpServletRequest request) throws IOException {
66                 List<GetAccessResult> appsList = null;
67                 EPUser user = EPUserUtils.getUserSession(request);
68                 appsList = getAccessService.getAppAccessList(user);
69                 Collections.sort(appsList, getAccessComparator);
70                 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/getAppList", "result =", appsList);
71                 return appsList;
72         }
73 }