1 16 package com.blandware.atleap.webapp.action.core.group; 17 18 import com.blandware.atleap.common.Constants; 19 import com.blandware.atleap.model.core.Group; 20 import com.blandware.atleap.service.core.GroupManager; 21 import com.blandware.atleap.service.exception.BeanAlreadyExistsException; 22 import com.blandware.atleap.webapp.action.core.BaseAction; 23 import com.blandware.atleap.webapp.form.GroupForm; 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 66 public final class UpdateGroupAction extends BaseAction { 67 76 public ActionForward execute(ActionMapping mapping, ActionForm form, 77 HttpServletRequest request, HttpServletResponse response) throws Exception { 78 79 if ( !isCancelled(request) ) { 80 81 GroupForm groupForm = (GroupForm) form; 82 83 String groupName = groupForm.getName(); 84 if ( GenericValidator.isBlankOrNull(groupName) ) { 85 if ( log.isWarnEnabled() ) { 86 log.warn("Missing group name. Returning to list..."); 87 } 88 return mapping.findForward("listGroups"); 89 } 90 91 request.getSession().setAttribute(WebappConstants.GROUP_NAME_KEY, groupName); 92 93 GroupManager groupManager = (GroupManager) getBean(Constants.GROUP_MANAGER_BEAN); 94 95 Group group = groupManager.retrieveGroup(groupName); 96 97 if ( group == null ) { 98 ActionMessages errors = new ActionMessages(); 100 errors.add("groupNotFound", new ActionMessage("core.group.errors.notFound")); 101 saveErrors(request, errors); 102 return mapping.findForward("listGroups"); 103 } 104 105 WebappUtil.copyProperties(group, groupForm, request); 106 107 try { 108 groupManager.updateGroup(group); 109 } catch ( BeanAlreadyExistsException e ) { 110 ActionMessages errors = new ActionMessages(); 112 errors.add("groupAlreadyExists", new ActionMessage("core.group.errors.alreadyExists")); 113 saveErrors(request, errors); 114 saveToken(request); 115 return mapping.getInputForward(); 116 } catch ( ObjectOptimisticLockingFailureException e ) { 117 ActionMessages errors = new ActionMessages(); 119 errors.add("updateFailed", new ActionMessage("core.group.errors.updateFailed")); 120 saveErrors(request, errors); 121 return mapping.findForward("callUpdateGroup"); 122 } 123 } 124 return mapping.findForward("listGroups"); 125 } 126 } | Popular Tags |