1 5 6 package com.quikj.application.communicator.applications.webtalk.controller; 7 8 import javax.servlet.http.*; 9 import org.apache.struts.action.*; 10 import org.apache.struts.util.*; 11 import java.sql.*; 12 import java.util.*; 13 import java.io.UnsupportedEncodingException ; 14 import java.net.*; 15 16 import com.quikj.application.communicator.admin.model.*; 17 import com.quikj.application.communicator.admin.controller.*; 18 import com.quikj.application.communicator.applications.webtalk.model.*; 19 import com.quikj.server.framework.AceLogger; 20 21 25 public class UserSearchAction extends Action 26 { 27 28 29 public UserSearchAction() 30 { 31 } 32 33 public ActionForward execute(ActionMapping mapping, 34 ActionForm form, 35 HttpServletRequest request, 36 HttpServletResponse response) throws UnsupportedEncodingException 37 { 38 UserSearchForm uform = (UserSearchForm)form; 39 40 ActionErrors errors = new ActionErrors(); 41 ActionMessages messages = new ActionMessages(); 42 43 Connection c = (Connection)request.getSession().getAttribute("connection"); 44 if (c == null) 45 { 46 errors.add(ActionErrors.GLOBAL_ERROR, 47 new ActionError("error.not.logged.in")); 48 saveErrors(request, errors); 49 return mapping.findForward("logon"); 50 } 51 52 AccountElement element = (AccountElement)request.getSession().getAttribute("userInfo"); 53 if (element.isAdminLevel() == false) 54 { 55 errors.add(ActionErrors.GLOBAL_ERROR, 56 new ActionError("error.insufficient.privilege")); 57 saveErrors(request, errors); 58 59 return mapping.findForward("main_menu"); 60 } 61 62 GroupTable groups = new GroupTable(); 63 groups.setConnection(c); 64 ArrayList group_list = groups.list(); 65 if (group_list != null) 66 { 67 ArrayList list = new ArrayList(); 68 Iterator iter = group_list.iterator(); 69 70 while (iter.hasNext() == true) 71 { 72 String group = (String )iter.next(); 73 list.add(new LabelValueBean(group, URLEncoder.encode(group, "UTF-8"))); 74 } 75 76 uform.setUserGroups(list); 77 } 78 79 UserTable user_tbl = new UserTable(); 80 user_tbl.setConnection(c); 81 82 UserElement e = new UserElement(); 83 e.setAdditionalInfo(uform.getAdditionalInfo()); 84 e.setAddress(uform.getAddress()); 85 e.setFullName(uform.getFullName()); 86 e.setUnavailXferTo(uform.getUnavailXferTo()); 87 e.setGatekeeper(uform.getGatekeeper()); 88 89 String name = uform.getName(); 90 if ((name == null) || (name.length() == 0)) 91 { 92 e.setName("%"); 93 } 94 else 95 { 96 e.setName(name); 97 } 98 99 Object [] ogroups = uform.getOwnsGroups(); 100 if (ogroups != null) 101 { 102 for (int i = 0; i < ogroups.length; i++) 103 { 104 if (ogroups[i] != null) 105 { 106 e.addOwnsGroup(URLDecoder.decode((String )ogroups[i], "UTF-8")); 107 } 108 } 109 } 110 111 ogroups = uform.getBelongsToGroups(); 112 if (ogroups != null) 113 { 114 for (int i = 0; i < ogroups.length; i++) 115 { 116 if (ogroups[i] != null) 117 { 118 e.addBelongsToGroup(URLDecoder.decode((String )ogroups[i], "UTF-8")); 119 } 120 } 121 } 122 123 ArrayList list = user_tbl.search(e); 124 125 if (list == null) 126 { 127 errors.add(ActionErrors.GLOBAL_ERROR, 128 new ActionError("error.db.failure")); 129 130 AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG, 131 "UserSearchAction.execute()/Search/by-" 132 + element.getName() 133 + ": " 134 + user_tbl.getErrorMessage()); 135 } 136 else 137 { 138 int num_items = list.size(); 139 140 if (num_items == 0) 141 { 142 messages.add(ActionMessages.GLOBAL_MESSAGE, 143 new ActionMessage("message.user.search.empty")); 144 } 145 else 146 { 147 ArrayList name_list = new ArrayList(); 149 for (int i = 0; i < num_items; i++) 150 { 151 HashMap map = new HashMap(); 152 map.put("name", list.get(i)); 153 map.put("submit", "Find"); 154 name_list.add(map); 155 } 156 request.setAttribute("users", name_list); 157 158 WebTalkRelatedTasks menu = new WebTalkRelatedTasks(); 160 menu.addLink(new LinkAttribute("Search users", "display_user_search")); 161 menu.addLink(new LinkAttribute("Administer users", "display_user_management")); 162 menu.addLink(new LinkAttribute("List all groups", "list_groups")); 163 menu.addLink(new LinkAttribute("Administer groups", "display_group_management")); 164 request.setAttribute("menu", menu); 165 166 return mapping.findForward("user_search_result"); 168 } 169 } 170 171 if (errors.isEmpty() == false) 172 { 173 saveErrors(request, errors); 174 } 175 176 if (messages.isEmpty() == false) 177 { 178 saveMessages(request, messages); 179 } 180 181 WebTalkRelatedTasks menu = new WebTalkRelatedTasks(); 183 menu.addLink(new LinkAttribute("Search users", "display_user_search")); 184 menu.addLink(new LinkAttribute("Administer users", "display_user_management")); 185 menu.addLink(new LinkAttribute("List all groups", "list_groups")); 186 menu.addLink(new LinkAttribute("Administer groups", "display_group_management")); 187 request.setAttribute("menu", menu); 188 189 return mapping.getInputForward(); 190 } 191 } 192 | Popular Tags |