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.form;
35  
36  import java.io.Serializable;
37  import java.sql.Date;
38  import java.time.LocalDate;
39  
40  import javax.validation.constraints.NotBlank;
41  import javax.validation.constraints.Size;
42  
43  import org.apache.commons.lang3.StringUtils;
44  
45  import com.fasterxml.jackson.annotation.JsonIgnore;
46  import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
47  
48  import fr.paris.lutece.portal.service.rbac.RBACResource;
49  import fr.paris.lutece.portal.service.workgroup.AdminWorkgroupResource;
50  
51  /**
52   * Business class of the Form
53   * 
54   * @author Laurent Payen
55   *
56   */
57  @JsonIgnoreProperties( ignoreUnknown = true )
58  public final class Form implements RBACResource, AdminWorkgroupResource, Serializable
59  {
60  
61      /**
62       * Serial version UID
63       */
64      private static final long serialVersionUID = 4742702767509625292L;
65  
66      /**
67       * Name of the resource type of Appointment Forms
68       */
69      @JsonIgnore
70      public static final String RESOURCE_TYPE = "APPOINTMENT_FORM";
71  
72      @JsonIgnore
73      public static final String ROLE_NONE = "none";
74  
75      /**
76       * Form Id
77       */
78      private int _nIdForm;
79  
80      /**
81       * Title of the form
82       */
83      @NotBlank( message = "#i18n{appointment.validation.appointmentform.Title.notEmpty}" )
84      @Size( max = 255, message = "#i18n{appointment.validation.appointmentform.Title.size}" )
85      private String _strTitle;
86  
87      /**
88       * Description of the form
89       */
90      @NotBlank( message = "#i18n{appointment.validation.appointmentform.Description.notEmpty}" )
91      private String _strDescription;
92  
93      /**
94       * Reference of the form
95       */
96      private String _strReference;
97  
98      /**
99       * Category of the form
100      */
101     private Integer _nIdCategory;
102 
103     /**
104      * Starting validity date of the form
105      */
106     private LocalDate _startingValidityDate;
107 
108     /**
109      * Ending validity date of the form
110      */
111     private LocalDate _endingValidityDate;
112 
113     /**
114      * Indicate whether the form is active or not
115      */
116     private boolean _bIsActive;
117 
118     /**
119      * Workflow Id
120      */
121     private int _nIdWorkflow;
122 
123     /**
124      * Workgroup
125      */
126     private String _strWorkgroup;
127 
128     /**
129      * _bIsMultislotAppointment
130      */
131     private boolean _bIsMultislotAppointment;
132 
133     /**
134      * The number of consecutive slots
135      */
136     private int _nNbConsecutiveSlots;
137 
138     /**
139      * Role FO
140      */
141     private String _strRole;
142     /**
143      * theoretical capacity per slot
144      */
145     private int _nCapacityPerSlot = 1;
146     
147     /**
148      * bIsAnonymizable
149      */
150     private boolean _bIsAnonymizable;
151 
152     /**
153      * Anonymization pattern %f %g %n
154      */
155     private String _strAnonymizationPattern;
156 
157     /**
158      * Get the form Id
159      * 
160      * @return the form Id
161      */
162     public int getIdForm( )
163     {
164         return _nIdForm;
165     }
166 
167     /**
168      * Set the form Id
169      * 
170      * @param nIdForm
171      *            the Id to set
172      */
173     public void setIdForm( int nIdForm )
174     {
175         this._nIdForm = nIdForm;
176     }
177 
178     /**
179      * Get the title of the form
180      * 
181      * @return the form title
182      */
183     public String getTitle( )
184     {
185         return _strTitle;
186     }
187 
188     /**
189      * Set the form title
190      * 
191      * @param title
192      *            the Title to set
193      */
194     public void setTitle( String strTitle )
195     {
196         this._strTitle = strTitle;
197     }
198 
199     /**
200      * Get the description of the form
201      * 
202      * @return the description of the form
203      */
204     public String getDescription( )
205     {
206         return _strDescription;
207     }
208 
209     /**
210      * Set the description of the form
211      * 
212      * @param description
213      *            the description to set
214      */
215     public void setDescription( String strDescription )
216     {
217         this._strDescription = strDescription;
218     }
219 
220     /**
221      * Get the reference of the form
222      * 
223      * @return the reference of the form
224      */
225     public String getReference( )
226     {
227         return _strReference;
228     }
229 
230     /**
231      * Set the reference of the form
232      * 
233      * @param reference
234      *            the reference to set
235      */
236     public void setReference( String strReference )
237     {
238         this._strReference = strReference;
239     }
240 
241     /**
242      * Get the category id of the form
243      * 
244      * @return the category id of the form
245      */
246     public Integer getIdCategory( )
247     {
248         return _nIdCategory;
249     }
250 
251     /**
252      * Set the category id of the form
253      * 
254      * @param nIdCategory
255      *            the category id to set
256      */
257     public void setIdCategory( Integer nIdCategory )
258     {
259         this._nIdCategory = nIdCategory;
260     }
261 
262     /**
263      * Get the starting validity date of the form (in LocalDate format)
264      * 
265      * @return the starting validity date of the form
266      */
267     public LocalDate getStartingValidityDate( )
268     {
269         return _startingValidityDate;
270     }
271 
272     /**
273      * Get the starting validity date of the form (in sql date format)
274      * 
275      * @return the starting validity date
276      */
277     public Date getStartingValiditySqlDate( )
278     {
279         Date date = null;
280         if ( _startingValidityDate != null )
281         {
282             date = Date.valueOf( _startingValidityDate );
283         }
284         return date;
285     }
286 
287     /**
288      * Set the starting date of the validity of the form
289      * 
290      * @param startValidity
291      *            the starting validity date to set
292      */
293     public void setStartingValidityDate( LocalDate startingValidityDate )
294     {
295         this._startingValidityDate = startingValidityDate;
296     }
297 
298     /**
299      * Set the starting validity date of the form
300      * 
301      * @param startingValidityDate
302      *            the starting validity date to set (in sql Date format)
303      */
304     public void setStartingValiditySqlDate( Date startingValidityDate )
305     {
306         if ( startingValidityDate != null )
307         {
308             this._startingValidityDate = startingValidityDate.toLocalDate( );
309         }
310         else
311         {
312             this._startingValidityDate = null;
313         }
314     }
315 
316     /**
317      * Get the end date of the validity of the form
318      * 
319      * @return the end validity date of the form
320      */
321     public LocalDate getEndingValidityDate( )
322     {
323         return _endingValidityDate;
324     }
325 
326     /**
327      * Get the ending validity date of the form (in sql date format)
328      * 
329      * @return the ending validity date
330      */
331     public Date getEndingValiditySqlDate( )
332     {
333         Date date = null;
334         if ( _endingValidityDate != null )
335         {
336             date = Date.valueOf( _endingValidityDate );
337         }
338         return date;
339     }
340 
341     /**
342      * Set the end date of the validity of the form
343      * 
344      * @param endValidity
345      *            the end validity date to set
346      */
347     public void setEndingValidityDate( LocalDate endingValidityDate )
348     {
349         this._endingValidityDate = endingValidityDate;
350     }
351 
352     /**
353      * Set the ending validity date of the form
354      * 
355      * @param endingValidityDate
356      *            the ending validity date to set (in sql Date format)
357      */
358     public void setEndingValiditySqlDate( Date endingValidityDate )
359     {
360         if ( endingValidityDate != null )
361         {
362             this._endingValidityDate = endingValidityDate.toLocalDate( );
363         }
364         else
365         {
366             this._endingValidityDate = null;
367         }
368     }
369 
370     /**
371      * Returns the IsActive
372      * 
373      * @return The IsActive
374      */
375     public boolean getIsActive( )
376     {
377         return _bIsActive;
378     }
379 
380     /**
381      * Set the active boolean value of the form
382      * 
383      * @param isActive
384      *            the boolean active value to set
385      */
386     public void setIsActive( boolean bIsActive )
387     {
388         this._bIsActive = bIsActive;
389     }
390 
391     /**
392      * Get the workflow id
393      * 
394      * @return the workflow id
395      */
396     public int getIdWorkflow( )
397     {
398         return _nIdWorkflow;
399     }
400 
401     /**
402      * Set the workflow Id
403      * 
404      * @param nIdWorkflow
405      *            the workflow id to set
406      */
407     public void setIdWorkflow( int nIdWorkflow )
408     {
409         this._nIdWorkflow = nIdWorkflow;
410     }
411 
412     @Override
413     public String getWorkgroup( )
414     {
415         return _strWorkgroup;
416     }
417 
418     /**
419      * Set the workgroup
420      * 
421      * @param strWorkgroup
422      *            the workgroup
423      */
424     public void setWorkgroup( String strWorkgroup )
425     {
426         this._strWorkgroup = strWorkgroup;
427     }
428 
429     @Override
430     public String getResourceTypeCode( )
431     {
432         return RESOURCE_TYPE;
433     }
434 
435     @Override
436     public String getResourceId( )
437     {
438         return Integer.toString( getIdForm( ) );
439     }
440 
441     /**
442      * Returns the IsMultislotAppointment
443      * 
444      * @return The IsMultislotAppointment
445      */
446     public boolean getIsMultislotAppointment( )
447     {
448         return _bIsMultislotAppointment;
449     }
450 
451     /**
452      * Sets the IsMultislotAppointment
453      * 
454      * @param bIsMultislotAppointment
455      *            The IsMultislotAppointment
456      */
457     public void setIsMultislotAppointment( boolean bIsMultislotAppointment )
458     {
459         _bIsMultislotAppointment = bIsMultislotAppointment;
460     }
461 
462     /**
463      * Get the number of consecutive slots
464      *
465      * @return the number of consecutive slots
466      */
467     public int getNbConsecutiveSlots( )
468     {
469         return _nNbConsecutiveSlots;
470     }
471 
472     /**
473      * Set the number of consecutive slots
474      *
475      * @param nbConsecutiveSlots
476      *            the number of consecutive slots
477      */
478     public void setNbConsecutiveSlots( int nbConsecutiveSlots )
479     {
480         this._nNbConsecutiveSlots = nbConsecutiveSlots;
481     }
482 
483     /**
484      * @return the strRole
485      */
486     public String getRole( )
487     {
488         return _strRole;
489     }
490 
491     /**
492      * @param strRole
493      *            the strRole to set
494      */
495     public void setRole( String strRole )
496     {
497         _strRole = StringUtils.isEmpty( strRole ) ? ROLE_NONE : strRole;
498     }
499 
500     /**
501      * Returns the theoretical capacity per slot
502      * 
503      * @return The theoretical capacity per slot
504      */
505     public int getCapacityPerSlot( )
506     {
507         return _nCapacityPerSlot;
508     }
509 
510     /**
511      * Sets the theoretical capacity per slot
512      * 
513      * @param nCapacityPerSlot
514      *            The theoretical capacity per slot
515      */
516     public void setCapacityPerSlot( int nCapacityPerSlot )
517     {
518         _nCapacityPerSlot = nCapacityPerSlot;
519     }
520 
521     public String getAnonymizationPattern()
522     {
523         return _strAnonymizationPattern;
524     }
525 
526     public void setAnonymizationPattern(String strAnonymizationPattern)
527     {
528         this._strAnonymizationPattern = strAnonymizationPattern;
529     }
530 
531 	public boolean isAnonymizable()
532 	{
533 		return _bIsAnonymizable;
534 	}
535 
536 	public void setAnonymizable(boolean bIsAnonymizable)
537 	{
538 		this._bIsAnonymizable = bIsAnonymizable;
539 	}
540 
541 }