| 1 5 6 package com.quikj.application.communicator.applications.webtalk.controller; 7 8 import java.sql.Connection ; 9 import java.util.ArrayList ; 10 import java.util.Iterator ; 11 12 import javax.servlet.http.HttpServletRequest ; 13 import javax.servlet.http.HttpServletResponse ; 14 15 import org.apache.struts.action.Action; 16 import org.apache.struts.action.ActionError; 17 import org.apache.struts.action.ActionErrors; 18 import org.apache.struts.action.ActionForm; 19 import org.apache.struts.action.ActionForward; 20 import org.apache.struts.action.ActionMapping; 21 import org.apache.struts.action.DynaActionForm; 22 23 import com.quikj.application.communicator.admin.controller.AdminConfig; 24 import com.quikj.application.communicator.admin.model.AccountElement; 25 import com.quikj.application.communicator.admin.model.AccountsTable; 26 import com.quikj.application.communicator.applications.webtalk.model.FeatureTable; 27 import com.quikj.application.communicator.applications.webtalk.model.FeatureTableElement; 28 import com.quikj.application.communicator.applications.webtalk.model.GroupTable; 29 import com.quikj.application.communicator.applications.webtalk.model.UserTable; 30 import com.quikj.server.framework.AceLogger; 31 32 36 public class DropCustomerAction extends Action 37 { 38 39 40 public DropCustomerAction() 41 { 42 } 43 44 public ActionForward execute(ActionMapping mapping, 45 ActionForm form, 46 HttpServletRequest request, 47 HttpServletResponse response) 48 { 49 ActionErrors errors = new ActionErrors(); 50 51 Connection c = (Connection )request.getSession().getAttribute("connection"); 52 if (c == null) 53 { 54 errors.add(ActionErrors.GLOBAL_ERROR, 55 new ActionError("error.not.logged.in")); 56 saveErrors(request, errors); 57 return mapping.findForward("logon"); 58 } 59 60 AccountElement element = (AccountElement)request.getSession().getAttribute("userInfo"); 61 if (element.isAdminLevel() == false) 62 { 63 errors.add(ActionErrors.GLOBAL_ERROR, 64 new ActionError("error.insufficient.privilege")); 65 saveErrors(request, errors); 66 67 return mapping.findForward("main_menu"); 68 } 69 70 String domain = (String )((DynaActionForm)form).get("domain"); 71 if ((domain == null) || (domain.length() == 0)) 72 { 73 75 errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.sequence")); 76 saveErrors(request, errors); 77 78 return mapping.findForward("display_drop_customer_intro"); 79 } 80 81 String submit = (String )((DynaActionForm)form).get("submit"); 82 83 if (submit.startsWith("Remove") == true) 84 { 85 ArrayList log = new ArrayList (); 87 88 StringBuffer buf = new StringBuffer ("Removing data associated with customer: "); 89 buf.append(domain); 90 buf.append("\n"); 91 log.add(buf.toString()); 92 log.add("\n"); 93 94 request.setAttribute("dropCustomerLog", log); 95 96 98 UserTable users = new UserTable(); 99 users.setConnection(c); 100 101 ArrayList operators = users.findMembersOnlyByGroupDomain(domain); 103 String operators_error = users.getErrorMessage(); 104 105 ArrayList owners = users.findOwnersByGroupDomain(domain); 107 String owners_error = users.getErrorMessage(); 108 109 if ((operators == null) || (owners == null)) 110 { 111 errors.add(ActionErrors.GLOBAL_ERROR, 112 new ActionError("error.customer.delete.finddata")); 113 114 saveErrors(request, errors); 115 116 buf = new StringBuffer ("\n*** ERROR *** Error encountered while attempting to find data related to this customer. Nothing has been deleted. Please check system logs, correct the problem and try using this wizard again later."); 118 buf.append("\n"); 119 log.add(buf.toString()); 120 121 String msg = "DropCustomerAction.execute()/by-" + element.getName() 123 + ": Error finding data in domain " + domain + ": "; 124 125 if (operators == null) 126 { 127 AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG, msg + 128 "operators - " + operators_error); 129 } 130 131 if (owners == null) 132 { 133 AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG, msg + 134 "group owners/features - " + owners_error); 135 } 136 137 return mapping.findForward(submit); 138 } 139 140 141 143 Iterator i = operators.iterator(); 144 while (i.hasNext()) 145 { 146 String name = (String )i.next(); 147 148 if (users.delete(name) == false) 149 { 150 if (users.getErrorMessage() != null) 151 { 152 errors.add(ActionErrors.GLOBAL_ERROR, 153 new ActionError("error.customer.delete.operator", new String (name))); 154 155 buf = new StringBuffer ("\n*** ERROR *** Error encountered while attempting to delete operator '"); 157 buf.append(name); 158 buf.append("'. You'll have to delete it yourself."); 159 buf.append("\n"); 160 log.add(buf.toString()); 161 162 AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG, 164 "DropCustomerAction.execute()/by-" 165 + element.getName() 166 + ": Error deleting webtalk user " 167 + name 168 + ": " 169 + users.getErrorMessage()); 170 } 171 } 172 else 173 { 174 buf = new StringBuffer ("Deleted operator '"); 176 buf.append(name); 177 buf.append("'\n"); 178 log.add(buf.toString()); 179 180 AceLogger.Instance().log(AceLogger.INFORMATIONAL, AceLogger.USER_LOG, 181 "User " + element.getName() + " deleted webtalk user " + name); 182 } 183 } 184 185 187 FeatureTable features = new FeatureTable(); 188 features.setConnection(c); 189 190 i = owners.iterator(); 191 while (i.hasNext()) 192 { 193 String name = (String )i.next(); 194 195 if (features.delete(name) == false) 197 { 198 if (features.getErrorMessage() != null) 199 { 200 errors.add(ActionErrors.GLOBAL_ERROR, 201 new ActionError("error.customer.delete.feature", new String (name))); 202 203 buf = new StringBuffer ("\n*** ERROR *** Error encountered while attempting to delete feature '"); 205 buf.append(name); 206 buf.append("'. You'll have to delete it yourself."); 207 buf.append("\n"); 208 log.add(buf.toString()); 209 210 AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG, 212 "DropCustomerAction.execute()/by-" 213 + element.getName() 214 + ": Error deleting feature " 215 + name 216 + ": " 217 + features.getErrorMessage()); 218 } 219 } 220 else 221 { 222 if (FeatureManagementAction.notifyAppServer(request, name, "deactivate", errors, "Delete/by-" + element.getName()) == true) 224 { 225 buf = new StringBuffer ("Deactivated feature '"); 227 buf.append(name); 228 buf.append("'\n"); 229 log.add(buf.toString()); 230 } 231 232 buf = new StringBuffer ("Deleted feature '"); 234 buf.append(name); 235 buf.append("'\n"); 236 log.add(buf.toString()); 237 238 AceLogger.Instance().log(AceLogger.INFORMATIONAL, AceLogger.USER_LOG, 239 "User " + element.getName() + " deleted feature " + name); 240 } 241 242 if (users.delete(name) == false) 244 { 245 if (users.getErrorMessage() != null) 246 { 247 errors.add(ActionErrors.GLOBAL_ERROR, 248 new ActionError("error.customer.delete.owner", new String (name))); 249 250 buf = new StringBuffer ("\n*** ERROR *** Error encountered while attempting to delete group owner '"); 252 buf.append(name); 253 buf.append("', groups owned by this user and canned messages specific to those groups. You'll have to delete this group owner yourself."); 254 buf.append("\n"); 255 log.add(buf.toString()); 256 257 AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG, 259 "DropCustomerAction.execute()/by-" 260 + element.getName() 261 + ": Error deleting webtalk user " 262 + name 263 + ", groups owned by this user and canned messages specific to those groups: " 264 + users.getErrorMessage()); 265 } 266 } 267 else 268 { 269 buf = new StringBuffer ("Deleted group owner '"); 271 buf.append(name); 272 buf.append("', groups owned by this user and canned messages specific to those groups\n"); 273 log.add(buf.toString()); 274 275 AceLogger.Instance().log(AceLogger.INFORMATIONAL, AceLogger.USER_LOG, 276 "User " + element.getName() + " deleted webtalk user " + name + ", groups owned by this user and canned messages specific to those groups"); 277 } 278 } 279 280 281 ArrayList stray_users = users.list(domain); 283 284 if (stray_users == null) 285 { 286 errors.add(ActionErrors.GLOBAL_ERROR, 287 new ActionError("error.customer.delete.strayusers")); 288 289 buf = new StringBuffer ("\n*** ERROR *** Error encountered while attempting to find stray users related to this customer. Search remaining Ace Operator users, and delete any that were associated with this customer."); 291 buf.append("\n"); 292 log.add(buf.toString()); 293 294 AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG, 295 "DropCustomerAction.execute()/by-" + element.getName() 296 + ": Error finding data in domain " + domain + ": " 297 + "stray users - " + users.getErrorMessage()); 298 } 299 else 300 { 301 303 i = stray_users.iterator(); 304 while (i.hasNext()) 305 { 306 String name = (String )i.next(); 307 308 if (users.delete(name) == false) 309 { 310 if (users.getErrorMessage() != null) 311 { 312 errors.add(ActionErrors.GLOBAL_ERROR, 313 new ActionError("error.customer.delete.strayuser", new String (name))); 314 315 buf = new StringBuffer ("\n*** ERROR *** Error encountered while attempting to delete stray user '"); 317 buf.append(name); 318 buf.append("', any groups owned by this user and canned messages specific to those groups. You'll have to delete this user yourself."); 319 buf.append("\n"); 320 log.add(buf.toString()); 321 322 AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG, 324 "DropCustomerAction.execute()/by-" 325 + element.getName() 326 + ": Error deleting webtalk user " 327 + name 328 + ", any groups owned by this user and canned messages specific to those groups: " 329 + users.getErrorMessage()); 330 } 331 } 332 else 333 { 334 buf = new StringBuffer ("Deleted stray user '"); 336 buf.append(name); 337 buf.append("', any groups owned by this user and canned messages specific to those groups\n"); 338 log.add(buf.toString()); 339 340 AceLogger.Instance().log(AceLogger.INFORMATIONAL, AceLogger.USER_LOG, 341 "User " + element.getName() + " deleted webtalk user " + name + ", any groups owned by this user and canned messages specific to those groups"); 342 } 343 } 344 } 345 346 347 GroupTable groups = new GroupTable(); 349 groups.setConnection(c); 350 351 ArrayList stray_groups = groups.list(domain); 352 353 if (stray_groups == null) 354 { 355 errors.add(ActionErrors.GLOBAL_ERROR, 356 new ActionError("error.customer.delete.straygroups")); 357 358 buf = new StringBuffer ("\n*** ERROR *** Error encountered while attempting to find stray groups related to this customer. List remaining Ace Operator groups, and delete any that were associated with this customer."); 360 buf.append("\n"); 361 log.add(buf.toString()); 362 363 AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG, 364 "DropCustomerAction.execute()/by-" + element.getName() 365 + ": Error finding data in domain " + domain + ": " 366 + "stray groups - " + groups.getErrorMessage()); 367 } 368 else 369 { 370 372 i = stray_groups.iterator(); 373 while (i.hasNext()) 374 { 375 String name = (String )i.next(); 376 377 if (groups.delete(name) == false) 378 { 379 if (groups.getErrorMessage() != null) 380 { 381 errors.add(ActionErrors.GLOBAL_ERROR, 382 new ActionError("error.customer.delete.straygroup", new String (name))); 383 384 buf = new StringBuffer ("\n*** ERROR *** Error encountered while attempting to delete stray group '"); 386 buf.append(name); 387 buf.append("' and canned messages specific to this group. You'll have to delete this group yourself."); 388 buf.append("\n"); 389 log.add(buf.toString()); 390 391 AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG, 393 "DropCustomerAction.execute()/by-" 394 + element.getName() 395 + ": Error deleting stray group " 396 + name 397 + " and canned messages specific to this group: " 398 + groups.getErrorMessage()); 399 } 400 } 401 else 402 { 403 buf = new StringBuffer ("Deleted stray group '"); 405 buf.append(name); 406 buf.append("' and canned messages specific to this group\n"); 407 log.add(buf.toString()); 408 409 AceLogger.Instance().log(AceLogger.INFORMATIONAL, AceLogger.USER_LOG, 410 "User " + element.getName() + " deleted stray group " + name + " and canned messages specific to this group"); 411 } 412 } 413 } 414 415 ArrayList stray_features = features.list(domain); 417 418 if (stray_features == null) 419 { 420 errors.add(ActionErrors.GLOBAL_ERROR, 421 new ActionError("error.customer.delete.strayfeatures")); 422 423 buf = new StringBuffer ("\n*** ERROR *** Error encountered while attempting to find stray features related to this customer. List remaining Ace Operator features, and delete any that were associated with this customer."); 425 buf.append("\n"); 426 log.add(buf.toString()); 427 428 AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG, 429 "DropCustomerAction.execute()/by-" + element.getName() 430 + ": Error finding data in domain " + domain + ": " 431 + "stray features - " + features.getErrorMessage()); 432 } 433 else 434 { 435 437 i = stray_features.iterator(); 438 while (i.hasNext()) 439 { 440 String name = ((FeatureTableElement)i.next()).getName(); 441 442 if (features.delete(name) == false) 443 { 444 if (features.getErrorMessage() != null) 445 { 446 errors.add(ActionErrors.GLOBAL_ERROR, 447 new ActionError("error.customer.delete.strayfeature", new String (name))); 448 449 buf = new StringBuffer ("\n*** ERROR *** Error encountered while attempting to delete stray feature '"); 451 buf.append(name); 452 buf.append("'. You'll have to delete this feature yourself."); 453 buf.append("\n"); 454 log.add(buf.toString()); 455 456 AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG, 458 "DropCustomerAction.execute()/by-" 459 + element.getName() 460 + ": Error deleting stray feature " 461 + name 462 + ": " 463 + features.getErrorMessage()); 464 } 465 } 466 else 467 { 468 if (FeatureManagementAction.notifyAppServer(request, name, "deactivate", errors, "Delete/by-" + element.getName()) == true) 470 { 471 buf = new StringBuffer ("Deactivated stray feature '"); 473 buf.append(name); 474 buf.append("'\n"); 475 log.add(buf.toString()); 476 } 477 478 buf = new StringBuffer ("Deleted stray feature '"); 480 buf.append(name); 481 buf.append("'\n"); 482 log.add(buf.toString()); 483 484 AceLogger.Instance().log(AceLogger.INFORMATIONAL, AceLogger.USER_LOG, 485 "User " + element.getName() + " deleted stray feature " + name); 486 } 487 } 488 } 489 490 AccountsTable accounts = new AccountsTable(AdminConfig.getInstance().getDBParams().getAdminDb()); 492 accounts.setConnection(c); 493 494 ArrayList system_accounts = accounts.list(domain); 495 496 if (system_accounts == null) 497 { 498 errors.add(ActionErrors.GLOBAL_ERROR, 499 new ActionError("error.customer.delete.accounts")); 500 501 buf = new StringBuffer ("\n*** ERROR *** Error encountered while attempting to find system user accounts related to this customer. Could not delete system user accounts that were associated with this customer, if there were any."); 503 buf.append("\n"); 504 log.add(buf.toString()); 505 506 AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG, 507 "DropCustomerAction.execute()/by-" + element.getName() 508 + ": Error finding data in domain " + domain + ": " 509 + "system user accounts - " + accounts.getErrorMessage()); 510 } 511 else 512 { 513 515 i = system_accounts.iterator(); 516 while (i.hasNext()) 517 { 518 String name = (String )i.next(); 519 520 if (accounts.delete(name) == false) 521 { 522 if (accounts.getErrorMessage() != null) 523 { 524 errors.add(ActionErrors.GLOBAL_ERROR, 525 new ActionError("error.customer.delete.account", new String (name))); 526 527 buf = new StringBuffer ("\n*** ERROR *** Error encountered while attempting to delete system user account '"); 529 buf.append(name); 530 buf.append("'. You'll have to delete this user account yourself."); 531 buf.append("\n"); 532 log.add(buf.toString()); 533 534 AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG, 536 "DropCustomerAction.execute()/by-" 537 + element.getName() 538 + ": Error deleting system user account " 539 + name 540 + " : " 541 + accounts.getErrorMessage()); 542 } 543 } 544 else 545 { 546 buf = new StringBuffer ("Deleted system user account '"); 548 buf.append(name); 549 buf.append("'\n"); 550 log.add(buf.toString()); 551 552 AceLogger.Instance().log(AceLogger.INFORMATIONAL, AceLogger.USER_LOG, 553 "User " + element.getName() + " deleted customer system user account " + name); 554 } 555 } 556 } 557 558 560 } 561 562 if (errors.isEmpty() == false) 563 { 564 saveErrors(request, errors); 565 } 566 567 return mapping.findForward(submit); 568 } 569 570 571 } 572 573 | Popular Tags |