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.appointment;
35
36 import java.sql.Timestamp;
37 import java.time.LocalDateTime;
38 import java.util.ArrayList;
39 import java.util.List;
40
41 import javax.validation.Valid;
42
43 import fr.paris.lutece.plugins.appointment.business.slot.Slot;
44 import fr.paris.lutece.plugins.appointment.business.user.User;
45
46 /**
47 * Business class of the Appointment
48 *
49 * @author Laurent Payen
50 *
51 */
52 public class Appointment extends User
53 {
54
55 /**
56 * Appointment resource type
57 */
58 public static final String APPOINTMENT_RESOURCE_TYPE = "appointment";
59
60 /**
61 * Serial version UID
62 */
63 private static final long serialVersionUID = -132212832777629802L;
64
65 /**
66 * Appointment Id
67 */
68 private int _nIdAppointment;
69
70 /**
71 * Reference of the Appointment
72 */
73 private String _strReference;
74
75 /**
76 * Number of places for the appointment
77 */
78 private int _nNbPlaces;
79 /**
80 * Tell if the appointment is cancelled or not
81 */
82 private boolean _bIsCancelled;
83
84 /**
85 * Id for a cancelled appointment
86 */
87 private int _nIdActionCancelled;
88
89 /**
90 * Id for a reported appointment
91 */
92 private int _nIdActionReported;
93
94 /**
95 * The rank for the notification (0 : no notification)
96 */
97 private int _notification;
98
99 /**
100 * The Admin User Id assigned to the appointment
101 */
102 private int _nIdAdminUser;
103
104 /**
105 * The Admin User who created the appointment (if not created by the user himself)
106 */
107 private String _strAdminUserCreate;
108
109 /**
110 * The slots on which the appointment is
111 */
112 private List<Slot> _listSlot;
113
114 /**
115 * The user of the appointment
116 */
117 @Valid
118 private User _user;
119 /**
120 * The date appointment taken
121 */
122 private LocalDateTime _dateAppointmentTaken;
123
124 /**
125 * The appointment slots
126 */
127 private List<AppointmentSlot> _listAppointmentSlot;
128
129 /**
130 * Tell if the appointment is surbooked or not
131 */
132 private boolean _bIsSurbooked;
133
134 /**
135 * Get the reference of the appointment
136 *
137 * @return the reference
138 */
139 public String getReference( )
140 {
141 return _strReference;
142 }
143
144 /**
145 * Set the reference of the appointment
146 *
147 * @param strReference
148 * the reference to set
149 */
150 public void setReference( String strReference )
151 {
152 this._strReference = strReference;
153 }
154
155 /**
156 * Get the number of places of the appointment
157 *
158 * @return the number of places
159 */
160 public int getNbPlaces( )
161 {
162 return _nNbPlaces;
163 }
164
165 /**
166 * Set the number of places for the appointment
167 *
168 * @param nNbPlaces
169 * the number of places to set
170 */
171 public void setNbPlaces( int nNbPlaces )
172 {
173 this._nNbPlaces = nNbPlaces;
174 }
175
176 /**
177 * Get if the appointment is cancelled
178 *
179 * @return true if the appointment is cancelled
180 */
181 public boolean getIsCancelled( )
182 {
183 return _bIsCancelled;
184 }
185
186 /**
187 * Set if the appointment is cancelled
188 *
189 * @param bIsCancelled
190 * the boolean value to set
191 */
192 public void setIsCancelled( boolean bIsCancelled )
193 {
194 this._bIsCancelled = bIsCancelled;
195 }
196
197 /**
198 * Get the id for the cancelled appointment
199 *
200 * @return the id
201 */
202 public int getIdActionCancelled( )
203 {
204 return _nIdActionCancelled;
205 }
206
207 /**
208 * Set the id for the cancelled action
209 *
210 * @param nIdActionCancelled
211 * the id to set
212 */
213 public void setIdActionCancelled( int nIdActionCancelled )
214 {
215 this._nIdActionCancelled = nIdActionCancelled;
216 }
217
218 /**
219 * Get the id for the reported appointment
220 *
221 * @return the id
222 */
223 public int getIdActionReported( )
224 {
225 return _nIdActionReported;
226 }
227
228 /**
229 * Set the id for the reported action
230 *
231 * @param nIdActionReported
232 * the id to set
233 */
234 public void setIdActionReported( int nIdActionReported )
235 {
236 this._nIdActionReported = nIdActionReported;
237 }
238
239 /**
240 * Get the rank for the notification (0 = no notification)
241 *
242 * @return the rank
243 */
244 public int getNotification( )
245 {
246 return _notification;
247 }
248
249 /**
250 * Set the rank for the notification
251 *
252 * @param notification
253 * the rank (default : 0, no notification)
254 */
255 public void setNotification( int notification )
256 {
257 this._notification = notification;
258 }
259
260 /**
261 * Get the Appointment Id
262 *
263 * @return the Appointment Id
264 */
265 public int getIdAppointment( )
266 {
267 return _nIdAppointment;
268 }
269
270 /**
271 * Set the Appointment Id
272 *
273 * @param nIdAppointment
274 * the Appointment Id to set
275 */
276 public void setIdAppointment( int nIdAppointment )
277 {
278 this._nIdAppointment = nIdAppointment;
279 }
280
281 /**
282 * get the admin user assigned to the appointment
283 *
284 * @return the assigned admin user id (if exists)
285 */
286 public int getIdAdminUser( )
287 {
288 return _nIdAdminUser;
289 }
290
291 /**
292 * set admin user id assigned to the appointment
293 *
294 * @param nIdAdminUser
295 */
296 public void setIdAdminUser( int nIdAdminUser )
297 {
298 this._nIdAdminUser = nIdAdminUser;
299 }
300
301 /**
302 * get the admin user who created the appointment (if exists)
303 *
304 * @return the admin user (if exists, null otherwise)
305 */
306 public String getAdminUserCreate( )
307 {
308 return _strAdminUserCreate;
309 }
310
311 /**
312 * set admin user id who created the appointment
313 *
314 * @param strAdminUser
315 */
316 public void setAdminUserCreate( String strAdminUser )
317 {
318 this._strAdminUserCreate = strAdminUser;
319 }
320
321 /**
322 * Get the list slot of the appointment
323 *
324 * @return the list of slot
325 */
326 public List<Slot> getSlot( )
327 {
328 return _listSlot;
329 }
330
331 /**
332 * Set the listslot of the appointment
333 *
334 * @param listSlot
335 * the slot to set
336 */
337 public void setSlot( List<Slot> listSlot )
338 {
339 _listSlot = listSlot;
340 }
341
342 public void addAllSlot( List<Slot> listSlot )
343 {
344
345 if ( _listSlot == null )
346 {
347
348 _listSlot = new ArrayList<>( );
349 }
350 _listSlot.addAll( listSlot );
351
352 }
353
354 public void addSlot( Slot slot )
355 {
356
357 if ( _listSlot == null )
358 {
359
360 _listSlot = new ArrayList<>( );
361 }
362
363 if ( _listSlot.stream( ).noneMatch( ( slt -> slt.getIdSlot( ) == slot.getIdSlot( ) ) ) )
364 {
365
366 _listSlot.add( slot );
367 }
368 }
369
370 /**
371 * Get the user of the appointment
372 *
373 * @return the user
374 */
375 public User getUser( )
376 {
377 return _user;
378 }
379
380 /**
381 * Set the user of the appointment
382 *
383 * @param user
384 * the user
385 */
386 public void setUser( User user )
387 {
388 this._user = user;
389 }
390
391 /**
392 * Get the list of appointment slot
393 *
394 * @return the list of appointmentslot
395 */
396 public List<AppointmentSlot> getListAppointmentSlot( )
397 {
398 return _listAppointmentSlot;
399 }
400
401 /**
402 * Set the list of listAppointmentSlot
403 *
404 * @param listAppointmentSlot
405 * the appointment slot to set
406 */
407 public void setListAppointmentSlot( List<AppointmentSlot> listAppointmentSlot )
408 {
409 _listAppointmentSlot = listAppointmentSlot;
410 }
411
412 /**
413 * Returns the DateAppointmentTaken
414 *
415 * @return The DateAppointmentTaken
416 */
417 public LocalDateTime getDateAppointmentTaken( )
418 {
419 return _dateAppointmentTaken;
420 }
421
422 /**
423 * Sets the DateAppointmentTaken
424 *
425 * @param dateAppointmentTaken
426 * The DateAppointmentTaken
427 */
428 public void setDateAppointmentTaken( LocalDateTime dateAppointmentTaken )
429 {
430 _dateAppointmentTaken = dateAppointmentTaken;
431 }
432
433 /**
434 * Get the date appointment taken (in sql date format)
435 *
436 * @return The DateAppointmentTaken
437 */
438 public Timestamp getAppointmentTakenSqlDate( )
439 {
440 Timestamp date = null;
441 if ( _dateAppointmentTaken != null )
442 {
443 date = Timestamp.valueOf( _dateAppointmentTaken );
444 }
445 return date;
446 }
447
448 /**
449 * Set the date appointment taken (in sql date format)
450 *
451 * @param endingValidityDate
452 * The DateAppointmentTaken to set (in sql Date format)
453 */
454 public void setAppointmentTakenSqlDate( Timestamp dateAppointmentTaken )
455 {
456 if ( dateAppointmentTaken != null )
457 {
458 this._dateAppointmentTaken = dateAppointmentTaken.toLocalDateTime( );
459 }
460 else
461 {
462 this._dateAppointmentTaken = null;
463 }
464 }
465
466 /**
467 * Get if the appointment is surbooked
468 *
469 * @return true if the appointment is surbooked
470 */
471 public boolean getIsSurbooked( )
472 {
473 return _bIsSurbooked;
474 }
475
476 /**
477 * Set if the appointment is surbooked
478 *
479 * @param bIsSurbooked
480 * the boolean value to set
481 */
482 public void setIsSurbooked( boolean bIsSurbooked )
483 {
484 this._bIsSurbooked = bIsSurbooked;
485 }
486 }