1 16 package com.blandware.atleap.webapp.action.core.user; 17 18 import com.blandware.atleap.common.Constants; 19 import com.blandware.atleap.service.core.UserManager; 20 import com.blandware.atleap.service.exception.BeanNotFoundException; 21 import com.blandware.atleap.webapp.action.core.BaseAction; 22 import com.blandware.atleap.webapp.form.UserForm; 23 import org.apache.commons.validator.GenericValidator; 24 import org.apache.struts.action.*; 25 26 import javax.servlet.http.HttpServletRequest ; 27 import javax.servlet.http.HttpServletResponse ; 28 29 48 public final class DeleteUserAction extends BaseAction { 49 58 public ActionForward execute(ActionMapping mapping, ActionForm form, 59 HttpServletRequest request, HttpServletResponse response) throws Exception { 60 61 UserForm userForm = (UserForm) form; 62 String userName = userForm.getName(); 63 if (GenericValidator.isBlankOrNull(userName)) { 64 if (log.isWarnEnabled()) { 65 log.warn("Missing user name. Returning to list..."); 66 } 67 return mapping.findForward("listUsers"); 68 } 69 70 if (userName.equals(request.getRemoteUser())) { 71 saveToken(request); 73 ActionMessages errors = new ActionMessages(); 74 errors.add("loggedUserCannotDelete", new ActionMessage("core.user.form.loggedUser.cannotDelete")); 75 saveErrors(request, errors); 76 return mapping.findForward("listUsers"); 77 } 78 79 UserManager userManager = (UserManager) getBean(Constants.USER_MANAGER_BEAN); 80 try { 81 userManager.deleteUser(userName); 82 } catch (BeanNotFoundException e) { 83 ActionMessages errors = new ActionMessages(); 85 errors.add("userNotFound", new ActionMessage("core.user.errors.notFound")); 86 saveErrors(request, errors); 87 return mapping.findForward("listUsers"); 88 } 89 return mapping.findForward("listUsers"); 90 } 91 92 } | Popular Tags |