KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * GroupWizardGroupAddAction.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 java.sql.*;
16 import java.util.*;
17
18 /**
19  *
20  * @author bhm
21  */

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

61             errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.hosting.wizard.sequence"));
62             saveErrors(request, errors);
63             
64             return mapping.findForward("display_group_wizard_intro");
65         }
66         
67         String JavaDoc submit = (String JavaDoc)((DynaActionForm)form).get("submit");
68         
69         if (submit.equals("Add Group") == true)
70         {
71             String JavaDoc domain = (String JavaDoc)request.getSession().getAttribute("groupWizardDomain");
72             String JavaDoc group_name = domain + '-' + ((String JavaDoc)((DynaActionForm)form).get("groupName")).trim();
73             
74             GroupTable groups = new GroupTable();
75             groups.setConnection(c);
76             
77             GroupElement e = new GroupElement();
78             
79             e.setMemberBusyNotificationControl(GroupElement.NOTIFY_ALL);
80             e.setMemberLoginNotificationControl(GroupElement.NOTIFY_ALL);
81             e.setOwnerBusyNotificationControl(GroupElement.NOTIFY_NONE);
82             e.setOwnerLoginNotificationControl(GroupElement.NOTIFY_NONE);
83             e.setName(group_name);
84             e.setDomain(domain);
85             
86             boolean status_ok = groups.create(e);
87             
88             if (status_ok == false)
89             {
90                 errors.add(ActionErrors.GLOBAL_ERROR,
91                 new ActionError("error.group.create.failure"));
92                 
93                 AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG,
94                 "GroupWizardGroupAddAction.execute()/Create Group/by-"
95                 + element.getName()
96                 + ": "
97                 + groups.getErrorMessage());
98             }
99             else
100             {
101                 AceLogger.Instance().log(AceLogger.INFORMATIONAL, AceLogger.USER_LOG,
102                 "User " + element.getName() + " created new group " +
103                 group_name);
104                 
105                 ActionMessages messages = new ActionMessages();
106                 messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("message.group.x.created", new String JavaDoc(group_name)));
107                 saveMessages(request, messages);
108                 
109                 // append to wizard action log
110
StringBuffer JavaDoc buf = new StringBuffer JavaDoc("\nCreated group '");
111                 buf.append(group_name);
112                 buf.append("'\n");
113                 log.add(buf.toString());
114                 
115                 
116                 // now add the group owner
117

118                 String JavaDoc groupowner_name = group_name;
119                 
120                 UserTable user_tbl = new UserTable();
121                 user_tbl.setConnection(c);
122                 
123                 UserElement u = new UserElement();
124                 
125                 u.setAdditionalInfo("Owner of group " + group_name + ", company: "
126                 + (String JavaDoc)request.getSession().getAttribute("groupWizardCompanyName") + ", url: "
127                 + (String JavaDoc)request.getSession().getAttribute("groupWizardCompanyUrl"));
128                 u.setAddress(((String JavaDoc)((DynaActionForm)form).get("messageboxEmail")).trim());
129                 u.setFullName(group_name + " Group");
130                 u.setName(groupowner_name);
131                 u.setUnavailXferTo("messagebox");
132                 u.setPassword("a1b2c3d4");
133                 u.addOwnsGroup(group_name);
134                 u.setDomain(domain);
135                 u.addBelongsToGroup(domain);
136                 
137                 status_ok = user_tbl.create(u);
138                 
139                 if (status_ok == false)
140                 {
141                     errors.add(ActionErrors.GLOBAL_ERROR,
142                     new ActionError("error.groupowner.create.failure", new String JavaDoc(groupowner_name), new String JavaDoc(group_name)));
143                     
144                     AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG,
145                     "GroupWizardGroupAddAction.execute()/Create Group Owner/by-"
146                     + element.getName()
147                     + ": "
148                     + user_tbl.getErrorMessage());
149                     
150                     // append to wizard action log
151
buf = new StringBuffer JavaDoc("\n*** ERROR *** creating group owner : The group owner named '");
152                     buf.append(groupowner_name);
153                     buf.append("' for the new group '");
154                     buf.append(group_name);
155                     buf.append("' could not be created because a user with that name already exists or there was a database error. If that user name already exists in the system, proceed with the wizard as you normally would. After finishing with the wizard, add the group owner and the feature for this new group yourself, using a unique name other than '");
156                     buf.append(groupowner_name);
157                     buf.append("'. Remember to activate the feature after adding it.");
158                     buf.append("\n");
159                     log.add(buf.toString());
160                 }
161                 else
162                 {
163                     AceLogger.Instance().log(AceLogger.INFORMATIONAL, AceLogger.USER_LOG,
164                     "User " + element.getName() + " created new webtalk user " +
165                     groupowner_name);
166                     
167                     // append to wizard action log
168
buf = new StringBuffer JavaDoc("\nCreated group owner '");
169                     buf.append(groupowner_name);
170                     buf.append("'\n");
171                     log.add(buf.toString());
172                     
173                     // now add and activate the feature
174

175                     Integer JavaDoc max_operators = (Integer JavaDoc)((DynaActionForm)form).get("maxOperators");
176                     
177                     FeatureTable tbl = new FeatureTable();
178                     tbl.setConnection(c);
179                     
180                     FeatureTableElement f = new FeatureTableElement();
181                     
182                     f.setActive(true);
183                     f.setClassName(FeatureOperatorManagementAction.CLASSNAME);
184                     f.setName(groupowner_name);
185                     f.setDomain(domain);
186                     
187                     HashMap map = new HashMap(4);
188                     
189                     map.put("max-sessions", ((Integer JavaDoc)((DynaActionForm)form).get("maxSessions")).toString());
190                     map.put("max-queue-size", new Integer JavaDoc(max_operators.intValue() * 4).toString());
191                     map.put("max-operators", max_operators.toString());
192                     map.put("proactive-monitoring", ((DynaActionForm)form).get("proactiveMonitoringEnabled"));
193                     
194                     f.setParams(map);
195                     
196                     if (tbl.create(f) == false)
197                     {
198                         errors.add(ActionErrors.GLOBAL_ERROR,
199                         new ActionError("error.groupfeature.create.failure", new String JavaDoc(groupowner_name), new String JavaDoc(group_name)));
200                         
201                         AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG,
202                         "GroupWizardGroupAddAction.execute()/Create Feature/by-"
203                         + element.getName()
204                         + ": "
205                         + tbl.getErrorMessage());
206                         
207                         // append to wizard action log
208
buf = new StringBuffer JavaDoc("\n*** ERROR *** creating feature : The feature named '");
209                         buf.append(groupowner_name);
210                         buf.append("' for the new group '");
211                         buf.append(group_name);
212                         buf.append("' could not be created because a feature with that name already exists or there was a database error. If that feature name does already exist in the system, proceed with the wizard as you normally would. After finishing with the wizard, remove the old (presumably unused) feature named '");
213                         buf.append(groupowner_name);
214                         buf.append("' and add a new feature with the same name and with the parameter settings you want for this new group (remember to activate the new feature after adding it). Note, a group owner named '");
215                         buf.append(groupowner_name);
216                         buf.append("' has just been successfully added to the system for the new group '");
217                         buf.append(group_name);
218                         buf.append("', and the parameter settings for feature '");
219                         buf.append(groupowner_name);
220                         buf.append("' will be applied to the new group.");
221                         buf.append("\n");
222                         log.add(buf.toString());
223                     }
224                     else
225                     {
226                         AceLogger.Instance().log(AceLogger.INFORMATIONAL, AceLogger.USER_LOG,
227                         "User " + element.getName() + " created active feature " +
228                         groupowner_name);
229                         
230                         // append to wizard action log
231
buf = new StringBuffer JavaDoc("\nCreated feature '");
232                         buf.append(groupowner_name);
233                         buf.append("'\n");
234                         log.add(buf.toString());
235                         
236                         // finally, activate the feature
237

238                         // notify the app server via RMI
239
if (FeatureManagementAction.notifyAppServer(request, groupowner_name, "activate", null, "Create Feature/by-" + element.getName()) == false)
240                         {
241                             errors.add(ActionErrors.GLOBAL_ERROR,
242                             new ActionError("error.groupfeature.activate.failure", new String JavaDoc(groupowner_name), new String JavaDoc(group_name)));
243                             
244                             // append to wizard action log
245
buf = new StringBuffer JavaDoc("\n*** WARNING *** The data for the new group got added successfully, but the feature ('");
246                             buf.append(groupowner_name);
247                             buf.append("') for the new operator group could not be activated at the Ace Application Server. You can proceed with the wizard, but afterward you'll need to (re)start the Application Server before the new group '");
248                             buf.append(group_name);
249                             buf.append("' can be used.");
250                             buf.append("\n");
251                             log.add(buf.toString());
252                         }
253                     }
254                 }
255             }
256         }
257         
258         WebTalkRelatedTasks menu = new WebTalkRelatedTasks();
259         request.setAttribute("menu", menu);
260         
261         if (submit.startsWith("Cancel") == false)
262         {
263             // add related tasks to the navigation bar
264

265             menu.addLink(new LinkAttribute("List all groups", "list_groups"));
266             menu.addLink(new LinkAttribute("List all features", "list_features"));
267             menu.addLink(new LinkAttribute("Search users", "display_user_search"));
268         }
269         
270         if (errors.isEmpty() == false)
271         {
272             saveErrors(request, errors);
273             return mapping.getInputForward();
274         }
275         
276         return mapping.findForward(submit);
277     }
278     
279     
280 }
281
Popular Tags