1 package org.nemesis.forum.webapp.admin.action; 2 3 import javax.servlet.http.HttpServletRequest ; 4 import javax.servlet.http.HttpServletResponse ; 5 6 import org.apache.commons.beanutils.PropertyUtils; 7 import org.apache.commons.logging.Log; 8 import org.apache.commons.logging.LogFactory; 9 import org.apache.struts.action.ActionError; 10 import org.apache.struts.action.ActionErrors; 11 import org.apache.struts.action.ActionForm; 12 import org.apache.struts.action.ActionForward; 13 import org.apache.struts.action.ActionMapping; 14 import org.nemesis.forum.ForumFactory; 15 import org.nemesis.forum.Group; 16 import org.nemesis.forum.ProfileManager; 17 import org.nemesis.forum.User; 18 import org.nemesis.forum.exception.AlreadyExistsException; 19 20 21 27 public class AddGroupAction extends BaseAction { 28 29 static protected Log log =LogFactory.getLog(AddGroupAction.class); 30 31 32 public ActionForward execute(ActionMapping mapping, 33 ActionForm form, 34 HttpServletRequest request, 35 HttpServletResponse response) 36 throws Exception { 37 38 checkUser(request); 40 checkPermission(request,OperationConstants.ADD_GROUP); 42 43 ActionErrors errors = new ActionErrors(); 44 45 if (isCancelled(request)) { 47 return (mapping.findForward("cancel")); 48 } 49 50 String name = (String )PropertyUtils.getSimpleProperty(form, "name"); 51 String description = (String )PropertyUtils.getSimpleProperty(form, "description"); 52 53 try { 54 55 56 ForumFactory forumFactory = ForumFactory.getInstance(getAuthToken(request)); 57 ProfileManager manager = forumFactory.getProfileManager(); 58 User user = manager.getUser(getAuthToken(request).getUserID()); 59 try { 60 Group newGroup = manager.createGroup(name); 61 newGroup.addAdministrator(user); 63 if( description != null ) { 64 newGroup.setDescription( description ); 65 } 66 } 67 catch( AlreadyExistsException aee ) { 68 errors.add("general", new ActionError("addGroup.alreadyExist")); 69 } 70 71 72 } catch (Exception e) { 73 String eid=this.getClass().getName()+"_"+System.currentTimeMillis(); 74 log.error("eid:"+eid+"\nsessionID" +request.getSession().getId(),e) ; 75 errors.add("general", new ActionError("error.general","erreur id:"+eid)); 76 } 77 78 if (!errors.isEmpty()) { 79 saveErrors(request, errors); 80 return (mapping.getInputForward()); 81 } 82 83 return mapping.findForward("success"); 84 } 85 86 } | Popular Tags |