KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * GroupWizardCannedMessageAddAction.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 GroupWizardCannedMessageAddAction extends Action
26 {
27     
28     /** Creates a new instance of UserManagementAction */
29     public GroupWizardCannedMessageAddAction()
30     {
31     }
32     
33     public ActionForward execute(ActionMapping mapping,
34     ActionForm form,
35     HttpServletRequest request,
36     HttpServletResponse response) throws UnsupportedEncodingException JavaDoc
37     {
38         GroupWizardCannedMessageForm cform = (GroupWizardCannedMessageForm)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 = cform.getSubmit();
74         
75         if (submit.startsWith("Add") == 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                     else
96                     {
97                         list.add(0, new LabelValueBean("All of this customer's groups",
98                                 URLEncoder.encode(group, "UTF-8")));
99                     }
100                 }
101                 
102                 cform.setUserGroups(list);
103             }
104             
105             CannedMessageTable tbl = new CannedMessageTable();
106             tbl.setConnection(c);
107             
108             CannedMessageElement e = new CannedMessageElement();
109             
110             e.setGroup(URLDecoder.decode(cform.getGroup(), "UTF-8"));
111             e.setDescription(cform.getDescription());
112             e.setMessage(cform.getFormattedContent());
113             
114             int len = cform.getDescription().length();
115             String JavaDoc id = domain + '-' + cform.getCounter() + '-' + cform.getDescription().substring(0, len < 20 ? len : 19);
116             e.setId(id);
117             
118             if (tbl.create(e) == false)
119             {
120                 errors.add(ActionErrors.GLOBAL_ERROR,
121                 new ActionError("error.groupmessage.create.failure", new String JavaDoc(id)));
122                 
123                 AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG,
124                 "GroupWizardCannedMessageAddAction.execute()/Create/by-"
125                 + element.getName()
126                 + ": "
127                 + tbl.getErrorMessage());
128             }
129             else
130             {
131                 AceLogger.Instance().log(AceLogger.INFORMATIONAL, AceLogger.USER_LOG,
132                 "User " + element.getName() + " created webtalk canned message " +
133                 id);
134                 
135                 ActionMessages messages = new ActionMessages();
136                 messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("message.groupmessage.x.created", new String JavaDoc(cform.getDescription())));
137                 saveMessages(request, messages);
138                 
139                 // append to wizard action log
140
StringBuffer JavaDoc buf = new StringBuffer JavaDoc("\nCreated canned message '");
141                 buf.append(cform.getDescription());
142                 buf.append("' using Message ID '");
143                 buf.append(id);
144                 buf.append("'\n");
145                 log.add(buf.toString());
146                 
147             }
148         }
149         
150         
151         WebTalkRelatedTasks menu = new WebTalkRelatedTasks();
152         request.setAttribute("menu", menu);
153         
154         if (submit.startsWith("Cancel") == false)
155         {
156             // add related tasks to the navigation bar
157

158             menu.addLink(new LinkAttribute("List all groups", "list_groups"));
159             menu.addLink(new LinkAttribute("List all features", "list_features"));
160             menu.addLink(new LinkAttribute("Search users", "display_user_search"));
161             menu.addLink(new LinkAttribute("Search canned messages", "display_canned_message_search"));
162         }
163         
164         if (errors.isEmpty() == false)
165         {
166             saveErrors(request, errors);
167             return mapping.getInputForward();
168         }
169         
170         if (submit.startsWith("Finished") == true)
171         {
172             // nothing new to add, we're at the end of the wizard
173
}
174         
175         return mapping.findForward(submit);
176     }
177     
178     
179 }
180
Popular Tags