KickJava   Java API By Example, From Geeks To Geeks.

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


1
2 package com.quikj.application.communicator.applications.webtalk.controller;
3
4 import javax.servlet.http.*;
5 import org.apache.struts.action.*;
6 import java.sql.*;
7 import java.util.*;
8
9 import com.quikj.application.communicator.admin.model.*;
10 import com.quikj.application.communicator.admin.controller.*;
11 import com.quikj.application.communicator.applications.webtalk.model.*;
12 import com.quikj.server.framework.AceLogger;
13
14 /**
15  *
16  * @author bhm
17  */

18 public class RestrictedAccessUserSearchAction extends Action
19 {
20     
21     /** Creates a new instance of RestrictedAccessUserSearchAction */
22     public RestrictedAccessUserSearchAction()
23     {
24     }
25     
26     public ActionForward execute(ActionMapping mapping,
27     ActionForm form,
28     HttpServletRequest request,
29     HttpServletResponse response)
30     {
31         RestrictedAccessUserSearchForm uform = (RestrictedAccessUserSearchForm)form;
32         
33         ActionErrors errors = new ActionErrors();
34         ActionMessages messages = new ActionMessages();
35         
36         Connection c = (Connection)request.getSession().getAttribute("connection");
37         if (c == null)
38         {
39             errors.add(ActionErrors.GLOBAL_ERROR,
40             new ActionError("error.not.logged.in"));
41             saveErrors(request, errors);
42             return mapping.findForward("logon");
43         }
44         
45         AccountElement element = (AccountElement)request.getSession().getAttribute("userInfo");
46         if (element.isAdminLevel() == false)
47         {
48             errors.add(ActionErrors.GLOBAL_ERROR,
49             new ActionError("error.insufficient.privilege"));
50             saveErrors(request, errors);
51             
52             return mapping.findForward("main_menu");
53         }
54         
55         RestrictedAccessUserTable tbl = new RestrictedAccessUserTable();
56         tbl.setConnection(c);
57         
58         RestrictedAccessUserElement e = new RestrictedAccessUserElement();
59        
60         String JavaDoc field = uform.getAdditionalInfo();
61         if ((field != null) && (field.length() > 0))
62         {
63             e.setAdditionalInfo(field);
64         }
65         
66         field = uform.getEmail();
67         if ((field != null) && (field.length() > 0))
68         {
69             e.setEmail(field);
70         }
71         
72         field = uform.getFullName();
73         if ((field != null) && (field.length() > 0))
74         {
75             e.setFullName(field);
76         }
77         
78         field = uform.getName();
79         if ((field != null) && (field.length() > 0))
80         {
81             e.setName(field);
82         }
83         
84         ArrayList list = tbl.search(e);
85         
86         if (list == null)
87         {
88             errors.add(ActionErrors.GLOBAL_ERROR,
89             new ActionError("error.db.failure"));
90             
91             AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG,
92             "RestrictedAccessUserSearchAction.execute()/Search/by-"
93             + element.getName()
94             + ": "
95             + tbl.getErrorMessage());
96         }
97         else
98         {
99             int num_items = list.size();
100             
101             if (num_items == 0)
102             {
103                 messages.add(ActionMessages.GLOBAL_MESSAGE,
104                 new ActionMessage("message.search.empty"));
105             }
106             else
107             {
108                 //store the search result items
109
ArrayList name_list = new ArrayList();
110                 for (int i = 0; i < num_items; i++)
111                 {
112                     HashMap map = new HashMap();
113                     map.put("name", list.get(i));
114                     map.put("submit", "Find");
115                     name_list.add(map);
116                 }
117                 request.setAttribute("users", name_list);
118                 
119                 // add related tasks to the navigation bar
120
WebTalkRelatedTasks menu = new WebTalkRelatedTasks();
121                 menu.addLink(new LinkAttribute("Search restricted access users", "display_restricted_access_user_search"));
122                 menu.addLink(new LinkAttribute("Administer restricted access users", "display_restricted_access_user_management"));
123                 request.setAttribute("menu", menu);
124                 
125                 // forward control to the search result screen
126
return mapping.findForward("restricted_access_user_search_result");
127             }
128         }
129         
130         if (errors.isEmpty() == false)
131         {
132             saveErrors(request, errors);
133         }
134         
135         if (messages.isEmpty() == false)
136         {
137             saveMessages(request, messages);
138         }
139         
140         // add related tasks to the navigation bar
141
WebTalkRelatedTasks menu = new WebTalkRelatedTasks();
142         menu.addLink(new LinkAttribute("Search restricted access users", "display_restricted_access_user_search"));
143         menu.addLink(new LinkAttribute("Administer restricted access users", "display_restricted_access_user_management"));
144         request.setAttribute("menu", menu);
145         
146         return mapping.getInputForward();
147     }
148 }
149
Popular Tags