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