KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > quikj > application > communicator > applications > webtalk > controller > GroupWizardUserAddAction


1 /*
2  * GroupWizardUserAddAction.java
3  *
4  */

5
6 package com.quikj.application.communicator.applications.webtalk.controller;
7
8 import com.quikj.application.communicator.applications.webtalk.model.*;
9 import com.quikj.application.communicator.admin.model.*;
10 import com.quikj.application.communicator.admin.controller.*;
11 import com.quikj.server.framework.*;
12
13 import javax.servlet.http.*;
14 import org.apache.struts.action.*;
15 import org.apache.struts.util.*;
16 import java.sql.*;
17 import java.util.*;
18 import java.io.UnsupportedEncodingException JavaDoc;
19 import java.net.*;
20
21 /**
22  *
23  * @author bhm
24  */

25 public class GroupWizardUserAddAction extends Action
26 {
27     
28     /** Creates a new instance of UserManagementAction */
29     public GroupWizardUserAddAction()
30     {
31     }
32     
33     public ActionForward execute(ActionMapping mapping,
34     ActionForm form,
35     HttpServletRequest request,
36     HttpServletResponse response) throws UnsupportedEncodingException JavaDoc
37     {
38         UserManagementForm uform = (UserManagementForm)form;
39         
40         ActionErrors errors = new ActionErrors();
41         
42         Connection c = (Connection)request.getSession().getAttribute("connection");
43         if (c == null)
44         {
45             errors.add(ActionErrors.GLOBAL_ERROR,
46             new ActionError("error.not.logged.in"));
47             saveErrors(request, errors);
48             return mapping.findForward("logon");
49         }
50         
51         AccountElement element = (AccountElement)request.getSession().getAttribute("userInfo");
52         if (element.isAdminLevel() == false)
53         {
54             errors.add(ActionErrors.GLOBAL_ERROR,
55             new ActionError("error.insufficient.privilege"));
56             saveErrors(request, errors);
57             
58             return mapping.findForward("main_menu");
59         }
60         
61         ArrayList log = (ArrayList) request.getSession().getAttribute("groupWizardLog");
62         if (log == null)
63         {
64             // did not get here through normal sequence
65

66             errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.hosting.wizard.sequence"));
67             saveErrors(request, errors);
68             
69             return mapping.findForward("display_group_wizard_intro");
70         }
71         
72         
73         String JavaDoc submit = uform.getSubmit();
74         
75         if (submit.equals("Create Operator") == true)
76         {
77             String JavaDoc domain = (String JavaDoc)request.getSession().getAttribute("groupWizardDomain");
78             
79             GroupTable groups = new GroupTable();
80             groups.setConnection(c);
81             ArrayList group_list = groups.list(domain);
82             if (group_list != null)
83             {
84                 ArrayList list = new ArrayList();
85                 Iterator iter = group_list.iterator();
86                 
87                 while (iter.hasNext() == true)
88                 {
89                     String JavaDoc group = (String JavaDoc)iter.next();
90                     
91                     if (group.equals(domain) == false)
92                     {
93                         list.add(new LabelValueBean(group, URLEncoder.encode(group, "UTF-8")));
94                     }
95                 }
96                 
97                 uform.setUserGroups(list);
98             }
99             
100             
101             UserTable user_tbl = new UserTable();
102             user_tbl.setConnection(c);
103             
104             UserElement e = new UserElement();
105             
106             e.setAdditionalInfo(uform.getAdditionalInfo());
107             e.setAddress(uform.getAddress());
108             e.setFullName(uform.getFullName());
109             e.setName(uform.getName());
110             e.setUnavailXferTo("messagebox");
111             e.setGatekeeper(uform.getGatekeeper());
112             e.setPassword(uform.getPassword());
113             e.setDomain(domain);
114             e.addBelongsToGroup(domain);
115             
116             Object JavaDoc[] ogroups = uform.getBelongsToGroups();
117             if (ogroups != null)
118             {
119                 for (int i = 0; i < ogroups.length; i++)
120                 {
121                     if (ogroups[i] != null)
122                     {
123                         String JavaDoc decoded_groups = URLDecoder.decode((String JavaDoc)ogroups[i], "UTF-8");
124                         e.addBelongsToGroup(decoded_groups);
125                     }
126                 }
127             }
128             
129             boolean status_ok = user_tbl.create(e);
130             
131             if (status_ok == false)
132             {
133                 errors.add(ActionErrors.GLOBAL_ERROR,
134                 new ActionError("error.account.create.failure"));
135                 
136                 AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG,
137                 "GroupWizardUserAddAction.execute()/Create/by-"
138                 + element.getName()
139                 + ": "
140                 + user_tbl.getErrorMessage());
141             }
142             else
143             {
144                 AceLogger.Instance().log(AceLogger.INFORMATIONAL, AceLogger.USER_LOG,
145                 "User " + element.getName() + " created webtalk user " +
146                 uform.getName());
147                 
148                 ActionMessages messages = new ActionMessages();
149                 messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("message.operator.x.created", new String JavaDoc(uform.getName())));
150                 saveMessages(request, messages);
151                 
152                 // append to wizard action log
153
StringBuffer JavaDoc buf = new StringBuffer JavaDoc("\nCreated operator '");
154                 buf.append(uform.getName());
155                 buf.append("'\n");
156                 log.add(buf.toString());
157                 
158             }
159         }
160         
161         
162         WebTalkRelatedTasks menu = new WebTalkRelatedTasks();
163         request.setAttribute("menu", menu);
164         
165         if (submit.startsWith("Cancel") == false)
166         {
167             // add related tasks to the navigation bar
168

169             menu.addLink(new LinkAttribute("List all groups", "list_groups"));
170             menu.addLink(new LinkAttribute("List all features", "list_features"));
171             menu.addLink(new LinkAttribute("Search users", "display_user_search"));
172         }
173         
174         if (errors.isEmpty() == false)
175         {
176             saveErrors(request, errors);
177             return mapping.getInputForward();
178         }
179         
180         if (submit.startsWith("Finished") == true)
181         {
182             menu.addLink(new LinkAttribute("Search canned messages", "display_canned_message_search"));
183         }
184         
185         return mapping.findForward(submit);
186     }
187     
188     
189 }
190
Popular Tags