1 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 17 21 public class GroupManagementAction extends Action 22 { 23 24 25 public GroupManagementAction() 26 { 27 } 28 29 public ActionForward execute(ActionMapping mapping, 30 ActionForm form, 31 HttpServletRequest request, 32 HttpServletResponse response) 33 { 34 GroupManagementForm gform = (GroupManagementForm)form; 35 36 ActionErrors errors = new ActionErrors(); 37 38 Connection c = (Connection)request.getSession().getAttribute("connection"); 39 if (c == null) 40 { 41 errors.add(ActionErrors.GLOBAL_ERROR, 42 new ActionError("error.not.logged.in")); 43 saveErrors(request, errors); 44 return mapping.findForward("logon"); 45 } 46 47 AccountElement element = (AccountElement)request.getSession().getAttribute("userInfo"); 48 if (element.isAdminLevel() == false) 49 { 50 errors.add(ActionErrors.GLOBAL_ERROR, 51 new ActionError("error.insufficient.privilege")); 52 saveErrors(request, errors); 53 54 return mapping.findForward("main_menu"); 55 } 56 57 if (gform.getSubmit().equals("Find") == true) 58 { 59 GroupTable groups = new GroupTable(); 60 groups.setConnection(c); 61 62 GroupElement e = groups.query(gform.getName()); 63 64 if (e == null) 65 { 66 errors.add(ActionErrors.GLOBAL_ERROR, 67 new ActionError("error.group.not.exist")); 68 69 if (groups.getErrorMessage() != null) 70 { 71 AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG, 72 "GroupManagementAction.execute()/Find/by-" 73 + element.getName() 74 + ": " 75 + groups.getErrorMessage()); 76 } 77 } 78 else 79 { 80 gform.setDomain(e.getDomain()); 81 82 switch(e.getMemberBusyNotificationControl()) 83 { 84 case GroupElement.NOTIFY_NONE: 85 { 86 gform.setMemberCallCountNotifyMembers(false); 87 gform.setMemberCallCountNotifyOwner(false); 88 } 89 break; 90 case GroupElement.NOTIFY_OWNER: 91 { 92 gform.setMemberCallCountNotifyMembers(false); 93 gform.setMemberCallCountNotifyOwner(true); 94 } 95 break; 96 case GroupElement.NOTIFY_MEMBERS: 97 { 98 gform.setMemberCallCountNotifyMembers(true); 99 gform.setMemberCallCountNotifyOwner(false); 100 } 101 break; 102 case GroupElement.NOTIFY_ALL: 103 { 104 gform.setMemberCallCountNotifyMembers(true); 105 gform.setMemberCallCountNotifyOwner(true); 106 } 107 break; 108 default: 109 errors.add(ActionErrors.GLOBAL_ERROR, 110 new ActionError("error.db.failure")); 111 112 AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG, 113 "GroupManagementAction.execute()/Find/by-" 114 + element.getName() 115 + ": " 116 + "Invalid DB value for MemberBusyNotificationControl : " 117 + e.getMemberBusyNotificationControl() 118 + ", group = " + e.getName()); 119 120 break; 121 } 122 123 switch(e.getMemberLoginNotificationControl()) 124 { 125 case GroupElement.NOTIFY_NONE: 126 { 127 gform.setMemberLoginNotifyMembers(false); 128 gform.setMemberLoginNotifyOwner(false); 129 } 130 break; 131 case GroupElement.NOTIFY_OWNER: 132 { 133 gform.setMemberLoginNotifyMembers(false); 134 gform.setMemberLoginNotifyOwner(true); 135 } 136 break; 137 case GroupElement.NOTIFY_MEMBERS: 138 { 139 gform.setMemberLoginNotifyMembers(true); 140 gform.setMemberLoginNotifyOwner(false); 141 } 142 break; 143 case GroupElement.NOTIFY_ALL: 144 { 145 gform.setMemberLoginNotifyMembers(true); 146 gform.setMemberLoginNotifyOwner(true); 147 } 148 break; 149 default: 150 errors.add(ActionErrors.GLOBAL_ERROR, 151 new ActionError("error.db.failure")); 152 153 AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG, 154 "GroupManagementAction.execute()/Find/by-" 155 + element.getName() 156 + ": " 157 + "Invalid DB value for MemberLoginNotificationControl : " 158 + e.getMemberLoginNotificationControl() 159 + ", group = " + e.getName()); 160 161 break; 162 } 163 164 switch(e.getOwnerBusyNotificationControl()) 165 { 166 case GroupElement.NOTIFY_NONE: 167 { 168 gform.setOwnerCallCountNotifyMembers(false); 169 } 170 break; 171 case GroupElement.NOTIFY_MEMBERS: 172 { 173 gform.setOwnerCallCountNotifyMembers(true); 174 } 175 break; 176 case GroupElement.NOTIFY_ALL: 177 { 178 gform.setOwnerCallCountNotifyMembers(true); 179 } 180 break; 181 default: 182 errors.add(ActionErrors.GLOBAL_ERROR, 183 new ActionError("error.db.failure")); 184 185 AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG, 186 "GroupManagementAction.execute()/Find/by-" 187 + element.getName() 188 + ": " 189 + "Invalid DB value for OwnerBusyNotificationControl : " 190 + e.getOwnerBusyNotificationControl() 191 + ", group = " + e.getName()); 192 193 break; 194 } 195 196 switch(e.getOwnerLoginNotificationControl()) 197 { 198 case GroupElement.NOTIFY_NONE: 199 { 200 gform.setOwnerLoginNotifyMembers(false); 201 } 202 break; 203 case GroupElement.NOTIFY_MEMBERS: 204 { 205 gform.setOwnerLoginNotifyMembers(true); 206 } 207 break; 208 case GroupElement.NOTIFY_ALL: 209 { 210 gform.setOwnerLoginNotifyMembers(true); 211 } 212 break; 213 default: 214 errors.add(ActionErrors.GLOBAL_ERROR, 215 new ActionError("error.db.failure")); 216 217 AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG, 218 "GroupManagementAction.execute()/Find/by-" 219 + element.getName() 220 + ": " 221 + "Invalid DB value for OwnerLoginNotificationControl() : " 222 + e.getOwnerLoginNotificationControl() 223 + ", group = " + e.getName()); 224 225 break; 226 } 227 } 228 } 229 else if (gform.getSubmit().equals("Modify") == true) 230 { 231 GroupTable groups = new GroupTable(); 232 groups.setConnection(c); 233 234 GroupElement e = new GroupElement(); 235 236 setNotificationControls(gform, e); 237 e.setName(gform.getName()); 238 e.setDomain(gform.getDomain()); 239 240 boolean status_ok = groups.modify(e); 241 242 if (status_ok == false) 243 { 244 errors.add(ActionErrors.GLOBAL_ERROR, 245 new ActionError("error.group.not.exist")); 246 247 AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG, 248 "GroupManagementAction.execute()/Modify/by-" 249 + element.getName() 250 + ": " 251 + groups.getErrorMessage()); 252 } 253 else 254 { 255 AceLogger.Instance().log(AceLogger.INFORMATIONAL, AceLogger.USER_LOG, 256 "User " + element.getName() + " modified data for group " + 257 gform.getName()); 258 259 ActionMessages messages = new ActionMessages(); 261 messages.add(ActionMessages.GLOBAL_MESSAGE, 262 new ActionMessage("message.group.modified")); 263 saveMessages(request, messages); 264 265 return mapping.findForward("webtalk_main_menu"); 266 } 267 } 268 else if (gform.getSubmit().equals("Create") == true) 269 { 270 GroupTable groups = new GroupTable(); 271 groups.setConnection(c); 272 273 GroupElement e = new GroupElement(); 274 275 setNotificationControls(gform, e); 276 e.setName(gform.getName()); 277 e.setDomain(gform.getDomain()); 278 279 boolean status_ok = groups.create(e); 280 281 if (status_ok == false) 282 { 283 errors.add(ActionErrors.GLOBAL_ERROR, 284 new ActionError("error.group.create.failure")); 285 286 AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG, 287 "GroupManagementAction.execute()/Create/by-" 288 + element.getName() 289 + ": " 290 + groups.getErrorMessage()); 291 } 292 else 293 { 294 AceLogger.Instance().log(AceLogger.INFORMATIONAL, AceLogger.USER_LOG, 295 "User " + element.getName() + " created new group " + 296 gform.getName()); 297 298 ActionMessages messages = new ActionMessages(); 300 messages.add(ActionMessages.GLOBAL_MESSAGE, 301 new ActionMessage("message.group.created")); 302 saveMessages(request, messages); 303 304 return mapping.findForward("webtalk_main_menu"); 305 } 306 } 307 else if (gform.getSubmit().equals("Delete") == true) 308 { 309 GroupTable groups = new GroupTable(); 310 groups.setConnection(c); 311 312 boolean status_ok = groups.delete(gform.getName()); 313 314 if (status_ok == false) 315 { 316 if (groups.getErrorMessage() == null) 317 { 318 errors.add(ActionErrors.GLOBAL_ERROR, 319 new ActionError("error.group.not.exist")); 320 } 321 else 322 { 323 errors.add(ActionErrors.GLOBAL_ERROR, 324 new ActionError("error.db.failure")); 325 326 AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG, 327 "GroupManagementAction.execute()/Delete/by-" 328 + element.getName() 329 + ": " 330 + groups.getErrorMessage()); 331 } 332 } 333 else 334 { 335 AceLogger.Instance().log(AceLogger.INFORMATIONAL, AceLogger.USER_LOG, 336 "User " + element.getName() + " deleted group " + 337 gform.getName()); 338 339 ActionMessages messages = new ActionMessages(); 341 messages.add(ActionMessages.GLOBAL_MESSAGE, 342 new ActionMessage("message.group.deleted")); 343 saveMessages(request, messages); 344 345 return mapping.findForward("webtalk_main_menu"); 346 } 347 } 348 349 if (errors.isEmpty() == false) 350 { 351 saveErrors(request, errors); 352 } 353 354 WebTalkRelatedTasks menu = new WebTalkRelatedTasks(); 356 menu.addLink(new LinkAttribute("List all groups", "list_groups")); 357 menu.addLink(new LinkAttribute("Search users", "display_user_search")); 358 menu.addLink(new LinkAttribute("Administer users", "display_user_management")); 359 request.setAttribute("menu", menu); 360 361 return mapping.getInputForward(); 362 } 363 364 private void setNotificationControls(GroupManagementForm gform, GroupElement e) 365 { 366 if (gform.isMemberCallCountNotifyMembers() == true) 368 { 369 if (gform.isMemberCallCountNotifyOwner() == true) 370 { 371 e.setMemberBusyNotificationControl(GroupElement.NOTIFY_ALL); 372 } 373 else 374 { 375 e.setMemberBusyNotificationControl(GroupElement.NOTIFY_MEMBERS); 376 } 377 } 378 else 379 { 380 if (gform.isMemberCallCountNotifyOwner() == true) 381 { 382 e.setMemberBusyNotificationControl(GroupElement.NOTIFY_OWNER); 383 } 384 else 385 { 386 e.setMemberBusyNotificationControl(GroupElement.NOTIFY_NONE); 387 } 388 } 389 390 if (gform.isMemberLoginNotifyMembers() == true) 392 { 393 if (gform.isMemberLoginNotifyOwner() == true) 394 { 395 e.setMemberLoginNotificationControl(GroupElement.NOTIFY_ALL); 396 } 397 else 398 { 399 e.setMemberLoginNotificationControl(GroupElement.NOTIFY_MEMBERS); 400 } 401 } 402 else 403 { 404 if (gform.isMemberLoginNotifyOwner() == true) 405 { 406 e.setMemberLoginNotificationControl(GroupElement.NOTIFY_OWNER); 407 } 408 else 409 { 410 e.setMemberLoginNotificationControl(GroupElement.NOTIFY_NONE); 411 } 412 } 413 414 if (gform.isOwnerCallCountNotifyMembers() == true) 416 { 417 e.setOwnerBusyNotificationControl(GroupElement.NOTIFY_MEMBERS); 418 } 419 else 420 { 421 e.setOwnerBusyNotificationControl(GroupElement.NOTIFY_NONE); 422 } 423 424 if (gform.isOwnerLoginNotifyMembers() == true) 426 { 427 e.setOwnerLoginNotificationControl(GroupElement.NOTIFY_MEMBERS); 428 } 429 else 430 { 431 e.setOwnerLoginNotificationControl(GroupElement.NOTIFY_NONE); 432 } 433 434 } 435 } 436 | Popular Tags |