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.forms.business;
35
36 import javax.validation.constraints.NotEmpty;
37 import javax.validation.constraints.Size;
38
39 import org.apache.commons.lang3.StringUtils;
40 import org.apache.commons.lang3.math.NumberUtils;
41
42 import fr.paris.lutece.portal.business.file.File;
43 import fr.paris.lutece.portal.service.rbac.RBACResource;
44 import fr.paris.lutece.portal.service.workgroup.AdminWorkgroupResource;
45
46 import java.sql.Date;
47 import java.sql.Timestamp;
48 import java.util.Base64;
49 import java.util.Comparator;
50 import java.util.List;
51
52
53
54
55 public class Form implements AdminWorkgroupResource, RBACResource, Comparator<Form>
56 {
57
58
59
60
61 public static final String RESOURCE_TYPE = "FORMS_FORM";
62
63
64
65
66 public static final int STATE_ENABLE = 1;
67
68
69
70
71 public static final int STATE_DISABLE = 0;
72
73
74 private int _nId;
75
76 @NotEmpty( message = "#i18n{forms.validation.form.Title.notEmpty}" )
77 @Size( max = 255, message = "#i18n{forms.validation.form.Title.size}" )
78 private String _strTitle;
79
80 @Size( max = 255, message = "#i18n{forms.validation.form.Description.size}" )
81 private String _strDescription;
82
83 private Timestamp _dateCreation;
84
85 private Timestamp _dateAvailabilityStartDate;
86
87 private Timestamp _dateAvailabilityEndDate;
88
89 private Timestamp _dateUpdate;
90
91 private String _strWorkgroup;
92
93 private List<FormAction> _listActions;
94
95 private int _nIdWorkflow;
96
97 private boolean _bAuthentificationNeeded;
98
99 @NotEmpty( message = "#i18n{forms.validation.form.Breadcrumb.notEmpty}" )
100 @Size( max = 255, message = "#i18n{forms.validation.form.Breadcrumb.size}" )
101 private String _strBreadcrumbName;
102
103 @Size( max = 255, message = "#i18n{forms.validation.form.ReturnUrl.size}" )
104 private String _strReturnUrl;
105
106 private boolean _bDisplaySummary;
107 private int _nMaxNumberResponse;
108 private boolean _bOneResponseByUser;
109
110 private int _nCurrentNumberResponse;
111
112 private boolean _bCaptchaStepInitial;
113 private boolean _bCaptchaStepFinal;
114 private boolean _bCaptchaRecap;
115
116 private boolean _bCountResponses;
117
118 private String _labelFinalButton;
119
120 @Size( max = 3000, message = "#i18n{forms.validation.form.UnavailableMessage.size}" )
121 private String _strUnavailableMessage;
122
123 private File _logo;
124
125 private int _nIdCategory;
126
127 private boolean _bBackupEnabled;
128
129
130
131
132 private boolean _bAccessToResponsesByRole;
133
134
135
136
137 public Form( )
138 {
139 super( );
140 }
141
142
143
144
145
146
147
148
149
150 Formorm" href="../../../../../../fr/paris/lutece/plugins/forms/business/Form.html#Form">Form( Form source )
151 {
152 _bAccessToResponsesByRole = source._bAccessToResponsesByRole;
153 _bAuthentificationNeeded = source._bAuthentificationNeeded;
154 _bBackupEnabled = source._bBackupEnabled;
155 _bCaptchaRecap = source._bCaptchaRecap;
156 _bCaptchaStepFinal = source._bCaptchaStepFinal;
157 _bCaptchaStepInitial = source._bCaptchaStepInitial;
158 _bCountResponses = source._bCountResponses;
159 _bDisplaySummary = source._bDisplaySummary;
160 _bOneResponseByUser = source._bOneResponseByUser;
161 _dateAvailabilityEndDate = source._dateAvailabilityEndDate;
162 _dateAvailabilityStartDate = source._dateAvailabilityStartDate;
163 _dateCreation = source._dateCreation;
164 _dateUpdate = source._dateUpdate;
165 _labelFinalButton = source._labelFinalButton;
166
167 _logo = source._logo;
168
169 _nId = source._nId;
170 _nIdCategory = source._nIdCategory;
171 _nIdWorkflow = source._nIdWorkflow;
172 _nMaxNumberResponse = source._nMaxNumberResponse;
173 _strBreadcrumbName = source._strBreadcrumbName;
174 _strDescription = source._strDescription;
175 _strReturnUrl = source._strReturnUrl;
176 _strTitle = source._strTitle;
177 _strUnavailableMessage = source._strUnavailableMessage;
178 _strWorkgroup = source._strWorkgroup;
179 }
180
181
182
183
184
185
186 public int getId( )
187 {
188 return _nId;
189 }
190
191
192
193
194
195
196
197 public void setId( int nId )
198 {
199 _nId = nId;
200 }
201
202
203
204
205
206
207 public String getTitle( )
208 {
209 return _strTitle;
210 }
211
212
213
214
215
216
217
218 public void setTitle( String strTitle )
219 {
220 _strTitle = strTitle;
221 }
222
223
224
225
226
227
228 public String getDescription( )
229 {
230 return _strDescription;
231 }
232
233
234
235
236
237
238
239 public void setDescription( String strDescription )
240 {
241 _strDescription = strDescription;
242 }
243
244
245
246
247
248
249 public Timestamp getCreationDate( )
250 {
251 return _dateCreation;
252 }
253
254
255
256
257
258
259
260 public void setCreationDate( Timestamp creationDate )
261 {
262 _dateCreation = creationDate;
263 }
264
265
266
267
268
269
270 public Timestamp getUpdateDate( )
271 {
272 return _dateUpdate;
273 }
274
275
276
277
278
279
280
281 public void setUpdateDate( Timestamp dateUpdate )
282 {
283
284 _dateUpdate = dateUpdate;
285 }
286
287
288
289
290
291
292 public Timestamp getAvailabilityStartDate( )
293 {
294 return _dateAvailabilityStartDate;
295 }
296
297
298
299
300
301
302
303 public void setAvailabilityStartDate( Timestamp dateAvailabilityStartDate )
304 {
305 _dateAvailabilityStartDate = dateAvailabilityStartDate;
306 }
307
308
309
310
311
312
313 public Timestamp getAvailabilityEndDate( )
314 {
315 return _dateAvailabilityEndDate;
316 }
317
318
319
320
321
322
323
324 public void setAvailabilityEndDate( Timestamp dateAvailabilityEndDate )
325 {
326 _dateAvailabilityEndDate = dateAvailabilityEndDate;
327 }
328
329
330
331
332 @Override
333 public String getResourceTypeCode( )
334 {
335 return RESOURCE_TYPE;
336 }
337
338
339
340
341 @Override
342 public String getResourceId( )
343 {
344 return StringUtils.EMPTY + _nId;
345 }
346
347
348
349
350 @Override
351 public String getWorkgroup( )
352 {
353 return _strWorkgroup;
354 }
355
356
357
358
359
360
361
362 public void setWorkgroup( String workGroup )
363 {
364 _strWorkgroup = workGroup;
365 }
366
367
368
369
370
371 public List<FormAction> getActions( )
372 {
373 return _listActions;
374 }
375
376
377
378
379
380
381
382 public void setActions( List<FormAction> formActions )
383 {
384 _listActions = formActions;
385 }
386
387
388
389
390
391
392 public boolean isActive( )
393 {
394 boolean bActive = false;
395 Date dToday = new Date( System.currentTimeMillis( ) );
396
397 if ( _dateAvailabilityStartDate != null && _dateAvailabilityStartDate.before( dToday )
398 && ( _dateAvailabilityEndDate == null || _dateAvailabilityEndDate.after( dToday ) ) )
399 {
400 bActive = true;
401 }
402 if ( _dateAvailabilityStartDate == null && ( _dateAvailabilityEndDate != null && _dateAvailabilityEndDate.after( dToday ) ) )
403 {
404 bActive = true;
405 }
406
407 return bActive;
408 }
409
410
411
412
413
414
415 public int getIdWorkflow( )
416 {
417 return _nIdWorkflow;
418 }
419
420
421
422
423
424
425
426 public void setIdWorkflow( int nIdWorkflow )
427 {
428 _nIdWorkflow = nIdWorkflow;
429 }
430
431
432
433
434 public boolean isAuthentificationNeeded( )
435 {
436 return _bAuthentificationNeeded;
437 }
438
439
440
441
442
443 public void setAuthentificationNeeded( boolean bAuthentificationNeeded )
444 {
445 this._bAuthentificationNeeded = bAuthentificationNeeded;
446 }
447
448
449
450
451
452
453 public String getBreadcrumbName( )
454 {
455 return _strBreadcrumbName;
456 }
457
458
459
460
461
462
463
464 public void setBreadcrumbName( String strBreadcrumbName )
465 {
466 _strBreadcrumbName = strBreadcrumbName;
467 }
468
469
470
471
472
473
474 public String getReturnUrl( )
475 {
476 return _strReturnUrl;
477 }
478
479
480
481
482
483
484
485 public void setReturnUrl( String strReturnUrl )
486 {
487 _strReturnUrl = strReturnUrl;
488 }
489
490
491
492
493
494
495 public boolean isDisplaySummary( )
496 {
497 return _bDisplaySummary;
498 }
499
500
501
502
503
504
505
506 public void setDisplaySummary( boolean bDisplaySummary )
507 {
508 _bDisplaySummary = bDisplaySummary;
509 }
510
511
512
513
514
515
516 public int getMaxNumberResponse( )
517 {
518 return _nMaxNumberResponse;
519 }
520
521
522
523
524
525
526
527 public void setMaxNumberResponse( int nMaxNumberResponse )
528 {
529 _nMaxNumberResponse = nMaxNumberResponse;
530 }
531
532
533
534
535
536
537 public boolean isOneResponseByUser( )
538 {
539 return _bOneResponseByUser;
540 }
541
542
543
544
545
546
547
548 public void setOneResponseByUser( boolean bOneResponseByUser )
549 {
550 _bOneResponseByUser = bOneResponseByUser;
551 }
552
553
554
555
556 public int getCurrentNumberResponse( )
557 {
558 return _nCurrentNumberResponse;
559 }
560
561
562
563
564
565 public void setCurrentNumberResponse( int nCurrentNumberResponse )
566 {
567 _nCurrentNumberResponse = nCurrentNumberResponse;
568 }
569
570
571
572
573 public boolean isCaptchaStepInitial( )
574 {
575 return _bCaptchaStepInitial;
576 }
577
578
579
580
581
582 public void setCaptchaStepInitial( boolean bCaptchaStepInitial )
583 {
584 _bCaptchaStepInitial = bCaptchaStepInitial;
585 }
586
587
588
589
590 public boolean isCaptchaStepFinal( )
591 {
592 return _bCaptchaStepFinal;
593 }
594
595
596
597
598
599 public void setCaptchaStepFinal( boolean bCaptchaStepFinal )
600 {
601 _bCaptchaStepFinal = bCaptchaStepFinal;
602 }
603
604
605
606
607 public boolean isCaptchaRecap( )
608 {
609 return _bCaptchaRecap;
610 }
611
612
613
614
615
616 public void setCaptchaRecap( boolean bCaptchaRecap )
617 {
618 _bCaptchaRecap = bCaptchaRecap;
619 }
620
621
622
623
624 public boolean isCountResponses( )
625 {
626 return _bCountResponses;
627 }
628
629
630
631
632
633 public void setCountResponses( boolean bCountResponse )
634 {
635 _bCountResponses = bCountResponse;
636 }
637
638
639
640
641 public String getLabelFinalButton( )
642 {
643 return _labelFinalButton;
644 }
645
646
647
648
649
650 public void setLabelFinalButton( String labelFinalButton )
651 {
652 _labelFinalButton = labelFinalButton;
653 }
654
655
656
657
658 public String getUnavailableMessage( )
659 {
660 return _strUnavailableMessage;
661 }
662
663
664
665
666
667 public void setUnavailableMessage( String strUnavailableMessage )
668 {
669 _strUnavailableMessage = strUnavailableMessage;
670 }
671
672
673
674
675 public File getLogo( )
676 {
677 return _logo;
678 }
679
680
681
682
683
684 public void setLogo( File logo )
685 {
686 _logo = logo;
687 }
688
689
690
691
692
693
694 public String getLogoBase64( )
695 {
696 if ( _logo == null || _logo.getPhysicalFile( ) == null )
697 {
698 return null;
699 }
700 return Base64.getEncoder( ).encodeToString( _logo.getPhysicalFile( ).getValue( ) );
701 }
702
703
704
705
706 public int getIdCategory( )
707 {
708 return _nIdCategory;
709 }
710
711
712
713
714
715 public void setIdCategory( int nIdCategory )
716 {
717 this._nIdCategory = nIdCategory;
718 }
719
720
721
722
723 public boolean isBackupEnabled( )
724 {
725 return _bBackupEnabled;
726 }
727
728
729
730
731 public void setBackupEnabled( boolean bBackupEnabled )
732 {
733 _bBackupEnabled = bBackupEnabled;
734 }
735
736
737
738
739 public FormCategory getCategory( )
740 {
741 return FormCategoryHome.findByPrimaryKey( _nIdCategory );
742 }
743
744
745
746
747 public boolean isAccessToResponsesByRole()
748 {
749 return _bAccessToResponsesByRole;
750 }
751
752
753
754
755
756 public void setAccessToResponsesByRole( boolean bAccessToResponsesByRole )
757 {
758 _bAccessToResponsesByRole = bAccessToResponsesByRole;
759 }
760
761
762
763 @Override
764 public int compare(Formref="../../../../../../fr/paris/lutece/plugins/forms/business/Form.html#Form">Form form1, Form form2) {
765 int nComparisonResult = NumberUtils.INTEGER_ZERO;
766 if (form1 == null) {
767 if (form2 != null) {
768 nComparisonResult = NumberUtils.INTEGER_MINUS_ONE;
769 }
770 } else {
771 if (form2 == null) {
772 nComparisonResult = NumberUtils.INTEGER_ONE;
773 } else {
774 nComparisonResult = compareFormsAviability(form1, form2);
775 }
776 }
777 return nComparisonResult;
778 }
779
780 private int compareFormsAviability(Formref="../../../../../../fr/paris/lutece/plugins/forms/business/Form.html#Form">Form form1, Form form2) {
781 int nComparisonResult = NumberUtils.INTEGER_ZERO;
782 if (form1.isActive()) {
783 if (!form2.isActive()) {
784 nComparisonResult = NumberUtils.INTEGER_ONE;
785 }
786 } else {
787 if (form2.isActive()) {
788 nComparisonResult = NumberUtils.INTEGER_MINUS_ONE;
789 } else {
790 boolean bIsSoonToBeActivatedForm1 = isSoonToBeActivated(form1);
791 boolean bIsSoonToBeActivatedForm2 = isSoonToBeActivated(form2);
792 if (bIsSoonToBeActivatedForm1 && !bIsSoonToBeActivatedForm2) {
793 nComparisonResult = NumberUtils.INTEGER_ONE;
794 } else if (!bIsSoonToBeActivatedForm1 && bIsSoonToBeActivatedForm2) {
795 nComparisonResult = NumberUtils.INTEGER_MINUS_ONE;
796 }
797 }
798 }
799 return nComparisonResult;
800 }
801
802
803
804
805
806
807 private boolean isSoonToBeActivated(Form form) {
808 Date dToday = new Date(System.currentTimeMillis());
809 if (form != null && form.getAvailabilityStartDate() != null && form.getAvailabilityStartDate().after(dToday) ) {
810 return true;
811 }
812 return false;
813 }
814 }