KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.nemesis.forum.webapp.admin.action;
2
3 import javax.servlet.http.HttpServletRequest JavaDoc;
4 import javax.servlet.http.HttpServletResponse JavaDoc;
5 import javax.servlet.http.HttpSession JavaDoc;
6
7 import org.apache.commons.beanutils.PropertyUtils;
8 import org.apache.commons.logging.Log;
9 import org.apache.commons.logging.LogFactory;
10 import org.apache.struts.action.ActionError;
11 import org.apache.struts.action.ActionErrors;
12 import org.apache.struts.action.ActionForm;
13 import org.apache.struts.action.ActionForward;
14 import org.apache.struts.action.ActionMapping;
15 import org.nemesis.forum.ForumFactory;
16 import org.nemesis.forum.Group;
17 import org.nemesis.forum.ProfileManager;
18 import org.nemesis.forum.User;
19 import org.nemesis.forum.exception.NotFoundException;
20
21
22 /**
23  * @author dlaurent
24  *
25  * 20 févr. 2003
26  * AddGroupAction.java
27  */

28 public class AddGroupAdminAction extends BaseAction {
29
30     static protected Log log =LogFactory.getLog(AddGroupAdminAction.class);
31
32
33     public ActionForward execute(ActionMapping mapping,
34                  ActionForm form,
35                  HttpServletRequest JavaDoc request,
36                  HttpServletResponse JavaDoc response)
37     throws Exception JavaDoc {
38  
39         //check logon
40
checkUser(request);
41         //check permission
42
checkPermission(request,OperationConstants.ADD_GROUP_ADMIN);
43                 
44         ActionErrors errors = new ActionErrors();
45         
46         
47         try {
48                 
49                 
50                 ForumFactory forumFactory = ForumFactory.getInstance(getAuthToken(request));
51                 ProfileManager manager = forumFactory.getProfileManager();
52                 User user = manager.getUser(getAuthToken(request).getUserID());
53                     
54                 Group group = manager.getGroup((String JavaDoc)PropertyUtils.getSimpleProperty(form, "group"));
55                 request.setAttribute("id",group.getID()+"") ;
56                 User u = manager.getUser((String JavaDoc)PropertyUtils.getSimpleProperty(form, "username"));
57                 // add user as an administrator of the group
58
group.addAdministrator(u);
59                     
60                 
61         } catch (NotFoundException e) {
62             errors.add("general", new ActionError("groupUser.error.notFound"));
63                 
64         } catch (Exception JavaDoc e) {
65             String JavaDoc eid=this.getClass().getName()+"_"+System.currentTimeMillis();
66             log.error("eid:"+eid+"\nsessionID" +request.getSession().getId(),e) ;
67             errors.add("general", new ActionError("error.general","erreur id:"+eid));
68         }
69         
70         if (!errors.isEmpty()) {
71             saveErrors(request, errors);
72             return mapping.findForward("success");
73         }
74         removeFormBean(mapping, request);
75         return mapping.findForward("success");
76     }
77     
78     protected void removeFormBean(ActionMapping mapping, HttpServletRequest JavaDoc request) {
79                // Remove the obsolete form bean
80
if (mapping.getAttribute() != null) {
81                    if ("request".equals(mapping.getScope())) {
82                        request.removeAttribute(mapping.getAttribute());
83                    } else {
84                       HttpSession JavaDoc session = request.getSession();
85                       session.removeAttribute(mapping.getAttribute());
86                    }
87                }
88             }
89
90 }
Popular Tags