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.service;
35  
36  import java.io.IOException;
37  import java.sql.Date;
38  import java.text.ParseException;
39  import java.util.Arrays;
40  import java.util.Calendar;
41  import java.util.List;
42  import java.util.Locale;
43  import java.util.regex.Matcher;
44  
45  import org.apache.commons.lang.StringUtils;
46  import org.joda.time.DateTime;
47  import org.joda.time.LocalDate;
48  import org.joda.time.Years;
49  import org.joda.time.format.DateTimeFormat;
50  import org.joda.time.format.DateTimeFormatter;
51  
52  import fr.paris.lutece.plugins.leaflet.business.GeolocItem;
53  import fr.paris.lutece.plugins.participatorybudget.business.Civility;
54  import fr.paris.lutece.plugins.participatorybudget.business.MyInfosForm;
55  import fr.paris.lutece.plugins.participatorybudget.service.campaign.CampaignService;
56  import fr.paris.lutece.plugins.participatorybudget.util.ParticipatoryBudgetConstants;
57  import fr.paris.lutece.portal.service.datastore.DatastoreService;
58  import fr.paris.lutece.portal.service.i18n.I18nService;
59  import fr.paris.lutece.portal.service.prefs.IPortalUserPreferencesService;
60  import fr.paris.lutece.portal.service.prefs.UserPreferencesService;
61  import fr.paris.lutece.portal.service.security.LuteceUser;
62  import fr.paris.lutece.portal.service.util.AppLogService;
63  import fr.paris.lutece.portal.service.util.AppPropertiesService;
64  import fr.paris.lutece.util.ReferenceList;
65  
66  /**
67   * MyInfos Service
68   */
69  public final class MyInfosService
70  {
71  
72      private static final java.util.regex.Pattern patternPostalCode = java.util.regex.Pattern.compile( ", (75[0-1][0-2][0-9]) PARIS" );
73      public static final String UNDEFINED_POSTALCODE_KEY = "undefined";
74      public static final String LUTECE_USER_KEY_VERIFIED = "user.validated";
75      private static final String PREF_KEY_EMAIL = "participatorybudget.email";
76      private static final String PREF_KEY_FIRSTNAME = "participatorybudget.firstname";
77      private static final String PREF_KEY_CREATIONDATE = "participatorybudget.creationdate";
78      private static final String PREF_KEY_CIVILITY = "participatorybudget.civility";
79      private static final String PREF_KEY_LASTNAME = "participatorybudget.lastname";
80      private static final String PREF_KEY_ADDRESS = "participatorybudget.address";
81      private static final String PREF_KEY_GEO_JSON = "participatorybudget.geojson";
82      private static final String PREF_KEY_BIRTHDATE = "participatorybudget.birthdate";
83      private static final String PREF_KEY_ARRONDISSEMENT_VOTE = "participatorybudget.arrondissement";
84      private static final String PREF_KEY_POSTAL_CODE = "participatorybudget.postalCode";
85      private static final String PREF_KEY_ILIVEINPARIS = "participatorybudget.iliveinparis";
86      // private static final String PREF_KEY_STAYCONNECTED = "participatorybudget.stayconnected";
87      private static final String PREF_KEY_SEND_ACCOUNT_VALIDATION = "participatorybudget.sendaccountvalidation";
88      private static final String PREF_KEY_ACCOUNT_VERIFIED = "participatorybudget.accountVerified";
89      private static final String PROPERTY_ARRONDISSEMENT = "participatorybudget.arrondissement.";
90      private static final String PROPERTY_SELECT_ARRONDISSEMENT = "participatorybudget.mes_infos.arrondissement";
91      private static final String PROPERTY_SELECT_POSTAL_CODE = "participatorybudget.mes_infos.postalCode";
92      private static final String PROPERTY_SELECT_POSTAL_CODE_16_KEY = "participatorybudget.mes_infos.postalCode16Key";
93      private static final String PROPERTY_SELECT_POSTAL_CODE_16_LABEL = "participatorybudget.mes_infos.postalCode16Label";
94      private static final String PREF_VALUE_ON = "on";
95      private static final String PREF_VALUE_OFF = "off";
96      private static final String DEFAULT_CHECKED = "default";
97      private static final String ADDRESS_SEPARATOR = " ";
98  
99      private static final String KEY_SEND_ACCOUNT_VALIDATION_BACK_URL = "participatorybudget.site_property.send_account_validation_back_url";
100     private static final String KEY_ENABLE_VALIDATION_ACCOUNT = "participatorybudget.site_property.enable_validation_account";
101 
102     private static final String TYPE_VALIDATE_ACCOUNT = "validate_account";
103     private static volatile ReferenceList _listArrondissements;
104     private static volatile ReferenceList _listPostalCode;
105     private static List<String> _listAuthorizedCities = Arrays.asList( AppPropertiesService
106             .getProperty( ParticipatoryBudgetConstants.PROPERTY_AUTHORIZED_CITIES ).split( ParticipatoryBudgetConstants.AUTHORIZED_CITIES_SEPARATOR ) );
107 
108     /** Private constructor */
109     private MyInfosService( )
110     {
111     }
112 
113     /**
114      * Load informations about the user from ParisConnect and local preferences
115      * 
116      * @param user
117      *            The User
118      * @return User's infos
119      */
120     public static MyInfosForm loadUserInfos( LuteceUser user )
121     {
122         MyInfosFormicipatorybudget/business/MyInfosForm.html#MyInfosForm">MyInfosForm myInfos = new MyInfosForm( );
123 
124         IPortalUserPreferencesService instance = UserPreferencesService.instance( );
125 
126         // Initialized to true, but can be changed in populate methods
127         myInfos.setIsValid( true );
128 
129         // Populate the MyInfosForm object
130         populateMyInfosData( myInfos, instance, user );
131 
132         return myInfos;
133     }
134 
135     /**
136      * Populate the MyInfosForm with the user data
137      * 
138      * @param myInfos
139      *            The instance of MyInfosForm
140      * @param instance
141      *            The IPortalUserPreferencesService instance
142      * @param user
143      *            The user
144      */
145     private static void populateMyInfosData( MyInfosForm myInfos, IPortalUserPreferencesService instance, LuteceUser user )
146     {
147         populateNickname( myInfos, instance, user );
148         populateCivility( myInfos, instance, user );
149         populateFirstName( myInfos, instance, user );
150         populateLastName( myInfos, instance, user );
151         populateBirthDate( myInfos, instance, user );
152         populateAddress( myInfos, instance, user );
153         populatePostalCode( myInfos, instance, user );
154         populateArrondissement( myInfos, instance, user );
155         populateGeoJson( myInfos, instance, user );
156         populateILiveInParisFlag( myInfos, instance, user );
157         populateSendAccountValidationFlag( myInfos, instance, user );
158         populateAccountVerifiedFlag( myInfos, instance, user );
159 
160     }
161 
162     /**
163      * load UserNickName
164      * 
165      * @param strLuteceUserName
166      *            strLuteceUserName
167      * @return UserNickName
168      */
169     public static String loadUserNickname( String strLuteceUserName )
170     {
171 
172         return UserPreferencesService.instance( ).getNickname( strLuteceUserName );
173 
174     }
175 
176     /**
177      * load UserNickName
178      * 
179      * @param strLuteceUserName
180      *            strLuteceUserName
181      * @return UserNickName
182      */
183     public static boolean isNicknameAlreadyExist( String strNickName )
184     {
185 
186         return !StringUtils.isEmpty( strNickName ) && UserPreferencesService.instance( ).existsNickname( strNickName.trim( ) );
187 
188     }
189 
190     /**
191      * return true if the user is verified
192      * 
193      * @param user
194      *            The User
195      * @return true if the user is verified
196      */
197     public static boolean isAccountVerified( LuteceUser user )
198     {
199 
200         String bEnableValidationAccount = DatastoreService.getDataValue( KEY_ENABLE_VALIDATION_ACCOUNT, "false" );
201 
202         if ( new Boolean( bEnableValidationAccount ) )
203         {
204 
205             // test if the user have verified his account
206             boolean bpVerified = UserPreferencesService.instance( ).getBoolean( user.getName( ), PREF_KEY_ACCOUNT_VERIFIED, false );
207             boolean openamVerified = user.getUserInfo( LUTECE_USER_KEY_VERIFIED ) != null ? new Boolean( user.getUserInfo( LUTECE_USER_KEY_VERIFIED ) ) : false;
208 
209             return openamVerified || bpVerified;
210         }
211 
212         return true;
213     }
214 
215     /**
216      * Save Users info into ParisConnect and local preferences
217      * 
218      * @param user
219      *            The User
220      * @param myInfos
221      *            The infos
222      */
223     public static void saveUserInfos( String strLuteceUserName, MyInfosForm myInfos )
224     {
225         IPortalUserPreferencesService instance = UserPreferencesService.instance( );
226 
227         // instance.clear( user.getName( ) );
228         String strCreationDate = instance.get( strLuteceUserName, PREF_KEY_CREATIONDATE, StringUtils.EMPTY );
229 
230         if ( strCreationDate == null || strCreationDate.isEmpty( ) )
231         {
232             Date dCreationDate = new Date( Calendar.getInstance( ).getTime( ).getTime( ) );
233             instance.put( strLuteceUserName, PREF_KEY_CREATIONDATE, dCreationDate.toString( ) );
234         }
235 
236         instance.put( strLuteceUserName, PREF_KEY_FIRSTNAME, myInfos.getFirstname( ) );
237         instance.put( strLuteceUserName, PREF_KEY_LASTNAME, myInfos.getLastname( ) );
238         instance.put( strLuteceUserName, PREF_KEY_ADDRESS, myInfos.getAddress( ) );
239         instance.put( strLuteceUserName, PREF_KEY_BIRTHDATE, myInfos.getBirthdate( ) );
240         instance.put( strLuteceUserName, PREF_KEY_ILIVEINPARIS, myInfos.getIliveinparis( ) );
241         instance.put( strLuteceUserName, PREF_KEY_CIVILITY, myInfos.getCivility( ) );
242         instance.put( strLuteceUserName, PREF_KEY_POSTAL_CODE, myInfos.getPostalCode( ) );
243         instance.put( strLuteceUserName, PREF_KEY_ARRONDISSEMENT_VOTE, myInfos.getArrondissement( ) );
244 
245         instance.put( strLuteceUserName, PREF_KEY_SEND_ACCOUNT_VALIDATION, myInfos.getSendaccountvalidation( ) );
246 
247         instance.put( strLuteceUserName, PREF_KEY_GEO_JSON, myInfos.getGeojson( ) );
248 
249         // subscribe alert
250         myInfos.setIsValid( isUserValid( myInfos ) );
251 
252         if ( !StringUtils.isEmpty( myInfos.getNickname( ) ) && !StringUtils.isEmpty( instance.getNickname( strLuteceUserName ) )
253                 && !myInfos.getNickname( ).equals( instance.getNickname( strLuteceUserName ) ) )
254         {
255             instance.setNickname( strLuteceUserName, myInfos.getNickname( ) );
256             MyInfosListenerService.updateNickName( strLuteceUserName, myInfos.getNickname( ) );
257 
258         }
259         else
260             if ( StringUtils.isEmpty( instance.getNickname( strLuteceUserName ) ) )
261             {
262 
263                 MyInfosListenerService.createNickName( strLuteceUserName, myInfos.getNickname( ) );
264             }
265         instance.setNickname( strLuteceUserName, myInfos.getNickname( ) );
266 
267     }
268 
269     /**
270      * Save Users email into localPreferences
271      * 
272      * @param user
273      *            The User
274      * @param strEmail
275      *            The email
276      */
277     public static void saveUserEmail( String strLuteceUserName, String strEmail )
278     {
279         IPortalUserPreferencesService instance = UserPreferencesService.instance( );
280         instance.put( strLuteceUserName, PREF_KEY_EMAIL, strEmail );
281     }
282 
283     /**
284      * Gives the user email
285      * 
286      * @param user
287      *            the user
288      * @return the user email
289      */
290     public static String getUserEmail( String strLuteceUserName )
291     {
292         return UserPreferencesService.instance( ).get( strLuteceUserName, PREF_KEY_EMAIL, StringUtils.EMPTY );
293     }
294 
295     /**
296      * check if a validation mail must be send to the user
297      * 
298      * @param user
299      *            the user
300      * @param myInfos
301      *            the user information
302      * @return
303      */
304     public static boolean mustSendAccountValidationMail( String strLuteceUserName, MyInfosForm myInfos )
305     {
306 
307         String bEnableValidationAccount = DatastoreService.getDataValue( KEY_ENABLE_VALIDATION_ACCOUNT, "false" );
308 
309         return new Boolean( bEnableValidationAccount ) && StringUtils.isNotEmpty( myInfos.getSendaccountvalidation( ) );
310     }
311 
312     /**
313      * Send account validation mail if the user never have validation mail
314      * 
315      * @param user
316      *            the user
317      */
318 
319     /**
320      * Provides the list of arrondissements
321      * 
322      * @return The list
323      */
324     // TODO Area concept should be generalized and configurable in back-office
325     public static ReferenceList getArrondissements( )
326     {
327         if ( _listArrondissements == null )
328         {
329             synchronized( MyInfosService.class )
330             {
331                 if ( _listArrondissements == null )
332                 {
333                     _listArrondissements = new ReferenceList( );
334                     _listArrondissements.addItem( UNDEFINED_POSTALCODE_KEY, I18nService.getLocalizedString( PROPERTY_SELECT_ARRONDISSEMENT, Locale.FRENCH ) );
335 
336                     _listArrondissements.addItem( "area_1", "Area 1" );
337                     _listArrondissements.addItem( "area_2", "Area 2" );
338                     _listArrondissements.addItem( "area_3", "Area 3" );
339                     _listArrondissements.addItem( "whole_city", "Whole city" );
340 
341                     // for (int i = 0; i < 20; i++) {
342                     // String strCode = "" + (75001 + i);
343                     // _listArrondissements.addItem(strCode, I18nService
344                     // .getLocalizedString(PROPERTY_ARRONDISSEMENT
345                     // + strCode, Locale.FRENCH));
346                     // }
347                 }
348             }
349         }
350 
351         return _listArrondissements;
352     }
353 
354     /**
355      * Provides the list of arrondissements
356      * 
357      * @return The list
358      */
359     public static ReferenceList getPostalCodes( )
360     {
361         if ( _listPostalCode == null )
362         {
363             synchronized( MyInfosService.class )
364             {
365                 if ( _listPostalCode == null )
366                 {
367                     _listPostalCode = new ReferenceList( );
368                     _listPostalCode.addItem( UNDEFINED_POSTALCODE_KEY, I18nService.getLocalizedString( PROPERTY_SELECT_POSTAL_CODE, Locale.FRENCH ) );
369 
370                     for ( int i = 0; i < 20; i++ )
371                     {
372                         String strCode = "" + ( 75001 + i );
373                         _listPostalCode.addItem( strCode, strCode );
374                         if ( i == 15 )
375                         {
376                             _listPostalCode.addItem( I18nService.getLocalizedString( PROPERTY_SELECT_POSTAL_CODE_16_KEY, Locale.FRENCH ),
377                                     I18nService.getLocalizedString( PROPERTY_SELECT_POSTAL_CODE_16_LABEL, Locale.FRENCH ) );
378                         }
379                     }
380                 }
381             }
382         }
383 
384         return _listPostalCode;
385     }
386 
387     /**
388      * Calculate age
389      * 
390      * @param strBirthDate
391      *            The birth date as a String
392      * @return The age
393      * @throws ParseException
394      *             if parsing failed
395      */
396     public static int getAge( String strBirthDate ) throws ParseException
397     {
398         DateTimeFormatter formatter = DateTimeFormat.forPattern( "dd/MM/yyyy" );
399         DateTime dateBirthdate = formatter.parseDateTime( strBirthDate );
400         Years years = Years.yearsBetween( new LocalDate( dateBirthdate ), new LocalDate( ) );
401 
402         return years.getYears( );
403     }
404 
405     public static boolean setAdressValid( MyInfosForm myInfos )
406     {
407 
408         GeolocItem geolocItem = null;
409         try
410         {
411             geolocItem = GeolocItem.fromJSON( myInfos.getGeojson( ) );
412 
413             Matcher m = patternPostalCode.matcher( geolocItem.getAddress( ) );
414             m.find( );
415 
416             String strPostalCode = m.group( 1 );
417 
418             if ( !StringUtils.isEmpty( strPostalCode ) )
419             {
420                 myInfos.setLatitude( geolocItem.getLat( ) );
421                 myInfos.setLongitude( geolocItem.getLon( ) );
422                 myInfos.setAddress( geolocItem.getAddress( ) );
423                 myInfos.setPostalCode( strPostalCode );
424                 return true;
425             }
426 
427         }
428         catch( IOException e )
429         {
430 
431             AppLogService.error( "MyInfosApp: malformed data from client: address = " + myInfos.getGeojson( ) + "; exeception " + e );
432         }
433 
434         return false;
435 
436     }
437 
438     /**
439      * Check if a user is valid or not
440      * 
441      * @param myInfos
442      *            True if the user is valid, valse otherwise
443      * @return
444      */
445     private static boolean isUserValid( MyInfosForm myInfos )
446     {
447         return StringUtils.isNotBlank( myInfos.getCivility( ) )
448                 // && StringUtils.isNotBlank(myInfos.getNickname())
449                 && StringUtils.isNotBlank( myInfos.getAddress( ) ) && StringUtils.isNotBlank( myInfos.getPostalCode( ) )
450                 && StringUtils.isNotBlank( myInfos.getArrondissement( ) ) && !UNDEFINED_POSTALCODE_KEY.equals( myInfos.getArrondissement( ) )
451                 && StringUtils.isNotBlank( myInfos.getBirthdate( ) )
452                 && ( StringUtils.isNotBlank( myInfos.getIliveinparis( ) ) && myInfos.getIliveinparis( ).equals( PREF_VALUE_ON ) );
453     }
454 
455     /**
456      * Populates the nickname into the specified information form.
457      * 
458      * @param myInfos
459      *            the information form
460      * @param userPreferenceService
461      *            the service containing the user preferences
462      * @param user
463      *            the connected user
464      */
465     private static void populateNickname( MyInfosForm myInfos, IPortalUserPreferencesService userPreferenceService, LuteceUser user )
466     {
467         String strNickname = userPreferenceService.getNickname( user );
468 
469         if ( !CampaignService.getInstance( ).isDuring( ParticipatoryBudgetConstants.VOTE ) && StringUtils.isBlank( strNickname ) )
470         {
471             myInfos.setIsValid( false );
472         }
473 
474         myInfos.setNickname( strNickname );
475     }
476 
477     /**
478      * Populates the civility into the specified information form.
479      * 
480      * @param myInfos
481      *            the information form
482      * @param userPreferenceService
483      *            the service containing the user preferences
484      * @param user
485      *            the connected user
486      */
487     private static void populateCivility( MyInfosForm myInfos, IPortalUserPreferencesService userPreferenceService, LuteceUser user )
488     {
489         String strCivility = userPreferenceService.get( user.getName( ), PREF_KEY_CIVILITY, null );
490 
491         if ( strCivility == null )
492         {
493             myInfos.setIsValid( false );
494 
495             strCivility = Civility.fromNumericCode( user.getUserInfo( LuteceUser.GENDER ) ).getLabelCode( );
496         }
497 
498         myInfos.setCivility( strCivility );
499     }
500 
501     /**
502      * Populates the first name into the specified information form.
503      * 
504      * @param myInfos
505      *            the information form
506      * @param userPreferenceService
507      *            the service containing the user preferences
508      * @param user
509      *            the connected user
510      */
511     private static void populateFirstName( MyInfosForm myInfos, IPortalUserPreferencesService userPreferenceService, LuteceUser user )
512     {
513         String strFirstName = userPreferenceService.get( user.getName( ), PREF_KEY_FIRSTNAME, null );
514 
515         myInfos.setFirstname( strFirstName != null ? strFirstName : user.getUserInfo( LuteceUser.NAME_GIVEN ) );
516     }
517 
518     /**
519      * Populates the last name into the specified information form.
520      * 
521      * @param myInfos
522      *            the information form
523      * @param userPreferenceService
524      *            the service containing the user preferences
525      * @param user
526      *            the connected user
527      */
528     private static void populateLastName( MyInfosForm myInfos, IPortalUserPreferencesService userPreferenceService, LuteceUser user )
529     {
530         String strLastName = userPreferenceService.get( user.getName( ), PREF_KEY_LASTNAME, null );
531 
532         if ( strLastName == null )
533         {
534             strLastName = user.getUserInfo( LuteceUser.NAME_FAMILY );
535 
536             if ( StringUtils.isEmpty( strLastName ) )
537             {
538                 strLastName = user.getUserInfo( LuteceUser.NAME_CIVILITY );
539             }
540         }
541 
542         myInfos.setLastname( strLastName );
543     }
544 
545     /**
546      * Populates the birth date into the specified information form.
547      * 
548      * @param myInfos
549      *            the information form
550      * @param userPreferenceService
551      *            the service containing the user preferences
552      * @param user
553      *            the connected user
554      */
555     private static void populateBirthDate( MyInfosForm myInfos, IPortalUserPreferencesService userPreferenceService, LuteceUser user )
556     {
557         String strBirthDate = userPreferenceService.get( user.getName( ), PREF_KEY_BIRTHDATE, null );
558 
559         if ( strBirthDate == null )
560         {
561             myInfos.setIsValid( false );
562 
563             strBirthDate = user.getUserInfo( LuteceUser.BDATE );
564         }
565 
566         myInfos.setBirthdate( strBirthDate );
567     }
568 
569     /**
570      * Populates the address into the specified information form.
571      * 
572      * @param myInfos
573      *            the information form
574      * @param userPreferenceService
575      *            the service containing the user preferences
576      * @param user
577      *            the connected user
578      */
579     private static void populateAddress( MyInfosForm myInfos, IPortalUserPreferencesService userPreferenceService, LuteceUser user )
580     {
581         String strAddress = userPreferenceService.get( user.getName( ), PREF_KEY_ADDRESS, null );
582 
583         if ( strAddress == null )
584         {
585             // TODO [JPO, 2019-10-12] Desactivated code to make OpenPB working without SuggestPOI
586             // myInfos.setIsValid( false );
587 
588             String strCity = user.getUserInfo( LuteceUser.HOME_INFO_POSTAL_CITY );
589 
590             if ( _listAuthorizedCities.contains( strCity.trim( ).toLowerCase( ) ) )
591             {
592                 strAddress = user.getUserInfo( LuteceUser.HOME_INFO_POSTAL_STREET ) + ADDRESS_SEPARATOR
593                         + user.getUserInfo( LuteceUser.HOME_INFO_POSTAL_POSTALCODE ) + ADDRESS_SEPARATOR + strCity;
594             }
595         }
596 
597         myInfos.setAddress( strAddress );
598     }
599 
600     /**
601      * Populates the postal code into the specified information form.
602      * 
603      * @param myInfos
604      *            the information form
605      * @param userPreferenceService
606      *            the service containing the user preferences
607      * @param user
608      *            the connected user
609      */
610     private static void populatePostalCode( MyInfosForm myInfos, IPortalUserPreferencesService userPreferenceService, LuteceUser user )
611     {
612         String strPostalCode = userPreferenceService.get( user.getName( ), PREF_KEY_POSTAL_CODE, StringUtils.EMPTY );
613 
614         if ( StringUtils.isBlank( strPostalCode ) )
615         {
616             // TODO [JPO, 2019-10-12] Desactivated code to make OpenPB working without SuggestPOI
617             // myInfos.setIsValid( false );
618         }
619 
620         myInfos.setPostalCode( strPostalCode );
621     }
622 
623     /**
624      * Populates the arrondissement into the specified information form.
625      * 
626      * @param myInfos
627      *            the information form
628      * @param userPreferenceService
629      *            the service containing the user preferences
630      * @param user
631      *            the connected user
632      */
633     private static void populateArrondissement( MyInfosForm myInfos, IPortalUserPreferencesService userPreferenceService, LuteceUser user )
634     {
635         String strArrondissement = userPreferenceService.get( user.getName( ), PREF_KEY_ARRONDISSEMENT_VOTE, StringUtils.EMPTY );
636 
637         if ( CampaignService.getInstance( ).isAfterBeginning( ParticipatoryBudgetConstants.SUBMIT )
638                 && CampaignService.getInstance( ).isBeforeEnd( ParticipatoryBudgetConstants.VOTE )
639                 && ( StringUtils.isBlank( strArrondissement ) || UNDEFINED_POSTALCODE_KEY.equals( strArrondissement ) ) )
640         {
641             myInfos.setIsValid( false );
642         }
643 
644         myInfos.setArrondissement( strArrondissement );
645     }
646 
647     /**
648      * Populates the geo json into the specified information form.
649      * 
650      * @param myInfos
651      *            the information form
652      * @param userPreferenceService
653      *            the service containing the user preferences
654      * @param user
655      *            the connected user
656      */
657     private static void populateGeoJson( MyInfosForm myInfos, IPortalUserPreferencesService userPreferenceService, LuteceUser user )
658     {
659         String strGeoJson = userPreferenceService.get( user.getName( ), PREF_KEY_GEO_JSON, StringUtils.EMPTY );
660 
661         if ( StringUtils.isBlank( strGeoJson ) )
662         {
663             // TODO [JPO, 2019-10-12] Desactivated code to make OpenPB working without SuggestPOI
664             // myInfos.setIsValid( false );
665         }
666 
667         myInfos.setGeojson( strGeoJson );
668     }
669 
670     /**
671      * Populates the flag ILiveInParis into the specified information form.
672      * 
673      * @param myInfos
674      *            the information form
675      * @param userPreferenceService
676      *            the service containing the user preferences
677      * @param user
678      *            the connected user
679      */
680     private static void populateILiveInParisFlag( MyInfosForm myInfos, IPortalUserPreferencesService userPreferenceService, LuteceUser user )
681     {
682         if ( userPreferenceService.existsKey( user.getName( ), PREF_KEY_ILIVEINPARIS ) )
683         {
684             String strILiveInParis = userPreferenceService.get( user.getName( ), PREF_KEY_ILIVEINPARIS, PREF_VALUE_OFF );
685 
686             if ( PREF_VALUE_OFF.equals( strILiveInParis ) )
687             {
688                 myInfos.setIsValid( false );
689             }
690 
691             myInfos.setIliveinparis( strILiveInParis );
692         }
693         else
694         {
695             myInfos.setIsValid( false );
696 
697             myInfos.setIliveinparis( DEFAULT_CHECKED );
698         }
699     }
700 
701     /**
702      * Populates the send account validation flag into the specified information form.
703      * 
704      * @param myInfos
705      *            the information form
706      * @param userPreferenceService
707      *            the service containing the user preferences
708      * @param user
709      *            the connected user
710      */
711     private static void populateSendAccountValidationFlag( MyInfosForm myInfos, IPortalUserPreferencesService userPreferenceService, LuteceUser user )
712     {
713         if ( userPreferenceService.existsKey( user.getName( ), PREF_KEY_SEND_ACCOUNT_VALIDATION ) )
714         {
715             myInfos.setSendaccountvalidation( userPreferenceService.get( user.getName( ), PREF_KEY_SEND_ACCOUNT_VALIDATION, PREF_VALUE_OFF ) );
716         }
717         else
718         {
719             myInfos.setSendaccountvalidation( DEFAULT_CHECKED );
720         }
721     }
722 
723     /**
724      * Populates the account verified validation flag into the specified information form.
725      * 
726      * @param myInfos
727      *            the information form
728      * @param userPreferenceService
729      *            the service containing the user preferences
730      * @param user
731      *            the connected user
732      */
733     private static void populateAccountVerifiedFlag( MyInfosForm myInfos, IPortalUserPreferencesService userPreferenceService, LuteceUser user )
734     {
735         myInfos.setAccountVerified( userPreferenceService.getBoolean( user.getName( ), PREF_KEY_ACCOUNT_VERIFIED, false ) );
736     }
737 
738 }