View Javadoc
1   /*
2    * Copyright (c) 2002-2017, Mairie de 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.directory.business;
35  
36  import fr.paris.lutece.plugins.directory.service.DirectoryService;
37  import fr.paris.lutece.plugins.directory.service.directorysearch.DirectorySearchItem;
38  import fr.paris.lutece.plugins.directory.utils.DirectoryErrorException;
39  import fr.paris.lutece.plugins.directory.utils.DirectoryUtils;
40  import fr.paris.lutece.portal.service.i18n.I18nService;
41  import fr.paris.lutece.portal.service.message.AdminMessage;
42  import fr.paris.lutece.portal.service.message.AdminMessageService;
43  import fr.paris.lutece.portal.service.plugin.Plugin;
44  import fr.paris.lutece.portal.service.util.AppPropertiesService;
45  import fr.paris.lutece.util.ReferenceList;
46  import fr.paris.lutece.util.xml.XmlUtil;
47  
48  import org.apache.commons.lang.StringUtils;
49  
50  import java.util.ArrayList;
51  import java.util.HashMap;
52  import java.util.List;
53  import java.util.Locale;
54  import java.util.Map;
55  
56  import javax.servlet.http.HttpServletRequest;
57  
58  /**
59   *
60   * EntryTypeGeolocation
61   *
62   */
63  public class EntryTypeGeolocation extends Entry
64  {
65      private Entry _entryAdditionalAddress;
66  
67      // PARAMETERS
68      public static final String PARAMETER_ID_ENTRY = "idEntry";
69      public static final String PARAMETER_ID_DIRECTORY = "idDirectory";
70      public static final String PARAMETER_MAP_PROVIDER = "map_provider";
71      public static final String PARAMETER_SHOWXY = "showxy";
72      public static final String PARAMETER_SUFFIX_X = "_x";
73      public static final String PARAMETER_SUFFIX_Y = "_y";
74      public static final String PARAMETER_SUFFIX_MAP_PROVIDER = "_map_provider";
75      public static final String PARAMETER_SUFFIX_ADDRESS = "_address";
76  
77      // PARAMETERS OF GISMAP ATTRIBUTS
78      public static final String PARAMETER_EDIT_MODE = "edit_mode";
79      public static final String PARAMETER_VIEW_NUMBER_ATT = "view_number_att";
80      public static final String PARAMETER_VIEW_NUMBER_GES = "view_number_ges";
81      // public static final String PARAMETER_SUFFIX_ADDITIONAL_ADDRESS = "_additional_address";
82      public static final String PARAMETER_SUFFIX_GEOMETRY = "_geometry";
83  
84      public static final String PARAMETER_EDIT_MODE_LIST = "gismap.edit.mode.list";
85  
86      // PUBLIC COSNTANTS
87      public static final String CONSTANT_ADDRESS = "address";
88      public static final String CONSTANT_X = "X";
89      public static final String CONSTANT_Y = "Y";
90      public static final String CONSTANT_PROVIDER = "provider";
91      public static final String CONSTANT_SHOWXY = "showxy";
92      // PUBLIC COSNTANTS OF GISMAP ATTRIBUTS
93      public static final String CONSTANT_EDIT_MODE = "editMode";
94      public static final String CONSTANT_VIEW_NUMBER_ATT = "viewNumberAtt";
95      public static final String CONSTANT_VIEW_NUMBER_GES = "viewNumberGes";
96      // public static final String CONSTANT_ADDITIONAL_ADDRESS = "additionalAddress";
97      public static final String CONSTANT_GEOMETRY = "geometry";
98  
99      // PRIVATE CONSTANTS
100     private static final int CONSTANT_POSITION_X = 0;
101     private static final int CONSTANT_POSITION_Y = 1;
102     private static final int CONSTANT_POSITION_MAP_PROVIDER = 2;
103     private static final int CONSTANT_POSITION_ADDRESS = 3;
104     // private static final int CONSTANT_POSITION_ADDITIONAL_ADDRESS = 4;
105     private static final int CONSTANT_POSITION_GEOMETRY = 4;
106     private static final int CONSTANT_FIELDS_COUNT = 5;
107 
108     // TEMPLATES
109     private static final String TEMPLATE_CREATE = "admin/plugins/directory/entrytypegeolocation/create_entry_type_geolocation.html";
110     private static final String TEMPLATE_MODIFY = "admin/plugins/directory/entrytypegeolocation/modify_entry_type_geolocation.html";
111     private static final String TEMPLATE_HTML_CODE_FORM_ENTRY = "admin/plugins/directory/entrytypegeolocation/html_code_form_entry_type_geolocation.html";
112     private static final String TEMPLATE_HTML_CODE_ENTRY_VALUE = "admin/plugins/directory/entrytypegeolocation/html_code_entry_value_type_geolocation.html";
113     private static final String TEMPLATE_HTML_CODE_FORM_SEARCH_ENTRY = "admin/plugins/directory/entrytypegeolocation/html_code_form_search_entry_type_geolocation.html";
114     private static final String TEMPLATE_HTML_FRONT_CODE_FORM_ENTRY = "skin/plugins/directory/entrytypegeolocation/html_code_form_entry_type_geolocation.html";
115     private static final String TEMPLATE_HTML_FRONT_CODE_ENTRY_VALUE = "skin/plugins/directory/entrytypegeolocation/html_code_entry_value_type_geolocation.html";
116     private static final String TEMPLATE_HTML_FRONT_CODE_FORM_SEARCH_ENTRY = "skin/plugins/directory/entrytypegeolocation/html_code_form_search_entry_type_geolocation.html";
117 
118     // SQL
119     private static final String SQL_JOIN_DIRECTORY_RECORD_FIELD = " JOIN directory_record_field drf ON drf.id_record = dr.id_record AND drf.id_entry = ? JOIN directory_field df ON df.id_entry = drf.id_entry AND df.id_field = drf.id_field AND title=? ";
120 
121     /**
122      * @return the _entryAdditionalAddress
123      */
124     public Entry getEntryAdditionalAddress( )
125     {
126         return _entryAdditionalAddress;
127     }
128 
129     /**
130      * @param entryAdditionalAddress
131      *            the entryAdditionalAddress to set
132      */
133     public void setEntryAdditionalAddress( Entry entryAdditionalAddress )
134     {
135         this._entryAdditionalAddress = entryAdditionalAddress;
136     }
137 
138     /**
139      *
140      * {@inheritDoc}
141      */
142     @Override
143     public String getTemplateCreate( )
144     {
145         return TEMPLATE_CREATE;
146     }
147 
148     /**
149      *
150      * {@inheritDoc}
151      */
152     @Override
153     public String getTemplateModify( )
154     {
155         return TEMPLATE_MODIFY;
156     }
157 
158     /**
159      *
160      * {@inheritDoc}
161      */
162     @Override
163     public String getTemplateHtmlFormEntry( boolean isDisplayFront )
164     {
165         if ( isDisplayFront )
166         {
167             return TEMPLATE_HTML_FRONT_CODE_FORM_ENTRY;
168         }
169 
170         return TEMPLATE_HTML_CODE_FORM_ENTRY;
171     }
172 
173     /**
174      *
175      * {@inheritDoc}
176      */
177     @Override
178     public String getTemplateHtmlFormSearchEntry( boolean isDisplayFront )
179     {
180         if ( isDisplayFront )
181         {
182             return TEMPLATE_HTML_FRONT_CODE_FORM_SEARCH_ENTRY;
183         }
184 
185         return TEMPLATE_HTML_CODE_FORM_SEARCH_ENTRY;
186     }
187 
188     /**
189      * {@inheritDoc}
190      */
191     @Override
192     public String getTemplateHtmlRecordFieldValue( boolean isDisplayFront )
193     {
194         if ( isDisplayFront )
195         {
196             return TEMPLATE_HTML_FRONT_CODE_ENTRY_VALUE;
197         }
198 
199         return TEMPLATE_HTML_CODE_ENTRY_VALUE;
200     }
201 
202     /**
203      *
204      * {@inheritDoc}
205      */
206     @Override
207     public String getEntryData( HttpServletRequest request, Locale locale )
208     {
209         String strTitle = request.getParameter( PARAMETER_TITLE );
210         String strHelpMessage = ( request.getParameter( PARAMETER_HELP_MESSAGE ) != null ) ? request.getParameter( PARAMETER_HELP_MESSAGE ).trim( ) : null;
211         String strHelpMessageSearch = ( request.getParameter( PARAMETER_HELP_MESSAGE_SEARCH ) != null ) ? request.getParameter( PARAMETER_HELP_MESSAGE_SEARCH )
212                 .trim( ) : null;
213         String strComment = request.getParameter( PARAMETER_COMMENT );
214         String strMandatory = request.getParameter( PARAMETER_MANDATORY );
215         String strIndexed = request.getParameter( PARAMETER_INDEXED );
216         String strIndexedAsTitle = request.getParameter( PARAMETER_INDEXED_AS_TITLE );
217         String strIndexedAsSummary = request.getParameter( PARAMETER_INDEXED_AS_SUMMARY );
218         String strShowInAdvancedSearch = request.getParameter( PARAMETER_SHOWN_IN_ADVANCED_SEARCH );
219         String strShowInResultList = request.getParameter( PARAMETER_SHOWN_IN_RESULT_LIST );
220         String strShowInResultRecord = request.getParameter( PARAMETER_SHOWN_IN_RESULT_RECORD );
221         String strShowInHistory = request.getParameter( PARAMETER_SHOWN_IN_HISTORY );
222         String strMapProvider = request.getParameter( PARAMETER_MAP_PROVIDER );
223         String strShowInExport = request.getParameter( PARAMETER_SHOWN_IN_EXPORT );
224         String strShowInCompleteness = request.getParameter( PARAMETER_SHOWN_IN_COMPLETENESS );
225         String strShowXY = request.getParameter( PARAMETER_SHOWXY );
226         String strEditMode = request.getParameter( PARAMETER_EDIT_MODE );
227         String strViewNumberAtt = request.getParameter( PARAMETER_VIEW_NUMBER_ATT );
228         String strViewNumberGes = request.getParameter( PARAMETER_VIEW_NUMBER_GES );
229 
230         String strIdEntry = request.getParameter( PARAMETER_ID_ENTRY );
231         int nIdEntry = Integer.parseInt( strIdEntry );
232 
233         String strIdDirectory = request.getParameter( PARAMETER_ID_DIRECTORY );
234         int nIdDirectory = Integer.parseInt( strIdDirectory );
235 
236         String strFieldError = DirectoryUtils.EMPTY_STRING;
237 
238         if ( ( strTitle == null ) || strTitle.trim( ).equals( DirectoryUtils.EMPTY_STRING ) )
239         {
240             strFieldError = FIELD_TITLE;
241         }
242 
243         if ( !strFieldError.equals( DirectoryUtils.EMPTY_STRING ) )
244         {
245             Object [ ] tabRequiredFields = {
246                 I18nService.getLocalizedString( strFieldError, locale )
247             };
248 
249             return AdminMessageService.getMessageUrl( request, MESSAGE_MANDATORY_FIELD, tabRequiredFields, AdminMessage.TYPE_STOP );
250         }
251 
252         // for don't update fields listFields=null
253         Field xField = findField( CONSTANT_X, getFields( ) );
254 
255         if ( xField == null )
256         {
257             xField = new Field( );
258         }
259 
260         xField.setEntry( this );
261         xField.setTitle( CONSTANT_X );
262         xField.setValue( CONSTANT_X );
263 
264         Field yField = findField( CONSTANT_Y, getFields( ) );
265 
266         if ( yField == null )
267         {
268             yField = new Field( );
269         }
270 
271         yField.setEntry( this );
272         yField.setTitle( CONSTANT_Y );
273         yField.setValue( CONSTANT_Y );
274 
275         Field mapProviderField = findField( CONSTANT_PROVIDER, getFields( ) );
276 
277         if ( mapProviderField == null )
278         {
279             mapProviderField = new Field( );
280         }
281 
282         mapProviderField.setEntry( this );
283         mapProviderField.setTitle( CONSTANT_PROVIDER );
284         mapProviderField.setValue( strMapProvider );
285 
286         Field addressField = findField( CONSTANT_ADDRESS, getFields( ) );
287 
288         if ( addressField == null )
289         {
290             addressField = new Field( );
291         }
292 
293         addressField.setEntry( this );
294         addressField.setTitle( CONSTANT_ADDRESS );
295 
296         /*
297          * Field additionalAddressField = findField( CONSTANT_ADDITIONAL_ADDRESS, getFields( ) );
298          * 
299          * if ( additionalAddressField == null ) { additionalAddressField = new Field( ); }
300          * 
301          * additionalAddressField.setEntry( this ); additionalAddressField.setTitle( CONSTANT_ADDITIONAL_ADDRESS );
302          */
303 
304         Field geometryField = findField( CONSTANT_GEOMETRY, getFields( ) );
305 
306         if ( geometryField == null )
307         {
308             geometryField = new Field( );
309         }
310 
311         geometryField.setEntry( this );
312         geometryField.setTitle( CONSTANT_GEOMETRY );
313 
314         Field showXYField = findField( CONSTANT_SHOWXY, getFields( ) );
315 
316         if ( showXYField == null )
317         {
318             showXYField = new Field( );
319         }
320 
321         showXYField.setEntry( this );
322         showXYField.setTitle( CONSTANT_SHOWXY );
323         showXYField.setValue( StringUtils.isNotBlank( strShowXY ) ? Boolean.TRUE.toString( ) : Boolean.FALSE.toString( ) );
324 
325         Field editModeField = findField( CONSTANT_EDIT_MODE, getFields( ) );
326 
327         if ( editModeField == null )
328         {
329             editModeField = new Field( );
330         }
331 
332         editModeField.setEntry( this );
333         editModeField.setTitle( CONSTANT_EDIT_MODE );
334         editModeField.setValue( strEditMode );
335 
336         Field viewNumberAttField = findField( CONSTANT_VIEW_NUMBER_ATT, getFields( ) );
337 
338         if ( viewNumberAttField == null )
339         {
340             viewNumberAttField = new Field( );
341         }
342 
343         viewNumberAttField.setEntry( this );
344         viewNumberAttField.setTitle( CONSTANT_VIEW_NUMBER_ATT );
345         viewNumberAttField.setValue( strViewNumberAtt );
346 
347         Field viewNumberGesField = findField( CONSTANT_VIEW_NUMBER_GES, getFields( ) );
348 
349         if ( viewNumberGesField == null )
350         {
351             viewNumberGesField = new Field( );
352         }
353 
354         viewNumberGesField.setEntry( this );
355         viewNumberGesField.setTitle( CONSTANT_VIEW_NUMBER_GES );
356         viewNumberGesField.setValue( strViewNumberGes );
357 
358         List<Field> listFields = new ArrayList<Field>( );
359         listFields.add( xField );
360         listFields.add( yField );
361         listFields.add( mapProviderField );
362         listFields.add( addressField );
363         // listFields.add( additionalAddressField );
364         listFields.add( geometryField );
365         listFields.add( showXYField );
366         listFields.add( editModeField );
367         listFields.add( viewNumberAttField );
368         listFields.add( viewNumberGesField );
369         this.setFields( listFields );
370 
371         this.setTitle( strTitle );
372         this.setHelpMessage( strHelpMessage );
373         this.setHelpMessageSearch( strHelpMessageSearch );
374         this.setComment( strComment );
375         this.setMandatory( strMandatory != null );
376         this.setIndexed( strIndexed != null );
377         this.setIndexedAsTitle( strIndexedAsTitle != null );
378         this.setIndexedAsSummary( strIndexedAsSummary != null );
379         this.setShownInAdvancedSearch( strShowInAdvancedSearch != null );
380         this.setShownInResultList( strShowInResultList != null );
381         this.setShownInResultRecord( strShowInResultRecord != null );
382         this.setFieldInLine( false );
383         this.setShownInHistory( strShowInHistory != null );
384         this.setMapProvider( MapProviderManager.getMapProvider( strMapProvider ) );
385         this.setShownInExport( strShowInExport != null );
386         this.setShownInCompleteness( strShowInCompleteness != null );
387 
388         IEntry entry = EntryHome.findByPrimaryKey( nIdEntry, DirectoryUtils.getPlugin( ) );
389         boolean update = false;
390         if ( entry != null )
391         {
392             update = true;
393             getAdditionalAddressEntry( 6, entry, locale, update );
394         }
395         else
396         {
397             entry = new Entry( );
398             Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, DirectoryUtils.getPlugin( ) );
399             entry.setDirectory( directory );
400             getAdditionalAddressEntry( 6, entry, locale, update );
401         }
402 
403         return null;
404     }
405 
406     /**
407      * Builds the {@link ReferenceList} of all available map providers
408      * 
409      * @return the {@link ReferenceList}
410      */
411     public ReferenceList getMapProvidersRefList( )
412     {
413         ReferenceList refList = new ReferenceList( );
414 
415         refList.addItem( DirectoryUtils.EMPTY_STRING, DirectoryUtils.EMPTY_STRING );
416 
417         for ( IMapProvider mapProvider : MapProviderManager.getMapProvidersList( ) )
418         {
419             refList.add( mapProvider.toRefItem( ) );
420         }
421 
422         return refList;
423     }
424 
425     /**
426      * Builds the {@link ReferenceList} of all available edit modes
427      * 
428      * @return the {@link ReferenceList}
429      */
430     public ReferenceList getEditModesRefList( )
431     {
432         String strEditModeListProperty = AppPropertiesService.getProperty( PARAMETER_EDIT_MODE_LIST );
433         ReferenceList refList = new ReferenceList( );
434         refList.addItem( StringUtils.EMPTY, StringUtils.EMPTY );
435         if ( strEditModeListProperty != null )
436         {
437             String [ ] strEditModeListPropertyArray = strEditModeListProperty.split( "," );
438 
439             for ( int i = 0; i < strEditModeListPropertyArray.length; i++ )
440             {
441                 refList.addItem( strEditModeListPropertyArray [i], strEditModeListPropertyArray [i] );
442             }
443         }
444 
445         return refList;
446     }
447 
448     /**
449      *
450      * {@inheritDoc}
451      */
452     @Override
453     public void getRecordFieldData( Record record, HttpServletRequest request, boolean bTestDirectoryError, boolean addNewValue,
454             List<RecordField> listRecordField, Locale locale ) throws DirectoryErrorException
455     {
456         List<String> listValue = new ArrayList<String>( );
457         String strXValue = request.getParameter( this.getIdEntry( ) + PARAMETER_SUFFIX_X );
458         String strYValue = request.getParameter( this.getIdEntry( ) + PARAMETER_SUFFIX_Y );
459         String strMapProviderValue = request.getParameter( this.getIdEntry( ) + PARAMETER_SUFFIX_MAP_PROVIDER );
460         String strAddressValue = request.getParameter( this.getIdEntry( ) + PARAMETER_SUFFIX_ADDRESS );
461         // String strAdditionalAddressValue = request.getParameter( this.getIdEntry( ) + PARAMETER_SUFFIX_ADDITIONAL_ADDRESS );
462         String strGeometryValue = request.getParameter( this.getIdEntry( ) + PARAMETER_SUFFIX_GEOMETRY );
463         listValue.add( strXValue );
464         listValue.add( strYValue );
465         listValue.add( strMapProviderValue );
466         listValue.add( strAddressValue );
467         // listValue.add( strAdditionalAddressValue );
468         listValue.add( strGeometryValue );
469 
470         getRecordFieldData( record, listValue, bTestDirectoryError, addNewValue, listRecordField, locale );
471     }
472 
473     /**
474      *
475      * {@inheritDoc}
476      */
477     @Override
478     public void addSearchCriteria( HashMap<String, Object> mapSearchItem, RecordField recordField )
479     {
480         String strValue;
481 
482         if ( recordField.getValue( ) != null )
483         {
484             if ( !CONSTANT_PROVIDER.equals( recordField.getField( ).getTitle( ) ) )
485             {
486                 strValue = new String( recordField.getValue( ) );
487 
488                 if ( !strValue.trim( ).equals( DirectoryUtils.EMPTY_STRING ) )
489                 {
490                     mapSearchItem.put( DirectorySearchItem.FIELD_CONTENTS, strValue );
491                 }
492             }
493         }
494     }
495 
496     /**
497      *
498      * {@inheritDoc}
499      */
500     @Override
501     public void getRecordFieldData( Record record, List<String> lstValue, boolean bTestDirectoryError, boolean addNewValue, List<RecordField> listRecordField,
502             Locale locale ) throws DirectoryErrorException
503     {
504         if ( lstValue.size( ) != CONSTANT_FIELDS_COUNT )
505         {
506             throw new DirectoryErrorException( this.getTitle( ) );
507         }
508 
509         String strXValue = lstValue.get( CONSTANT_POSITION_X );
510         String strYValue = lstValue.get( CONSTANT_POSITION_Y );
511         String strMapProviderValue = lstValue.get( CONSTANT_POSITION_MAP_PROVIDER );
512         String strAddressValue = lstValue.get( CONSTANT_POSITION_ADDRESS );
513         // String strAdditionalAddressValue = lstValue.get( CONSTANT_POSITION_ADDITIONAL_ADDRESS );
514         String strGeometryValue = lstValue.get( CONSTANT_POSITION_GEOMETRY );
515 
516         Field xField = findField( CONSTANT_X, getFields( ) );
517         Field yField = findField( CONSTANT_Y, getFields( ) );
518 
519         if ( bTestDirectoryError )
520         {
521             if ( this.isMandatory( ) )
522             {
523                 if ( ( StringUtils.isBlank( strXValue ) || StringUtils.isBlank( strYValue ) ) && StringUtils.isBlank( strAddressValue ) )
524                 {
525                     throw new DirectoryErrorException( this.getTitle( ) );
526                 }
527             }
528             else
529                 if ( ( StringUtils.isBlank( strXValue ) && StringUtils.isNotBlank( strYValue ) )
530                         || ( StringUtils.isNotBlank( strXValue ) && StringUtils.isBlank( strYValue ) ) )
531                 {
532                     throw new DirectoryErrorException( this.getTitle( ) );
533                 }
534         }
535 
536         RecordField recordFieldX = new RecordField( );
537         recordFieldX.setEntry( this );
538         recordFieldX.setValue( strXValue );
539         recordFieldX.setField( xField );
540         listRecordField.add( recordFieldX );
541 
542         RecordField recordFieldY = new RecordField( );
543         recordFieldY.setEntry( this );
544         recordFieldY.setValue( strYValue );
545         recordFieldY.setField( yField );
546         listRecordField.add( recordFieldY );
547 
548         IMapProvider mapProvider = MapProviderManager.getMapProvider( strMapProviderValue );
549         Field mapProviderField = findField( CONSTANT_PROVIDER, getFields( ) );
550 
551         RecordField recordFieldMapProvider = new RecordField( );
552         recordFieldMapProvider.setEntry( this );
553 
554         if ( mapProvider == null )
555         {
556             strMapProviderValue = mapProviderField.getValue( );
557         }
558 
559         recordFieldMapProvider.setValue( strMapProviderValue );
560         recordFieldMapProvider.setField( mapProviderField );
561         listRecordField.add( recordFieldMapProvider );
562 
563         RecordField recordFieldAddress = new RecordField( );
564         Field addressField = findField( CONSTANT_ADDRESS, getFields( ) );
565 
566         recordFieldAddress.setEntry( this );
567         recordFieldAddress.setValue( strAddressValue );
568         recordFieldAddress.setField( addressField );
569         listRecordField.add( recordFieldAddress );
570 
571         /*
572          * RecordField recordFieldAddtionalAddress = new RecordField( ); Field additionalAddressField = findField( CONSTANT_ADDITIONAL_ADDRESS, getFields( ) );
573          * 
574          * recordFieldAddtionalAddress.setEntry( this ); recordFieldAddtionalAddress.setValue( strAdditionalAddressValue );
575          * recordFieldAddtionalAddress.setField( additionalAddressField ); listRecordField.add( recordFieldAddtionalAddress );
576          */
577 
578         RecordField recordFieldGeometry = new RecordField( );
579         Field geometryField = findField( CONSTANT_GEOMETRY, getFields( ) );
580 
581         recordFieldGeometry.setEntry( this );
582         recordFieldGeometry.setValue( strGeometryValue );
583         recordFieldGeometry.setField( geometryField );
584         listRecordField.add( recordFieldGeometry );
585     }
586 
587     /**
588      *
589      * {@inheritDoc}
590      */
591     @Override
592     public void getImportRecordFieldData( Record record, byte [ ] decodedBytes, String nomFile, boolean b, List<RecordField> listRecordField, Locale locale )
593             throws DirectoryErrorException
594     {
595         super.getImportRecordFieldData( record, decodedBytes, nomFile, b, listRecordField, locale );
596     }
597 
598     /**
599      *
600      * {@inheritDoc}
601      */
602     @Override
603     public void getImportRecordFieldData( Record record, String strImportValue, boolean bTestDirectoryError, List<RecordField> listRecordField, Locale locale )
604             throws DirectoryErrorException
605     {
606         List<String> lstValue = splitGeolocationValues( strImportValue );
607 
608         getRecordFieldData( record, lstValue, bTestDirectoryError, false, listRecordField, locale );
609     }
610 
611     /**
612      * Split the import value to X, Y, provider and address
613      * 
614      * @param strNotSplittedValue
615      *            the import value
616      * @return a list of string
617      */
618     private List<String> splitGeolocationValues( String strNotSplittedValue )
619     {
620         Field showXYField = findField( CONSTANT_SHOWXY, getFields( ) );
621 
622         // if ( !strNotSplittedValue.contains( DirectoryUtils.CONSTANT_COMA ) )
623         if ( !Boolean.parseBoolean( showXYField.getValue( ) ) )
624         {
625             List<String> lstValue = new ArrayList<String>( );
626 
627             for ( int nCpt = 0; nCpt < CONSTANT_FIELDS_COUNT; nCpt++ )
628             {
629                 lstValue.add( StringUtils.EMPTY );
630             }
631 
632             if ( StringUtils.isNotBlank( strNotSplittedValue ) )
633             {
634                 lstValue.remove( CONSTANT_POSITION_ADDRESS );
635                 lstValue.add( CONSTANT_POSITION_ADDRESS, strNotSplittedValue );
636             }
637 
638             return lstValue;
639         }
640 
641         /** DIRECTORY-70 : The X, Y and provider are not displayed in the export */
642         /*
643          * // first, split coma "," if ( StringUtils.isBlank( strNotSplittedValue ) ) { List<String> listEmptyValues = new ArrayList<String>( );
644          * 
645          * for ( int nCpt = 0; nCpt < CONSTANT_FIELDS_COUNT; nCpt++ ) { listEmptyValues.add( DirectoryUtils.EMPTY_STRING ); }
646          * 
647          * return listEmptyValues; }
648          * 
649          * String[] comaSplitted = strNotSplittedValue.split( DirectoryUtils.CONSTANT_COMA );
650          * 
651          * if ( ( comaSplitted == null ) || ( comaSplitted.length < 3 ) ) { throw new DirectoryErrorException( this.getTitle( ) ); }
652          */
653         String [ ] comaSplitted = strNotSplittedValue.split( DirectoryUtils.CONSTANT_COMA );
654 
655         List<String> listGeolocValues = new ArrayList<String>( 4 );
656         StringBuilder sbAddress = new StringBuilder( );
657 
658         for ( int i = 0; i < comaSplitted.length; i++ )
659         {
660             if ( i < CONSTANT_POSITION_ADDRESS )
661             {
662                 listGeolocValues.add( comaSplitted [i] );
663             }
664             else
665                 if ( i == CONSTANT_POSITION_ADDRESS )
666                 {
667                     sbAddress.append( comaSplitted [i] );
668                 }
669                 else
670                 {
671                     sbAddress.append( DirectoryUtils.CONSTANT_COMA );
672                     sbAddress.append( comaSplitted [i] );
673                 }
674         }
675 
676         listGeolocValues.add( sbAddress.toString( ) );
677 
678         return listGeolocValues;
679 
680         // for ( String strValue : comaSplitted )
681         // {
682         // if ( strValue.startsWith( CONSTANT_X + DirectoryUtils.CONSTANT_EQUAL ) )
683         // {
684         // tabGeolocationValues[CONSTANT_POSITION_X] = strValue.substring( ( CONSTANT_X +
685         // DirectoryUtils.CONSTANT_EQUAL ).length( ) );
686         // }
687         // else if ( strValue.startsWith( CONSTANT_Y + DirectoryUtils.CONSTANT_EQUAL ) )
688         // {
689         // tabGeolocationValues[CONSTANT_POSITION_Y] = strValue.substring( ( CONSTANT_Y +
690         // DirectoryUtils.CONSTANT_EQUAL ).length( ) );
691         // }
692         // else if ( strValue.startsWith( CONSTANT_PROVIDER + DirectoryUtils.CONSTANT_EQUAL ) )
693         // {
694         // tabGeolocationValues[CONSTANT_POSITION_MAP_PROVIDER] = strValue.substring( ( CONSTANT_PROVIDER +
695         // DirectoryUtils.CONSTANT_EQUAL ).length( ) );
696         // }
697         // else if ( strValue.startsWith( CONSTANT_ADDRESS + DirectoryUtils.CONSTANT_EQUAL ) )
698         // {
699         // tabGeolocationValues[CONSTANT_POSITION_ADDRESS] = strValue.substring( ( CONSTANT_ADDRESS +
700         // DirectoryUtils.CONSTANT_EQUAL ).length( ) );
701         // }
702         // else
703         // {
704         // if ( StringUtils.isNotBlank( tabGeolocationValues[CONSTANT_POSITION_ADDRESS] ) )
705         // {
706         // tabGeolocationValues[CONSTANT_POSITION_ADDRESS] += strValue;
707         // }
708         // else
709         // {
710         // throw new DirectoryErrorException( this.getTitle( ) );
711         // }
712         // }
713         // }
714         //
715         // return Arrays.asList( tabGeolocationValues );
716     }
717 
718     /**
719      *
720      * {@inheritDoc}
721      */
722     @Override
723     public String toString( )
724     {
725         return "Entry Type Geolocation " + this.getFields( ) + " " + this.getMapProvider( );
726     }
727 
728     /**
729      * Finds a field according to its title
730      * 
731      * @param fieldName
732      *            the title
733      * @param fieldList
734      *            the list
735      * @return the found field, <code>null</code> otherwise.
736      */
737     private Field findField( String fieldName, List<Field> fieldList )
738     {
739         if ( StringUtils.isBlank( fieldName ) || ( fieldList == null ) || ( fieldList.size( ) == 0 ) )
740         {
741             return null;
742         }
743 
744         for ( Field field : fieldList )
745         {
746             if ( fieldName.equals( field.getTitle( ) ) )
747             {
748                 return field;
749             }
750         }
751 
752         return null;
753     }
754 
755     /**
756      *
757      * {@inheritDoc}
758      */
759     @Override
760     public String convertRecordFieldTitleToString( RecordField recordField, Locale locale, boolean displayFront )
761     {
762         if ( ( recordField != null ) && ( recordField.getField( ) != null ) )
763         {
764             return recordField.getValue( );
765         }
766 
767         /*
768          * if ( displayFront ) { if ( recordField != null && recordField.getField( ) != null && recordField.getField( ).getTitle( ) != null ) { if (
769          * CONSTANT_X.equals( recordField.getField( ).getTitle( ) ) ) { return CONSTANT_X + DirectoryUtils.CONSTANT_EQUAL + recordField.getValue( ); } else if (
770          * CONSTANT_Y.equals( recordField.getField( ).getTitle( ) ) ) { return CONSTANT_Y + DirectoryUtils.CONSTANT_EQUAL + recordField.getValue( ); } else if (
771          * CONSTANT_PROVIDER.equals( recordField.getField( ).getTitle( ) ) ) { return DirectoryUtils.EMPTY_STRING; } } }
772          */
773         return super.convertRecordFieldTitleToString( recordField, locale, displayFront );
774     }
775 
776     /**
777      *
778      * {@inheritDoc}
779      */
780     @Override
781     public String convertRecordFieldValueToString( RecordField recordField, Locale locale, boolean bDisplayFront, boolean bExportDirectory )
782     {
783         if ( ( recordField != null ) && ( recordField.getField( ) != null ) && ( recordField.getField( ).getTitle( ) != null ) )
784         {
785             if ( CONSTANT_X.equals( recordField.getField( ).getTitle( ) ) || CONSTANT_Y.equals( recordField.getField( ).getTitle( ) )
786                     || CONSTANT_PROVIDER.equals( recordField.getField( ).getTitle( ) ) || CONSTANT_ADDRESS.equals( recordField.getField( ).getTitle( ) ) )
787             {
788                 return recordField.getValue( );
789             }
790 
791             return StringUtils.EMPTY;
792         }
793 
794         return super.convertRecordFieldValueToString( recordField, locale, bDisplayFront, bExportDirectory );
795     }
796 
797     /**
798      * {@inheritDoc}
799      */
800     @Override
801     public boolean isSortable( )
802     {
803         return true;
804     }
805 
806     /**
807      * Join that get only the address.
808      */
809     @Override
810     public String getSQLJoin( )
811     {
812         return SQL_JOIN_DIRECTORY_RECORD_FIELD;
813     }
814 
815     /**
816      *
817      * Returns the entry id and field title parameter
818      */
819     @Override
820     public List<Object> getSQLParametersValues( )
821     {
822         List<Object> listParameters = new ArrayList<Object>( );
823         listParameters.add( Integer.valueOf( getIdEntry( ) ) );
824         listParameters.add( CONSTANT_ADDRESS );
825 
826         return listParameters;
827     }
828 
829     /**
830      * {@inheritDoc}
831      */
832     @Override
833     public void getXml( Plugin plugin, Locale locale, StringBuffer strXml )
834     {
835         Map<String, String> model = new HashMap<String, String>( );
836         model.put( ATTRIBUTE_ENTRY_ID, String.valueOf( this.getIdEntry( ) ) );
837         model.put( ATTRIBUTE_ENTRY_ID_TYPE, String.valueOf( this.getEntryType( ).getIdType( ) ) );
838         model.put( CONSTANT_SHOWXY, Boolean.toString( DirectoryService.getInstance( ).showXY( this ) ) );
839 
840         XmlUtil.beginElement( strXml, TAG_ENTRY, model );
841         XmlUtil.addElementHtml( strXml, TAG_TITLE, this.getTitle( ) );
842         XmlUtil.endElement( strXml, TAG_ENTRY );
843     }
844 
845     public void getAdditionalAddressEntry( int nIdEntryType, IEntry entry, Locale locale, boolean update )
846     {
847         EntryType entryType = EntryTypeHome.findByPrimaryKey( nIdEntryType, DirectoryUtils.getPlugin( ) );
848         IEntry entryAdditionalAddress = DirectoryUtils.createEntryByType( nIdEntryType, DirectoryUtils.getPlugin( ) );
849 
850         if ( entryAdditionalAddress != null )
851         {
852             entryAdditionalAddress.setEntryType( entryType );
853 
854             entryAdditionalAddress.setDirectory( entry.getDirectory( ) );
855 
856             entryAdditionalAddress.setTitle( I18nService.getLocalizedString( "directory.additional_address.title", locale ) );
857             entryAdditionalAddress.setHelpMessage( "" );
858             entryAdditionalAddress.setHelpMessageSearch( "" );
859             entryAdditionalAddress.setComment( "" );
860 
861             if ( entryAdditionalAddress.getFields( ) == null )
862             {
863                 ArrayList<Field> listFields = new ArrayList<Field>( );
864                 Field field = new Field( );
865                 field.setTitle( "additionalAddress" );
866                 field.setValue( "" );
867                 // FieldHome.create(field, pluginDirectory);
868                 listFields.add( field );
869                 entryAdditionalAddress.setFields( listFields );
870             }
871 
872             entryAdditionalAddress.getFields( ).get( 0 ).setWidth( 50 );
873             entryAdditionalAddress.getFields( ).get( 0 ).setMaxSizeEnter( 50 );
874             entryAdditionalAddress.setMandatory( false );
875             entryAdditionalAddress.setIndexed( false );
876             entryAdditionalAddress.setIndexedAsTitle( false );
877             entryAdditionalAddress.setIndexedAsSummary( false );
878             entryAdditionalAddress.setShownInAdvancedSearch( false );
879             entryAdditionalAddress.setShownInResultList( true );
880             entryAdditionalAddress.setShownInResultRecord( true );
881             entryAdditionalAddress.setShownInHistory( true );
882             entryAdditionalAddress.setAutocompleteEntry( false );
883             entryAdditionalAddress.setShownInExport( true );
884             entryAdditionalAddress.setShownInCompleteness( false );
885 
886             if ( update )
887             {
888                 EntryHome.update( entryAdditionalAddress, DirectoryUtils.getPlugin( ) );
889 
890                 if ( entryAdditionalAddress.getFields( ) != null )
891                 {
892                     for ( Field field : entryAdditionalAddress.getFields( ) )
893                     {
894                         field.setEntry( entryAdditionalAddress );
895                         FieldHome.update( field, DirectoryUtils.getPlugin( ) );
896                     }
897                 }
898             }
899             else
900             {
901                 EntryHome.create( entryAdditionalAddress, DirectoryUtils.getPlugin( ) );
902 
903                 if ( entryAdditionalAddress.getFields( ) != null )
904                 {
905                     for ( Field field : entryAdditionalAddress.getFields( ) )
906                     {
907                         field.setEntry( entryAdditionalAddress );
908                         FieldHome.create( field, DirectoryUtils.getPlugin( ) );
909                     }
910                 }
911             }
912 
913         }
914     }
915 }