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.sql.ResultSet;
37  import java.sql.Timestamp;
38  import java.time.LocalTime;
39  import java.util.ArrayList;
40  import java.util.HashMap;
41  import java.util.List;
42  import java.util.Map;
43  
44  import org.apache.commons.lang3.StringUtils;
45  
46  import fr.paris.lutece.plugins.appointment.business.UtilDAO;
47  import fr.paris.lutece.plugins.appointment.business.slot.Slot;
48  import fr.paris.lutece.plugins.appointment.business.user.User;
49  import fr.paris.lutece.plugins.appointment.web.dto.AppointmentFilterDTO;
50  import fr.paris.lutece.portal.service.plugin.Plugin;
51  import fr.paris.lutece.util.sql.DAOUtil;
52  
53  /**
54   * This class provides Data Access methods for Appointment objects
55   * 
56   * @author Laurent Payen
57   *
58   */
59  public final class AppointmentDAO extends UtilDAO implements IAppointmentDAO
60  {
61  
62      private static final String SQL_QUERY_NEW_PK = "SELECT max(id_appointment) FROM appointment_appointment";
63      private static final String SQL_QUERY_INSERT = "INSERT INTO appointment_appointment (id_appointment, reference, nb_places, is_cancelled, id_action_cancelled, notification, id_admin_user, id_user, id_slot) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
64      private static final String SQL_QUERY_UPDATE = "UPDATE appointment_appointment SET reference = ?, nb_places = ?, is_cancelled = ?, id_action_cancelled = ?, notification = ?, id_admin_user = ?, id_user = ?, id_slot = ? WHERE id_appointment = ?";
65      private static final String SQL_QUERY_DELETE = "DELETE FROM appointment_appointment WHERE id_appointment = ?";
66      private static final String SQL_QUERY_SELECT_COLUMNS = "SELECT appointment.id_appointment, appointment.reference, appointment.nb_places, appointment.is_cancelled, appointment.id_action_cancelled, appointment.notification, appointment.id_admin_user, appointment.id_user, appointment.id_slot FROM appointment_appointment appointment";
67      private static final String SQL_QUERY_SELECT = SQL_QUERY_SELECT_COLUMNS + " WHERE id_appointment = ?";
68      private static final String SQL_QUERY_SELECT_BY_ID_USER = SQL_QUERY_SELECT_COLUMNS + " WHERE id_user = ?";
69      private static final String SQL_QUERY_SELECT_BY_ID_SLOT = SQL_QUERY_SELECT_COLUMNS + " WHERE id_slot = ?";
70      private static final String SQL_QUERY_SELECT_BY_REFERENCE = SQL_QUERY_SELECT_COLUMNS + " WHERE reference = ?";
71      private static final String SQL_QUERY_SELECT_BY_ID_FORM = SQL_QUERY_SELECT_COLUMNS
72              + " INNER JOIN appointment_slot slot ON appointment.id_slot = slot.id_slot WHERE slot.id_form = ?";
73      private static final String SQL_QUERY_SELECT_BY_FILTER = "SELECT "
74              + "app.id_appointment, app.reference, app.nb_places, app.is_cancelled, app.id_action_cancelled, app.notification, app.id_admin_user, app.id_user, app.id_slot, "
75              + "user.id_user, user.guid, user.first_name, user.last_name, user.email, user.phone_number, "
76              + "slot.id_slot, slot.starting_date_time, slot.ending_date_time, slot.is_open, slot.is_specific, slot.max_capacity, slot.nb_remaining_places, slot.id_form "
77              + "FROM appointment_appointment app " + "INNER JOIN appointment_user user ON app.id_user = user.id_user "
78              + "INNER JOIN appointment_slot slot ON app.id_slot = slot.id_slot " + "WHERE slot.id_form = ?";
79  
80      private static final String SQL_QUERY_GET_APPOINTMENT_FILL_PARAMETERS = "SELECT DISTINCT ge.id_entry AS identry, a.record_field_value AS recordfieldvalue, a.title2 FROM genatt_entry ge INNER JOIN (SELECT record_field_value, de.title, gf.title AS title2    FROM directory_record_field drf INNER JOIN directory_entry de ON de.id_entry = drf.id_entry LEFT OUTER JOIN genatt_field gf ON gf.value = drf.record_field_value WHERE drf.id_record=?) a ON a.title = ge.title WHERE id_resource = ? OR  id_entry = ?";
81      private static final String SQL_QUERY_CHECK_SECURITY_KEY = "SELECT a.record_field_value AS cle, b.id_form AS id_form FROM directory_record_field  a INNER JOIN (SELECT c.id_form, a.id_record FROM directory_record_field a INNER JOIN directory_field b ON b.id_field = a.id_field INNER JOIN appointment_form c ON c.title = b.title WHERE a.id_entry = ? and a.id_record=?) b ON b.id_record = a.id_record WHERE a.id_record = ? AND a.id_entry = ?";
82      private static final String SQL_QUERY_CHECK_NB_CRENEAUX_RESTANTS = "SELECT record_field_value - a.nb_creneaux_reserves AS creneaux_restants FROM directory_record_field INNER JOIN ( select count(*) as nb_creneaux_reserves from appointment_appointment where id_appointment in ( SELECT id_appointment from appointment_appointment_response where id_response IN ( SELECT id_response FROM genatt_response JOIN ( SELECT record_field_value FROM directory_record_field WHERE id_record=? AND id_entry=? ) a WHERE id_entry = ( SELECT id_entry FROM genatt_entry WHERE title = 'N° du projet' AND id_resource = ? ) AND response_value = ( SELECT record_field_value AS numero_projet FROM directory_record_field WHERE id_record=? AND id_entry=? ) ) ) and is_cancelled <> -10 ) a WHERE id_record=? AND id_entry=?";
83      private static final String SQL_QUERY_GET_ID_FORM_BY_NUMERO = "SELECT af.id_form FROM directory_record_field drf INNER JOIN directory_field df ON df.id_field = drf.id_field INNER JOIN appointment_form af ON af.title = df.title WHERE drf.id_entry = ? AND drf.id_record=?";
84      private static final String SQL_QUERY_CHECK_SELECTED_ANIMATION = "SELECT record_field_value FROM directory_record_field drf INNER JOIN directory_entry de ON de.id_entry = drf.id_entry LEFT OUTER JOIN genatt_field gf ON gf.value = drf.record_field_value WHERE drf.id_record = ? and gf.title IN (?)";
85  
86      private static final String SQL_FILTER_FIRST_NAME = "UPPER(user.first_name) LIKE ?";
87      private static final String SQL_FILTER_LAST_NAME = "UPPER(user.last_name) LIKE ?";
88      private static final String SQL_FILTER_EMAIL = "UPPER(user.email) LIKE ?";
89      private static final String SQL_FILTER_STATUS = "app.is_cancelled = ?";
90      private static final String SQL_FILTER_DATE_APPOINTMENT_MIN = "slot.starting_date_time >= ?";
91      private static final String SQL_FILTER_DATE_APPOINTMENT_MAX = "slot.starting_date_time < ?";
92  
93      private static final String CONSTANT_AND = " AND ";
94      private static final String CONSTANT_PERCENT = "%";
95  
96      @Override
97      public synchronized void insert( Appointment appointment, Plugin plugin )
98      {
99          appointment.setIdAppointment( getNewPrimaryKey( SQL_QUERY_NEW_PK, plugin ) );
100         DAOUtil daoUtil = buildDaoUtil( SQL_QUERY_INSERT, appointment, plugin, true );
101         executeUpdate( daoUtil );
102     }
103 
104     @Override
105     public void update( Appointment appointment, Plugin plugin )
106     {
107         DAOUtil daoUtil = buildDaoUtil( SQL_QUERY_UPDATE, appointment, plugin, false );
108         executeUpdate( daoUtil );
109     }
110 
111     @Override
112     public void delete( int nIdAppointment, Plugin plugin )
113     {
114         DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE, plugin );
115         daoUtil.setInt( 1, nIdAppointment );
116         executeUpdate( daoUtil );
117     }
118 
119     @Override
120     public Appointment select( int nIdAppointment, Plugin plugin )
121     {
122         DAOUtil daoUtil = null;
123         Appointment appointment = null;
124         try
125         {
126             daoUtil = new DAOUtil( SQL_QUERY_SELECT, plugin );
127             daoUtil.setInt( 1, nIdAppointment );
128             daoUtil.executeQuery( );
129             if ( daoUtil.next( ) )
130             {
131                 appointment = buildAppointment( daoUtil );
132             }
133         }
134         finally
135         {
136             if ( daoUtil != null )
137             {
138                 daoUtil.free( );
139             }
140         }
141         return appointment;
142     }
143 
144     @Override
145     public List<Appointment> findByIdUser( int nIdUser, Plugin plugin )
146     {
147         DAOUtil daoUtil = null;
148         List<Appointment> listAppointment = new ArrayList<>( );
149         try
150         {
151             daoUtil = new DAOUtil( SQL_QUERY_SELECT_BY_ID_USER, plugin );
152             daoUtil.setInt( 1, nIdUser );
153             daoUtil.executeQuery( );
154             while ( daoUtil.next( ) )
155             {
156                 listAppointment.add( buildAppointment( daoUtil ) );
157             }
158         }
159         finally
160         {
161             if ( daoUtil != null )
162             {
163                 daoUtil.free( );
164             }
165         }
166         return listAppointment;
167     }
168 
169     @Override
170     public List<Appointment> findByIdSlot( int nIdSlot, Plugin plugin )
171     {
172         DAOUtil daoUtil = null;
173         List<Appointment> listAppointment = new ArrayList<>( );
174         try
175         {
176             daoUtil = new DAOUtil( SQL_QUERY_SELECT_BY_ID_SLOT, plugin );
177             daoUtil.setInt( 1, nIdSlot );
178             daoUtil.executeQuery( );
179             while ( daoUtil.next( ) )
180             {
181                 listAppointment.add( buildAppointment( daoUtil ) );
182             }
183         }
184         finally
185         {
186             if ( daoUtil != null )
187             {
188                 daoUtil.free( );
189             }
190         }
191         return listAppointment;
192     }
193 
194     @Override
195     public Appointment findByReference( String strReference, Plugin plugin )
196     {
197         DAOUtil daoUtil = null;
198         Appointment appointment = null;
199         try
200         {
201             daoUtil = new DAOUtil( SQL_QUERY_SELECT_BY_REFERENCE, plugin );
202             daoUtil.setString( 1, strReference );
203             daoUtil.executeQuery( );
204             if ( daoUtil.next( ) )
205             {
206                 appointment = buildAppointment( daoUtil );
207             }
208         }
209         finally
210         {
211             if ( daoUtil != null )
212             {
213                 daoUtil.free( );
214             }
215         }
216         return appointment;
217     }
218 
219     @Override
220     public List<Appointment> findByFilter( AppointmentFilterDTO appointmentFilter, Plugin plugin )
221     {
222         List<Appointment> listAppointment = new ArrayList<Appointment>( );
223         DAOUtil daoUtil = new DAOUtil( getSqlQueryFromFilter( appointmentFilter ), plugin );
224         addFilterParametersToDAOUtil( appointmentFilter, daoUtil );
225         daoUtil.executeQuery( );
226         while ( daoUtil.next( ) )
227         {
228             listAppointment.add( buildAppointmentHeavy( daoUtil ) );
229         }
230         daoUtil.free( );
231         return listAppointment;
232     }
233 
234     /**
235      * Add all the filters to the daoUtil
236      * 
237      * @param appointmentFilter
238      *            the filter
239      * @param daoUtil
240      *            the daoutil
241      */
242     private void addFilterParametersToDAOUtil( AppointmentFilterDTO appointmentFilter, DAOUtil daoUtil )
243     {
244         int nIndex = 1;
245         daoUtil.setInt( nIndex++, appointmentFilter.getIdForm( ) );
246         if ( appointmentFilter.getFirstName( ) != null )
247         {
248             daoUtil.setString( nIndex++, CONSTANT_PERCENT + appointmentFilter.getFirstName( ).toUpperCase( ) + CONSTANT_PERCENT );
249         }
250         if ( appointmentFilter.getLastName( ) != null )
251         {
252             daoUtil.setString( nIndex++, CONSTANT_PERCENT + appointmentFilter.getLastName( ).toUpperCase( ) + CONSTANT_PERCENT );
253         }
254         if ( appointmentFilter.getEmail( ) != null )
255         {
256             daoUtil.setString( nIndex++, CONSTANT_PERCENT + appointmentFilter.getEmail( ).toUpperCase( ) + CONSTANT_PERCENT );
257         }
258         if ( appointmentFilter.getStatus( ) != -1 )
259         {
260             daoUtil.setInt( nIndex++, appointmentFilter.getStatus( ) );
261         }
262         if ( appointmentFilter.getStartingDateOfSearch( ) != null )
263         {
264             Timestamp startingTimestamp;
265             if ( StringUtils.isNotEmpty( appointmentFilter.getStartingTimeOfSearch( ) ) )
266             {
267                 startingTimestamp = Timestamp.valueOf( appointmentFilter.getStartingDateOfSearch( ).toLocalDate( )
268                         .atTime( LocalTime.parse( appointmentFilter.getStartingTimeOfSearch( ) ) ) );
269             }
270             else
271             {
272                 startingTimestamp = Timestamp.valueOf( appointmentFilter.getStartingDateOfSearch( ).toLocalDate( ).atStartOfDay( ) );
273             }
274             daoUtil.setTimestamp( nIndex++, startingTimestamp );
275         }
276         if ( appointmentFilter.getEndingDateOfSearch( ) != null )
277         {
278             Timestamp endingTimestamp;
279             if ( StringUtils.isNotEmpty( appointmentFilter.getEndingTimeOfSearch( ) ) )
280             {
281                 endingTimestamp = Timestamp.valueOf( appointmentFilter.getEndingDateOfSearch( ).toLocalDate( )
282                         .atTime( LocalTime.parse( appointmentFilter.getEndingTimeOfSearch( ) ) ) );
283             }
284             else
285             {
286                 endingTimestamp = Timestamp.valueOf( appointmentFilter.getEndingDateOfSearch( ).toLocalDate( ).atTime( LocalTime.MAX ) );
287             }
288             daoUtil.setTimestamp( nIndex++, endingTimestamp );
289         }
290     }
291 
292     /**
293      * Build the sql query with the elements of the filter
294      * 
295      * @param appointmentFilter
296      *            the filter
297      * @return the query
298      */
299     private String getSqlQueryFromFilter( AppointmentFilterDTO appointmentFilter )
300     {
301         StringBuilder sbSql = new StringBuilder( SQL_QUERY_SELECT_BY_FILTER );
302         if ( appointmentFilter.getFirstName( ) != null )
303         {
304             sbSql.append( CONSTANT_AND );
305             sbSql.append( SQL_FILTER_FIRST_NAME );
306         }
307         if ( appointmentFilter.getLastName( ) != null )
308         {
309             sbSql.append( CONSTANT_AND );
310             sbSql.append( SQL_FILTER_LAST_NAME );
311         }
312         if ( appointmentFilter.getEmail( ) != null )
313         {
314             sbSql.append( CONSTANT_AND );
315             sbSql.append( SQL_FILTER_EMAIL );
316         }
317         if ( appointmentFilter.getStatus( ) != -1 )
318         {
319             sbSql.append( CONSTANT_AND );
320             sbSql.append( SQL_FILTER_STATUS );
321         }
322         if ( appointmentFilter.getStartingDateOfSearch( ) != null )
323         {
324             sbSql.append( CONSTANT_AND );
325             sbSql.append( SQL_FILTER_DATE_APPOINTMENT_MIN );
326         }
327         if ( appointmentFilter.getEndingDateOfSearch( ) != null )
328         {
329             sbSql.append( CONSTANT_AND );
330             sbSql.append( SQL_FILTER_DATE_APPOINTMENT_MAX );
331         }
332         return sbSql.toString( );
333     }
334 
335     @Override
336     public List<Appointment> findByIdForm( int nIdForm, Plugin plugin )
337     {
338         DAOUtil daoUtil = null;
339         List<Appointment> listAppointment = new ArrayList<>( );
340         try
341         {
342             daoUtil = new DAOUtil( SQL_QUERY_SELECT_BY_ID_FORM, plugin );
343             daoUtil.setInt( 1, nIdForm );
344             daoUtil.executeQuery( );
345             while ( daoUtil.next( ) )
346             {
347                 listAppointment.add( buildAppointment( daoUtil ) );
348             }
349         }
350         finally
351         {
352             if ( daoUtil != null )
353             {
354                 daoUtil.free( );
355             }
356         }
357         return listAppointment;
358     }
359 
360     /**
361      * Build an Appointment business object from the resultset
362      * 
363      * @param daoUtil
364      *            the prepare statement util object
365      * @return a new Appointment business object with all its attributes assigned
366      */
367     private Appointment buildAppointment( DAOUtil daoUtil )
368     {
369         int nIndex = 1;
370         Appointment appointment = new Appointment( );
371         appointment.setIdAppointment( daoUtil.getInt( nIndex++ ) );
372         appointment.setReference( daoUtil.getString( nIndex++ ) );
373         appointment.setNbPlaces( daoUtil.getInt( nIndex++ ) );
374         appointment.setIsCancelled( daoUtil.getBoolean( nIndex++ ) );
375         appointment.setIdActionCancelled( daoUtil.getInt( nIndex++ ) );
376         appointment.setNotification( daoUtil.getInt( nIndex++ ) );
377         appointment.setIdAdminUser( daoUtil.getInt( nIndex++ ) );
378         appointment.setIdUser( daoUtil.getInt( nIndex++ ) );
379         appointment.setIdSlot( daoUtil.getInt( nIndex ) );
380         return appointment;
381     }
382 
383     /**
384      * Build an appointment business object with its complete slot and its complete user
385      * 
386      * @param daoUtil
387      *            the daoutil
388      * @return the appointment
389      */
390     private Appointment buildAppointmentHeavy( DAOUtil daoUtil )
391     {
392         int nIndex = 1;
393         Appointment appointment = new Appointment( );
394         appointment.setIdAppointment( daoUtil.getInt( nIndex++ ) );
395         appointment.setReference( daoUtil.getString( nIndex++ ) );
396         appointment.setNbPlaces( daoUtil.getInt( nIndex++ ) );
397         appointment.setIsCancelled( daoUtil.getBoolean( nIndex++ ) );
398         appointment.setIdActionCancelled( daoUtil.getInt( nIndex++ ) );
399         appointment.setNotification( daoUtil.getInt( nIndex++ ) );
400         appointment.setIdAdminUser( daoUtil.getInt( nIndex++ ) );
401         appointment.setIdUser( daoUtil.getInt( nIndex++ ) );
402         appointment.setIdSlot( daoUtil.getInt( nIndex++ ) );
403         User user = new User( );
404         user.setIdUser( daoUtil.getInt( nIndex++ ) );
405         user.setGuid( daoUtil.getString( nIndex++ ) );
406         user.setFirstName( daoUtil.getString( nIndex++ ) );
407         user.setLastName( daoUtil.getString( nIndex++ ) );
408         user.setEmail( daoUtil.getString( nIndex++ ) );
409         user.setPhoneNumber( daoUtil.getString( nIndex++ ) );
410         appointment.setUser( user );
411         Slot slot = new Slot( );
412         slot.setIdSlot( daoUtil.getInt( nIndex++ ) );
413         slot.setStartingTimeStampDate( daoUtil.getTimestamp( nIndex++ ) );
414         slot.setEndingTimeStampDate( daoUtil.getTimestamp( nIndex++ ) );
415         slot.setIsOpen( daoUtil.getBoolean( nIndex++ ) );
416         slot.setIsSpecific( daoUtil.getBoolean( nIndex++ ) );
417         slot.setMaxCapacity( daoUtil.getInt( nIndex++ ) );
418         slot.setNbRemainingPlaces( daoUtil.getInt( nIndex++ ) );
419         slot.setIdForm( daoUtil.getInt( nIndex ) );
420         appointment.setSlot( slot );
421         return appointment;
422     }
423 
424     /**
425      * Build a daoUtil object with the query and all the attributes of the Appointment
426      * 
427      * @param query
428      *            the query
429      * @param appointment
430      *            the Appointment
431      * @param plugin
432      *            the plugin
433      * @param isInsert
434      *            true if it is an insert query (in this case, need to set the id). If false, it is an update, in this case, there is a where parameter id to
435      *            set
436      * @return a new daoUtil with all its values assigned
437      */
438     private DAOUtil buildDaoUtil( String query, Appointment appointment, Plugin plugin, boolean isInsert )
439     {
440         int nIndex = 1;
441         DAOUtil daoUtil = new DAOUtil( query, plugin );
442         if ( isInsert )
443         {
444             daoUtil.setInt( nIndex++, appointment.getIdAppointment( ) );
445         }
446         daoUtil.setString( nIndex++, appointment.getReference( ) );
447         daoUtil.setInt( nIndex++, appointment.getNbPlaces( ) );
448         daoUtil.setBoolean( nIndex++, appointment.getIsCancelled( ) );
449         daoUtil.setInt( nIndex++, appointment.getIdActionCancelled( ) );
450         daoUtil.setInt( nIndex++, appointment.getNotification( ) );
451         daoUtil.setInt( nIndex++, appointment.getIdAdminUser( ) );
452         daoUtil.setInt( nIndex++, appointment.getIdUser( ) );
453         daoUtil.setInt( nIndex++, appointment.getIdSlot( ) );
454         if ( !isInsert )
455         {
456             daoUtil.setInt( nIndex, appointment.getIdAppointment( ) );
457         }
458         return daoUtil;
459     }
460 
461     /**
462      * Execute a safe update (Free the connection in case of error when execute the query)
463      * 
464      * @param daoUtil
465      *            the daoUtil
466      */
467     private void executeUpdate( DAOUtil daoUtil )
468     {
469         try
470         {
471             daoUtil.executeUpdate( );
472         }
473         finally
474         {
475             if ( daoUtil != null )
476             {
477                 daoUtil.free( );
478             }
479         }
480     }
481 
482     /**
483      * {@inheritDoc}
484      */
485     @Override
486     public HashMap<String,String> getAppointmentFillParameters( Integer idKiosque, String idFormUser, Integer idEntryEmail, Plugin plugin ){
487         DAOUtil daoUtil = new DAOUtil( SQL_QUERY_GET_APPOINTMENT_FILL_PARAMETERS, plugin );
488 
489         int nIndex = 1;
490         daoUtil.setInt( nIndex++, Integer.valueOf( idFormUser ) );
491         daoUtil.setInt( nIndex++, idKiosque );
492         daoUtil.setInt( nIndex++, idEntryEmail );
493         daoUtil.executeQuery( );
494 
495         HashMap<String,String> parametersMap = new HashMap();
496 
497         while ( daoUtil.next( ) )
498         {
499             parametersMap.put( daoUtil.getString( 1 ), null == daoUtil.getString( 3 )?daoUtil.getString( 2 ):daoUtil.getString( 3 ) );
500         }
501 
502         daoUtil.free( );
503 
504         return parametersMap;
505     }
506 
507     /**
508      * {@inheritDoc}
509      */
510     @Override
511     public boolean checkSecurityKey( String idForm, String idFormUser, String securityKey, int idEntryKiosque, int idEntryCleSecurite, Plugin plugin ){
512 
513         boolean result = false;
514 
515         DAOUtil daoUtil = new DAOUtil( SQL_QUERY_CHECK_SECURITY_KEY, plugin );
516 
517         int nIndex = 1;
518 
519         daoUtil.setInt( nIndex++, Integer.valueOf( idEntryKiosque ) );
520         daoUtil.setInt( nIndex++, Integer.valueOf( idFormUser ) );
521         daoUtil.setInt( nIndex++, Integer.valueOf( idFormUser ) );
522         daoUtil.setInt( nIndex++, Integer.valueOf( idEntryCleSecurite ) );
523 
524         daoUtil.executeQuery( );
525 
526         String securityKeyResult = null;
527         Integer idFormResult = null;
528 
529         while ( daoUtil.next( ) )
530         {
531             securityKeyResult = daoUtil.getString( 1 );
532             idFormResult = daoUtil.getInt( 2 );
533         }
534 
535         daoUtil.free( );
536 
537         if( null != securityKeyResult && securityKey.equals( securityKeyResult ) && null != idFormResult && idFormResult == Integer.valueOf( idForm ) ){
538             result = true;
539         }
540 
541         return result;
542     }
543 
544     /**
545      * {@inheritDoc}
546      */
547     @Override
548     public boolean checkNbCreneauxRestants( String idForm, String idFormUser, Integer idEntryDates, Integer idEntryNumero, Plugin plugin ){
549 
550         DAOUtil daoUtil = new DAOUtil( SQL_QUERY_CHECK_NB_CRENEAUX_RESTANTS, plugin );
551 
552         int nIndex = 1;
553 
554         daoUtil.setInt( nIndex++, Integer.valueOf( idFormUser ) );
555         daoUtil.setInt( nIndex++, idEntryDates );
556         daoUtil.setInt( nIndex++, Integer.valueOf( idForm ) );
557         daoUtil.setInt( nIndex++, Integer.valueOf( idFormUser ) );
558         daoUtil.setInt( nIndex++, idEntryNumero );
559         daoUtil.setInt( nIndex++, Integer.valueOf( idFormUser ) );
560         daoUtil.setInt( nIndex++, idEntryDates );
561 
562         daoUtil.executeQuery( );
563 
564         Integer nbCreneauxRestants = null;
565 
566         while ( daoUtil.next( ) )
567         {
568             nbCreneauxRestants = daoUtil.getInt( 1 );
569         }
570 
571         daoUtil.free( );
572 
573         return null!=nbCreneauxRestants && nbCreneauxRestants>0;
574     }
575 
576     /**
577      * {@inheritDoc}
578      */
579     @Override
580     public boolean checkSelectedAnimation( String idFormUser, String[] animations, Plugin plugin )
581     {
582 
583         boolean result = false;
584 
585         StringBuilder builder = new StringBuilder( );
586         for ( String animation : animations )
587         {
588             builder.append( StringUtils.wrap( animation, "'" ) );
589             builder.append( "," );
590         }
591         builder.deleteCharAt( builder.length( ) - 1 );
592 
593         String query = SQL_QUERY_CHECK_SELECTED_ANIMATION.replaceFirst("\\?", idFormUser).replaceFirst( "\\?", builder.toString( ) );
594 
595         DAOUtil daoUtil = new DAOUtil( query, plugin );
596 
597         daoUtil.executeQuery( );
598 
599         if ( daoUtil.next( ) )
600         {
601             result = true;
602         }
603 
604         daoUtil.free( );
605 
606         return result;
607 
608     }
609 
610 }