1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.appointment.service;
35
36 import java.time.LocalDate;
37 import java.time.LocalDateTime;
38 import java.time.LocalTime;
39 import java.util.HashMap;
40 import java.util.List;
41 import java.util.Map;
42 import java.util.stream.Collectors;
43
44 import org.apache.commons.collections.CollectionUtils;
45
46 import fr.paris.lutece.plugins.appointment.business.planning.TimeSlot;
47 import fr.paris.lutece.plugins.appointment.business.planning.WeekDefinition;
48 import fr.paris.lutece.plugins.appointment.business.planning.WorkingDay;
49 import fr.paris.lutece.plugins.appointment.business.rule.ReservationRule;
50 import fr.paris.lutece.plugins.appointment.business.slot.Period;
51 import fr.paris.lutece.plugins.appointment.business.slot.Slot;
52 import fr.paris.lutece.plugins.appointment.business.slot.SlotHome;
53 import fr.paris.lutece.plugins.appointment.service.listeners.SlotListenerManager;
54
55
56
57
58
59
60
61 public final class SlotService
62 {
63
64
65
66
67 private SlotService( )
68 {
69 }
70
71
72
73
74
75
76
77
78
79
80
81
82 public static List<Slot> findSlotsByIdFormAndDateRange( int nIdForm, LocalDateTime startingDateTime, LocalDateTime endingDateTime )
83 {
84 List<Slot> listSlots = SlotHome.findByIdFormAndDateRange( nIdForm, startingDateTime, endingDateTime );
85 for ( Slot slot : listSlots )
86 {
87 addDateAndTimeToSlot( slot );
88 }
89 return listSlots;
90 }
91
92
93
94
95
96
97
98
99
100
101
102
103 public static List<Slot> findSlotWithAppointmentByDateRange( int nIdForm, LocalDateTime startingDateTime, LocalDateTime endingDateTime )
104 {
105 List<Slot> listSlots = SlotHome.findSlotWithAppointmentByDateRange( nIdForm, startingDateTime, endingDateTime );
106 for ( Slot slot : listSlots )
107 {
108 addDateAndTimeToSlot( slot );
109 }
110 return listSlots;
111 }
112
113
114
115
116
117
118
119
120 public static List<Slot> findSpecificSlotsByIdForm( int nIdForm )
121 {
122 List<Slot> listSpecificSlots = SlotHome.findIsSpecificByIdForm( nIdForm );
123 for ( Slot slot : listSpecificSlots )
124 {
125 addDateAndTimeToSlot( slot );
126 }
127 return listSpecificSlots;
128 }
129
130
131
132
133
134
135
136
137
138
139
140
141 public static HashMap<LocalDateTime, Slot> buildMapSlotsByIdFormAndDateRangeWithDateForKey( int nIdForm, LocalDateTime startingDateTime,
142 LocalDateTime endingDateTime )
143 {
144 HashMap<LocalDateTime, Slot> mapSlots = new HashMap<>( );
145 for ( Slot slot : findSlotsByIdFormAndDateRange( nIdForm, startingDateTime, endingDateTime ) )
146 {
147 mapSlots.put( slot.getStartingDateTime( ), slot );
148 }
149 return mapSlots;
150 }
151
152
153
154
155
156
157
158
159 public static List<Slot> findListSlot( int nIdForm )
160 {
161 return SlotHome.findByIdForm( nIdForm );
162 }
163
164
165
166
167
168
169
170
171 public static List<Slot> findListSlotByIdAppointment( int nIdAppointment )
172 {
173 return SlotHome.findByIdAppointment( nIdAppointment );
174 }
175
176
177
178
179
180
181
182
183
184
185
186
187 public static List<Slot> findListOpenSlotByIdFormAndDateRange( int nIdForm, LocalDateTime startingDateTime, LocalDateTime endingDateTime )
188 {
189 return SlotHome.findOpenSlotsByIdFormAndDateRange( nIdForm, startingDateTime, endingDateTime );
190 }
191
192
193
194
195
196
197
198
199 public static Slot findSlotById( int nIdSlot )
200 {
201 Slot slot = SlotHome.findByPrimaryKey( nIdSlot );
202 if ( slot != null )
203 {
204 SlotService.addDateAndTimeToSlot( slot );
205 }
206 return slot;
207 }
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222 public static List<Slot> buildListSlot( int nIdForm, HashMap<LocalDate, WeekDefinition> mapWeekDefinition, LocalDate startingDate, LocalDate endingDate )
223 {
224 Map<WeekDefinition, ReservationRule> mapReservationRule = ReservationRuleService.findAllReservationRule( nIdForm, mapWeekDefinition.values( ) );
225 return buildListSlot( nIdForm, mapReservationRule, startingDate, endingDate, 0 );
226 }
227
228
229
230
231
232
233
234
235
236
237
238
239
240 public static List<Slot> buildListSlot( int nIdForm, Map<WeekDefinition, ReservationRule> mapReservationRule, LocalDate startingDate, LocalDate endingDate )
241 {
242 return buildListSlot( nIdForm, mapReservationRule, startingDate, endingDate, 0 );
243 }
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260 public static List<Slot> buildListSlot( int nIdForm, Map<WeekDefinition, ReservationRule> mapReservationRule, LocalDate startingDate, LocalDate endingDate,
261 int nNbPlaces )
262 {
263 return buildListSlot( nIdForm, mapReservationRule, startingDate, endingDate, nNbPlaces, false );
264 }
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283 public static List<Slot> buildListSlot( int nIdForm, Map<WeekDefinition, ReservationRule> mapReservationRule, LocalDate startingDate, LocalDate endingDate,
284 int nNbPlaces, boolean bAllOpenSlot )
285 {
286 if ( nNbPlaces < 1 )
287 {
288 return CalendarBuilder.buildListSlot( nIdForm, mapReservationRule, startingDate, endingDate );
289 }
290 else
291 {
292 return CalendarBuilder.buildListSlot( nIdForm, mapReservationRule, startingDate, endingDate, nNbPlaces, bAllOpenSlot );
293 }
294 }
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313 public static Slot buildSlot( int nIdForm, Period period, int nMaxCapacity, int nNbRemainingPlaces, int nNbPotentialRemainingPlaces, int nNbPlacesTaken,
314 boolean bIsOpen, boolean bIsSpecific )
315 {
316 Slotugins/appointment/business/slot/Slot.html#Slot">Slot slot = new Slot( );
317 slot.setIdSlot( 0 );
318 slot.setIdForm( nIdForm );
319 slot.setStartingDateTime( period.getStartingDateTime( ) );
320 slot.setEndingDateTime( period.getEndingDateTime( ) );
321 slot.setMaxCapacity( nMaxCapacity );
322 slot.setNbRemainingPlaces( nNbRemainingPlaces );
323 slot.setNbPotentialRemainingPlaces( nNbPotentialRemainingPlaces );
324 slot.setNbPlacestaken( nNbPlacesTaken );
325 slot.setIsOpen( bIsOpen );
326 slot.setIsSpecific( bIsSpecific );
327 addDateAndTimeToSlot( slot );
328 return slot;
329 }
330
331
332
333
334
335
336
337
338 public static boolean isSpecificSlot( Slot slot )
339 {
340 LocalDate dateOfSlot = slot.getStartingDateTime( ).toLocalDate( );
341 ReservationRule reservationRule = ReservationRuleService.findReservationRuleByIdFormAndClosestToDateOfApply( slot.getIdForm( ), dateOfSlot );
342 WorkingDay workingDay = WorkingDayService.getWorkingDayOfDayOfWeek( reservationRule.getListWorkingDay( ), dateOfSlot.getDayOfWeek( ) );
343 List<TimeSlot> listTimeSlot = null;
344 if ( workingDay != null )
345 {
346 listTimeSlot = TimeSlotService.findListTimeSlotByWorkingDay( workingDay.getIdWorkingDay( ) );
347 }
348 return isSpecificSlot( slot, workingDay, listTimeSlot, reservationRule.getMaxCapacityPerSlot( ) );
349 }
350
351
352
353
354
355
356
357
358
359
360
361
362 public static boolean isSpecificSlot( Slot slot, WorkingDay workingDay, List<TimeSlot> listTimeSlot, int nMaxCapacity )
363 {
364 boolean bIsSpecific = Boolean.TRUE;
365 List<TimeSlot> listMatchTimeSlot = null;
366 if ( workingDay == null )
367 {
368 if ( !slot.getIsOpen( ) && slot.getMaxCapacity( ) == nMaxCapacity )
369 {
370 bIsSpecific = Boolean.FALSE;
371 }
372 }
373 else
374 {
375 listMatchTimeSlot = listTimeSlot.stream( )
376 .filter( t -> ( t.getStartingTime( ).equals( slot.getStartingDateTime( ).toLocalTime( ) ) )
377 && ( t.getEndingTime( ).equals( slot.getEndingDateTime( ).toLocalTime( ) ) ) && ( t.getIsOpen( ) == slot.getIsOpen( ) )
378 && ( t.getMaxCapacity( ) == slot.getMaxCapacity( ) ) )
379 .collect( Collectors.toList( ) );
380 if ( CollectionUtils.isNotEmpty( listMatchTimeSlot ) )
381 {
382 bIsSpecific = Boolean.FALSE;
383 }
384 }
385 return bIsSpecific;
386 }
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401 public static void updateSlot( Slot slot, boolean bEndingTimeHasChanged, LocalTime previousEndingTime, boolean bShifSlot )
402 {
403
404 SlotSafeService.updateSlot( slot, bEndingTimeHasChanged, previousEndingTime, bShifSlot );
405
406 }
407
408
409
410
411
412
413
414 public static void updateRemainingPlaces( Slot slot )
415 {
416 SlotSafeService.updateRemainingPlaces( slot );
417 }
418
419
420
421
422
423
424
425
426 public static Slot="../../../../../../fr/paris/lutece/plugins/appointment/business/slot/Slot.html#Slot">Slot saveSlot( Slot slot )
427 {
428 return SlotSafeService.saveSlot( slot );
429
430 }
431
432
433
434
435
436
437
438 public static Slot../../../../../../fr/paris/lutece/plugins/appointment/business/slot/Slot.html#Slot">Slot updateSlot( Slot slot )
439 {
440 return SlotSafeService.updateSlot( slot );
441 }
442
443
444
445
446
447
448
449 public static void addDateAndTimeToSlot( Slot slot )
450 {
451 if ( slot.getStartingDateTime( ) != null )
452 {
453 slot.setDate( slot.getStartingDateTime( ).toLocalDate( ) );
454 slot.setStartingTime( slot.getStartingDateTime( ).toLocalTime( ) );
455 }
456 if ( slot.getEndingDateTime( ) != null )
457 {
458 slot.setEndingTime( slot.getEndingDateTime( ).toLocalTime( ) );
459 }
460 }
461
462
463
464
465
466
467
468
469 public static Slot../../../../../../fr/paris/lutece/plugins/appointment/business/slot/Slot.html#Slot">Slot createSlot( Slot slot )
470 {
471 return SlotSafeService.createSlot( slot );
472 }
473
474
475
476
477
478
479
480 public static void deleteListSlots( List<Slot> listSlotToDelete )
481 {
482
483 for ( Slot slotToDelete : listSlotToDelete )
484 {
485 SlotSafeService.removeSlotInMemory( slotToDelete.getIdSlot( ) );
486 SlotHome.delete( slotToDelete.getIdSlot( ) );
487 SlotListenerManager.notifyListenersSlotRemoval( slotToDelete );
488 }
489
490 }
491
492
493
494
495
496
497
498 public static void deleteSlot( Slot slot )
499 {
500 int nIdSlot = slot.getIdSlot( );
501 SlotSafeService.removeSlotInMemory( nIdSlot );
502 SlotHome.delete( nIdSlot );
503 SlotListenerManager.notifyListenersSlotRemoval( slot );
504 }
505
506
507
508
509
510
511
512
513 public static Slot findSlotWithMaxDate( int nIdForm )
514 {
515 return SlotHome.findSlotWithTheMaxDate( nIdForm );
516 }
517
518 }