KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * DropCustomerAction.java
3  *
4  */

5
6 package com.quikj.application.communicator.applications.webtalk.controller;
7
8 import java.sql.Connection JavaDoc;
9 import java.util.ArrayList JavaDoc;
10 import java.util.Iterator JavaDoc;
11
12 import javax.servlet.http.HttpServletRequest JavaDoc;
13 import javax.servlet.http.HttpServletResponse JavaDoc;
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 /**
33  *
34  * @author bhm
35  */

36 public class DropCustomerAction extends Action
37 {
38     
39     /** Creates a new instance of GroupManagementAction */
40     public DropCustomerAction()
41     {
42     }
43     
44     public ActionForward execute(ActionMapping mapping,
45     ActionForm form,
46     HttpServletRequest JavaDoc request,
47     HttpServletResponse JavaDoc response)
48     {
49         ActionErrors errors = new ActionErrors();
50         
51         Connection JavaDoc c = (Connection JavaDoc)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 JavaDoc domain = (String JavaDoc)((DynaActionForm)form).get("domain");
71         if ((domain == null) || (domain.length() == 0))
72         {
73             // did not get here through normal sequence
74

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 JavaDoc submit = (String JavaDoc)((DynaActionForm)form).get("submit");
82         
83         if (submit.startsWith("Remove") == true)
84         {
85             // create action log
86
ArrayList JavaDoc log = new ArrayList JavaDoc();
87             
88             StringBuffer JavaDoc buf = new StringBuffer JavaDoc("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             // first get most of the data needed, make sure no big DB errors
97

98             UserTable users = new UserTable();
99             users.setConnection(c);
100             
101             // get the list of operators
102
ArrayList JavaDoc operators = users.findMembersOnlyByGroupDomain(domain);
103             String JavaDoc operators_error = users.getErrorMessage();
104             
105             // get the list of group owners/features
106
ArrayList JavaDoc owners = users.findOwnersByGroupDomain(domain);
107             String JavaDoc 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                 // append to wizard action log
117
buf = new StringBuffer JavaDoc("\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                 // log the error(s)
122
String JavaDoc 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             // delete the operators
142

143             Iterator JavaDoc i = operators.iterator();
144             while (i.hasNext())
145             {
146                 String JavaDoc name = (String JavaDoc)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 JavaDoc(name)));
154                         
155                         // append to wizard action log
156
buf = new StringBuffer JavaDoc("\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                         // log the error
163
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                     // append to wizard action log
175
buf = new StringBuffer JavaDoc("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             // delete the features & group owners
186

187             FeatureTable features = new FeatureTable();
188             features.setConnection(c);
189             
190             i = owners.iterator();
191             while (i.hasNext())
192             {
193                 String JavaDoc name = (String JavaDoc)i.next();
194                 
195                 // delete feature if present
196
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 JavaDoc(name)));
202                         
203                         // append to wizard action log
204
buf = new StringBuffer JavaDoc("\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                         // log the error
211
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                     // notify app server via RMI
223
if (FeatureManagementAction.notifyAppServer(request, name, "deactivate", errors, "Delete/by-" + element.getName()) == true)
224                     {
225                         // append to wizard action log
226
buf = new StringBuffer JavaDoc("Deactivated feature '");
227                         buf.append(name);
228                         buf.append("'\n");
229                         log.add(buf.toString());
230                     }
231                     
232                     // append to wizard action log
233
buf = new StringBuffer JavaDoc("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                 // delete group owner
243
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 JavaDoc(name)));
249                         
250                         // append to wizard action log
251
buf = new StringBuffer JavaDoc("\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                         // log the error
258
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                     // append to wizard action log
270
buf = new StringBuffer JavaDoc("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             // get a list of any stray users
282
ArrayList JavaDoc 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                 // append to wizard action log
290
buf = new StringBuffer JavaDoc("\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                 // delete any stray users
302

303                 i = stray_users.iterator();
304                 while (i.hasNext())
305                 {
306                     String JavaDoc name = (String JavaDoc)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 JavaDoc(name)));
314                             
315                             // append to wizard action log
316
buf = new StringBuffer JavaDoc("\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                             // log the error
323
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                         // append to wizard action log
335
buf = new StringBuffer JavaDoc("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             // get a list of any stray groups
348
GroupTable groups = new GroupTable();
349             groups.setConnection(c);
350             
351             ArrayList JavaDoc 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                 // append to wizard action log
359
buf = new StringBuffer JavaDoc("\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                 // delete any stray groups
371

372                 i = stray_groups.iterator();
373                 while (i.hasNext())
374                 {
375                     String JavaDoc name = (String JavaDoc)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 JavaDoc(name)));
383                             
384                             // append to wizard action log
385
buf = new StringBuffer JavaDoc("\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                             // log the error
392
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                         // append to wizard action log
404
buf = new StringBuffer JavaDoc("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             // get a list of any stray features
416
ArrayList JavaDoc 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                 // append to wizard action log
424
buf = new StringBuffer JavaDoc("\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                 // delete and deactivate
436

437                 i = stray_features.iterator();
438                 while (i.hasNext())
439                 {
440                     String JavaDoc 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 JavaDoc(name)));
448                             
449                             // append to wizard action log
450
buf = new StringBuffer JavaDoc("\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                             // log the error
457
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                         // notify app server via RMI
469
if (FeatureManagementAction.notifyAppServer(request, name, "deactivate", errors, "Delete/by-" + element.getName()) == true)
470                         {
471                             // append to wizard action log
472
buf = new StringBuffer JavaDoc("Deactivated stray feature '");
473                             buf.append(name);
474                             buf.append("'\n");
475                             log.add(buf.toString());
476                         }
477                         
478                         // append to wizard action log
479
buf = new StringBuffer JavaDoc("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             // delete any ace user accounts associated with this domain
491
AccountsTable accounts = new AccountsTable(AdminConfig.getInstance().getDBParams().getAdminDb());
492             accounts.setConnection(c);
493             
494             ArrayList JavaDoc 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                 // append to wizard action log
502
buf = new StringBuffer JavaDoc("\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                 // delete any system user accounts for this customer
514

515                 i = system_accounts.iterator();
516                 while (i.hasNext())
517                 {
518                     String JavaDoc name = (String JavaDoc)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 JavaDoc(name)));
526                             
527                             // append to wizard action log
528
buf = new StringBuffer JavaDoc("\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                             // log the error
535
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                         // append to wizard action log
547
buf = new StringBuffer JavaDoc("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             // all done !
559

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