View Javadoc
1   /*
2    * Copyright (c) 2002-2014, Mairie de Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.plugins.calendar.business;
35  
36  import fr.paris.lutece.plugins.calendar.service.AgendaResource;
37  import fr.paris.lutece.portal.service.image.ImageResource;
38  import fr.paris.lutece.portal.service.plugin.Plugin;
39  import fr.paris.lutece.portal.service.spring.SpringContextService;
40  import fr.paris.lutece.portal.service.util.AppException;
41  
42  import java.util.Calendar;
43  import java.util.List;
44  
45  
46  /**
47   * This class provides instances management methods (selectEventsList,
48   * findByPrimaryKey, findAgendasList ...) for
49   * Calendar objects ( AgendaResource, Events, ...)
50   */
51  public final class CalendarHome
52  {
53      // Static variable pointed at the DAO instance
54      private static ICalendarDAO _dao = SpringContextService.getBean( "calendar.calendarDAO" );
55  
56      /**
57       * Create a new CalendarHome
58       */
59      private CalendarHome( )
60      {
61      }
62  
63      /**
64       * Insert a new agenda in the table calendar_agendas.
65       * 
66       * @param agenda The AgendaResource object
67       * @param plugin The Plugin using this data access service
68       */
69      public static void createAgenda( AgendaResource agenda, Plugin plugin )
70      {
71          _dao.insertAgenda( agenda, plugin );
72      }
73  
74      /**
75       * Update the agenda in the table calendar_agendas
76       * @param agenda The reference of AgendaResource
77       * @param plugin The Plugin using this data access service
78       */
79      public static void updateAgenda( AgendaResource agenda, Plugin plugin )
80      {
81          _dao.storeAgenda( agenda, plugin );
82      }
83  
84      /**
85       * Delete an agenda from the table calendar_agendas
86       * @param nAgendaId The agenda Id
87       * @param plugin The Plugin using this data access service
88       */
89      public static void removeAgenda( int nAgendaId, Plugin plugin )
90      {
91          _dao.deleteAgenda( nAgendaId, plugin );
92      }
93  
94      /**
95       * Load the list of AgendaResources
96       * 
97       * @param plugin The plugin
98       * @return The Collection of the AgendaResources
99       */
100     public static List<AgendaResource> findAgendaResourcesList( Plugin plugin )
101     {
102         return _dao.selectAgendaResourceList( plugin );
103     }
104 
105     /**
106      * Returns an instance of a AgendaResource whose identifier is specified in
107      * parameter
108      * 
109      * @param nKey The Primary key of the contact
110      * @param plugin The Plugin object
111      * @return an instance of AgendaResource
112      */
113     public static AgendaResource findAgendaResource( int nKey, Plugin plugin )
114     {
115         return _dao.loadAgenda( nKey, plugin );
116     }
117 
118     /**
119      * Insert a new event in the table calendar_events.
120      * @param event the event
121      * @param plugin The Plugin using this data access service
122      * @param strUserLogin user login
123      * @throws fr.paris.lutece.portal.service.util.AppException AppException
124      */
125     public static void createEvent( SimpleEvent event, Plugin plugin, String strUserLogin ) throws AppException
126     {
127         _dao.insertEvent( event, plugin, strUserLogin );
128     }
129 
130     /**
131      * Update the event in the table calendar_event
132      * @param event The reference of SimpleEvent
133      * @param bPeriodiciteUpdated true if periodicite, false otherwise
134      * @param plugin The Plugin using this data access service
135      */
136     public static void updateEvent( SimpleEvent event, boolean bPeriodiciteUpdated, Plugin plugin )
137     {
138         _dao.storeEvent( event, plugin, bPeriodiciteUpdated );
139     }
140 
141     /**
142      * Delete an Event from the table calendar_events
143      * @param nEventId The event id
144      * @param nAgendaId The agenda Id
145      * @param plugin The Plugin using this data access service
146      */
147     public static void removeEvent( int nAgendaId, int nEventId, Plugin plugin )
148     {
149         _dao.deleteEvent( nAgendaId, nEventId, plugin );
150     }
151 
152     /**
153      * Load the data of SimpleEvent from the table
154      * @return the instance of the SimpleEvent
155      * @param nEventId The event id
156      * @param plugin The plugin
157      */
158     public static SimpleEvent findEvent( int nEventId, Plugin plugin )
159     {
160         return _dao.loadEvent( nEventId, plugin );
161     }
162 
163     /**
164      * Load the list of Events
165      * @return The Collection of the Events
166      * @param nSortEvents An integer used for sorting issues
167      * @param plugin The plugin
168      * @param nAgendaId The identifier of the agenda
169      */
170     public static List<SimpleEvent> findEventsList( int nAgendaId, int nSortEvents, Plugin plugin )
171     {
172         return _dao.selectEventsList( nAgendaId, nSortEvents, plugin );
173     }
174 
175     /**
176      * Load the list of Events
177      * @return The Collection of the Events
178      * @param nSortEvents An integer used for sorting issues
179      * @param plugin The plugin
180      * @param nAgendaId The identifier of the agenda
181      * @param strUserLogin user login
182      */
183     public static List<SimpleEvent> findEventsListByUserLogin( int nAgendaId, int nSortEvents, Plugin plugin,
184             String strUserLogin )
185     {
186         return _dao.selectEventsListByUserLogin( nAgendaId, nSortEvents, plugin, strUserLogin );
187     }
188 
189     /**
190      * Load the list of Occurrences linked with an event
191      * @return The Collection of the Occurrences
192      * @param nSortEvents An integer used for sorting issues
193      * @param plugin The plugin
194      * @param nAgendaId The identifier of the agenda
195      * @param nEventId The identifier of an event
196      * 
197      */
198     public static List<OccurrenceEvent> findOccurrencesList( int nAgendaId, int nEventId, int nSortEvents, Plugin plugin )
199     {
200         return _dao.selectOccurrencesList( nAgendaId, nEventId, nSortEvents, plugin );
201     }
202 
203     /**
204      * Load the list of Occurrences
205      * @param nSortEvents An integer used for sorting issues
206      * @param plugin The plugin
207      * @param nAgendaId The identifier of the agenda
208      * @return The Collection of the Occurrences
209      * 
210      */
211     public static List<OccurrenceEvent> findOccurrencesList( int nAgendaId, int nSortEvents, Plugin plugin )
212     {
213         return _dao.selectOccurrencesList( nAgendaId, nSortEvents, plugin );
214     }
215 
216     /**
217      * Load the list of Occurrences ordered by occurrences id
218      * @return The Collection of the Occurrences
219      * @param plugin The plugin
220      * @param nAgendaId The identifier of the agenda
221      * 
222      */
223     public static List<OccurrenceEvent> findOccurrencesByIdList( int nAgendaId, Plugin plugin )
224     {
225         return _dao.selectOccurrencesByIdList( nAgendaId, plugin );
226     }
227 
228     /**
229      * Load the data of Occurrence from the table
230      * @return the instance of the OccurrenceEvent
231      * @param nOccurrenceId The occurrence id
232      * @param plugin The plugin
233      */
234     public static OccurrenceEvent findOccurrence( int nOccurrenceId, Plugin plugin )
235     {
236         return _dao.loadOccurrence( nOccurrenceId, plugin );
237     }
238 
239     /**
240      * Update the occurrence in the table calendar_events_occurrences
241      * 
242      * @param occurrence The reference of OccurrenceEvent
243      * @param plugin The Plugin using this data access service
244      */
245     public static void updateOccurrence( OccurrenceEvent occurrence, Plugin plugin )
246     {
247         _dao.storeOccurrence( occurrence, plugin );
248     }
249 
250     /**
251      * Returns the number of days within which the events will occur
252      * @param nEventId The id of the event
253      * @param plugin Plugin
254      * @return Returns the number of days
255      */
256     public static int getRepetitionDays( int nEventId, Plugin plugin )
257     {
258         return _dao.getRepetitionDays( nEventId, plugin );
259     }
260 
261     /**
262      * Returns the number of occurrence for an event
263      * @param nEventId The id of the event
264      * @return Returns the number of occurrence
265      * @param plugin The Plugin using this data access service
266      */
267     public static int getOccurrenceNumber( int nEventId, Plugin plugin )
268     {
269         return _dao.getOccurrenceNumber( nEventId, plugin );
270     }
271 
272     /**
273      * Delete an Event from the table calendar_events
274      * @param nOccurrenceId The occurrence id
275      * @param nEventId The identifier of an event
276      * @param nAgendaId The id of the agenda
277      * @param plugin The Plugin using this data access service
278      */
279     public static void removeOccurrence( int nOccurrenceId, int nEventId, int nAgendaId, Plugin plugin )
280     {
281         _dao.deleteOccurrence( nOccurrenceId, nEventId, nAgendaId, plugin );
282     }
283 
284     /**
285      * Return the image resource for the specified category id
286      * @param nCategoryId The identifier of Category object
287      * @param plugin Plugin
288      * @return ImageResource
289      */
290     public static ImageResource getImageResource( int nCategoryId, Plugin plugin )
291     {
292         return _dao.loadImageResource( nCategoryId, plugin );
293     }
294 
295     /**
296      * Load the list of Events
297      * 
298      * @return The Collection of the Events
299      * @param plugin The plugin
300      * @param filter The CalendarFilter Object
301      */
302     public static List<Event> findEventsByFilter( CalendarFilter filter, Plugin plugin )
303     {
304         return _dao.selectByFilter( filter, plugin );
305     }
306 
307     /**
308      * Load the list of top Events
309      * @param plugin The plugin
310      * @return The list of events
311      */
312     public static List<SimpleEvent> findTopEventList( Plugin plugin )
313     {
314         return _dao.selectTopEventsList( plugin );
315     }
316 
317     /**
318      * Return 1 if the day contains an event 0 otherwise
319      * @param calendar The day
320      * @param plugin The plugin
321      * @return 1 if the day contains an event 0 otherwise
322      */
323     public static boolean hasOccurrenceEvent( Calendar calendar, Plugin plugin )
324     {
325         return _dao.hasOccurenceEvent( calendar, plugin );
326     }
327 
328     /**
329      * Load the list of events
330      * @param nAgendaId the agenda ID
331      * @param nSortEvents An integer used for sorting issues
332      * @param nNextDays the number of days
333      * @param plugin plugin
334      * @return the list of events
335      */
336     public static List<SimpleEvent> findEventsList( int nAgendaId, int nSortEvents, int nNextDays, Plugin plugin )
337     {
338         return _dao.selectEventsList( nAgendaId, nSortEvents, nNextDays, plugin );
339     }
340 
341     /**
342      * Get the list of calendar IDs
343      * @param plugin {@link Plugin}
344      * @return the list of calendar ids
345      */
346     public static List<Integer> findCalendarIds( Plugin plugin )
347     {
348         return _dao.selectCalendarIds( plugin );
349     }
350 }