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