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.slot;
35  
36  import java.io.Serializable;
37  import java.sql.Timestamp;
38  import java.time.LocalDate;
39  import java.time.LocalDateTime;
40  import java.time.LocalTime;
41  
42  import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
43  
44  /**
45   * The business class of the slot
46   * 
47   * @author Laurent Payen
48   *
49   */
50  @JsonIgnoreProperties( ignoreUnknown = true )
51  public final class Slot implements Serializable, Cloneable
52  {
53  
54      /**
55       * Serial version UID
56       */
57      private static final long serialVersionUID = 9054234926836931062L;
58  
59      /**
60       * Id of the slot
61       */
62      private int _nIdSlot;
63  
64      /**
65       * Date of the slot
66       */
67      private LocalDate _date;
68  
69      /**
70       * Starting Time of The Slot
71       */
72      private LocalTime _startingTime;
73  
74      /**
75       * Ending Time Of The Slot
76       */
77      private LocalTime _endingTime;
78  
79      /**
80       * Starting date (Date + Time) of the slot
81       */
82      private LocalDateTime _startingDateTime;
83  
84      /**
85       * Ending date (Date + Time) of the slot
86       */
87      private LocalDateTime _endingDateTime;
88  
89      /**
90       * Indicate whether the slot is open or not
91       */
92      private boolean _bIsOpen;
93  
94      /**
95       * Indicate whether the slot has been created with the specific week configuration
96       */
97      private boolean _bIsSpecific;
98  
99      /**
100      * Indicate whether the slot is passed or not
101      */
102     private boolean _bIsPassed = Boolean.FALSE;
103 
104     /**
105      * Max Capacity of the Slot
106      */
107     private int _nMaxCapacity;
108 
109     /**
110      * Nb Remaining Places of the slot
111      */
112     private int _nNbRemainingPlaces;
113 
114     /**
115      * Nb Potential Remaining Places of the slot
116      */
117     private int _nNbPotentialRemainingPlaces;
118 
119     /**
120      * Nb Places Taken
121      */
122     private int _nNbPlacesTaken;
123 
124     /**
125      * Form Id the slot belongs to (foreign key)
126      */
127     private int _nIdForm;
128     /**
129      * is full if ( _bIsFull == 1 || _nNbPotentialRemainingPlaces <= 0 ): the slot is full
130      */
131     private int _bIsFull;
132 
133     /**
134      * Get the id of the slot
135      * 
136      * @return the id of the slot
137      */
138     public int getIdSlot( )
139     {
140         return _nIdSlot;
141     }
142 
143     /**
144      * Get the date of the slot
145      * 
146      * @return the date of the slot
147      */
148     public LocalDate getDate( )
149     {
150         return _date;
151     }
152 
153     /**
154      * Set the date of the slot
155      * 
156      * @param date
157      *            the date to set
158      */
159     public void setDate( LocalDate date )
160     {
161         this._date = date;
162     }
163 
164     /**
165      * Get the starting time of the slot
166      * 
167      * @return the starting time of the slot
168      */
169     public LocalTime getStartingTime( )
170     {
171         return _startingTime;
172     }
173 
174     /**
175      * Set the starting time of the slot
176      * 
177      * @param startingTime
178      *            the starting time to set
179      */
180     public void setStartingTime( LocalTime startingTime )
181     {
182         this._startingTime = startingTime;
183     }
184 
185     /**
186      * Get the ending time of the slot
187      * 
188      * @return the ending time of the slot
189      */
190     public LocalTime getEndingTime( )
191     {
192         return _endingTime;
193     }
194 
195     /**
196      * Set the ending time of the slot
197      * 
198      * @param endingTime
199      *            the ending time to set
200      */
201     public void setEndingTime( LocalTime endingTime )
202     {
203         this._endingTime = endingTime;
204     }
205 
206     /**
207      * Set the id of the slot
208      * 
209      * @param nIdSlot
210      *            the id to set
211      */
212     public void setIdSlot( int nIdSlot )
213     {
214         this._nIdSlot = nIdSlot;
215     }
216 
217     /**
218      * Get the starting date of the slot
219      * 
220      * @return the starting date of the slot
221      */
222     public LocalDateTime getStartingDateTime( )
223     {
224         return _startingDateTime;
225     }
226 
227     /**
228      * Get the starting date of the slot
229      * 
230      * @return the starting date of the slot (in Sql Timestamp format)
231      */
232     public Timestamp getStartingTimestampDate( )
233     {
234         Timestamp timestamp = null;
235         if ( this._startingDateTime != null )
236         {
237             timestamp = Timestamp.valueOf( this._startingDateTime );
238         }
239         return timestamp;
240     }
241 
242     /**
243      * Set the starting date of the slot
244      * 
245      * @param startingDateTime
246      *            the starting date to set
247      */
248     public void setStartingDateTime( LocalDateTime startingDateTime )
249     {
250         this._startingDateTime = startingDateTime;
251     }
252 
253     /**
254      * Set the starting date of the slot
255      * 
256      * @param startingTimeStampDate
257      *            the starting date to set (in Timestamp format)
258      */
259     public void setStartingTimeStampDate( Timestamp startingTimeStampDate )
260     {
261         if ( startingTimeStampDate != null )
262         {
263             this._startingDateTime = startingTimeStampDate.toLocalDateTime( );
264         }
265     }
266 
267     /**
268      * Get the ending date of the slot
269      * 
270      * @return the ending date of the slot
271      */
272     public LocalDateTime getEndingDateTime( )
273     {
274         return _endingDateTime;
275     }
276 
277     /**
278      * Get the ending date of the slot
279      * 
280      * @return the ending date of the slot (in Sql Timestamp format)
281      */
282     public Timestamp getEndingTimestampDate( )
283     {
284         Timestamp timestamp = null;
285         if ( this._endingDateTime != null )
286         {
287             timestamp = Timestamp.valueOf( _endingDateTime );
288         }
289         return timestamp;
290     }
291 
292     /**
293      * Set the ending date of the slot
294      * 
295      * @param endingDateTime
296      *            the ending date of the slot (in LocalDateTime format)
297      */
298     public void setEndingDateTime( LocalDateTime endingDateTime )
299     {
300         this._endingDateTime = endingDateTime;
301     }
302 
303     /**
304      * Set the ending date of the slot
305      * 
306      * @param endingTimeStampDate
307      *            the ending date of the slot (in Timestamp format)
308      */
309     public void setEndingTimeStampDate( Timestamp endingTimeStampDate )
310     {
311         if ( endingTimeStampDate != null )
312         {
313             this._endingDateTime = endingTimeStampDate.toLocalDateTime( );
314         }
315     }
316 
317     /**
318      * Indicate if the slot is open or not
319      * 
320      * @return true if the slot is open
321      */
322     public boolean getIsOpen( )
323     {
324         return _bIsOpen;
325     }
326 
327     /**
328      * Set the boolean open value of the slot
329      * 
330      * @param bIsOpen
331      *            the boolean open value to set
332      */
333     public void setIsOpen( boolean bIsOpen )
334     {
335         this._bIsOpen = bIsOpen;
336     }
337 
338     /**
339      * Indicate if the slot is specific or not
340      * 
341      * @return true if the slot is specific
342      */
343     public boolean getIsSpecific( )
344     {
345         return _bIsSpecific;
346     }
347 
348     /**
349      * Set the boolean specific value of the slot
350      * 
351      * @param bIsSpecific
352      *            the boolean open value to set
353      */
354     public void setIsSpecific( boolean bIsSpecific )
355     {
356         this._bIsSpecific = bIsSpecific;
357     }
358 
359     /**
360      * Indicate if the slot is passed or not
361      * 
362      * @return true if the slot is specific
363      */
364     public boolean getIsPassed( )
365     {
366         return _bIsPassed;
367     }
368 
369     /**
370      * Set the boolean passed value of the slot
371      * 
372      * @param bIsSpecific
373      *            the boolean open value to set
374      */
375     public void setIsPassed( boolean bIsPassed )
376     {
377         this._bIsPassed = bIsPassed;
378     }
379 
380     /**
381      * Get number of remaining places of the slot
382      * 
383      * @return the number of remaining places of the slot
384      */
385     public int getNbRemainingPlaces( )
386     {
387         return _nNbRemainingPlaces;
388     }
389 
390     /**
391      * Set the number of remaining places of the slot
392      * 
393      * @param nNbRemainingPlaces
394      *            the number of remaining places
395      */
396     public void setNbRemainingPlaces( int nNbRemainingPlaces )
397     {
398         this._nNbRemainingPlaces = nNbRemainingPlaces;
399     }
400 
401     /**
402      * Get the potential remaining places on the slot
403      * 
404      * @return the number of potential ramaining places
405      */
406     public int getNbPotentialRemainingPlaces( )
407     {
408         return _nNbPotentialRemainingPlaces;
409     }
410 
411     /**
412      * Set the potential number of remaining places on the slot
413      * 
414      * @param nNbPotentialRemainingPlaces
415      *            the number to set
416      */
417     public void setNbPotentialRemainingPlaces( int nNbPotentialRemainingPlaces )
418     {
419         this._nNbPotentialRemainingPlaces = nNbPotentialRemainingPlaces;
420     }
421 
422     /**
423      * Get the nb places taken on the slot
424      * 
425      * @return the number of places taken
426      */
427     public int getNbPlacesTaken( )
428     {
429         return _nNbPlacesTaken;
430     }
431 
432     /**
433      * Set the number of places taken on the slot
434      * 
435      * @param nNbPlacesTaken
436      *            the number to set
437      */
438     public void setNbPlacestaken( int nNbPlacestaken )
439     {
440         this._nNbPlacesTaken = nNbPlacestaken;
441     }
442 
443     /**
444      * Get the maximum capacity of the slot
445      * 
446      * @return the maximum capacity
447      */
448     public int getMaxCapacity( )
449     {
450         return _nMaxCapacity;
451     }
452 
453     /**
454      * Set the maximum capacity of the slot
455      * 
456      * @param nMaxCapacity
457      *            the maximum capacity to set
458      */
459     public void setMaxCapacity( int nMaxCapacity )
460     {
461         this._nMaxCapacity = nMaxCapacity;
462     }
463 
464     /**
465      * Get the Form Id the slot belongs to
466      * 
467      * @return the FOrm Id
468      */
469     public int getIdForm( )
470     {
471         return _nIdForm;
472     }
473 
474     /**
475      * Set the Form Id the Slot belongs to
476      * 
477      * @param nIdForm
478      *            the Form Id to set
479      */
480     public void setIdForm( int nIdForm )
481     {
482         this._nIdForm = nIdForm;
483     }
484 
485     /**
486      * Returns the IsFull
487      * 
488      * @return The IsFull
489      */
490     public boolean getIsFull( )
491     {
492         if ( _bIsFull == 1 )
493         {
494             return true;
495         }
496         return _nNbPotentialRemainingPlaces <= 0;
497 
498     }
499 
500     /**
501      * Sets the IsFull
502      * 
503      * @param bIsFull
504      *            The IsFull ( _bIsFull == 1: if is full)
505      */
506     public void setIsFull( int bIsFull )
507     {
508         _bIsFull = bIsFull;
509     }
510     @Override
511     public Slot clone() throws CloneNotSupportedException {
512       return (Slot) super.clone();
513     }
514 }