1 21 package com.jaspersoft.jasperserver.war.control; 22 23 import javax.servlet.ServletException ; 24 import javax.servlet.http.HttpServletRequest ; 25 import javax.servlet.http.HttpServletResponse ; 26 27 import org.springframework.validation.BindException; 28 import org.springframework.web.bind.ServletRequestDataBinder; 29 import org.springframework.web.multipart.support.ByteArrayMultipartFileEditor; 30 import org.springframework.web.servlet.ModelAndView; 31 import org.springframework.web.servlet.mvc.SimpleFormController; 32 33 import com.jaspersoft.jasperserver.api.common.domain.ExecutionContext; 34 import com.jaspersoft.jasperserver.api.common.domain.impl.ExecutionContextImpl; 35 36 import com.jaspersoft.jasperserver.api.metadata.user.domain.Role; 37 import com.jaspersoft.jasperserver.api.metadata.user.domain.impl.hibernate.RepoRole; 38 import com.jaspersoft.jasperserver.api.metadata.user.service.UserAuthorityService; 39 import com.jaspersoft.jasperserver.api.metadata.user.service.impl.UserAuthorityServiceImpl; 40 import com.jaspersoft.jasperserver.war.common.JasperServerUtil; 41 42 public class CRUDRoleController extends SimpleFormController { 43 44 protected UserAuthorityService userAuthService; 46 47 52 public UserAuthorityService getUserAuthService() { 53 return userAuthService; 54 } 55 56 61 public void setUserAuthService(UserAuthorityService userAuthService) { 62 this.userAuthService = userAuthService; 63 } 64 65 71 public Object formBackingObject(HttpServletRequest request) { 72 73 String rolename = null; 74 String fromPage = request.getParameter("frompage"); 75 if(fromPage != null && fromPage.equals("ObjectPermissionToRole")) 76 rolename = request.getParameter("selectedrole"); 77 else 78 rolename = request.getParameter("roleName"); 79 80 ExecutionContext context = new ExecutionContextImpl(); 81 Role roleUnit = null; 82 if(rolename == null || rolename.trim().length()==0) 83 roleUnit = userAuthService.newRole(context); 84 else { 85 roleUnit = userAuthService.getRole(context, rolename); 86 } 87 88 if(roleUnit == null) { 90 roleUnit = userAuthService.newRole(context); 91 } 92 93 request.setAttribute("roleList", userAuthService.getRoles(context, null)); 94 return roleUnit; 95 } 96 97 102 public ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, 103 Object command, BindException errors) throws Exception { 104 105 String fromPage = request.getParameter("frompage"); 106 Role roleUnit = (Role)command; 107 108 String extdef = request.getParameter("extDefined"); 110 if(extdef != null && extdef.equals("true")) 111 roleUnit.setExternallyDefined(true); 112 else 113 roleUnit.setExternallyDefined(false); 114 115 JasperServerUtil.trimDTOFieldSpaces(roleUnit); 116 117 userAuthService.putRole(null, roleUnit); 118 119 if(fromPage != null && !fromPage.equals("ObjectPermissionToRole")) { 120 return new ModelAndView("AdminStatus"); 121 } else { 122 return new ModelAndView(fromPage); 123 } 124 } 125 126 131 protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) 132 throws ServletException { 133 binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor()); 134 } 135 136 137 } 138 | Popular Tags |