View Javadoc
1   /*
2    * Copyright (c) 2002-2020, 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.campagnebp.business;
35  
36  import java.io.Serializable;
37  import java.text.ParseException;
38  import java.util.Set;
39  
40  import javax.validation.ConstraintViolation;
41  import javax.validation.Validator;
42  import javax.validation.constraints.Pattern;
43  
44  import org.hibernate.validator.constraints.NotEmpty;
45  
46  import fr.paris.lutece.plugins.campagnebp.service.MyInfosService;
47  import fr.paris.lutece.portal.service.util.AppLogService;
48  import fr.paris.lutece.util.beanvalidation.BeanValidationUtil;
49  
50  /**
51   * MesInfosForm
52   */
53  public class MyInfosForm implements Serializable, Cloneable
54  {
55      private static final long serialVersionUID = 3729142258589861636L;
56      private String _strNickname;
57  
58      @NotEmpty( message = "budgetparticipatif.validation.civility.notEmpty" )
59      private String _strCivility;
60      // @NotEmpty( message = "budgetparticipatif.validation.firstname.notEmpty" )
61      private String _strFirstname;
62      // @NotEmpty( message = "budgetparticipatif.validation.lastname.notEmpty" )
63      private String _strLastname;
64      private String _strPostalCode;
65      @NotEmpty( message = "budgetparticipatif.validation.address.notEmpty" )
66      private String _strAddress;
67      private Double _dLongitude;
68      private Double _dLatitude;
69      @NotEmpty( message = "budgetparticipatif.validation.birthdate.notEmpty" )
70      @Pattern( regexp = "(0?[1-9]|[12][0-9]|3[01])/(0?[1-9]|1[012])/((19|20)\\d\\d)", message = "budgetparticipatif.validation.birthdate.pattern" )
71      private String _strBirthdate;
72      // @NotEmpty( message = "budgetparticipatif.validation.arrondissement.notEmpty" )
73      // @Pattern( regexp = "(7500[1-9])|(7501[0-9])|(75020)", message = "budgetparticipatif.validation.arrondissement.pattern" )
74      private String _strArrondissement;
75      @NotEmpty( message = "budgetparticipatif.validation.iliveinparis.notEmpty" )
76      private String _strIliveinparis;
77      private String _strStayconnected;
78      private boolean _bIsValid;
79      // @Min( value = 15 , message = "budgetparticipatif.validation.age.min" )
80      private int _nAge;
81      private String _strSendaccountvalidation;
82      private boolean _bAccountVerified;
83      @NotEmpty( message = "budgetparticipatif.validation.geojson.notEmpty" )
84      private String _strGeojson;
85  
86      /**
87       * Returns the Firstname
88       * 
89       * @return The Firstname
90       */
91      public String getFirstname( )
92      {
93          return _strFirstname;
94      }
95  
96      /**
97       * Sets the Firstname
98       * 
99       * @param strFirstname
100      *            The Firstname
101      */
102     public void setFirstname( String strFirstname )
103     {
104         _strFirstname = strFirstname;
105     }
106 
107     /**
108      * Returns the Lastname
109      * 
110      * @return The Lastname
111      */
112     public String getLastname( )
113     {
114         return _strLastname;
115     }
116 
117     /**
118      * Sets the Lastname
119      * 
120      * @param strLastname
121      *            The Lastname
122      */
123     public void setLastname( String strLastname )
124     {
125         _strLastname = strLastname;
126     }
127 
128     /**
129      * Returns the Address
130      * 
131      * @return The Address
132      */
133     public String getAddress( )
134     {
135         return _strAddress;
136     }
137 
138     /**
139      * Sets the Address
140      * 
141      * @param strAddress
142      *            The Address
143      */
144     public void setAddress( String strAddress )
145     {
146         _strAddress = strAddress;
147     }
148 
149     /**
150      * Returns the Birthdate
151      * 
152      * @return The Birthdate
153      */
154     public String getBirthdate( )
155     {
156         return _strBirthdate;
157     }
158 
159     /**
160      * Sets the Birthdate
161      * 
162      * @param strBirthdate
163      *            The Birthdate
164      */
165     public void setBirthdate( String strBirthdate )
166     {
167         _strBirthdate = strBirthdate;
168 
169         // Validate Birth Date format before calculating the age
170         Validator validator = BeanValidationUtil.getValidator( );
171         Set<ConstraintViolation<MyInfosForm>> constraintViolations = validator.validateProperty( this, "_strBirthdate" );
172         if ( constraintViolations.isEmpty( ) )
173         {
174             try
175             {
176                 _nAge = MyInfosService.getAge( strBirthdate );
177             }
178             catch( ParseException ex )
179             {
180                 _nAge = 0;
181                 AppLogService.error( "Error setting age from birthdate" + ex.getMessage( ), ex );
182             }
183         }
184         else
185         {
186             _nAge = 18; // A valid age to not create a violation since the date format is not valid
187         }
188     }
189 
190     /**
191      * Returns the Age
192      * 
193      * @return The Age
194      */
195     public int getAge( )
196     {
197         return _nAge;
198     }
199 
200     /**
201      * Returns the Arrondissement
202      * 
203      * @return The Arrondissement
204      */
205     public String getArrondissement( )
206     {
207         return _strArrondissement;
208     }
209 
210     /**
211      * Sets the Arrondissement
212      * 
213      * @param strArrondissement
214      *            The Arrondissement
215      */
216     public void setArrondissement( String strArrondissement )
217     {
218         _strArrondissement = strArrondissement;
219     }
220 
221     /**
222      * Returns the Iliveinparis
223      * 
224      * @return The Iliveinparis
225      */
226     public String getIliveinparis( )
227     {
228         return _strIliveinparis;
229     }
230 
231     /**
232      * Sets the Iliveinparis
233      * 
234      * @param strIliveinparis
235      *            The Iliveinparis
236      */
237     public void setIliveinparis( String strIliveinparis )
238     {
239         _strIliveinparis = strIliveinparis;
240     }
241 
242     /**
243      * Returns the Stayconnected
244      * 
245      * @return The Stayconnected
246      */
247     public String getStayconnected( )
248     {
249         return _strStayconnected;
250     }
251 
252     /**
253      * Sets the Stayconnected
254      * 
255      * @param strStayconnected
256      *            The Stayconnected
257      */
258     public void setStayconnected( String strStayconnected )
259     {
260         _strStayconnected = strStayconnected;
261     }
262 
263     /**
264      * Check if the user is valid or not
265      * 
266      * @return True if the user is valid
267      */
268     public boolean getIsValid( )
269     {
270         return _bIsValid;
271     }
272 
273     /**
274      * Set the user to valid or not valid
275      * 
276      * @param bIsValid
277      *            True if the user is valid, false otherwise
278      */
279     public void setIsValid( boolean bIsValid )
280     {
281         _bIsValid = bIsValid;
282     }
283 
284     /**
285      * {@inheritDoc}
286      */
287     @Override
288     public MyInfosForm clone( )
289     {
290         try
291         {
292             return (MyInfosForm) super.clone( );
293         }
294         catch( CloneNotSupportedException e )
295         {
296             return null;
297         }
298     }
299 
300     /**
301      * Send Account Validation
302      * 
303      * @param strSendAccountValidation
304      *            strSendAccountValidation
305      */
306     public void setSendaccountvalidation( String strSendAccountValidation )
307     {
308 
309         _strSendaccountvalidation = strSendAccountValidation;
310 
311     }
312 
313     /**
314      * Returns the SendAccountValidation
315      * 
316      * @return The SendAccountValidation
317      */
318     public String getSendaccountvalidation( )
319     {
320         return _strSendaccountvalidation;
321     }
322 
323     /**
324      * 
325      * @return true if the account is verified
326      */
327     public boolean isAccountVerified( )
328     {
329         return _bAccountVerified;
330     }
331 
332     /**
333      * 
334      * @param _bAccountVerified
335      *            true if the account is verified
336      */
337     public void setAccountVerified( boolean _bAccountVerified )
338     {
339         this._bAccountVerified = _bAccountVerified;
340     }
341 
342     /**
343      * @return The nickname
344      */
345     public String getNickname( )
346     {
347         return _strNickname;
348     }
349 
350     /**
351      * @param _strNickname
352      *            The nickname
353      */
354     public void setNickname( String _strNickname )
355     {
356         this._strNickname = _strNickname;
357     }
358 
359     /**
360      * 
361      * @return The civility
362      */
363     public String getCivility( )
364     {
365         return _strCivility;
366     }
367 
368     /**
369      * @param strCivility
370      *            The civility
371      */
372     public void setCivility( String strCivility )
373     {
374         this._strCivility = strCivility;
375     }
376 
377     /**
378      * 
379      * @return the postal code
380      */
381     public String getPostalCode( )
382     {
383         return _strPostalCode;
384     }
385 
386     /**
387      * 
388      * @param _strPostalCode
389      *            the postal code
390      */
391     public void setPostalCode( String _strPostalCode )
392     {
393         this._strPostalCode = _strPostalCode;
394     }
395 
396     /**
397      * 
398      * @return the longitude
399      */
400     public Double getLongitude( )
401     {
402         return _dLongitude;
403     }
404 
405     /**
406      * 
407      * @param _dLongitude
408      *            the longitude
409      */
410     public void setLongitude( Double _dLongitude )
411     {
412         this._dLongitude = _dLongitude;
413     }
414 
415     /**
416      * 
417      * @return the latitude
418      */
419     public Double getLatitude( )
420     {
421         return _dLatitude;
422     }
423 
424     /**
425      * 
426      * @param _dLatitude
427      *            the latitude
428      */
429     public void setLatitude( Double _dLatitude )
430     {
431         this._dLatitude = _dLatitude;
432     }
433 
434     /**
435      * @return The GeoJSON
436      */
437     public String getGeojson( )
438     {
439         return _strGeojson;
440     }
441 
442     /**
443      * @param _strGeojson
444      *            The GeoJSON
445      */
446     public void setGeojson( String _strGeojson )
447     {
448         this._strGeojson = _strGeojson;
449     }
450 
451 }