KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jaspersoft > jasperserver > war > action > LogEventAction


1 /*
2  * Copyright (C) 2006 JasperSoft http://www.jaspersoft.com
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed WITHOUT ANY WARRANTY; and without the
10  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
15  * or write to:
16  *
17  * Free Software Foundation, Inc.,
18  * 59 Temple Place - Suite 330,
19  * Boston, MA USA 02111-1307
20  */

21 package com.jaspersoft.jasperserver.war.action;
22
23 import java.util.List JavaDoc;
24
25 import org.springframework.webflow.action.FormAction;
26 import org.springframework.webflow.Event;
27 import org.springframework.webflow.RequestContext;
28 import com.jaspersoft.jasperserver.api.metadata.common.service.RepositoryService;
29 import com.jaspersoft.jasperserver.api.metadata.view.domain.FilterCriteria;
30 import com.jaspersoft.jasperserver.api.common.domain.LogEvent;
31 import com.jaspersoft.jasperserver.api.engine.common.service.LoggingService;
32
33 public class LogEventAction extends FormAction
34 {
35
36     private LoggingService loggingService;
37     private static final String JavaDoc SHOW_ALL_EVENTS = "showAll";
38     private static final String JavaDoc SHOW_UNREAD_EVENTS = "showUnread";
39     private static final String JavaDoc SHOW_EVENTS = "showEvents";
40
41
42     public LoggingService getLoggingService()
43     {
44         return loggingService;
45     }
46
47     public void setLoggingService(LoggingService loggingService)
48     {
49         this.loggingService = loggingService;
50     }
51
52
53     public Event getEvents(RequestContext context) throws Exception JavaDoc
54     {
55         List JavaDoc events = null;
56
57         String JavaDoc show = (String JavaDoc) context.getFlowScope().get(SHOW_EVENTS);
58         if (SHOW_ALL_EVENTS.equals(show))
59             events = loggingService.getUserEvents(null);
60         else if (SHOW_UNREAD_EVENTS.equals(show))
61             events = loggingService.getUnreadEvents(null);
62         else
63             events = loggingService.getUserEvents(null);
64
65         context.getFlowScope().put("events", events);
66
67         return success();
68     }
69     /**
70      *
71      */

72     public Event changeEventsType(RequestContext context) throws Exception JavaDoc
73     {
74         String JavaDoc show = context.getRequestParameters().get(SHOW_EVENTS);
75         context.getFlowScope().put(SHOW_EVENTS, show);
76         return success();
77     }
78
79
80     private long[] getIds(RequestContext context)
81     {
82         String JavaDoc[] stringIds;
83         long[] ids;
84
85         if (context.getRequestParameters().contains("selectedIds"))
86         {
87             Object JavaDoc parameter = context.getRequestParameters().getMap().get("selectedIds");
88             if (parameter instanceof String JavaDoc)
89                 stringIds = new String JavaDoc[]{(String JavaDoc)parameter};
90             else
91                 stringIds = (String JavaDoc[])parameter;
92
93             ids = new long[stringIds.length];
94             for (int i = 0; i < stringIds.length; i++)
95                 ids[i] = Long.parseLong(stringIds[i]);
96             return ids;
97         }
98         return null;
99     }
100
101     public Event delete(RequestContext context) throws Exception JavaDoc
102     {
103         long[] ids = getIds(context);
104         if (ids != null)
105             loggingService.delete(null, ids);
106         return success();
107     }
108
109     public Event markAsRead(RequestContext context) throws Exception JavaDoc
110     {
111         long[] ids = getIds(context);
112         if (ids != null) {
113             for (int i = 0; i < ids.length; i++) {
114                 LogEvent event = loggingService.getLogEvent(null, ids[i]);
115                 if (event.getState() != LogEvent.STATE_READ) {
116                     event.setState(LogEvent.STATE_READ);
117                     loggingService.update(event);
118                 }
119             }
120         }
121         return success();
122     }
123
124
125     public Event markAsUnread(RequestContext context) throws Exception JavaDoc
126     {
127         long[] ids = getIds(context);
128         if (ids != null) {
129             for (int i = 0; i < ids.length; i++) {
130                 LogEvent event = loggingService.getLogEvent(null, ids[i]);
131                 if (event.getState() != LogEvent.STATE_UNREAD) {
132                     event.setState(LogEvent.STATE_UNREAD);
133                     loggingService.update(event);
134                 }
135             }
136         }
137         return success();
138     }
139
140
141     /**
142      *
143      */

144     public Event setupViewForm(RequestContext context) throws Exception JavaDoc
145     {
146         String JavaDoc id = context.getRequestParameters().get("eventId");
147         try {
148             LogEvent event = loggingService.getLogEvent(null, Long.parseLong(id));
149             if (event.getState() == LogEvent.STATE_UNREAD) {
150                 event.setState(LogEvent.STATE_READ);
151                 loggingService.update(event);
152             }
153             context.getRequestScope().put("event", event);
154             return success();
155         } catch(NumberFormatException JavaDoc e) {
156             return error();
157         }
158     }
159
160 }
161
Popular Tags