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.web.dto;
35  
36  import java.time.LocalDateTime;
37  import java.time.LocalTime;
38  import java.util.ArrayList;
39  import java.util.Collection;
40  import java.util.HashMap;
41  import java.util.List;
42  import java.util.Locale;
43  import java.util.Map;
44  
45  import fr.paris.lutece.plugins.appointment.business.appointment.Appointment;
46  import fr.paris.lutece.plugins.genericattributes.business.Response;
47  import fr.paris.lutece.plugins.workflowcore.business.action.Action;
48  import fr.paris.lutece.plugins.workflowcore.business.state.State;
49  import fr.paris.lutece.portal.service.i18n.I18nService;
50  
51  /**
52   * The DTO for an appointment in front office
53   * 
54   * @author Laurent Payen
55   *
56   */
57  public final class AppointmentDTO extends Appointment
58  {
59  
60      private static final String PROPERTY_EMPTY_FIELD_FIRST_NAME = "appointment.validation.appointment.FirstName.notEmpty";
61      private static final String PROPERTY_EMPTY_FIELD_LAST_NAME = "appointment.validation.appointment.LastName.notEmpty";
62      private static final String PROPERTY_UNVAILABLE_EMAIL = "appointment.validation.appointment.Email.email";
63      private static final String PROPERTY_MESSAGE_EMPTY_EMAIL = "appointment.validation.appointment.Email.notEmpty";
64      private static final String PROPERTY_EMPTY_CONFIRM_EMAIL = "appointment.validation.appointment.EmailConfirmation.email";
65      private static final String PROPERTY_UNVAILABLE_CONFIRM_EMAIL = "appointment.message.error.confirmEmail";
66      private static final String PROPERTY_EMPTY_NB_SEATS = "appointment.validation.appointment.NbBookedSeat.notEmpty";
67      private static final String PROPERTY_UNVAILABLE_NB_SEATS = "appointment.validation.appointment.NbBookedSeat.error";
68      private static final String PROPERTY_MAX_APPOINTMENT_PERIODE = "appointment.message.error.MaxAppointmentPeriode";
69      private static final String PROPERTY_MAX_APPOINTMENT_PERIODE_BACK = "appointment.info.appointment.emailerror";
70      private static final String PROPERTY_NB_DAY_BETWEEN_TWO_APPOINTMENTS = "appointment.validation.appointment.NbMinDaysBetweenTwoAppointments.error";
71      public static final String PROPERTY_APPOINTMENT_STATUS_UNRESERVED = "appointment.message.labelStatusUnreserved";
72      public static final String PROPERTY_APPOINTMENT_STATUS_RESERVED = "appointment.message.labelStatusReserved";
73  
74      /**
75       * Serial version UID
76       */
77      private static final long serialVersionUID = 703930649594406505L;
78  
79      /**
80       * The Date of the appointment in string format
81       */
82      private String _strDateOfTheAppointment;
83  
84      /**
85       * The name of the admin user
86       */
87      private String _strAdminUser;
88  
89      /**
90       * The starting date in LocalDateTime
91       */
92      private LocalDateTime _startingDateTime;
93  
94      /**
95       * The ending date in LocalDateTime
96       */
97      private LocalDateTime _endingDateTime;
98  
99      /**
100      * The starting time
101      */
102     private LocalTime _startingTime;
103 
104     /**
105      * The ending time
106      */
107     private LocalTime _endingTime;
108 
109     /**
110      * The state of the appointment
111      */
112     private transient State _state;
113 
114     /**
115      * The Form Id
116      */
117     private int _nIdForm;
118 
119     /**
120      * the number of booked seats for this appointment
121      */
122     private int _nNbBookedSeats = 1;
123 
124     /**
125      * The maximum number of seats the user can book
126      */
127     private int _nNbMaxPotentialBookedSeats;
128 
129     /**
130      * The Map of the responses for the additional entries of the form
131      */
132     private Map<Integer, List<Response>> _mapResponsesByIdEntry = new HashMap<>( );
133 
134     /**
135      * The list of the responses for the additional entries of the form
136      */
137     private List<Response> _listResponse;
138 
139     /**
140      * List of the available action of the workflow for this appointment
141      */
142     private transient Collection<Action> _listWorkflowActions;
143     /**
144      * The appointment is saved
145      */
146     private boolean _bIsSaved;
147     /**
148      * The overbooking is allowed
149      */
150     private boolean _bOverbookingAllowed;
151 
152     /**
153      * Email confirm of the User
154      */
155     private String _strEmailConfirm;
156 
157     /**
158      * Get the name of the admin user
159      * 
160      * @return the admin user name
161      */
162     public String getAdminUser( )
163     {
164         return _strAdminUser;
165     }
166 
167     /**
168      * Set the name of the admin user
169      * 
170      * @param _strAdminUser
171      *            the admin user name to set
172      */
173     public void setAdminUser( String strAdminUser )
174     {
175         this._strAdminUser = strAdminUser;
176     }
177 
178     /**
179      * Get the state of the appointment
180      * 
181      * @return the state of the appointment
182      */
183     public State getState( )
184     {
185         return _state;
186     }
187 
188     /**
189      * Set the state of the appointment
190      * 
191      * @param state
192      *            the state to set
193      */
194     public void setState( State state )
195     {
196         this._state = state;
197     }
198 
199     /**
200      * Get the starting date time of the appointment
201      * 
202      * @return the starting date time
203      */
204     public LocalDateTime getStartingDateTime( )
205     {
206         return _startingDateTime;
207     }
208 
209     /**
210      * Set the starting date time of the appointment
211      * 
212      * @param startingDateTime
213      *            the starting date time
214      */
215     public void setStartingDateTime( LocalDateTime startingDateTime )
216     {
217         this._startingDateTime = startingDateTime;
218     }
219 
220     /**
221      * Get the ending date time of the appointment
222      * 
223      * @return the ending date time
224      */
225     public LocalDateTime getEndingDateTime( )
226     {
227         return _endingDateTime;
228     }
229 
230     /**
231      * Set the ending date time of the appointment
232      * 
233      * @param endingDateTime
234      *            the ending date time
235      */
236     public void setEndingDateTime( LocalDateTime endingDateTime )
237     {
238         this._endingDateTime = endingDateTime;
239     }
240 
241     /**
242      * Get the starting time of the appointment
243      * 
244      * @return the starting time
245      */
246     public LocalTime getStartingTime( )
247     {
248         return _startingTime;
249     }
250 
251     /**
252      * Set the starting time of the appointment
253      * 
254      * @param startingTime
255      *            the starting time to set
256      */
257     public void setStartingTime( LocalTime startingTime )
258     {
259         this._startingTime = startingTime;
260     }
261 
262     /**
263      * Get the ending time of the appointment
264      * 
265      * @return the ending time
266      */
267     public LocalTime getEndingTime( )
268     {
269         return _endingTime;
270     }
271 
272     /**
273      * Set the ending time of the appointment
274      * 
275      * @param endingTime
276      *            the ending time
277      */
278     public void setEndingTime( LocalTime endingTime )
279     {
280         this._endingTime = endingTime;
281     }
282 
283     /**
284      * Get the date of the appointment
285      * 
286      * @return the date of the appointment
287      */
288     public String getDateOfTheAppointment( )
289     {
290         return _strDateOfTheAppointment;
291     }
292 
293     /**
294      * Set the date of the appointment
295      * 
296      * @param strDateOfTheAppointment
297      *            the date to set
298      */
299     public void setDateOfTheAppointment( String strDateOfTheAppointment )
300     {
301         this._strDateOfTheAppointment = strDateOfTheAppointment;
302     }
303 
304     /**
305      * Get the list of the responses of the additional entries of the form
306      * 
307      * @return the list of the responses
308      */
309     public List<Response> getListResponse( )
310     {
311         return _listResponse;
312     }
313 
314     /**
315      * Set the list of the responses of the additional entries of the form
316      * 
317      * @param listResponse
318      *            the list of the responses to set
319      */
320     public void setListResponse( List<Response> listResponse )
321     {
322         this._listResponse = listResponse;
323     }
324 
325     /**
326      * Get the form Id
327      * 
328      * @return the form Id
329      */
330     public int getIdForm( )
331     {
332         return _nIdForm;
333     }
334 
335     /**
336      * Set the Form Id
337      * 
338      * @param nIdForm
339      *            the form Id to set
340      */
341     public void setIdForm( int nIdForm )
342     {
343         this._nIdForm = nIdForm;
344     }
345 
346     /**
347      * Get the number of booked seats for the appointment
348      * 
349      * @return the number of booked seats
350      */
351     public int getNbBookedSeats( )
352     {
353         return _nNbBookedSeats;
354     }
355 
356     /**
357      * Set the number of booked seats for the appointment
358      * 
359      * @param nNumberOfPlacesReserved
360      *            the number to set
361      */
362     public void setNbBookedSeats( int nNumberOfPlacesReserved )
363     {
364         this._nNbBookedSeats = nNumberOfPlacesReserved;
365     }
366 
367     /**
368      * Get the maximum number of booked seats the user can take
369      * 
370      * @return the max number of booked seats
371      */
372     public int getNbMaxPotentialBookedSeats( )
373     {
374         return _nNbMaxPotentialBookedSeats;
375     }
376 
377     /**
378      * Set the maximum number of booked seats the user can take
379      * 
380      * @param nNbMaxPotentialBookedSeats
381      *            the maximum number to set
382      */
383     public void setNbMaxPotentialBookedSeats( int nNbMaxPotentialBookedSeats )
384     {
385         this._nNbMaxPotentialBookedSeats = nNbMaxPotentialBookedSeats;
386     }
387 
388     /**
389      * Get the available actions of the workflow for this appointment
390      * 
391      * @return the actions
392      */
393     public Collection<Action> getListWorkflowActions( )
394     {
395         return _listWorkflowActions;
396     }
397 
398     /**
399      * Set the available actions of the workflow for this appointment
400      * 
401      * @param listWorkflowActions
402      */
403     public void setListWorkflowActions( Collection<Action> listWorkflowActions )
404     {
405         this._listWorkflowActions = listWorkflowActions;
406     }
407 
408     /**
409      * Get the map of the responses of the additional entries of the form
410      * 
411      * @return the map of the responses
412      */
413     public Map<Integer, List<Response>> getMapResponsesByIdEntry( )
414     {
415         return _mapResponsesByIdEntry;
416     }
417 
418     /**
419      * Set the map of the responses of the addtional entries of the form to the appointment
420      * 
421      * @param mapResponsesByIdEntry
422      *            the map to set
423      */
424     public void setMapResponsesByIdEntry( Map<Integer, List<Response>> mapResponsesByIdEntry )
425     {
426         this._mapResponsesByIdEntry = mapResponsesByIdEntry;
427     }
428 
429     public void clearMapResponsesByIdEntry( )
430     {
431         this._mapResponsesByIdEntry.clear( );
432     }
433 
434     /**
435      * Returns the IsSaved
436      * 
437      * @return The IsSaved
438      */
439     public boolean getIsSaved( )
440     {
441         return _bIsSaved;
442     }
443 
444     /**
445      * Sets the IsSaved
446      * 
447      * @param bIsSaved
448      *            The IsSaved
449      */
450     public void setIsSaved( boolean bIsSaved )
451     {
452         _bIsSaved = bIsSaved;
453     }
454 
455     /**
456      * Returns the OverbookingAllowed
457      * 
458      * @return The OverbookingAllowed
459      */
460     public boolean getOverbookingAllowed( )
461     {
462         return _bOverbookingAllowed;
463     }
464 
465     /**
466      * Sets the OverbookingAllowed
467      * 
468      * @param bOverbookingAllowed
469      *            The OverbookingAllowed
470      */
471     public void setOverbookingAllowed( boolean bOverbookingAllowed )
472     {
473         _bOverbookingAllowed = bOverbookingAllowed;
474     }
475 
476     /**
477      * Returns the email confirm
478      *
479      * @return The email confirm
480      */
481     public String getEmailConfirm() {
482         return _strEmailConfirm;
483     }
484 
485     /**
486      * Sets the email confirm
487      *
488      * @param strEmailConfirm
489      *            The email confirm
490      */
491     public void setConfirmEmail(String strEmailConfirm) {
492         this._strEmailConfirm = strEmailConfirm;
493     }
494 
495     /**
496      * Get all the possible errors of the form
497      * 
498      * @param locale
499      *            the locale
500      * @return a list of all the possible errors of the form
501      */
502     public static List<String> getAllErrors( Locale locale )
503     {
504         List<String> listAllErrors = new ArrayList<>( );
505         listAllErrors.add( I18nService.getLocalizedString( PROPERTY_EMPTY_FIELD_LAST_NAME, locale ) );
506         listAllErrors.add( I18nService.getLocalizedString( PROPERTY_EMPTY_FIELD_FIRST_NAME, locale ) );
507         listAllErrors.add( I18nService.getLocalizedString( PROPERTY_UNVAILABLE_EMAIL, locale ) );
508         listAllErrors.add( I18nService.getLocalizedString( PROPERTY_MESSAGE_EMPTY_EMAIL, locale ) );
509         listAllErrors.add( I18nService.getLocalizedString( PROPERTY_EMPTY_CONFIRM_EMAIL, locale ) );
510         listAllErrors.add( I18nService.getLocalizedString( PROPERTY_UNVAILABLE_CONFIRM_EMAIL, locale ) );
511         listAllErrors.add( I18nService.getLocalizedString( PROPERTY_EMPTY_NB_SEATS, locale ) );
512         listAllErrors.add( I18nService.getLocalizedString( PROPERTY_UNVAILABLE_NB_SEATS, locale ) );
513         listAllErrors.add( I18nService.getLocalizedString( PROPERTY_MAX_APPOINTMENT_PERIODE, locale ) );
514         listAllErrors.add( I18nService.getLocalizedString( PROPERTY_MAX_APPOINTMENT_PERIODE_BACK, locale ) );
515         listAllErrors.add( I18nService.getLocalizedString( PROPERTY_NB_DAY_BETWEEN_TWO_APPOINTMENTS, locale ) );
516         return listAllErrors;
517     }
518 
519 }