KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nemesis > forum > webapp > admin > action > AddGroupAction


1 package org.nemesis.forum.webapp.admin.action;
2
3 import javax.servlet.http.HttpServletRequest JavaDoc;
4 import javax.servlet.http.HttpServletResponse JavaDoc;
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 /**
22  * @author dlaurent
23  *
24  * 20 févr. 2003
25  * AddGroupAction.java
26  */

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 JavaDoc request,
35                  HttpServletResponse JavaDoc response)
36     throws Exception JavaDoc {
37  
38         //check logon
39
checkUser(request);
40         //check permission
41
checkPermission(request,OperationConstants.ADD_GROUP);
42         
43         ActionErrors errors = new ActionErrors();
44         
45         // user need cancel
46
if (isCancelled(request)) {
47               return (mapping.findForward("cancel"));
48          }
49         
50         String JavaDoc name = (String JavaDoc)PropertyUtils.getSimpleProperty(form, "name");
51         String JavaDoc description = (String JavaDoc)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                     // add logged user as an administrator of the new group
62
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 JavaDoc e) {
73             String JavaDoc 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