KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > quikj > application > communicator > admin > controller > LogDeleteAction


1 /*
2  * LogDeleteAction.java
3  *
4  * Created on June 4, 2003, 2:49 PM
5  */

6
7 package com.quikj.application.communicator.admin.controller;
8
9 /**
10  *
11  * @author bhm
12  */

13
14
15 import javax.servlet.http.*;
16 import org.apache.struts.action.*;
17 import java.sql.*;
18 import com.quikj.application.communicator.admin.model.*;
19 import com.quikj.server.framework.AceLogger;
20
21
22 public class LogDeleteAction extends Action
23 {
24     
25     /** Creates a new instance of LogDeleteAction */
26     public LogDeleteAction()
27     {
28     }
29     
30     public ActionForward execute(ActionMapping mapping,
31     ActionForm form,
32     HttpServletRequest request,
33     HttpServletResponse response)
34     {
35         LogDeleteForm lform = (LogDeleteForm)form;
36         
37         ActionErrors errors = new ActionErrors();
38         ActionMessages messages = new ActionMessages();
39         
40         Connection c = (Connection)request.getSession().getAttribute("connection");
41         if (c == null)
42         {
43             errors.add(ActionErrors.GLOBAL_ERROR,
44             new ActionError("error.not.logged.in"));
45             saveErrors(request, errors);
46             return mapping.findForward("logon");
47         }
48         
49         AccountElement element = (AccountElement)request.getSession().getAttribute("userInfo");
50         if (element.isAdminLevel() == false)
51         {
52             errors.add(ActionErrors.GLOBAL_ERROR,
53             new ActionError("error.insufficient.privilege"));
54             saveErrors(request, errors);
55             
56             return mapping.findForward("main_menu");
57         }
58         
59         // Create the logs table :
60
LogsTable log_tbl = new LogsTable(AdminConfig.getInstance().getDBParams().getAdminDb());
61         log_tbl.setConnection(c);
62         
63         int count = log_tbl.delete(new Timestamp(lform.getPriorToDate().getTime()));
64
65         if (count == 0)
66         {
67             if (log_tbl.getErrorMessage() != null)
68             {
69                 errors.add(ActionErrors.GLOBAL_ERROR,
70                 new ActionError("error.db.failure"));
71                 
72                 AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG,
73                 "LogDeleteAction.execute()/Delete/by-"
74                 + element.getName()
75                 + ": "
76                 + log_tbl.getErrorMessage());
77                 
78                 saveErrors(request, errors);
79                 // Forward control back to the main menu :
80
return mapping.findForward("main_menu");
81             } // error case
82
} // count = 0
83

84         // Tell the user the number of logs which were deleted :
85
messages.add(ActionMessages.GLOBAL_MESSAGE,
86         new ActionMessage("message.logs.deleted", new Integer JavaDoc(count)));
87         saveMessages(request, messages);
88         
89         // forward control to the main menu :
90
return mapping.findForward("main_menu");
91         
92     } // execute
93

94 } // LogDeleteAction
95
Popular Tags