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