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.DayOfWeek;
37 import java.time.LocalDate;
38 import java.time.LocalTime;
39 import java.util.ArrayList;
40 import java.util.List;
41 import java.util.stream.Collectors;
42
43 import org.apache.commons.collections.CollectionUtils;
44
45 import fr.paris.lutece.plugins.appointment.business.appointment.Appointment;
46 import fr.paris.lutece.plugins.appointment.business.comment.CommentHome;
47 import fr.paris.lutece.plugins.appointment.business.display.Display;
48 import fr.paris.lutece.plugins.appointment.business.display.DisplayHome;
49 import fr.paris.lutece.plugins.appointment.business.form.Form;
50 import fr.paris.lutece.plugins.appointment.business.form.FormHome;
51 import fr.paris.lutece.plugins.appointment.business.localization.Localization;
52 import fr.paris.lutece.plugins.appointment.business.localization.LocalizationHome;
53 import fr.paris.lutece.plugins.appointment.business.message.FormMessage;
54 import fr.paris.lutece.plugins.appointment.business.message.FormMessageHome;
55 import fr.paris.lutece.plugins.appointment.business.planning.ClosingDay;
56 import fr.paris.lutece.plugins.appointment.business.planning.ClosingDayHome;
57 import fr.paris.lutece.plugins.appointment.business.planning.TimeSlot;
58 import fr.paris.lutece.plugins.appointment.business.planning.TimeSlotHome;
59 import fr.paris.lutece.plugins.appointment.business.planning.WeekDefinition;
60 import fr.paris.lutece.plugins.appointment.business.planning.WeekDefinitionHome;
61 import fr.paris.lutece.plugins.appointment.business.planning.WorkingDay;
62 import fr.paris.lutece.plugins.appointment.business.planning.WorkingDayHome;
63 import fr.paris.lutece.plugins.appointment.business.rule.FormRule;
64 import fr.paris.lutece.plugins.appointment.business.rule.FormRuleHome;
65 import fr.paris.lutece.plugins.appointment.business.rule.ReservationRule;
66 import fr.paris.lutece.plugins.appointment.business.rule.ReservationRuleHome;
67 import fr.paris.lutece.plugins.appointment.business.slot.Slot;
68 import fr.paris.lutece.plugins.appointment.business.slot.SlotHome;
69 import fr.paris.lutece.plugins.appointment.service.listeners.AppointmentListenerManager;
70 import fr.paris.lutece.plugins.appointment.service.listeners.FormListenerManager;
71 import fr.paris.lutece.plugins.appointment.web.dto.AppointmentFormDTO;
72 import fr.paris.lutece.plugins.genericattributes.business.Entry;
73 import fr.paris.lutece.plugins.genericattributes.business.EntryFilter;
74 import fr.paris.lutece.plugins.genericattributes.business.EntryHome;
75 import fr.paris.lutece.portal.service.util.AppException;
76 import fr.paris.lutece.portal.service.util.AppLogService;
77 import fr.paris.lutece.util.ReferenceList;
78 import fr.paris.lutece.util.sql.TransactionManager;
79
80
81
82
83
84
85
86 public final class FormService
87 {
88
89
90
91
92 private FormService( )
93 {
94 }
95
96
97
98
99
100
101
102
103
104
105 public static int copyForm( int nIdForm, String newNameForCopy )
106 {
107
108 AppointmentFormDTO appointmentForm = buildAppointmentForm( nIdForm, 0 );
109 appointmentForm.setTitle( newNameForCopy );
110 appointmentForm.setIsActive( Boolean.FALSE );
111 appointmentForm.setDateStartValidity( null );
112 appointmentForm.setDateEndValidity( null );
113
114 Form form = FormService.createForm( appointmentForm );
115 int nIdNewForm = form.getIdForm( );
116
117 DisplayService.createDisplay( appointmentForm, nIdNewForm );
118
119 LocalizationService.createLocalization( appointmentForm, nIdNewForm );
120
121 FormRuleService.createFormRule( appointmentForm, nIdNewForm );
122
123
124
125 WeekDefinition copyWeekDefinition;
126 int idCopyReservationRule;
127 WorkingDay copyWorkingDay;
128 int idCopyWorkingDay;
129 TimeSlot copyTimeSlot;
130 List<WeekDefinition> listWeekDefinitions = WeekDefinitionService.findListWeekDefinition( nIdForm );
131 List<WorkingDay> listWorkingDays;
132 List<TimeSlot> listTimeSlots;
133
134
135
136 ReservationRule copyReservationRule;
137 List<ReservationRule> listReservationRules = ReservationRuleService.findListReservationRule( nIdForm );
138 for ( ReservationRule reservationRule : listReservationRules )
139 {
140 int nOldReservationRule = reservationRule.getIdReservationRule( );
141 copyReservationRule = reservationRule;
142 copyReservationRule.setIdReservationRule( 0 );
143 copyReservationRule.setIdForm( nIdNewForm );
144 ReservationRuleService.saveReservationRule( copyReservationRule );
145 listWorkingDays = copyReservationRule.getListWorkingDay( );
146 idCopyReservationRule = copyReservationRule.getIdReservationRule( );
147
148 for ( WorkingDay workingDay : listWorkingDays )
149 {
150 copyWorkingDay = workingDay;
151 copyWorkingDay.setIdWorkingDay( 0 );
152 copyWorkingDay.setIdReservationRule( idCopyReservationRule );
153 copyWorkingDay = WorkingDayService.saveWorkingDay( copyWorkingDay );
154 idCopyWorkingDay = copyWorkingDay.getIdWorkingDay( );
155 listTimeSlots = workingDay.getListTimeSlot( );
156 for ( TimeSlot timeSlot : listTimeSlots )
157 {
158 copyTimeSlot = timeSlot;
159 copyTimeSlot.setIdTimeSlot( 0 );
160 copyTimeSlot.setIdWorkingDay( idCopyWorkingDay );
161 TimeSlotService.saveTimeSlot( copyTimeSlot );
162 }
163 }
164 List<WeekDefinition> listWeekDef = listWeekDefinitions.stream( ).filter( week -> week.getIdReservationRule( ) == nOldReservationRule )
165 .collect( Collectors.toList( ) );
166 if ( CollectionUtils.isNotEmpty( listWeekDef ) )
167 {
168
169 for ( WeekDefinition weekDefinition : listWeekDef )
170 {
171 copyWeekDefinition = weekDefinition;
172 copyWeekDefinition.setIdWeekDefinition( 0 );
173 copyWeekDefinition.setIdReservationRule( idCopyReservationRule );
174 WeekDefinitionHome.create( copyWeekDefinition );
175 }
176 }
177 }
178
179
180 FormMessage formMessage = FormMessageService.findFormMessageByIdForm( nIdForm );
181 FormMessage copyFormMessage = formMessage;
182 copyFormMessage.setIdFormMessage( 0 );
183 copyFormMessage.setIdForm( nIdNewForm );
184 FormMessageService.saveFormMessage( copyFormMessage );
185
186
187 List<ClosingDay> listClosingDays = ClosingDayService.findListClosingDay( nIdForm );
188 ClosingDay copyClosingDay;
189 for ( ClosingDay closingDay : listClosingDays )
190 {
191 copyClosingDay = closingDay;
192 copyClosingDay.setIdClosingDay( 0 );
193 copyClosingDay.setIdForm( nIdNewForm );
194 ClosingDayService.saveClosingDay( copyClosingDay );
195 }
196
197
198 List<Slot> listSpecificSlots = SlotService.findSpecificSlotsByIdForm( nIdForm );
199 Slot copySpecificSlot;
200 for ( Slot specificSlot : listSpecificSlots )
201 {
202 copySpecificSlot = specificSlot;
203
204 copySpecificSlot.setIdSlot( 0 );
205 copySpecificSlot.setIdForm( nIdNewForm );
206 copySpecificSlot.setNbPotentialRemainingPlaces( specificSlot.getMaxCapacity( ) );
207 copySpecificSlot.setNbRemainingPlaces( specificSlot.getMaxCapacity( ) );
208 copySpecificSlot.setNbPlacestaken( 0 );
209
210 SlotHome.create( copySpecificSlot );
211 }
212
213 EntryFilter entryFilter = new EntryFilter( );
214 entryFilter.setIdResource( nIdForm );
215 entryFilter.setResourceType( AppointmentFormDTO.RESOURCE_TYPE );
216 entryFilter.setEntryParentNull( EntryFilter.FILTER_TRUE );
217 entryFilter.setFieldDependNull( EntryFilter.FILTER_TRUE );
218 List<Entry> listEntries = EntryHome.getEntryList( entryFilter );
219 for ( Entry entry : listEntries )
220 {
221 entry.setIdResource( nIdNewForm );
222 EntryHome.copy( entry );
223 }
224 FormListenerManager.notifyListenersFormCreation( nIdForm );
225 return nIdNewForm;
226 }
227
228
229
230
231
232
233
234
235 public static Form="../../../../../../fr/paris/lutece/plugins/appointment/business/form/Form.html#Form">Form saveForm( Form form )
236 {
237 return FormHome.create( form );
238 }
239
240
241
242
243
244
245
246
247 public static int createAppointmentForm( AppointmentFormDTO appointmentForm )
248 {
249 Form form = FormService.createForm( appointmentForm );
250 int nIdForm = form.getIdForm( );
251 FormMessageService.createFormMessageWithDefaultValues( nIdForm );
252 LocalDate dateNow = LocalDate.now( );
253 DisplayService.createDisplay( appointmentForm, nIdForm );
254 LocalizationService.createLocalization( appointmentForm, nIdForm );
255 FormRuleService.createFormRule( appointmentForm, nIdForm );
256 ReservationRule reservationRule = ReservationRuleService.createReservationRule( appointmentForm, nIdForm );
257 int nMaxCapacity = reservationRule.getMaxCapacityPerSlot( );
258 LocalDate startWeek = ( appointmentForm.getDateStartValidity( ) != null ) ? appointmentForm.getDateStartValidity( ).toLocalDate( ) : dateNow;
259 LocalDate endWeek = ( appointmentForm.getDateEndValidity( ) != null ) ? appointmentForm.getDateEndValidity( ).toLocalDate( ) : startWeek.plusYears( 1 );
260 WeekDefinitionService.createWeekDefinition( reservationRule.getIdReservationRule( ), startWeek, endWeek );
261 LocalTime startingTime = LocalTime.parse( appointmentForm.getTimeStart( ) );
262 LocalTime endingTime = LocalTime.parse( appointmentForm.getTimeEnd( ) );
263 int nDuration = appointmentForm.getDurationAppointments( );
264 for ( DayOfWeek dayOfWeek : WorkingDayService.getOpenDays( appointmentForm ) )
265 {
266 WorkingDayService.generateWorkingDayAndListTimeSlot( reservationRule.getIdReservationRule( ), dayOfWeek, startingTime, endingTime, nDuration,
267 nMaxCapacity );
268 }
269 FormListenerManager.notifyListenersFormCreation( nIdForm );
270 return nIdForm;
271 }
272
273
274
275
276
277
278
279
280 public static void updateGlobalParameters( AppointmentFormDTO appointmentForm )
281 {
282 int nIdForm = appointmentForm.getIdForm( );
283 DisplayService.updateDisplay( appointmentForm, nIdForm );
284 LocalizationService.updateLocalization( appointmentForm, nIdForm );
285 FormRuleService.updateFormRule( appointmentForm, nIdForm );
286 FormService.updateForm( appointmentForm );
287 }
288
289
290
291
292
293
294 public static List<AppointmentFormDTO> buildAllActiveAppointmentForm( )
295 {
296 List<AppointmentFormDTO> listActiveAppointmentForm = new ArrayList<>( );
297 for ( Form form : FormHome.findActiveForms( ) )
298 {
299 listActiveAppointmentForm.add( buildAppointmentForm( form.getIdForm( ), 0 ) );
300 }
301 return listActiveAppointmentForm;
302 }
303
304
305
306
307
308
309
310 public static List<AppointmentFormDTO> buildAllAppointmentFormLight( )
311 {
312 List<AppointmentFormDTO> listAppointmentFormLight = new ArrayList<>( );
313 for ( Form form : FormService.findAllForms( ) )
314 {
315 listAppointmentFormLight.add( buildAppointmentFormLight( form ) );
316 }
317 return listAppointmentFormLight;
318 }
319
320
321
322
323
324
325 public static ReferenceList findAllInReferenceList( )
326 {
327 List<Form> listForm = findAllForms( );
328 ReferenceList refListForms = new ReferenceList( listForm.size( ) );
329 for ( Form form : listForm )
330 {
331 refListForms.addItem( form.getIdForm( ), form.getTitle( ) );
332 }
333 return refListForms;
334 }
335
336
337
338
339
340
341 public static List<AppointmentFormDTO> buildAllActiveAndDisplayedOnPortletAppointmentForm( )
342 {
343 List<AppointmentFormDTO> listAppointmentForm = new ArrayList<>( );
344 for ( Form form : FormService.findAllActiveAndDisplayedOnPortletForms( ) )
345 {
346 listAppointmentForm.add( buildAppointmentForm( form.getIdForm( ), 0 ) );
347 }
348 return listAppointmentForm;
349 }
350
351
352
353
354
355
356
357
358 public static AppointmentFormDTO buildAppointmentFormLight( Form form )
359 {
360 AppointmentFormDTO/AppointmentFormDTO.html#AppointmentFormDTO">AppointmentFormDTO appointmentForm = new AppointmentFormDTO( );
361 if ( form != null )
362 {
363 fillAppointmentFormWithFormPart( appointmentForm, form );
364 }
365 return appointmentForm;
366 }
367
368
369
370
371
372
373
374
375 public static AppointmentFormDTO buildAppointmentFormLight( int nIdForm )
376 {
377 Form form = FormService.findFormLightByPrimaryKey( nIdForm );
378 return buildAppointmentFormLight( form );
379 }
380
381
382
383
384
385
386
387
388
389
390
391 public static AppointmentFormDTO buildAppointmentForm( int nIdForm, int nIdReservationRule )
392 {
393 ReservationRule reservationRule = null;
394 if ( nIdReservationRule > 0 )
395 {
396 reservationRule = ReservationRuleService.findReservationRuleById( nIdReservationRule );
397 }
398 return buildAppointmentForm( nIdForm, reservationRule );
399 }
400
401
402
403
404
405
406
407
408
409
410
411 public static AppointmentFormDTO buildAppointmentForm( int nIdForm, ReservationRule reservationRule )
412 {
413 AppointmentFormDTO appointmentForm = buildAppointmentFormWithoutReservationRule( nIdForm );
414 LocalDate dateOfApply = LocalDate.now( );
415 if ( reservationRule == null )
416 {
417 reservationRule = ReservationRuleService.findReservationRuleByIdFormAndClosestToDateOfApply( nIdForm, dateOfApply );
418 }
419
420 if ( reservationRule != null )
421 {
422 fillAppointmentFormWithReservationRulePart( appointmentForm, reservationRule );
423 }
424
425 return appointmentForm;
426 }
427
428
429
430
431
432
433
434
435
436 public static AppointmentFormDTO buildAppointmentFormWithoutReservationRule( int nIdForm )
437 {
438 AppointmentFormDTO/AppointmentFormDTO.html#AppointmentFormDTO">AppointmentFormDTO appointmentForm = new AppointmentFormDTO( );
439 Form form = FormService.findFormLightByPrimaryKey( nIdForm );
440 fillAppointmentFormWithFormPart( appointmentForm, form );
441 Display display = DisplayService.findDisplayWithFormId( form.getIdForm( ) );
442 if ( display != null )
443 {
444 fillAppointmentFormWithDisplayPart( appointmentForm, display );
445 }
446 Localization localization = LocalizationService.findLocalizationWithFormId( form.getIdForm( ) );
447 if ( localization != null )
448 {
449 fillAppointmentFormWithLocalizationPart( appointmentForm, localization );
450 }
451 FormRule formRule = FormRuleService.findFormRuleWithFormId( form.getIdForm( ) );
452 if ( formRule != null )
453 {
454 fillAppointmentFormWithFormRulePart( appointmentForm, formRule );
455 }
456
457 return appointmentForm;
458 }
459
460
461
462
463
464
465
466
467
468 public static void fillAppointmentFormWithReservationRulePart( AppointmentFormDTO appointmentForm, ReservationRule reservationRule )
469 {
470 List<WorkingDay> listWorkingDay = reservationRule.getListWorkingDay( );
471 if ( CollectionUtils.isNotEmpty( listWorkingDay ) )
472 {
473 for ( WorkingDay workingDay : listWorkingDay )
474 {
475 DayOfWeek dayOfWeek = DayOfWeek.of( workingDay.getDayOfWeek( ) );
476 switch( dayOfWeek )
477 {
478 case MONDAY:
479 appointmentForm.setIsOpenMonday( Boolean.TRUE );
480 break;
481 case TUESDAY:
482 appointmentForm.setIsOpenTuesday( Boolean.TRUE );
483 break;
484 case WEDNESDAY:
485 appointmentForm.setIsOpenWednesday( Boolean.TRUE );
486 break;
487 case THURSDAY:
488 appointmentForm.setIsOpenThursday( Boolean.TRUE );
489 break;
490 case FRIDAY:
491 appointmentForm.setIsOpenFriday( Boolean.TRUE );
492 break;
493 case SATURDAY:
494 appointmentForm.setIsOpenSaturday( Boolean.TRUE );
495 break;
496 case SUNDAY:
497 appointmentForm.setIsOpenSunday( Boolean.TRUE );
498 break;
499 }
500 }
501
502
503 LocalTime minStartingTime = WorkingDayService.getMinStartingTimeOfAListOfWorkingDay( listWorkingDay );
504 LocalTime maxEndingTime = WorkingDayService.getMaxEndingTimeOfAListOfWorkingDay( listWorkingDay );
505 appointmentForm.setTimeStart( minStartingTime.toString( ) );
506 appointmentForm.setTimeEnd( maxEndingTime.toString( ) );
507 }
508 appointmentForm.setDurationAppointments( reservationRule.getDurationAppointments( ) );
509 appointmentForm.setIdReservationRule( reservationRule.getIdReservationRule( ) );
510 appointmentForm.setMaxCapacityPerSlot( reservationRule.getMaxCapacityPerSlot( ) );
511 appointmentForm.setMaxPeoplePerAppointment( reservationRule.getMaxPeoplePerAppointment( ) );
512 appointmentForm.setName( reservationRule.getName( ) );
513 appointmentForm.setDescriptionRule( reservationRule.getDescriptionRule( ) );
514 appointmentForm.setColor( reservationRule.getColor( ) );
515 }
516
517
518
519
520
521
522
523
524
525 private static void fillAppointmentFormWithFormRulePart( AppointmentFormDTO appointmentForm, FormRule formRule )
526 {
527 appointmentForm.setEnableCaptcha( formRule.getIsCaptchaEnabled( ) );
528 appointmentForm.setEnableMandatoryEmail( formRule.getIsMandatoryEmailEnabled( ) );
529 appointmentForm.setActiveAuthentication( formRule.getIsActiveAuthentication( ) );
530 appointmentForm.setNbDaysBeforeNewAppointment( formRule.getNbDaysBeforeNewAppointment( ) );
531 appointmentForm.setMinTimeBeforeAppointment( formRule.getMinTimeBeforeAppointment( ) );
532 appointmentForm.setNbMaxAppointmentsPerUser( formRule.getNbMaxAppointmentsPerUser( ) );
533 appointmentForm.setNbDaysForMaxAppointmentsPerUser( formRule.getNbDaysForMaxAppointmentsPerUser( ) );
534 appointmentForm.setBoOverbooking( formRule.getBoOverbooking( ) );
535 }
536
537
538
539
540
541
542
543
544
545 private static void fillAppointmentFormWithFormPart( AppointmentFormDTO appointmentForm, Form form )
546 {
547 appointmentForm.setIdForm( form.getIdForm( ) );
548 appointmentForm.setTitle( form.getTitle( ) );
549 appointmentForm.setDescription( form.getDescription( ) );
550 appointmentForm.setReference( form.getReference( ) );
551 if ( form.getIdCategory( ) == null || form.getIdCategory( ) == 0 )
552 {
553 appointmentForm.setIdCategory( -1 );
554 }
555 else
556 {
557 appointmentForm.setIdCategory( form.getIdCategory( ) );
558 }
559 appointmentForm.setDateStartValidity( form.getStartingValiditySqlDate( ) );
560 appointmentForm.setDateEndValidity( form.getEndingValiditySqlDate( ) );
561 appointmentForm.setIdWorkflow( form.getIdWorkflow( ) );
562 appointmentForm.setWorkgroup( form.getWorkgroup( ) );
563 appointmentForm.setIsActive( form.getIsActive( ) );
564 appointmentForm.setIsMultislotAppointment( form.getIsMultislotAppointment( ) );
565 appointmentForm.setNbConsecutiveSlots( form.getNbConsecutiveSlots( ) );
566 appointmentForm.setRole( form.getRole( ) );
567 appointmentForm.setCapacityPerSlot( form.getCapacityPerSlot( ) );
568 appointmentForm.setAnonymizable(form.isAnonymizable());
569 appointmentForm.setAnonymizationPattern(form.getAnonymizationPattern());
570 }
571
572
573
574
575
576
577
578
579
580 private static void fillAppointmentFormWithDisplayPart( AppointmentFormDTO appointmentForm, Display display )
581 {
582 appointmentForm.setDisplayTitleFo( display.isDisplayTitleFo( ) );
583 appointmentForm.setIcon( display.getIcon( ) );
584 appointmentForm.setNbWeeksToDisplay( display.getNbWeeksToDisplay( ) );
585 appointmentForm.setIsDisplayedOnPortlet( display.isDisplayedOnPortlet( ) );
586 appointmentForm.setCalendarTemplateId( display.getIdCalendarTemplate( ) );
587 }
588
589
590
591
592
593
594
595
596
597 private static void fillAppointmentFormWithLocalizationPart( AppointmentFormDTO appointmentForm, Localization localization )
598 {
599 if ( localization != null )
600 {
601 if ( localization.getLongitude( ) != null )
602 {
603 appointmentForm.setLongitude( localization.getLongitude( ) );
604 }
605 if ( localization.getLatitude( ) != null )
606 {
607 appointmentForm.setLatitude( localization.getLatitude( ) );
608 }
609 if ( localization.getAddress( ) != null )
610 {
611 appointmentForm.setAddress( localization.getAddress( ) );
612 }
613 }
614
615 }
616
617
618
619
620
621
622
623
624 private static Form createForm( AppointmentFormDTO appointmentForm )
625 {
626 Formugins/appointment/business/form/Form.html#Form">Form form = new Form( );
627 fillInFormWithAppointmentForm( form, appointmentForm );
628 FormHome.create( form );
629 return form;
630 }
631
632
633
634
635
636
637
638
639 public static Form updateForm( AppointmentFormDTO appointmentForm )
640 {
641 Form form = FormService.findFormLightByPrimaryKey( appointmentForm.getIdForm( ) );
642 fillInFormWithAppointmentForm( form, appointmentForm );
643 FormService.updateForm( form );
644 return form;
645 }
646
647
648
649
650
651
652
653
654 public static Form../../../../../../fr/paris/lutece/plugins/appointment/business/form/Form.html#Form">Form updateForm( Form form )
655 {
656 Form formUpdated = FormHome.update( form );
657 FormListenerManager.notifyListenersFormChange( formUpdated.getIdForm( ) );
658 return formUpdated;
659 }
660
661
662
663
664
665
666
667
668
669
670 public static Formr/paris/lutece/plugins/appointment/business/form/Form.html#Form">Form fillInFormWithAppointmentForm( Form form, AppointmentFormDTO appointmentForm )
671 {
672 form.setTitle( appointmentForm.getTitle( ) );
673 form.setDescription( appointmentForm.getDescription( ) );
674 form.setReference( appointmentForm.getReference( ) );
675 if ( appointmentForm.getIdCategory( ) == -1 )
676 {
677 form.setIdCategory( null );
678 }
679 else
680 {
681 form.setIdCategory( appointmentForm.getIdCategory( ) );
682 }
683 form.setStartingValiditySqlDate( appointmentForm.getDateStartValidity( ) );
684 form.setEndingValiditySqlDate( appointmentForm.getDateEndValidity( ) );
685 form.setIsActive( appointmentForm.getIsActive( ) );
686 form.setIdWorkflow( appointmentForm.getIdWorkflow( ) );
687 form.setWorkgroup( appointmentForm.getWorkgroup( ) );
688 form.setIsMultislotAppointment( appointmentForm.getIsMultislotAppointment( ) );
689 form.setNbConsecutiveSlots( appointmentForm.getNbConsecutiveSlots( ) );
690 form.setRole( appointmentForm.getRole( ) );
691 form.setCapacityPerSlot( appointmentForm.getCapacityPerSlot( ) );
692 form.setAnonymizable(appointmentForm.isAnonymizable());
693 form.setAnonymizationPattern( appointmentForm.getAnonymizationPattern( ) );
694 return form;
695 }
696
697
698
699
700
701
702
703 public static void removeForm( int nIdForm )
704 {
705 TransactionManager.beginTransaction( AppointmentPlugin.getPlugin( ) );
706 try
707 {
708
709 for ( Appointment appointment : AppointmentService.findListAppointmentByIdForm( nIdForm ) )
710 {
711 AppointmentResponseService.removeResponsesByIdAppointment( appointment.getIdAppointment( ) );
712 }
713
714 SlotHome.deleteByIdForm( nIdForm );
715
716 for ( ReservationRule rule : ReservationRuleHome.findByIdForm( nIdForm ) )
717 {
718
719 List<WorkingDay> listWorkingDay = WorkingDayService.findListWorkingDayByWeekDefinitionRule( rule.getIdReservationRule( ) );
720 for ( WorkingDay workingDay : listWorkingDay )
721 {
722
723 TimeSlotHome.deleteByIdWorkingDay( workingDay.getIdWorkingDay( ) );
724 WorkingDayHome.delete( workingDay.getIdWorkingDay( ) );
725
726 }
727 WeekDefinitionHome.deleteByIdReservationRule( rule.getIdReservationRule( ) );
728 ReservationRuleHome.delete( rule.getIdReservationRule( ) );
729 }
730
731 ClosingDayHome.deleteByIdForm( nIdForm );
732 FormRuleHome.deleteByIdFom( nIdForm );
733 DisplayHome.deleteByIdForm( nIdForm );
734 LocalizationHome.deleteByIdForm( nIdForm );
735 FormMessageHome.deleteByIdForm( nIdForm );
736 CommentHome.removeByIdFom( nIdForm );
737 FormHome.delete( nIdForm );
738 EntryService.getService( ).removeEntriesByIdAppointmentForm( nIdForm );
739
740 TransactionManager.commitTransaction( AppointmentPlugin.getPlugin( ) );
741
742 FormListenerManager.notifyListenersFormRemoval( nIdForm );
743 AppointmentListenerManager.notifyListenersAppointmentFormRemoval( nIdForm );
744
745 }
746 catch( Exception e )
747 {
748 TransactionManager.rollBack( AppointmentPlugin.getPlugin( ) );
749 AppLogService.error( "Error delete form: " + nIdForm + e.getMessage( ), e );
750 throw new AppException( e.getMessage( ), e );
751
752 }
753 }
754
755
756
757
758
759
760 public static List<Form> findAllForms( )
761 {
762 return FormHome.findAllForms( );
763 }
764
765
766
767
768
769
770 public static List<Form> findAllActiveForms( )
771 {
772 return FormHome.findActiveForms( );
773 }
774
775
776
777
778
779
780 public static List<Form> findAllActiveAndDisplayedOnPortletForms( )
781 {
782 return FormHome.findActiveAndDisplayedOnPortletForms( );
783 }
784
785
786
787
788
789
790
791
792 public static Form findFormLightByPrimaryKey( int nIdForm )
793 {
794 return FormHome.findByPrimaryKey( nIdForm );
795 }
796
797
798
799
800
801
802
803
804 public static List<Form> findFormsByTitle( String strTitle )
805 {
806 return FormHome.findByTitle( strTitle );
807 }
808
809 }