View Javadoc
1   /*
2    * Copyright (c) 2002-2022, City of 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.appointment.business.appointment;
35  
36  import java.util.List;
37  
38  import fr.paris.lutece.plugins.appointment.service.AppointmentPlugin;
39  import fr.paris.lutece.plugins.appointment.web.dto.AppointmentFilterDTO;
40  import fr.paris.lutece.portal.service.plugin.Plugin;
41  import fr.paris.lutece.portal.service.plugin.PluginService;
42  import fr.paris.lutece.portal.service.spring.SpringContextService;
43  
44  /**
45   * This class provides instances management methods for Appointment objects
46   * 
47   * @author Laurent Payen
48   *
49   */
50  public final class AppointmentHome
51  {
52  
53      // Static variable pointed at the DAO instance
54      private static IAppointmentDAO _dao = SpringContextService.getBean( "appointment.appointmentDAO" );
55      private static Plugin _plugin = PluginService.getPlugin( AppointmentPlugin.PLUGIN_NAME );
56  
57      /**
58       * Private constructor - this class does not need to be instantiated
59       */
60      private AppointmentHome( )
61      {
62      }
63  
64      /**
65       * Create an instance of the Appointment class
66       * 
67       * @param appointment
68       *            The instance of the Appointment which contains the informations to store
69       * @return The instance of the Appointment which has been created with its primary key.
70       */
71      public static Appointment../../../../../../fr/paris/lutece/plugins/appointment/business/appointment/Appointment.html#Appointment">Appointment create( Appointment appointment )
72      {
73          _dao.insert( appointment, _plugin );
74  
75          return appointment;
76      }
77  
78      /**
79       * Update of the Appointment which is specified in parameter
80       * 
81       * @param appointment
82       *            The instance of the Appointment which contains the data to store
83       * @return The instance of the Appointment which has been updated
84       */
85      public static Appointment../../../../../../fr/paris/lutece/plugins/appointment/business/appointment/Appointment.html#Appointment">Appointment update( Appointment appointment )
86      {
87          _dao.update( appointment, _plugin );
88  
89          return appointment;
90      }
91  
92      /**
93       * Update date appointment, update AppointmentSlot
94       * 
95       * @param appointment
96       *            the appointment
97       * @param plugin
98       *            the plugin
99       */
100     public static void updateAppointmentDate( Appointment appointment )
101     {
102         _dao.updateAppointmentDate( appointment, _plugin );
103     }
104 
105     /**
106      * Delete the Appointment whose identifier is specified in parameter
107      * 
108      * @param nKey
109      *            The appointment Id
110      */
111     public static void delete( int nKey )
112     {
113         _dao.delete( nKey, _plugin );
114     }
115 
116     /**
117      * Return an instance of the Appointment whose identifier is specified in parameter
118      * 
119      * @param nKey
120      *            The Appointment primary key
121      * @return an instance of the Appointment
122      */
123     public static Appointment findByPrimaryKey( int nKey )
124     {
125         return _dao.select( nKey, _plugin );
126     }
127 
128     /**
129      * Return an instance of the Appointment whose reference is specified in parameter
130      * 
131      * @param strReference
132      *            The Appointment reference
133      * @return an instance of the Appointment
134      */
135     public static Appointment findByReference( String strReference )
136     {
137         return _dao.findByReference( strReference, _plugin );
138     }
139 
140     /**
141      * Return the appointments of a user
142      * 
143      * @param nIdUser
144      *            the User Id
145      * @return a list of the user appointments
146      */
147     public static List<Appointment> findByIdUser( int nIdUser )
148     {
149         return _dao.findByIdUser( nIdUser, _plugin );
150     }
151 
152     /**
153      * Return the appointments of a user by Guid
154      * 
155      * @param nIdUser
156      *            the User Guid
157      * @return a list of the user appointments
158      */
159     public static List<Appointment> findByGuidUser( String strGuidUser )
160     {
161         return _dao.findByGuidUser( strGuidUser, _plugin );
162     }
163 
164     /**
165      * Return the appointments of a slot
166      * 
167      * @param nIdSlot
168      * @return a list of the appointments of the slot
169      */
170     public static List<Appointment> findByIdSlot( int nIdSlot )
171     {
172         return _dao.findByIdSlot( nIdSlot, _plugin );
173     }
174 
175     /**
176      * Returns the list of appointments of a slot
177      * 
178      * @param listIdSlot
179      *            the list Slot Id
180      * @param plugin
181      *            the plugin
182      * @return a list of the appointments
183      */
184     public static List<Appointment> findByListIdSlot( List<Integer> listIdSlot )
185     {
186 
187         return _dao.findByListIdSlot( listIdSlot, _plugin );
188 
189     }
190 
191     /**
192      * Return a list of appointment of a form
193      * 
194      * @param nIdForm
195      *            the form id
196      * @return the list of the appointments
197      */
198     public static List<Appointment> findByIdForm( int nIdForm )
199     {
200         return _dao.findByIdForm( nIdForm, _plugin );
201     }
202 
203     /**
204      * Returns a list of appointment matching the filter
205      * 
206      * @param appointmentFilter
207      *            the filter
208      * @return a list of appointments
209      */
210     public static List<Appointment> findByFilter( AppointmentFilterDTO appointmentFilter )
211     {
212         return _dao.findByFilter( appointmentFilter, _plugin );
213     }
214     public static List<Integer> findIdsByFilter( AppointmentFilterDTO appointmentFilter )
215     {
216         return _dao.findIdsByFilter( appointmentFilter, _plugin );
217     }
218 
219     /**
220      * Find a list of appointments by id category and mail
221      * 
222      * @param nIdCategory
223      *            the id category
224      * @param mail
225      *            the mail
226      * @return list of appointments
227      */
228     public static List<Appointment> findByMailAndCategory( int nIdCategory, String mail )
229     {
230         return _dao.findByCategoryAndMail( nIdCategory, mail, _plugin );
231     }
232 
233     /**
234      * returns a list of all appointment ids.
235      * 
236      * @param plugin
237      * @return
238      */
239     public static List<Integer> selectAllAppointmentId( )
240     {
241         return _dao.selectAllAppointmentId( _plugin );
242     }
243 }