1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.calendar.service;
35
36 import fr.paris.lutece.plugins.calendar.business.CalendarHome;
37 import fr.paris.lutece.plugins.calendar.business.OccurrenceEvent;
38 import fr.paris.lutece.plugins.calendar.business.SimpleEvent;
39 import fr.paris.lutece.plugins.calendar.service.cache.EventListCacheService;
40 import fr.paris.lutece.plugins.calendar.web.CalendarView;
41 import fr.paris.lutece.plugins.calendar.web.Constants;
42 import fr.paris.lutece.plugins.calendar.web.EventList;
43 import fr.paris.lutece.portal.service.cache.ICacheKeyService;
44 import fr.paris.lutece.portal.service.plugin.Plugin;
45 import fr.paris.lutece.portal.service.plugin.PluginService;
46 import fr.paris.lutece.portal.service.security.LuteceUser;
47 import fr.paris.lutece.portal.service.util.AppLogService;
48 import fr.paris.lutece.portal.service.util.AppPropertiesService;
49 import fr.paris.lutece.portal.web.PortalJspBean;
50
51 import java.util.HashMap;
52 import java.util.List;
53 import java.util.Map;
54
55 import org.apache.commons.lang.StringUtils;
56
57
58
59
60
61 public class EventListService
62 {
63
64 private static final String KEY_CALENDAR = "calendar";
65
66
67 private ICacheKeyService _cksEventList;
68 private EventListCacheService _cacheEventList = EventListCacheService.getInstance( );
69 private CalendarService _calendarService;
70
71
72
73
74 public EventListService( )
75 {
76 init( );
77 }
78
79
80
81
82 private void init( )
83 {
84 _cacheEventList.initCache( );
85 }
86
87
88
89
90
91
92 public EventList newEventList( int nViewType )
93 {
94 EventList eventlist = null;
95 String strEventListKeyName = StringUtils.EMPTY;
96
97 switch ( nViewType )
98 {
99 case CalendarView.TYPE_DAY:
100 strEventListKeyName = AppPropertiesService.getProperty( Constants.PROPERTY_EVENTLIST_VIEW_DAY );
101
102 break;
103
104 case CalendarView.TYPE_WEEK:
105 strEventListKeyName = AppPropertiesService.getProperty( Constants.PROPERTY_EVENTLIST_VIEW_WEEK );
106
107 break;
108
109 case CalendarView.TYPE_MONTH:
110 strEventListKeyName = AppPropertiesService.getProperty( Constants.PROPERTY_EVENTLIST_VIEW_MONTH );
111
112 break;
113
114 default:
115 }
116
117 if ( StringUtils.isNotEmpty( strEventListKeyName ) )
118 {
119 String strClassKey = Constants.PROPERTY_EVENTLIST + strEventListKeyName + Constants.SUFFIX_CLASS;
120 String strClass = AppPropertiesService.getProperty( strClassKey );
121
122 try
123 {
124 eventlist = (EventList) Class.forName( strClass ).newInstance( );
125 }
126 catch ( ClassNotFoundException e )
127 {
128 AppLogService.error( e.getMessage( ), e );
129 }
130 catch ( IllegalAccessException e )
131 {
132 AppLogService.error( e.getMessage( ), e );
133 }
134 catch ( InstantiationException e )
135 {
136 AppLogService.error( e.getMessage( ), e );
137 }
138 }
139
140 return eventlist;
141 }
142
143
144
145
146
147
148
149
150 public List<SimpleEvent> getSimpleEvents( int nAgendaId, int nSortEvents )
151 {
152 String strKey = getKey( nAgendaId );
153 List<SimpleEvent> listEvents = (List<SimpleEvent>) _cacheEventList.getFromCache( strKey );
154 if ( listEvents == null )
155 {
156 Plugin plugin = PluginService.getPlugin( CalendarPlugin.PLUGIN_NAME );
157 listEvents = CalendarHome.findEventsList( nAgendaId, nSortEvents, plugin );
158 _cacheEventList.putInCache( strKey, listEvents );
159 }
160
161 return listEvents;
162 }
163
164
165
166
167
168
169
170
171
172 public List<SimpleEvent> getSimpleEventsByUserLogin( int nAgendaId, LuteceUser user )
173 {
174 String strKey = getKey( nAgendaId, user );
175 List<SimpleEvent> listEvents = (List<SimpleEvent>) _cacheEventList.getFromCache( strKey );
176 if ( listEvents == null )
177 {
178 Plugin plugin = PluginService.getPlugin( CalendarPlugin.PLUGIN_NAME );
179 listEvents = CalendarHome
180 .findEventsListByUserLogin( nAgendaId, Constants.SORT_ASC, plugin, user.getName( ) );
181 _cacheEventList.putInCache( strKey, listEvents );
182 }
183
184 return listEvents;
185 }
186
187
188
189
190
191
192
193
194
195
196 public List<OccurrenceEvent> getOccurrenceEvents( int nAgendaId, int nEventId, int nIsAscSort, Plugin plugin )
197 {
198 return CalendarHome.findOccurrencesList( nAgendaId, nEventId, nIsAscSort, plugin );
199 }
200
201
202
203
204
205
206
207 public SimpleEvent getEvent( int nEventId, Plugin plugin )
208 {
209 return CalendarHome.findEvent( nEventId, plugin );
210 }
211
212
213
214
215
216
217
218 public int getRepititionDays( int nEventId, Plugin plugin )
219 {
220 return CalendarHome.getRepetitionDays( nEventId, plugin );
221 }
222
223
224
225
226
227
228
229 public void doAddEvent( SimpleEvent event, LuteceUser user, Plugin plugin )
230 {
231 String strUserLogin = ( user == null ) ? StringUtils.EMPTY : user.getName( );
232 CalendarHome.createEvent( event, plugin, strUserLogin );
233
234
235 _cacheEventList.removeCache( getKey( event.getIdCalendar( ) ) );
236 if ( user != null )
237 {
238 _cacheEventList.removeCache( getKey( event.getIdCalendar( ), user ) );
239 }
240 _calendarService.removeCache( event.getIdCalendar( ) );
241 }
242
243
244
245
246
247
248 public void doModifyOccurrenceEvent( OccurrenceEvent occurrenceEvent, Plugin plugin )
249 {
250 CalendarHome.updateOccurrence( occurrenceEvent, plugin );
251
252
253 _calendarService.removeCache( occurrenceEvent.getIdCalendar( ) );
254 }
255
256
257
258
259
260
261
262
263
264 public void doModifySimpleEvent( SimpleEvent event, boolean bPeriociteModify, LuteceUser user, Plugin plugin )
265 {
266 CalendarHome.updateEvent( event, bPeriociteModify, plugin );
267
268
269 _cacheEventList.removeCache( getKey( event.getIdCalendar( ) ) );
270 if ( user != null )
271 {
272 _cacheEventList.removeCache( getKey( event.getIdCalendar( ), user ) );
273 }
274 _calendarService.removeCache( event.getIdCalendar( ) );
275 }
276
277
278
279
280
281
282
283
284 public void doRemoveEvent( int nAgendaId, int nEventId, LuteceUser user, Plugin plugin )
285 {
286 CalendarHome.removeEvent( nAgendaId, nEventId, plugin );
287
288 _cacheEventList.removeCache( getKey( nAgendaId ) );
289 if ( user != null )
290 {
291 _cacheEventList.removeCache( getKey( nAgendaId, user ) );
292 }
293 }
294
295
296
297
298
299
300
301 public void setEventListCacheKeyService( ICacheKeyService cacheKeyService )
302 {
303 _cksEventList = cacheKeyService;
304 }
305
306
307
308
309
310 public void setCalendarService( CalendarService calendarService )
311 {
312 _calendarService = calendarService;
313 }
314
315
316
317
318
319
320
321
322 private String getKey( int nAgendaId )
323 {
324 Map<String, String> mapParams = new HashMap<String, String>( );
325 mapParams.put( KEY_CALENDAR, Integer.toString( nAgendaId ) );
326
327 return _cksEventList.getKey( mapParams, PortalJspBean.MODE_HTML, null );
328 }
329
330
331
332
333
334
335
336 private String getKey( int nAgendaId, LuteceUser user )
337 {
338 Map<String, String> mapParams = new HashMap<String, String>( );
339 mapParams.put( KEY_CALENDAR, Integer.toString( nAgendaId ) );
340
341 return _cksEventList.getKey( mapParams, PortalJspBean.MODE_HTML, user );
342 }
343 }