1 16 package com.blandware.atleap.webapp.action.core.role; 17 18 import com.blandware.atleap.common.Constants; 19 import com.blandware.atleap.model.core.Role; 20 import com.blandware.atleap.service.core.RoleManager; 21 import com.blandware.atleap.service.exception.BeanAlreadyExistsException; 22 import com.blandware.atleap.webapp.action.core.BaseAction; 23 import com.blandware.atleap.webapp.form.RoleForm; 24 import com.blandware.atleap.webapp.util.core.WebappConstants; 25 import com.blandware.atleap.webapp.util.core.WebappUtil; 26 import org.apache.commons.validator.GenericValidator; 27 import org.apache.struts.action.ActionForm; 28 import org.apache.struts.action.ActionForward; 29 import org.apache.struts.action.ActionMapping; 30 import org.apache.struts.action.ActionMessage; 31 import org.apache.struts.action.ActionMessages; 32 import org.springframework.orm.ObjectOptimisticLockingFailureException; 33 34 import javax.servlet.http.HttpServletRequest ; 35 import javax.servlet.http.HttpServletResponse ; 36 37 65 public final class UpdateRoleAction extends BaseAction { 66 75 public ActionForward execute(ActionMapping mapping, ActionForm form, 76 HttpServletRequest request, HttpServletResponse response) throws Exception { 77 78 if ( !isCancelled(request) ) { 79 80 RoleForm roleForm = (RoleForm) form; 81 82 String roleName = roleForm.getName(); 83 if ( GenericValidator.isBlankOrNull(roleName) ) { 84 if ( log.isWarnEnabled() ) { 85 log.warn("Missing role name. Returning to list..."); 86 } 87 return mapping.findForward("listRoles"); 88 } 89 90 request.getSession().setAttribute(WebappConstants.ROLE_NAME_KEY, roleName); 91 92 RoleManager roleManager = (RoleManager) getBean(Constants.ROLE_MANAGER_BEAN); 93 94 Role role = roleManager.retrieveRole(roleName); 95 96 if ( role == null ) { 97 ActionMessages errors = new ActionMessages(); 99 errors.add("roleNotFound", new ActionMessage("core.role.errors.notFound")); 100 saveErrors(request, errors); 101 return mapping.findForward("listRoles"); 102 } 103 104 WebappUtil.copyProperties(role, roleForm, request); 105 106 try { 107 roleManager.updateRole(role); 108 } catch ( BeanAlreadyExistsException e ) { 109 ActionMessages errors = new ActionMessages(); 111 errors.add("roleAlreadyExists", new ActionMessage("core.role.errors.alreadyExists")); 112 saveErrors(request, errors); 113 saveToken(request); 114 return mapping.getInputForward(); 115 } catch ( ObjectOptimisticLockingFailureException e ) { 116 ActionMessages errors = new ActionMessages(); 118 errors.add("updateFailed", new ActionMessage("core.role.errors.updateFailed")); 119 saveErrors(request, errors); 120 return mapping.findForward("callUpdateRole"); 121 } 122 } 123 return mapping.findForward("listRoles"); 124 } 125 } | Popular Tags |