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 javax.servlet.http.HttpServletRequest;
 
  23 import javax.servlet.http.HttpServletResponse;
 
  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;
 
  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.
 
  46 @org.springframework.context.annotation.Configuration
 
  47 @EnableAspectJAutoProxy
 
  49 public class RoleManageController extends EPRestrictedBaseController {
 
  52         private RoleController roleController;
 
  55         private RoleListController roleListController;
 
  58         private RoleFunctionListController roleFunctionListController;
 
  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.
 
  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
 
  73         @RequestMapping(value = { "/portalApi/get_roles" }, method = RequestMethod.GET)
 
  74         public void getRoles(HttpServletRequest request, HttpServletResponse response) {
 
  75                 getRoleListController().getRoles(request, response);
 
  78         @RequestMapping(value = { "/portalApi/role_list/toggleRole" }, method = RequestMethod.POST)
 
  79         public PortalRestResponse<String> toggleRole(HttpServletRequest request, HttpServletResponse response) {
 
  80                 PortalRestResponse<String> portalRestResponse = null;
 
  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());
 
  87                 return portalRestResponse;              
 
  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);
 
  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);
 
 100         @RequestMapping(value = { "/portalApi/role/removeRoleFunction" }, method = RequestMethod.POST)
 
 101         public ModelAndView removeRoleRoleFunction(HttpServletRequest request, HttpServletResponse response)
 
 103                 return getRoleController().removeRoleFunction(request, response);
 
 106         @RequestMapping(value = { "/portalApi/role/addRoleFunction" }, method = RequestMethod.POST)
 
 107         public ModelAndView addRoleRoRoleFunction(HttpServletRequest request, HttpServletResponse response)
 
 109                 return getRoleController().addRoleFunction(request, response);
 
 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);
 
 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);
 
 122         @RequestMapping(value = { "/portalApi/get_role" }, method = RequestMethod.GET)
 
 123         public void getRole(HttpServletRequest request, HttpServletResponse response) {
 
 124                 getRoleController().getRole(request, response);
 
 127         @RequestMapping(value = { "/portalApi/get_role_functions" }, method = RequestMethod.GET)
 
 128         public void getRoleFunctionList(HttpServletRequest request, HttpServletResponse response) {
 
 129                 getRoleFunctionListController().getRoleFunctionList(request, response);
 
 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);
 
 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);
 
 142         public RoleListController getRoleListController() {
 
 143                 return roleListController;
 
 146         public void setRoleListController(RoleListController roleListController) {
 
 147                 this.roleListController = roleListController;
 
 150         public RoleController getRoleController() {
 
 151                 return roleController;
 
 154         public void setRoleController(RoleController roleController) {
 
 155                 this.roleController = roleController;
 
 158         public RoleFunctionListController getRoleFunctionListController() {
 
 159                 return roleFunctionListController;
 
 162         public void setRoleFunctionListController(RoleFunctionListController roleFunctionListController) {
 
 163                 this.roleFunctionListController = roleFunctionListController;