Update license; improve coverage; add docs dir
[portal.git] / ecomp-portal-BE-common / src / main / java / org / openecomp / portalapp / portal / controller / RoleManageController.java
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
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
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  *
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
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
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.
33  *
34  * ============LICENSE_END============================================
35  *
36  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
37  */
38 package org.openecomp.portalapp.portal.controller;
39
40 import javax.servlet.http.HttpServletRequest;
41 import javax.servlet.http.HttpServletResponse;
42
43 import org.openecomp.portalapp.controller.EPRestrictedBaseController;
44 import org.openecomp.portalapp.controller.core.RoleController;
45 import org.openecomp.portalapp.controller.core.RoleFunctionListController;
46 import org.openecomp.portalapp.controller.core.RoleListController;
47 import org.openecomp.portalapp.portal.domain.EPApp;
48 import org.openecomp.portalapp.portal.ecomp.model.PortalRestResponse;
49 import org.openecomp.portalapp.portal.ecomp.model.PortalRestStatusEnum;
50 import org.openecomp.portalapp.portal.logging.aop.EPAuditLog;
51 import org.openecomp.portalapp.portal.service.ExternalAccessRolesService;
52 import org.openecomp.portalapp.portal.service.ExternalAccessRolesServiceImpl;
53 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
54 import org.springframework.beans.factory.annotation.Autowired;
55 import org.springframework.context.annotation.EnableAspectJAutoProxy;
56 import org.springframework.web.bind.annotation.RequestBody;
57 import org.springframework.web.bind.annotation.RequestMapping;
58 import org.springframework.web.bind.annotation.RequestMethod;
59 import org.springframework.web.bind.annotation.RestController;
60 import org.springframework.web.servlet.ModelAndView;
61
62 /**
63  * Proxies REST calls to role-management functions that arrive on paths
64  * /portalApi/* over to controller methods provided by the SDK-Core library.
65  * Those controller methods are mounted on paths not exposed by the Portal FE.
66  */
67 @RestController
68 @org.springframework.context.annotation.Configuration
69 @EnableAspectJAutoProxy
70 @EPAuditLog
71 public class RoleManageController extends EPRestrictedBaseController {
72         private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RoleManageController.class);
73
74         @Autowired
75         private RoleController roleController;
76
77         @Autowired
78         private RoleListController roleListController;
79
80         @Autowired
81         private RoleFunctionListController roleFunctionListController;
82
83
84         @Autowired
85         ExternalAccessRolesService externalAccessRolesService;
86         /**
87          * Calls an SDK-Core library method that gets the available roles and writes
88          * them to the request object. Portal specifies a Hibernate mappings from
89          * the Role class to the fn_role_v view, which ensures that only Portal
90          * (app_id is null) roles are fetched.
91          * 
92          * Any method declared void (no return value) or returning null causes the
93          * audit log aspect method to declare failure. TODO: should return a JSON
94          * string.
95          * 
96          * @param request
97          * @param response
98          */
99         @RequestMapping(value = { "/portalApi/get_roles" }, method = RequestMethod.GET)
100         public void getRoles(HttpServletRequest request, HttpServletResponse response) {
101                 getRoleListController().getRoles(request, response);
102         }
103
104         @RequestMapping(value = { "/portalApi/role_list/toggleRole" }, method = RequestMethod.POST)
105         public PortalRestResponse<String> toggleRole(HttpServletRequest request, HttpServletResponse response) {
106                 PortalRestResponse<String> portalRestResponse = null;
107                 try{
108                         getRoleListController().toggleRole(request, response);
109                         portalRestResponse = new PortalRestResponse<String>(PortalRestStatusEnum.OK, "success", null);
110                 }catch (Exception e) {
111                         return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "failure", e.getMessage());
112                 }
113                 return portalRestResponse;              
114         }
115
116         @RequestMapping(value = { "/portalApi/role_list/removeRole" }, method = RequestMethod.POST)
117         public ModelAndView removeRole(HttpServletRequest request, HttpServletResponse response) throws Exception {
118                 return getRoleListController().removeRole(request, response);
119         }
120
121         @RequestMapping(value = { "/portalApi/role/saveRole" }, method = RequestMethod.POST)
122         public ModelAndView saveRole(HttpServletRequest request, HttpServletResponse response) throws Exception {
123                 return getRoleController().saveRole(request, response);
124         }
125
126         @RequestMapping(value = { "/portalApi/role/removeRoleFunction" }, method = RequestMethod.POST)
127         public ModelAndView removeRoleRoleFunction(HttpServletRequest request, HttpServletResponse response)
128                         throws Exception {
129                 return getRoleController().removeRoleFunction(request, response);
130         }
131
132         @RequestMapping(value = { "/portalApi/role/addRoleFunction" }, method = RequestMethod.POST)
133         public ModelAndView addRoleRoRoleFunction(HttpServletRequest request, HttpServletResponse response)
134                         throws Exception {
135                 return getRoleController().addRoleFunction(request, response);
136         }
137
138         @RequestMapping(value = { "/portalApi/role/removeChildRole" }, method = RequestMethod.POST)
139         public ModelAndView removeChildRole(HttpServletRequest request, HttpServletResponse response) throws Exception {
140                 return getRoleController().removeChildRole(request, response);
141         }
142
143         @RequestMapping(value = { "/portalApi/role/addChildRole" }, method = RequestMethod.POST)
144         public ModelAndView addChildRole(HttpServletRequest request, HttpServletResponse response) throws Exception {
145                 return getRoleController().addChildRole(request, response);
146         }
147
148         @RequestMapping(value = { "/portalApi/get_role" }, method = RequestMethod.GET)
149         public void getRole(HttpServletRequest request, HttpServletResponse response) throws Exception{
150                 getRoleController().getRole(request, response);
151         }
152
153         @RequestMapping(value = { "/portalApi/get_role_functions" }, method = RequestMethod.GET)
154         public void getRoleFunctionList(HttpServletRequest request, HttpServletResponse response) {
155                 getRoleFunctionListController().getRoleFunctionList(request, response);
156         }
157
158         @RequestMapping(value = { "/portalApi/role_function_list/saveRoleFunction" }, method = RequestMethod.POST)
159         public void saveRoleFunction(HttpServletRequest request, HttpServletResponse response, @RequestBody String roleFunc) throws Exception {
160                 getRoleFunctionListController().saveRoleFunction(request, response, roleFunc);
161         }
162
163         @RequestMapping(value = { "/portalApi/role_function_list/removeRoleFunction" }, method = RequestMethod.POST)
164         public void removeRoleFunction(HttpServletRequest request, HttpServletResponse response, @RequestBody String roleFunc) throws Exception {
165                 getRoleFunctionListController().removeRoleFunction(request, response, roleFunc);
166         }
167
168         public RoleListController getRoleListController() {
169                 return roleListController;
170         }
171
172         public void setRoleListController(RoleListController roleListController) {
173                 this.roleListController = roleListController;
174         }
175
176         public RoleController getRoleController() {
177                 return roleController;
178         }
179
180         public void setRoleController(RoleController roleController) {
181                 this.roleController = roleController;
182         }
183
184         public RoleFunctionListController getRoleFunctionListController() {
185                 return roleFunctionListController;
186         }
187
188         public void setRoleFunctionListController(RoleFunctionListController roleFunctionListController) {
189                 this.roleFunctionListController = roleFunctionListController;
190         }
191
192         @RequestMapping(value = { "/portalApi/syncRoles" }, method = RequestMethod.GET)
193         public void  syncRoles(EPApp app)
194         {
195                 try {
196                         externalAccessRolesService.syncApplicationRolesWithEcompDB(app);
197                 } catch (Exception e) {
198                         logger.error(EELFLoggerDelegate.debugLogger, "failed syncRoles");
199                 }
200         }
201 }