2d0fe27985c673158bed9fc34b9d8c2a9edd7a93
[portal.git] / ecomp-portal-BE-common / src / main / java / org / openecomp / portalapp / portal / controller / RoleManageController.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 javax.servlet.http.HttpServletRequest;
23 import javax.servlet.http.HttpServletResponse;
24
25 import org.openecomp.portalapp.controller.EPRestrictedBaseController;
26 import org.openecomp.portalapp.controller.core.RoleController;
27 import org.openecomp.portalapp.controller.core.RoleFunctionListController;
28 import org.openecomp.portalapp.controller.core.RoleListController;
29 import org.openecomp.portalapp.portal.ecomp.model.PortalRestResponse;
30 import org.openecomp.portalapp.portal.ecomp.model.PortalRestStatusEnum;
31 import org.openecomp.portalapp.portal.logging.aop.EPAuditLog;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.context.annotation.EnableAspectJAutoProxy;
34 import org.springframework.web.bind.annotation.RequestBody;
35 import org.springframework.web.bind.annotation.RequestMapping;
36 import org.springframework.web.bind.annotation.RequestMethod;
37 import org.springframework.web.bind.annotation.RestController;
38 import org.springframework.web.servlet.ModelAndView;
39
40 /**
41  * Proxies REST calls to role-management functions that arrive on paths
42  * /portalApi/* over to controller methods provided by the SDK-Core library.
43  * Those controller methods are mounted on paths not exposed by the Portal FE.
44  */
45 @RestController
46 @org.springframework.context.annotation.Configuration
47 @EnableAspectJAutoProxy
48 @EPAuditLog
49 public class RoleManageController extends EPRestrictedBaseController {
50
51         @Autowired
52         private RoleController roleController;
53
54         @Autowired
55         private RoleListController roleListController;
56
57         @Autowired
58         private RoleFunctionListController roleFunctionListController;
59
60         /**
61          * Calls an SDK-Core library method that gets the available roles and writes
62          * them to the request object. Portal specifies a Hibernate mappings from
63          * the Role class to the fn_role_v view, which ensures that only Portal
64          * (app_id is null) roles are fetched.
65          * 
66          * Any method declared void (no return value) or returning null causes the
67          * audit log aspect method to declare failure. TODO: should return a JSON
68          * string.
69          * 
70          * @param request
71          * @param response
72          */
73         @RequestMapping(value = { "/portalApi/get_roles" }, method = RequestMethod.GET)
74         public void getRoles(HttpServletRequest request, HttpServletResponse response) {
75                 getRoleListController().getRoles(request, response);
76         }
77
78         @RequestMapping(value = { "/portalApi/role_list/toggleRole" }, method = RequestMethod.POST)
79         public PortalRestResponse<String> toggleRole(HttpServletRequest request, HttpServletResponse response) {
80                 PortalRestResponse<String> portalRestResponse = null;
81                 try{
82                         getRoleListController().toggleRole(request, response);
83                         portalRestResponse = new PortalRestResponse<String>(PortalRestStatusEnum.OK, "success", null);
84                 }catch (Exception e) {
85                         return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "failure", e.getMessage());
86                 }
87                 return portalRestResponse;              
88         }
89
90         @RequestMapping(value = { "/portalApi/role_list/removeRole" }, method = RequestMethod.POST)
91         public ModelAndView removeRole(HttpServletRequest request, HttpServletResponse response) throws Exception {
92                 return getRoleListController().removeRole(request, response);
93         }
94
95         @RequestMapping(value = { "/portalApi/role/saveRole" }, method = RequestMethod.POST)
96         public ModelAndView saveRole(HttpServletRequest request, HttpServletResponse response) throws Exception {
97                 return getRoleController().saveRole(request, response);
98         }
99
100         @RequestMapping(value = { "/portalApi/role/removeRoleFunction" }, method = RequestMethod.POST)
101         public ModelAndView removeRoleRoleFunction(HttpServletRequest request, HttpServletResponse response)
102                         throws Exception {
103                 return getRoleController().removeRoleFunction(request, response);
104         }
105
106         @RequestMapping(value = { "/portalApi/role/addRoleFunction" }, method = RequestMethod.POST)
107         public ModelAndView addRoleRoRoleFunction(HttpServletRequest request, HttpServletResponse response)
108                         throws Exception {
109                 return getRoleController().addRoleFunction(request, response);
110         }
111
112         @RequestMapping(value = { "/portalApi/role/removeChildRole" }, method = RequestMethod.POST)
113         public ModelAndView removeChildRole(HttpServletRequest request, HttpServletResponse response) throws Exception {
114                 return getRoleController().removeChildRole(request, response);
115         }
116
117         @RequestMapping(value = { "/portalApi/role/addChildRole" }, method = RequestMethod.POST)
118         public ModelAndView addChildRole(HttpServletRequest request, HttpServletResponse response) throws Exception {
119                 return getRoleController().addChildRole(request, response);
120         }
121
122         @RequestMapping(value = { "/portalApi/get_role" }, method = RequestMethod.GET)
123         public void getRole(HttpServletRequest request, HttpServletResponse response) {
124                 getRoleController().getRole(request, response);
125         }
126
127         @RequestMapping(value = { "/portalApi/get_role_functions" }, method = RequestMethod.GET)
128         public void getRoleFunctionList(HttpServletRequest request, HttpServletResponse response) {
129                 getRoleFunctionListController().getRoleFunctionList(request, response);
130         }
131
132         @RequestMapping(value = { "/portalApi/role_function_list/saveRoleFunction" }, method = RequestMethod.POST)
133         public void saveRoleFunction(HttpServletRequest request, HttpServletResponse response, @RequestBody String roleFunc) throws Exception {
134                 getRoleFunctionListController().saveRoleFunction(request, response, roleFunc);
135         }
136
137         @RequestMapping(value = { "/portalApi/role_function_list/removeRoleFunction" }, method = RequestMethod.POST)
138         public void removeRoleFunction(HttpServletRequest request, HttpServletResponse response, @RequestBody String roleFunc) throws Exception {
139                 getRoleFunctionListController().removeRoleFunction(request, response, roleFunc);
140         }
141
142         public RoleListController getRoleListController() {
143                 return roleListController;
144         }
145
146         public void setRoleListController(RoleListController roleListController) {
147                 this.roleListController = roleListController;
148         }
149
150         public RoleController getRoleController() {
151                 return roleController;
152         }
153
154         public void setRoleController(RoleController roleController) {
155                 this.roleController = roleController;
156         }
157
158         public RoleFunctionListController getRoleFunctionListController() {
159                 return roleFunctionListController;
160         }
161
162         public void setRoleFunctionListController(RoleFunctionListController roleFunctionListController) {
163                 this.roleFunctionListController = roleFunctionListController;
164         }
165
166 }