View Javadoc
1   /*******************************************************************************
2    *   Gisgraphy Project 
3    * 
4    *   This library is free software; you can redistribute it and/or
5    *   modify it under the terms of the GNU Lesser General Public
6    *   License as published by the Free Software Foundation; either
7    *   version 2.1 of the License, or (at your option) any later version.
8    * 
9    *   This library is distributed in the hope that it will be useful,
10   *   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   *   Lesser General Public License for more details.
13   * 
14   *   You should have received a copy of the GNU Lesser General Public
15   *   License along with this library; if not, write to the Free Software
16   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
17   * 
18   *  Copyright 2008  Gisgraphy project 
19   *  David Masclet <davidmasclet@gisgraphy.com>
20   *  
21   *  
22   *******************************************************************************/
23  /**
24   *
25   */
26  package com.gisgraphy.importer;
27  
28  import static com.gisgraphy.importer.ImporterHelper.checkUrl;
29  
30  import java.io.File;
31  import java.util.ArrayList;
32  import java.util.List;
33  
34  import org.slf4j.Logger;
35  import org.slf4j.LoggerFactory;
36  import org.springframework.beans.factory.annotation.Required;
37  
38  import com.gisgraphy.helper.CommentedProperties;
39  
40  /**
41   * @author <a href="mailto:david.masclet@gisgraphy.com">David Masclet</a>
42   *         Represents a configuration for importers For more informations for
43   *         this options see the User Guide
44   */
45  public class ImporterConfig {
46  	
47  	 public static final String PROPERTIES_CONFIG_FILE_CLASSPATH = "/env.properties";
48  
49  	public static final String OPENSTREETMAP_FILL_ISIN_FIELD_NAME = "importerConfig.openstreetmap.fill.isin.field";
50  
51  	/**
52       * A list of options is separated by this. e.g : a list of regexp options
53       */
54      public static final String OPTION_SEPARATOR = ";";
55      
56      /**
57       * A list of options is separated by this. e.g : a list of regexp options
58       */
59      public static final String REGEXP_SEPARATOR = "|";
60  
61      /**
62       * The relative path of the directory that contains importer metadata
63       */
64      public static final String IMPORTER_METADATA_RELATIVE_PATH = "IMPORTER-METADATA-DO_NOT_REMOVE";
65  
66      /**
67       * the name of the file that gives the information if the import is done or
68       * not
69       */
70      public static final String ALREADY_DONE_FILE_NAME = "importNotAlreadyDone";
71  
72      /**
73       * The default feature code if no one is specified
74       */
75      public final static String DEFAULT_FEATURE_CODE = "UNK";
76      /**
77       * The default feature class if no one is specified
78       */
79      public final static String DEFAULT_FEATURE_CLASS = "UNK";
80  
81      /**
82       * The default regexp if no one is specified in the env.properties file
83       */
84      public final static String BASE_ACCEPT_REGEX = "ADM|COUNTRY|";
85  
86      /**
87       * The regexp to use to import all the city
88       */
89      public final static String DEFAULT_ACCEPT_REGEX_CITY = BASE_ACCEPT_REGEX + "CITY$";
90  
91      /**
92       * The regexp to use to import all the feature class / code
93       */
94      public final static String ACCEPT_ALL_REGEX_OPTION = ".*";
95  
96      /**
97       * Default value for {@link #maxInsertsBeforeFlush}
98       */
99      public final static int DEFAULT_MAX_INSERT_BEFORE_FLUSH = 1000;
100 
101     /**
102      * How many lines do we have to process before flushing
103      * 
104      * @see #DEFAULT_MAX_INSERT_BEFORE_FLUSH
105      */
106     private int maxInsertsBeforeFlush = DEFAULT_MAX_INSERT_BEFORE_FLUSH;
107 
108     public final static String OPENSTREETMAP_DEFAULT_FILES_TO_DOWNLOAD = "allcountries.tar.bz2";
109     
110     public final static String OPENSTREETMAP_HOUSENUMBER_DEFAULT_FILES_TO_DOWNLOAD = "allcountries.tar.bz2";
111     
112     public final static String OPENSTREETMAP_CITIES_DEFAULT_FILES_TO_DOWNLOAD = "allcountries.tar.bz2";
113     
114     public final static String OPENSTREETMAP_POI_DEFAULT_FILES_TO_DOWNLOAD = "allcountries.tar.bz2";
115     
116     public final static String QUATTROSHAPES_DEFAULT_FILES_TO_DOWNLOAD = "shapes.tar.bz2";
117 
118     public final static String GEONAMES_ALTERNATENAME_ZIP_FILE="alternateNames.zip";
119     
120     public final static String GEONAMES_COMPRESSED_FILE_EXTENSION=".zip";
121     
122     public final static String OPENSTREETAMP_COMPRESSED_FILE_EXTENSION=".tar.bz2";
123     
124     public final static String GEONAMES_DEFAULT_FILES_TO_DOWNLOAD = "allCountries.zip"+OPTION_SEPARATOR+GEONAMES_ALTERNATENAME_ZIP_FILE;
125     
126     
127 
128     /**
129      * Default option if the Adm1 file has already been processed
130      * 
131      * @see AdmExtracterStrategyOptions
132      */
133     public AdmExtracterStrategyOptions DEFAULT_ADM1_EXTRACTER_STRATEGY_OPTION = AdmExtracterStrategyOptions.reprocess;
134     /**
135      * Default option if the adm2 file has already been processed
136      * 
137      * @see AdmExtracterStrategyOptions
138      */
139     public AdmExtracterStrategyOptions DEFAULT_ADM2_EXTRACTER_STRATEGY_OPTION = AdmExtracterStrategyOptions.reprocess;
140 
141     /**
142      * Default option if the Adm3 file has already been processed
143      * 
144      * @see AdmExtracterStrategyOptions
145      */
146     public AdmExtracterStrategyOptions DEFAULT_ADM3_EXTRACTER_STRATEGY_OPTION = AdmExtracterStrategyOptions.reprocess;
147     /**
148      * Default option if the adm4 file has already been processed
149      * 
150      * @see AdmExtracterStrategyOptions
151      */
152     public AdmExtracterStrategyOptions DEFAULT_ADM4_EXTRACTER_STRATEGY_OPTION = AdmExtracterStrategyOptions.reprocess;
153 
154     /**
155      * The logger
156      */
157     protected static final Logger logger = LoggerFactory.getLogger(ImporterConfig.class);
158 
159    
160 
161     private boolean wrongNumberOfFieldsThrows = false;
162 
163     private boolean missingRequiredFieldThrows = false;
164 
165     private boolean importGisFeatureEmbededAlternateNames = false;
166 
167     private String geonamesDir;
168 
169     private String openStreetMapDir;
170     
171     private String quattroshapesDir;
172     
173     private String openStreetMapHouseNumberDir;
174 
175     private String openStreetMapCitiesDir;
176     
177     private String openStreetMapPoisDir;
178     
179     private String geonamesZipCodeDir;
180 
181     private String openstreetMapDownloadURL;
182     
183     private String quattroshapesDownloadURL;
184     
185     private String openstreetMapHouseNumbersDownloadURL;
186     
187     private String openstreetMapCitiesDownloadURL;
188     
189     private String openstreetMapPoisDownloadURL;
190 
191     private String geonamesDownloadURL;
192 
193     private String geonamesZipCodeDownloadURL;
194 
195     private boolean retrieveFiles = false;
196 
197     private String geonamesFilesToDownload = "";
198 
199     private String openStreetMapFilesToDownload = "";
200     
201     private String quattroshapesFilesToDownload = "";
202     
203     private String openStreetMapHouseNumberFilesToDownload = "";
204     
205     private String openStreetMapCitiesFilesToDownload = "";
206     
207     private String openStreetMapPoisFilesToDownload = "";
208 
209     private boolean geonamesImporterEnabled = true;
210 
211     private boolean openstreetmapImporterEnabled = true;
212     
213     private boolean quattroshapesImporterEnabled = true;
214     
215     private boolean openstreetmapHouseNumberImporterEnabled = true;
216 
217     private boolean openStreetMapFillIsIn = true;
218     
219     private String adm1FileName;
220 
221     private String adm2FileName;
222 
223     private String adm3FileName;
224 
225     private String adm4FileName;
226 
227     private String languageFileName;
228 
229     private String countriesFileName;
230 
231     private String alternateNamesFileName;
232 
233     private String acceptRegExString = "*";
234 
235     private boolean tryToDetectAdmIfNotFound = true;
236 
237     private boolean syncAdmCodesWithLinkedAdmOnes = true;
238 
239     private AdmExtracterStrategyOptions adm1ExtracterStrategyIfAlreadyExists;
240 
241     private AdmExtracterStrategyOptions adm2ExtracterStrategyIfAlreadyExists;
242 
243     private AdmExtracterStrategyOptions adm3ExtracterStrategyIfAlreadyExists;
244 
245     private AdmExtracterStrategyOptions adm4ExtracterStrategyIfAlreadyExists;
246 
247     private String alternateNameFeaturesFileName;
248 
249     private String alternateNameAdm1FileName;
250 
251     private String alternateNameAdm2FileName;
252 
253     private String alternateNameCountryFileName;
254     
255     private boolean renameFilesAfterProcessing = false;
256     
257     
258     /*
259      *  
260      __ _  ___  ___  _ __   __ _ _ __ ___   ___  ___ 
261  	/ _` |/ _ \/ _ \| '_ \ / _` | '_ ` _ \ / _ \/ __|
262    | (_| |  __/ (_) | | | | (_| | | | | | |  __/\__ \
263  	\__, |\___|\___/|_| |_|\__,_|_| |_| |_|\___||___/
264  	|___/ 
265      * 
266      */
267     
268     /**
269      * @return true if the importer should process the import of Geonames data
270      */
271     public boolean isGeonamesImporterEnabled() {
272     	return geonamesImporterEnabled;
273     }
274     
275     /**
276      * @param geonamesImporterEnabled
277      *            enable or disable Geonames importer
278      * @see ImporterConfig#isGeonamesImporterEnabled()
279      */
280     @Required
281     public void setGeonamesImporterEnabled(boolean geonamesImporterEnabled) {
282     	this.geonamesImporterEnabled = geonamesImporterEnabled;
283     }
284 
285     /**
286      * @return The option
287      * @see #setGeonamesDownloadURL(String)
288      */
289     public String getGeonamesDownloadURL() {
290     	return geonamesDownloadURL;
291     }
292 
293     /**
294      * The HTTP URL of the directory Where Geonames files are to be download
295      * from
296      * 
297      * @param importerGeonamesDownloadURL
298      *            The option
299      */
300     @Required
301     public void setGeonamesDownloadURL(String importerGeonamesDownloadURL) {
302 	if (!importerGeonamesDownloadURL.endsWith("/")) {
303 	    this.geonamesDownloadURL = importerGeonamesDownloadURL + "/";
304 	} else {
305 	    this.geonamesDownloadURL = importerGeonamesDownloadURL;
306 	}
307 	logger.debug("set geonamesDownloadURL to " + this.geonamesDownloadURL);
308     }
309     
310 
311    
312     /**
313      * @return The option
314      * @see #setGeonamesDir(String)
315      */
316     public String getGeonamesDir() {
317     	return this.geonamesDir;
318     }
319 
320     
321     /**
322      * The directory where the Geonames files will be retrieved and processed.
323      * It must ends with / or \ according to the System
324      * 
325      * @param importerGeonamesDir
326      *            the option
327      */
328     @Required
329     public void setGeonamesDir(String importerGeonamesDir) {
330 	if (!importerGeonamesDir.endsWith(File.separator)) {
331 	    logger.debug(importerGeonamesDir + " does not end with " + File.separator);
332 	    this.geonamesDir = importerGeonamesDir + File.separator;
333 	} else {
334 	    this.geonamesDir = importerGeonamesDir;
335 	}
336 	logger.debug("set geonamesDir to " + this.geonamesDir);
337     }
338 
339     /**
340      * @return true if the directory with the file to import exists and is
341      *         accessible
342      */
343     public boolean isGeonamesDownloadDirectoryAccessible() {
344     	return isDirectoryAccessible(getGeonamesDir());
345     }
346    
347     /**
348      * @return The option
349      * @see #setGeonamesFilesToDownload(String)
350      */
351     public String getGeonamesFilesToDownload() {
352     	return this.geonamesFilesToDownload;
353     }
354     
355     /**
356      * The list of the Geonames files to be download from the
357      * {@link #geonamesDownloadURL}. the several files will be separated by
358      * {@link #OPTION_SEPARATOR}, if not set or null, defaulting to {@link #GEONAMES_DEFAULT_FILES_TO_DOWNLOAD}
359      * 
360      * @param geonamesFilesToDownload
361      *            the filesToDownload to set
362      */
363     @Required
364     public void setGeonamesFilesToDownload(String geonamesFilesToDownload) {
365 	if (geonamesFilesToDownload == null || geonamesFilesToDownload.trim().equals("")) {
366 	    logger.warn("the option geonamesFilesToDownload is not set and will be set to his default value : " + GEONAMES_DEFAULT_FILES_TO_DOWNLOAD);
367 	    this.geonamesFilesToDownload = GEONAMES_DEFAULT_FILES_TO_DOWNLOAD;
368 	} else {
369 	    this.geonamesFilesToDownload = geonamesFilesToDownload;
370 	    logger.info("geonamesFilesToDownload=" + geonamesFilesToDownload);
371 	}
372     }
373     
374    
375     
376     /**
377      * @return A list of string with the files to be download, processed from
378      *         {@link #geonamesFilesToDownload}
379      */
380     public List<String> getGeonamesDownloadFilesListFromOption() {
381     	return splitSemiColmunStringToList(geonamesFilesToDownload);
382     }
383     
384     /*
385      *       _       
386  		 ___(_)_ __  
387 		|_  / | '_ \ 
388  		 / /| | |_) |
389 		/___|_| .__/ 
390       		|_|   
391      */
392     
393     /**
394      * @return The option
395      * @see #setGeonamesZipCodeDownloadURL(String)
396      */
397     public String getGeonamesZipCodeDownloadURL() {
398     	return geonamesZipCodeDownloadURL;
399     }
400 
401     /**
402      * The HTTP URL of the directory Where Geonames zip files are to be download
403      * from
404      * 
405      * @param geonamesZipCodeDownloadURL
406      *            The option
407      */
408     @Required
409     public void setGeonamesZipCodeDownloadURL(String geonamesZipCodeDownloadURL) {
410 	if (!geonamesZipCodeDownloadURL.endsWith("/")) {
411 	    this.geonamesZipCodeDownloadURL = geonamesZipCodeDownloadURL + "/";
412 	} else {
413 	    this.geonamesZipCodeDownloadURL = geonamesZipCodeDownloadURL;
414 	}
415 	logger.debug("set geonamesZipCodeDownloadURL to " + this.geonamesZipCodeDownloadURL);
416     }
417 
418     
419     
420     /**
421      * @return the zipcode directory where the zipcode data are
422      */
423     public String getGeonamesZipCodeDir() {
424     	return geonamesZipCodeDir;
425     }
426     
427     /**
428      * The directory where the zip code files will be retrieved and
429      * processed. It must ends with / or \ according to the System
430      * 
431      * @param geonamesZipCodeDir
432      *            the option
433      */
434     @Required
435     public void setGeonamesZipCodeDir(String geonamesZipCodeDir) {
436 	if (!geonamesZipCodeDir.endsWith(File.separator)) {
437 	    logger.debug(geonamesZipCodeDir + " does not end with " + File.separator);
438 	    this.geonamesZipCodeDir = geonamesZipCodeDir + File.separator;
439 	} else {
440 	    this.geonamesZipCodeDir = geonamesZipCodeDir;
441 	}
442 	logger.debug("set geonamesZipCodeDir to " + this.geonamesZipCodeDir);
443     }
444 
445    
446 
447     
448     
449     
450     /*
451 	                           _                 _       
452 	  ___  ___ _ __ ___    ___| |_ _ __ ___  ___| |_ ___ 
453 	 / _ \/ __| '_ ` _ \  / __| __| '__/ _ \/ _ \ __/ __|
454 	| (_) \__ \ | | | | | \__ \ |_| | |  __/  __/ |_\__ \
455 	 \___/|___/_| |_| |_| |___/\__|_|  \___|\___|\__|___/
456 	                                                     
457      */
458     
459     /**
460      * @param openstreetmapImporterEnabled
461      *            enable or disable Openstreetmap importer
462      * @see ImporterConfig#isOpenstreetmapImporterEnabled()
463      */
464     @Required
465     public void setOpenstreetmapImporterEnabled(boolean openstreetmapImporterEnabled) {
466     	this.openstreetmapImporterEnabled = openstreetmapImporterEnabled;
467     	if (!openstreetmapImporterEnabled){
468     		this.openstreetmapHouseNumberImporterEnabled = false;
469     	}
470     }
471     
472     /**
473      * @return true if the importer should process the import of Openstreetmap
474      *         data
475      * @see ImporterConfig#isGeonamesImporterEnabled()
476      */
477     public boolean isOpenstreetmapImporterEnabled() {
478     	return openstreetmapImporterEnabled;
479     }
480     
481   
482     
483     /**
484      * @return The option
485      * @see #setOpenstreetMapDownloadURL(String)
486      */
487     public String getOpenstreetMapDownloadURL() {
488     	return openstreetMapDownloadURL;
489     }
490     
491     /**
492      * The HTTP URL of the directory Where openstreetmap streets files are to be
493      * download from
494      * 
495      * @param openstreetMapDownloadURL
496      *            The option
497      */
498     @Required
499     public void setOpenstreetMapDownloadURL(String openstreetMapDownloadURL) {
500 	if (!openstreetMapDownloadURL.endsWith("/")) {
501 	    this.openstreetMapDownloadURL = openstreetMapDownloadURL + "/";
502 	} else {
503 	    this.openstreetMapDownloadURL = openstreetMapDownloadURL;
504 	}
505 	logger.debug("set openstreetMapDownloadURL to " + this.openstreetMapDownloadURL);
506     }
507    
508     /**
509      * @return The option
510      * @see #setOpenStreetMapDir(String)
511      */
512     public String getOpenStreetMapDir() {
513     	return this.openStreetMapDir;
514     }
515     
516     /**
517      * The directory where the openStreetMap files will be retrieved and
518      * processed. It must ends with / or \ according to the System
519      * 
520      * @param importerOpenStreetMapDir
521      *            the option
522      */
523     @Required
524     public void setOpenStreetMapDir(String importerOpenStreetMapDir) {
525 	if (!importerOpenStreetMapDir.endsWith(File.separator)) {
526 	    logger.debug(openStreetMapDir + " does not end with " + File.separator);
527 	    this.openStreetMapDir = importerOpenStreetMapDir + File.separator;
528 	} else {
529 	    this.openStreetMapDir = importerOpenStreetMapDir;
530 	}
531 	logger.debug("set openStreetMapDir to " + this.openStreetMapDir);
532     }
533     
534     /**
535      * @return true if the directory with the file to import exists and is
536      *         accessible
537      */
538     public boolean isOpenStreetMapDownloadDirectoryAccessible() {
539     	return isDirectoryAccessible(getOpenStreetMapDir());
540     }
541     
542     /**
543      * @return The option
544      * @see #setOpenStreetMapFilesToDownload(String)
545      */
546     public String getOpenStreetMapFilesToDownload() {
547     	return this.openStreetMapFilesToDownload;
548     }
549     
550     /**
551      * The list of the Openstreetmap files to be download from the
552      * {@link #openstreetMapDownloadURL}. the several files will be separated by
553      * {@link #OPTION_SEPARATOR}. if null or empty, will be set to {
554      * {@link #OPENSTREETMAP_DEFAULT_FILES_TO_DOWNLOAD}
555      * 
556      * @param openStreetMapFilesToDownload
557      *            The openstreetmap files to download to set
558      */
559     @Required
560     public void setOpenStreetMapFilesToDownload(String openStreetMapFilesToDownload) {
561 	if (openStreetMapFilesToDownload == null || openStreetMapFilesToDownload.trim().equals("")) {
562 	    logger.warn("the option openStreetMapFilesToDownload is not set and will be set to his default value : " + OPENSTREETMAP_DEFAULT_FILES_TO_DOWNLOAD);
563 	    this.openStreetMapFilesToDownload = OPENSTREETMAP_DEFAULT_FILES_TO_DOWNLOAD;
564 	} else {
565 	    this.openStreetMapFilesToDownload = openStreetMapFilesToDownload;
566 	    logger.info("openStreetMapFilesToDownload=" + this.openStreetMapFilesToDownload);
567 	}
568     }
569     
570    
571     /**
572      * @return A list of string with the files to be download, processed from
573      *         {@link #openStreetMapFilesToDownload}
574      */
575     public List<String> getOpenStreetMapDownloadFilesListFromOption() {
576     	return splitSemiColmunStringToList(openStreetMapFilesToDownload);
577     }
578     
579     
580    /*
581     												_                   
582 		 ___  ___ _ __ ___    _ __  _   _ _ __ ___ | |__   ___ _ __ ___ 
583 		/ _ \/ __| '_ ` _ \  | '_ \| | | | '_ ` _ \| '_ \ / _ \ '__/ __|
584 	   | (_) \__ \ | | | | | | | | | |_| | | | | | | |_) |  __/ |  \__ \
585 		\___/|___/_| |_| |_| |_| |_|\__,_|_| |_| |_|_.__/ \___|_|  |___/
586                          
587     */
588     
589     /**
590      * @return true if the importer should process the import of Openstreetmap house numbers
591      *         data
592      * @see ImporterConfig#isGeonamesImporterEnabled()
593      */
594     public boolean isOpenstreetmapHouseNumberImporterEnabled() {
595     	return  openstreetmapHouseNumberImporterEnabled;
596     }
597     
598     /**
599      * @param openstreetmapHouseNumberImporterEnabled
600      *            enable or disable Openstreetmap house numbers importer
601      * @see ImporterConfig#isOpenstreetmapImporterEnabled()
602      */
603     @Required
604     public void setOpenstreetmapHouseNumberImporterEnabled(boolean openstreetmapHouseNumberImporterEnabled) {
605     	this.openstreetmapHouseNumberImporterEnabled = openstreetmapHouseNumberImporterEnabled;
606     	if (!openstreetmapImporterEnabled){
607     		this.openstreetmapHouseNumberImporterEnabled = false;
608     	}
609     }
610     
611     /**
612      * @return The option
613      * @see #setOpenstreetMaphouseNumbersDownloadURL(String)
614      */
615     public String getOpenstreetMaphouseNumbersDownloadURL() {
616     	return openstreetMapHouseNumbersDownloadURL;
617     }
618     
619     /**
620      * The HTTP URL of the directory Where openstreetmap house numbers files are to be
621      * download from
622      * 
623      * @param openstreetMapHouseNumberDownloadURL
624      *            The option
625      */
626     @Required
627     public void setOpenstreetMaphouseNumbersDownloadURL(String openstreetMapHouseNumberDownloadURL) {
628 	if (!openstreetMapHouseNumberDownloadURL.endsWith("/")) {
629 	    this.openstreetMapHouseNumbersDownloadURL = openstreetMapHouseNumberDownloadURL + "/";
630 	} else {
631 	    this.openstreetMapHouseNumbersDownloadURL = openstreetMapHouseNumberDownloadURL;
632 	}
633 	logger.debug("set openstreetMaphouseNumberDownloadURL to " + this.openstreetMapHouseNumbersDownloadURL);
634     }
635     
636    
637     /**
638      * @return The option
639      * @see #setOpenStreetMapHouseNumberDir(String)
640      */
641     public String getOpenStreetMapHouseNumberDir() {
642     	return this.openStreetMapHouseNumberDir;
643     } 
644     
645     /**
646      * The directory where the openStreetMap files for house numbers will be retrieved and
647      * processed. It must ends with / or \ according to the System
648      * 
649      * @param importerOpenStreetMapHouseNumberDir
650      *            the option
651      */
652     @Required
653     public void setOpenStreetMapHouseNumberDir(String importerOpenStreetMapHouseNumberDir) {
654 	if (!importerOpenStreetMapHouseNumberDir.endsWith(File.separator)) {
655 	    logger.debug(openStreetMapHouseNumberDir + " does not end with " + File.separator);
656 	    this.openStreetMapHouseNumberDir = importerOpenStreetMapHouseNumberDir + File.separator;
657 	} else {
658 	    this.openStreetMapHouseNumberDir = importerOpenStreetMapHouseNumberDir;
659 	}
660 	logger.debug("set openStreetMapHouseNumberDir to " + this.openStreetMapHouseNumberDir);
661     }
662     
663     
664     /**
665      * @return true if the directory with the file to import exists and is
666      *         accessible
667      */
668     public boolean isOpenStreetMapHouseNumberDownloadDirectoryAccessible() {
669     	return isDirectoryAccessible(getOpenStreetMapHouseNumberDir());
670     }
671     
672     /**
673      * @return The option
674      * @see #setOpenStreetMapHouseNumberFilesToDownload(String)
675      */
676     public String getOpenStreetMapHouseNumberFilesToDownload() {
677     	return this.openStreetMapHouseNumberFilesToDownload;
678     }
679     
680     /**
681      * The list of the Openstreetmap house number files to be download from the
682      * {@link #openstreetMapHouseNumbersDownloadURL}. the several files will be separated by
683      * {@link #OPTION_SEPARATOR}. if null or empty, will be set to {
684      * {@link #OPENSTREETMAP_HOUSENUMBER_DEFAULT_FILES_TO_DOWNLOAD}
685      * 
686      * @param openStreetMapHouseNumberFilesToDownload
687      *            The openstreetmap files to download to set
688      */
689     @Required
690     public void setOpenStreetMapHouseNumberFilesToDownload(String openStreetMapHouseNumberFilesToDownload) {
691 	if (openStreetMapHouseNumberFilesToDownload == null || openStreetMapHouseNumberFilesToDownload.trim().equals("")) {
692 	    logger.warn("the option openStreetMapHouseNumberFilesToDownload is not set and will be set to his default value : " + OPENSTREETMAP_HOUSENUMBER_DEFAULT_FILES_TO_DOWNLOAD);
693 	    this.openStreetMapHouseNumberFilesToDownload = OPENSTREETMAP_HOUSENUMBER_DEFAULT_FILES_TO_DOWNLOAD;
694 	} else {
695 	    this.openStreetMapHouseNumberFilesToDownload = openStreetMapHouseNumberFilesToDownload;
696 	    logger.info("openStreetMapHouseNumberFilesToDownload=" + this.openStreetMapHouseNumberFilesToDownload);
697 	}
698     }
699 
700     /**
701      * @return A list of string with the files to be download, processed from
702      *         {@link #openStreetMapHouseNumberFilesToDownload}
703      */
704     public List<String> getOpenStreetMapHouseNumberDownloadFilesListFromOption() {
705     	return splitSemiColmunStringToList(openStreetMapHouseNumberFilesToDownload);
706     }
707     
708     
709    /*
710     *                          _ _   _           
711   	 ___  ___ _ __ ___     ___(_) |_(_) ___  ___ 
712  	/ _ \/ __| '_ ` _ \   / __| | __| |/ _ \/ __|
713    | (_) \__ \ | | | | | | (__| | |_| |  __/\__ \
714  	\___/|___/_| |_| |_|  \___|_|\__|_|\___||___/
715     */
716     
717     
718     /**
719      * @return The option
720      * @see #setOpenstreetMapCitiesDownloadURL(String)
721      */
722     public String getOpenstreetMapCitiesDownloadURL() {
723     	return openstreetMapCitiesDownloadURL;
724     }
725     
726     /**
727      * The HTTP URL of the directory Where openstreetmap cities files are to be
728      * download from
729      * 
730      * @param openstreetMapCitiesDownloadURL
731      *            The option
732      */
733     @Required
734     public void setOpenstreetMapCitiesDownloadURL(String openstreetMapCitiesDownloadURL) {
735 	if (!openstreetMapCitiesDownloadURL.endsWith("/")) {
736 	    this.openstreetMapCitiesDownloadURL = openstreetMapCitiesDownloadURL + "/";
737 	} else {
738 	    this.openstreetMapCitiesDownloadURL = openstreetMapCitiesDownloadURL;
739 	}
740 	logger.debug("set openstreetMapCitiesDownloadURL to " + this.openstreetMapCitiesDownloadURL);
741     }
742     
743 
744     /**
745      * @return The option
746      * @see #setOpenStreetMapCitiesDir(String)
747      */
748     public String getOpenStreetMapCitiesDir() {
749     	return this.openStreetMapCitiesDir;
750     }
751     
752 
753     /**
754      * The directory where the openStreetMap cities files will be retrieved and
755      * processed. It must ends with / or \ according to the System
756      * 
757      * @param openStreetMapCitiesDir
758      *            the option
759      */
760     @Required
761     public void setOpenStreetMapCitiesDir(String openStreetMapCitiesDir) {
762 	if (!openStreetMapCitiesDir.endsWith(File.separator)) {
763 	    logger.debug(openStreetMapCitiesDir + " does not end with " + File.separator);
764 	    this.openStreetMapCitiesDir = openStreetMapCitiesDir + File.separator;
765 	} else {
766 	    this.openStreetMapCitiesDir = openStreetMapCitiesDir;
767 	}
768 	logger.debug("set openStreetMapCitiesDir to " + this.openStreetMapCitiesDir);
769     }
770     
771     
772     
773     /**
774      * @return true if the directory with the osm cities file to import exists and is
775      *         accessible
776      */
777     public boolean isOpenStreetMapCitiesDirectoryAccessible() {
778     	return isDirectoryAccessible(getOpenStreetMapCitiesDir());
779     }
780     
781     /**
782      * @return The option
783      * @see #setOpenStreetMapCitiesFilesToDownload(String)
784      */
785     public String getOpenStreetMapCitiesFilesToDownload() {
786     	return this.openStreetMapCitiesFilesToDownload;
787     }
788     
789     
790    
791     
792     
793     /**
794      * The list of the cities Openstreetmap to be download from the
795      * {@link #openstreetMapCitiesDownloadURL}. the several files will be separated by
796      * {@link #OPTION_SEPARATOR}. if null or empty, will be set to {
797      * {@link #OPENSTREETMAP_CITIES_DEFAULT_FILES_TO_DOWNLOAD}
798      * 
799      * @param openStreetMapCitiesFilesToDownload
800      *            The openstreetmap filesToDownload to set
801      */
802     @Required
803     public void setOpenStreetMapCitiesFilesToDownload(String openStreetMapCitiesFilesToDownload) {
804 	if (openStreetMapCitiesFilesToDownload == null || openStreetMapCitiesFilesToDownload.trim().equals("")) {
805 	    logger.warn("the option openStreetMapCitiesFilesToDownload is not set and will be set to his default value : " + OPENSTREETMAP_CITIES_DEFAULT_FILES_TO_DOWNLOAD);
806 	    this.openStreetMapCitiesFilesToDownload = OPENSTREETMAP_CITIES_DEFAULT_FILES_TO_DOWNLOAD;
807 	} else {
808 	    this.openStreetMapCitiesFilesToDownload = openStreetMapCitiesFilesToDownload;
809 	    logger.info("openStreetMapCitiesFilesToDownload=" + openStreetMapCitiesFilesToDownload);
810 	}
811     }
812     
813     /**
814      * @return A list of string with the files to be download, processed from
815      *         {@link #openStreetMapCitiesFilesToDownload}
816      */
817     public List<String> getOpenStreetMapCitiesDownloadFilesListFromOption() {
818     	return splitSemiColmunStringToList(openStreetMapCitiesFilesToDownload);
819     }
820     
821     /*
822   	 ___  ___ _ __ ___    _ __   ___ (_)
823  	/ _ \/ __| '_ ` _ \  | '_ \ / _ \| |
824    | (_) \__ \ | | | | | | |_) | (_) | |
825  	\___/|___/_| |_| |_| | .__/ \___/|_|
826                       	 |_|            
827 
828      */
829 
830    
831     /**
832      * @return The option
833      * @see #setOpenstreetMapPoisDownloadURL(String)
834      */
835     public String getOpenstreetMapPoisDownloadURL() {
836     	return openstreetMapPoisDownloadURL;
837     }
838 
839    
840     /**
841      * The HTTP URL of the directory Where openstreetmap POI files are to be
842      * download from
843      * 
844      * @param openstreetMapPoisDownloadURL
845      *            The option
846      */
847     @Required
848     public void setOpenstreetMapPoisDownloadURL(String openstreetMapPoisDownloadURL) {
849 	if (!openstreetMapPoisDownloadURL.endsWith("/")) {
850 	    this.openstreetMapPoisDownloadURL = openstreetMapPoisDownloadURL + "/";
851 	} else {
852 	    this.openstreetMapPoisDownloadURL = openstreetMapPoisDownloadURL;
853 	}
854 	logger.debug("set openstreetMapPoisDownloadURL to " + this.openstreetMapPoisDownloadURL);
855     }
856 
857     
858     /**
859      * @return The option
860      * @see #setOpenStreetMapPoisDir(String)
861      */
862     public String getOpenStreetMapPoisDir() {
863     	return this.openStreetMapPoisDir;
864     }
865 
866     
867     /**
868      * The directory where the openStreetMap POI files will be retrieved and
869      * processed. It must ends with / or \ according to the System
870      * 
871      * @param openStreetMapPoisDir
872      *            the option
873      */
874     @Required
875     public void setOpenStreetMapPoisDir(String openStreetMapPoisDir) {
876 	if (!openStreetMapPoisDir.endsWith(File.separator)) {
877 	    logger.debug(openStreetMapPoisDir + " does not end with " + File.separator);
878 	    this.openStreetMapPoisDir = openStreetMapPoisDir + File.separator;
879 	} else {
880 	    this.openStreetMapPoisDir = openStreetMapPoisDir;
881 	}
882 	logger.debug("set openStreetMapPoisDir to " + this.openStreetMapPoisDir);
883     }
884     
885     /**
886      * @return true if the directory with the osm Poi file to import exists and is
887      *         accessible
888      */
889     public boolean isOpenStreetMapPoisDirectoryAccessible() {
890     	return isDirectoryAccessible(getOpenStreetMapPoisDir());
891     }
892 
893     /**
894      * @return The option
895      * @see #setOpenStreetMapPoisFilesToDownload(String)
896      */
897     public String getOpenStreetMapPoisFilesToDownload() {
898     	return this.openStreetMapPoisFilesToDownload;
899     }
900     
901     /**
902      * The list of the Openstreetmap POI to be download from the
903      * {@link #openstreetMapPoisDownloadURL}. the several files will be separated by
904      * {@link #OPTION_SEPARATOR}. if null or empty, will be set to {
905      * {@link #OPENSTREETMAP_POI_DEFAULT_FILES_TO_DOWNLOAD}
906      * 
907      * @param openStreetMapPoisFilesToDownload
908      *            The openstreetmap filesToDownload to set
909      */
910     @Required
911     public void setOpenStreetMapPoisFilesToDownload(String openStreetMapPoisFilesToDownload) {
912 	if (openStreetMapPoisFilesToDownload == null || openStreetMapPoisFilesToDownload.trim().equals("")) {
913 	    logger.warn("the option openStreetMapPoisFilesToDownload is not set and will be set to his default value : " + OPENSTREETMAP_POI_DEFAULT_FILES_TO_DOWNLOAD);
914 	    this.openStreetMapPoisFilesToDownload = OPENSTREETMAP_POI_DEFAULT_FILES_TO_DOWNLOAD;
915 	} else {
916 	    this.openStreetMapPoisFilesToDownload = openStreetMapPoisFilesToDownload;
917 	    logger.info("openStreetMapPoisFilesToDownload=" + openStreetMapPoisFilesToDownload);
918 	}
919     }
920     
921     
922     /**
923      * @return A list of string with the files to be download, processed from
924      *         {@link #openStreetMapCitiesFilesToDownload}
925      */
926     public List<String> getOpenStreetMapPoisDownloadFilesListFromOption() {
927     	return splitSemiColmunStringToList(openStreetMapPoisFilesToDownload);
928     }
929     
930     /*
931                    _   _                 _                           
932   __ _ _   _  __ _| |_| |_ _ __ ___  ___| |__   __ _ _ __   ___  ___ 
933  / _` | | | |/ _` | __| __| '__/ _ \/ __| '_ \ / _` | '_ \ / _ \/ __|
934 | (_| | |_| | (_| | |_| |_| | | (_) \__ \ | | | (_| | |_) |  __/\__ \
935  \__, |\__,_|\__,_|\__|\__|_|  \___/|___/_| |_|\__,_| .__/ \___||___/
936     |_|                                             |_|              
937 
938      */
939     
940     /**
941      * @param 
942      *            enable or disable quattroshapes importer
943      * @see ImporterConfig#isQuattroshapesImporterEnabled()
944      */
945     @Required
946     public void setQuattroshapesImporterEnabled(boolean quattroshapesImporterEnabled) {
947     	this.quattroshapesImporterEnabled = quattroshapesImporterEnabled;
948     }
949     
950     /**
951      * @return true if the importer should process the import of quattroshapes
952      *         data
953      * @see ImporterConfig#isQuattroshapesImporterEnabled()
954      */
955     public boolean isQuattroshapesImporterEnabled() {
956     	return quattroshapesImporterEnabled;
957     }
958     
959     /**
960      * @return The option
961      * @see #setQuattroshapesDownloadURL(String)
962      */
963     public String getQuattroshapesDownloadURL() {
964     	return quattroshapesDownloadURL;
965     }
966 
967    
968     /**
969      * The HTTP URL of the directory Where quattroshapes files are to be
970      * download from
971      * 
972      * @param quattroshapesDownloadURL
973      *            The option
974      */
975     @Required
976     public void setQuattroshapesDownloadURL(String quattroshapesDownloadURL) {
977 	if (!quattroshapesDownloadURL.endsWith("/")) {
978 	    this.quattroshapesDownloadURL = quattroshapesDownloadURL + "/";
979 	} else {
980 	    this.quattroshapesDownloadURL = quattroshapesDownloadURL;
981 	}
982 	logger.debug("set quattroshapesDownloadURL to " + this.quattroshapesDownloadURL);
983     }
984 
985     
986     /**
987      * @return The option
988      * @see #setQuattroshapesDir(String)
989      */
990     public String getQuattroshapesDir() {
991     	return this.quattroshapesDir;
992     }
993 
994     
995     /**
996      * The directory where the quattroshapes files will be retrieved and
997      * processed. It must ends with / or \ according to the System
998      * 
999      * @param quattroshapesDir
1000      *            the option
1001      */
1002     @Required
1003     public void setQuattroshapesDir(String quattroshapesDir) {
1004 	if (!quattroshapesDir.endsWith(File.separator)) {
1005 	    logger.debug(quattroshapesDir + " does not end with " + File.separator);
1006 	    this.quattroshapesDir = quattroshapesDir + File.separator;
1007 	} else {
1008 	    this.quattroshapesDir = quattroshapesDir;
1009 	}
1010 	logger.debug("set quattroshapesDir to " + this.quattroshapesDir);
1011     }
1012     
1013     /**
1014      * @return true if the directory with the quattroshapes file to import exists and is
1015      *         accessible
1016      */
1017     public boolean isQuattroshapesDirectoryAccessible() {
1018     	return isDirectoryAccessible(getQuattroshapesDir());
1019     }
1020 
1021     /**
1022      * @return The option
1023      * @see #setQuattroshapesFilesToDownload(String)
1024      */
1025     public String getQuattroshapesFilesToDownload() {
1026     	return this.quattroshapesFilesToDownload;
1027     }
1028     
1029     /**
1030      * The list of the Openstreetmap POI to be download from the
1031      * {@link #openstreetMapPoisDownloadURL}. the several files will be separated by
1032      * {@link #OPTION_SEPARATOR}. if null or empty, will be set to {
1033      * {@link #OPENSTREETMAP_POI_DEFAULT_FILES_TO_DOWNLOAD}
1034      * 
1035      * @param openStreetMapPoisFilesToDownload
1036      *            The openstreetmap filesToDownload to set
1037      */
1038     @Required
1039     public void setQuattroshapesFilesToDownload(String quattroshapesFilesToDownload) {
1040 	if (quattroshapesFilesToDownload == null || quattroshapesFilesToDownload.trim().equals("")) {
1041 	    logger.warn("the option quattroshapesFilesToDownload is not set and will be set to his default value : " + QUATTROSHAPES_DEFAULT_FILES_TO_DOWNLOAD);
1042 	    this.quattroshapesFilesToDownload = QUATTROSHAPES_DEFAULT_FILES_TO_DOWNLOAD;
1043 	} else {
1044 	    this.quattroshapesFilesToDownload = quattroshapesFilesToDownload;
1045 	    logger.info("quattroshapesFilesToDownload=" + quattroshapesFilesToDownload);
1046 	}
1047     }
1048     
1049     
1050     /**
1051      * @return A list of string with the files to be download, processed from
1052      *         {@link #openStreetMapCitiesFilesToDownload}
1053      */
1054     public List<String> getQuattroshapesFilesDownloadFilesListFromOption() {
1055     	return splitSemiColmunStringToList(quattroshapesFilesToDownload);
1056     }
1057     
1058     
1059     //_____________________________________________________end importer specific config______________________________
1060     
1061     private List<String> splitSemiColmunStringToList(String stringToSplit) {
1062 	List<String> list = new ArrayList<String>();
1063 	if (stringToSplit != null && stringToSplit.length() != 0) {
1064 	    String[] splited = stringToSplit.split(OPTION_SEPARATOR);
1065 	    for (int i = 0; i < splited.length; i++) {
1066 		list.add(splited[i]);
1067 	    }
1068 	}
1069 	return list;
1070     }
1071 
1072 
1073     /**
1074      * What should we do if the Adm file for the specified level has already
1075      * been processed It is a wrapper method around
1076      * {@link #DEFAULT_ADM3_EXTRACTER_STRATEGY_OPTION} and
1077      * {@link #DEFAULT_ADM4_EXTRACTER_STRATEGY_OPTION}
1078      */
1079     public AdmExtracterStrategyOptions getAdmExtracterStrategyOptionsForAdm(int admLevel) {
1080 	if (admLevel == 1) {
1081 	    return adm1ExtracterStrategyIfAlreadyExists;
1082 	} else if (admLevel == 2) {
1083 	    return adm2ExtracterStrategyIfAlreadyExists;
1084 	} else if (admLevel == 3) {
1085 	    return adm3ExtracterStrategyIfAlreadyExists;
1086 	} else if (admLevel == 4) {
1087 	    return adm4ExtracterStrategyIfAlreadyExists;
1088 	} else {
1089 	    throw new RuntimeException(" can not get AdmExtracterStrategyOptions For Adm with level " + admLevel);
1090 	}
1091     }
1092 
1093     /**
1094      * @return The option
1095      * @see #setAcceptRegExString(String)
1096      */
1097     public String getAcceptRegExString() {
1098     	return this.acceptRegExString;
1099     }
1100 
1101     /**
1102      * @return The option
1103      * @see #setSyncAdmCodesWithLinkedAdmOnes(boolean)
1104      */
1105     public boolean isSyncAdmCodesWithLinkedAdmOnes() {
1106     	return this.syncAdmCodesWithLinkedAdmOnes;
1107     }
1108 
1109     /**
1110      * @return The option
1111      * @see #setTryToDetectAdmIfNotFound(boolean)
1112      */
1113     public boolean isTryToDetectAdmIfNotFound() {
1114     	return this.tryToDetectAdmIfNotFound;
1115     }
1116 
1117     /**
1118      * List of regular expressions for placetype (class name without .class to be
1119      * import.<br>
1120      * <br>
1121      * 
1122      * "ADM" and "country" are automaticaly
1123      * imported (Administrative division and country).<br>
1124      * Examples :
1125      * <ul>
1126      * <li>.* : import all gisfeatures, no matter their feature class and
1127      * feature code</li>
1128      * <li> {@link #DEFAULT_ACCEPT_REGEX_CITY} : import all adm city and countries</li>
1129      * <li>ATM : import all ATM</li>
1130      * <li>ATM|RESTAURANT : import all ATM and restaurant</li>
1131      * </ul>
1132      * 
1133      * @param acceptRegExString
1134      *            the option
1135      */
1136     @Required
1137     public void setAcceptRegExString(String acceptRegExString) {
1138 	if (acceptRegExString == null || acceptRegExString.trim().equals("") || acceptRegExString.equals(ACCEPT_ALL_REGEX_OPTION)) {
1139 	    logger.warn("the option acceptRegExString is not set and will be set to his default value : " + ACCEPT_ALL_REGEX_OPTION);
1140 	    this.acceptRegExString = ACCEPT_ALL_REGEX_OPTION;
1141 	    return;
1142 	}
1143 	this.acceptRegExString = BASE_ACCEPT_REGEX + acceptRegExString;
1144 		logger.info("acceptRegExString=" + this.acceptRegExString);
1145     }
1146 
1147     /**
1148      * The linked Adm may not be the same as the one which would be found with
1149      * the ADMcodes from the csv file if TryToDetectAdmIfNotFound is set to
1150      * true. in this case error corecting is done. tis option determine if the
1151      * ADMXcode must be equals to the linked ADM or if they must be equals to
1152      * the value in the CSVFile note that the admXnames are always sync with the
1153      * Linked Adm if true : the AdmXcodes of the imported GisFeature will be the
1154      * gisFeature.getAdm.getAdmXcode.<br>
1155      * <br>
1156      * if false : the AdmXcode for a GisFeature will be the values of the CSV
1157      * dump file. That means : If the option tryToDetectAdmIfNotFound is set to
1158      * true : the Adm will be suggest if the AdmXcodes values of the CSV dump
1159      * file doesn't correspond to an already known Adm. In that case the
1160      * suggested Adm will have AdmXcodes different from the CSV dump file ones.
1161      * This option allow you to set The AdmXcodes for the gisFeature with the
1162      * detected Adm value instead of the CSV file ones.<br/>
1163      * In other words : AdmXcodes of the linked Adm and AdmXcodes of the
1164      * gisFeature will always be the same if this option is true. it is
1165      * recommended to let it to true
1166      * 
1167      * @param setAdmCodesWithLinkedAdmObject
1168      *            The option to set
1169      */
1170     @Required
1171     public void setSyncAdmCodesWithLinkedAdmOnes(boolean setAdmCodesWithLinkedAdmObject) {
1172     	this.syncAdmCodesWithLinkedAdmOnes = setAdmCodesWithLinkedAdmObject;
1173     	logger.info("setAdmCodesWithLinkedAdmObject=" + setAdmCodesWithLinkedAdmObject);
1174     }
1175 
1176     /**
1177      * If this option is set to true : The importer will try to detect Adm for
1178      * features if the AdmXcodes values does not correspond to a known Adm. it
1179      * is a process of error correction if set to false error correction is
1180      * disabled
1181      * 
1182      * @param tryToDetectAdmIfNotFound
1183      *            The option
1184      */
1185     @Required
1186     public void setTryToDetectAdmIfNotFound(boolean tryToDetectAdmIfNotFound) {
1187     	this.tryToDetectAdmIfNotFound = tryToDetectAdmIfNotFound;
1188     	logger.info("tryToDetectAdmIfNotFound=" + tryToDetectAdmIfNotFound);
1189     }
1190 
1191     /**
1192      * @return The option
1193      * @see #setAdm1ExtracterStrategyIfAlreadyExists(AdmExtracterStrategyOptions)
1194      */
1195     public AdmExtracterStrategyOptions getAdm1ExtracterStrategyIfAlreadyExists() {
1196     	return this.adm1ExtracterStrategyIfAlreadyExists;
1197     }
1198 
1199     /**
1200      * What should we do if the Adm1 file has already been processed
1201      * 
1202      * @see #DEFAULT_ADM1_EXTRACTER_STRATEGY_OPTION
1203      * @param adm1ExtracterStrategy
1204      *            The option
1205      */
1206     @Required
1207     public void setAdm1ExtracterStrategyIfAlreadyExists(AdmExtracterStrategyOptions adm1ExtracterStrategy) {
1208     	this.adm1ExtracterStrategyIfAlreadyExists = adm1ExtracterStrategy;
1209     }
1210 
1211     /**
1212      * @return The option
1213      * @see #setAdm2ExtracterStrategyIfAlreadyExists(AdmExtracterStrategyOptions)
1214      */
1215     public AdmExtracterStrategyOptions getAdm2ExtracterStrategyIfAlreadyExists() {
1216     	return this.adm2ExtracterStrategyIfAlreadyExists;
1217     }
1218 
1219     /**
1220      * What should we do if the Adm2 file has already been processed
1221      * 
1222      * @see #DEFAULT_ADM2_EXTRACTER_STRATEGY_OPTION
1223      * @param adm2ExtracterStrategy
1224      *            The option
1225      */
1226     @Required
1227     public void setAdm2ExtracterStrategyIfAlreadyExists(AdmExtracterStrategyOptions adm2ExtracterStrategy) {
1228     	this.adm2ExtracterStrategyIfAlreadyExists = adm2ExtracterStrategy;
1229     }
1230 
1231     /**
1232      * @return The option
1233      * @see #setAdm3ExtracterStrategyIfAlreadyExists(AdmExtracterStrategyOptions)
1234      */
1235     public AdmExtracterStrategyOptions getAdm3ExtracterStrategyIfAlreadyExists() {
1236     	return this.adm3ExtracterStrategyIfAlreadyExists;
1237     }
1238 
1239     /**
1240      * What should we do if the Adm3 file has already been processed
1241      * 
1242      * @see #DEFAULT_ADM3_EXTRACTER_STRATEGY_OPTION
1243      * @param adm3ExtracterStrategy
1244      *            The option
1245      */
1246     @Required
1247     public void setAdm3ExtracterStrategyIfAlreadyExists(AdmExtracterStrategyOptions adm3ExtracterStrategy) {
1248     	this.adm3ExtracterStrategyIfAlreadyExists = adm3ExtracterStrategy;
1249     }
1250 
1251     /**
1252      * @return the option
1253      * @see ImporterConfig#setAdm4ExtracterStrategyIfAlreadyExists(AdmExtracterStrategyOptions)
1254      */
1255     public AdmExtracterStrategyOptions getAdm4ExtracterStrategyIfAlreadyExists() {
1256     	return this.adm4ExtracterStrategyIfAlreadyExists;
1257     }
1258 
1259     /**
1260      * What should we do if the Adm4 file has already been processed
1261      * 
1262      * @see #DEFAULT_ADM3_EXTRACTER_STRATEGY_OPTION
1263      * @param adm4ExtracterStrategy
1264      *            The option
1265      */
1266     @Required
1267     public void setAdm4ExtracterStrategyIfAlreadyExists(AdmExtracterStrategyOptions adm4ExtracterStrategy) {
1268     	adm4ExtracterStrategyIfAlreadyExists = adm4ExtracterStrategy;
1269     }
1270 
1271     /**
1272      * @return The option
1273      * @see #setMissingRequiredFieldThrows(boolean)
1274      * @see MissingRequiredFieldException
1275      */
1276     public boolean isMissingRequiredFieldThrows() {
1277     	return this.missingRequiredFieldThrows;
1278     }
1279 
1280     /**
1281      * Set to true this options force the import process to stop if a required
1282      * field is missing.<br>
1283      * Set to false it ignore the error and try to continue (recommended)
1284      * 
1285      * @param missingRequiredFieldThrows
1286      *            The option
1287      * @see MissingRequiredFieldException
1288      */
1289     @Required
1290     public void setMissingRequiredFieldThrows(boolean missingRequiredFieldThrows) {
1291     	this.missingRequiredFieldThrows = missingRequiredFieldThrows;
1292     }
1293 
1294     /**
1295      * @return The option
1296      * @see #setWrongNumberOfFieldsThrows(boolean)
1297      */
1298     public boolean isWrongNumberOfFieldsThrows() {
1299     	return this.wrongNumberOfFieldsThrows;
1300     }
1301 
1302     /**
1303      * Set to true this option force the import process to stop if an error is
1304      * throw.<br>
1305      * Set to false it ignore the error and try to continue (recommended)
1306      * 
1307      * @param wrongNumberOfFieldsThrows
1308      *            The option
1309      */
1310     @Required
1311     public void setWrongNumberOfFieldsThrows(boolean wrongNumberOfFieldsThrows) {
1312     	this.wrongNumberOfFieldsThrows = wrongNumberOfFieldsThrows;
1313     }
1314 
1315     /**
1316      * @return The option
1317      * @see #setImportGisFeatureEmbededAlternateNames(boolean)
1318      */
1319     public boolean isImportGisFeatureEmbededAlternateNames() {
1320     	return importGisFeatureEmbededAlternateNames;
1321     }
1322 
1323     /**
1324      * Set to true the alternate names of the country dump are imported. Set to
1325      * false it will import the alternate names from the alternatenames dump
1326      * file
1327      * 
1328      * @param importGisFeatureEmbededAlternateNames
1329      *            The option
1330      */
1331     @Required
1332     public void setImportGisFeatureEmbededAlternateNames(boolean importGisFeatureEmbededAlternateNames) {
1333     	this.importGisFeatureEmbededAlternateNames = importGisFeatureEmbededAlternateNames;
1334     }
1335 
1336    
1337     
1338    
1339     /**
1340      * @return The option
1341      * @see #setRetrieveFiles(boolean)
1342      */
1343     public boolean isRetrieveFiles() {
1344     	return this.retrieveFiles;
1345     }
1346 
1347     /**
1348      * Whether we should download the geonames file or use the one already
1349      * present in the {@link #geonamesDir}
1350      * 
1351      * @param retrieveFiles
1352      *            The options
1353      */
1354     @Required
1355     public void setRetrieveFiles(boolean retrieveFiles) {
1356     	this.retrieveFiles = retrieveFiles;
1357     }
1358 
1359     
1360     
1361    
1362     /**
1363      * @return the option
1364      * @see #getAdm1FileName()
1365      */
1366     public String getAdm1FileName() {
1367     	return this.adm1FileName;
1368     }
1369 
1370     /**
1371      * The name of the Geonames dump file containing the ADM with level 1
1372      * 
1373      * @param adm1FileName
1374      *            The option
1375      */
1376     @Required
1377     public void setAdm1FileName(String adm1FileName) {
1378     	this.adm1FileName = adm1FileName;
1379     }
1380 
1381     /**
1382      * @return The option
1383      * @see #getAdm2FileName()
1384      */
1385     public String getAdm2FileName() {
1386     	return this.adm2FileName;
1387     }
1388 
1389     /**
1390      * The name of the Geonames dump file containing the ADM with level 2
1391      * 
1392      * @param adm2FileName
1393      *            The option
1394      */
1395     @Required
1396     public void setAdm2FileName(String adm2FileName) {
1397     	this.adm2FileName = adm2FileName;
1398     }
1399 
1400     /**
1401      * @return The option
1402      * @see #getAdm3FileName()
1403      */
1404     public String getAdm3FileName() {
1405     	return this.adm3FileName;
1406     }
1407 
1408     /**
1409      * The name of the Geonames dump file containing the ADM with level 3
1410      * 
1411      * @param adm3FileName
1412      *            the adm3FileName to set
1413      */
1414     @Required
1415     public void setAdm3FileName(String adm3FileName) {
1416     	this.adm3FileName = adm3FileName;
1417     }
1418 
1419     /**
1420      * @return The option
1421      * @see #getAdm4FileName()
1422      */
1423     public String getAdm4FileName() {
1424     	return adm4FileName;
1425     }
1426 
1427     /**
1428      * The name of the Geonames dump file containing the ADM with level 4
1429      * 
1430      * @param adm4FileName
1431      *            The option
1432      */
1433     @Required
1434     public void setAdm4FileName(String adm4FileName) {
1435     	this.adm4FileName = adm4FileName;
1436     }
1437 
1438     /**
1439      * @return The Option
1440      * @see #getCountriesFileName()
1441      */
1442     public String getCountriesFileName() {
1443     	return this.countriesFileName;
1444     }
1445 
1446     /**
1447      * The name of the Geonames dump file containing the countries informations
1448      * 
1449      * @param countryFileName
1450      *            The option
1451      */
1452     @Required
1453     public void setCountriesFileName(String countryFileName) {
1454     	this.countriesFileName = countryFileName;
1455     }
1456 
1457     /**
1458      * @return The option
1459      * @see #setLanguageFileName(String)
1460      */
1461     public String getLanguageFileName() {
1462     	return this.languageFileName;
1463     }
1464 
1465     /**
1466      * The name of the Geonames dump file containing the language informations
1467      * 
1468      * @param languageFileName
1469      *            The option
1470      */
1471     @Required
1472     public void setLanguageFileName(String languageFileName) {
1473     	this.languageFileName = languageFileName;
1474     }
1475 
1476     /**
1477      * @return The option
1478      * @see #getAlternateNamesFileName()
1479      */
1480     public String getAlternateNamesFileName() {
1481     	return alternateNamesFileName;
1482     }
1483 
1484     /**
1485      * The name of the Geonames dump file containing the alternate names
1486      * 
1487      * @param alternateNamesFileName
1488      *            The option
1489      */
1490     @Required
1491     public void setAlternateNamesFileName(String alternateNamesFileName) {
1492     	this.alternateNamesFileName = alternateNamesFileName;
1493     }
1494 
1495     /**
1496      * Optional setting that allows to specify the number of inserts that can be
1497      * done before flushing. This is useful since most ORM technologies use a
1498      * so-called Level-2 cache that will store all the persisted data until they
1499      * are either comitted or flushed...default value is
1500      * {@link #DEFAULT_MAX_INSERT_BEFORE_FLUSH}
1501      * 
1502      * @param maxInsertsBeforeFlush
1503      *            The option
1504      */
1505     @Required
1506     public void setMaxInsertsBeforeFlush(int maxInsertsBeforeFlush) {
1507     	this.maxInsertsBeforeFlush = maxInsertsBeforeFlush;
1508     }
1509 
1510     /**
1511      * @return The option
1512      * @see #setMaxInsertsBeforeFlush(int)
1513      */
1514     public int getMaxInsertsBeforeFlush() {
1515     	return this.maxInsertsBeforeFlush;
1516     }
1517 
1518     /**
1519      * @param directoryPath
1520      *            The directory to check. it can be absolute or relative
1521      * @return true if the path is a directory (not a file) AND exists AND is
1522      *         writable
1523      */
1524     private boolean isDirectoryAccessible(String directoryPath) {
1525     	File dir = new File(directoryPath);
1526 		boolean ok = dir.exists() && dir.isDirectory() && dir.canWrite();
1527     	if (!ok){
1528     		logger.error("directory "+directoryPath+"' is not accessible");
1529     	} 
1530     	return ok;
1531     }
1532 
1533 
1534 
1535     /**
1536      * @return true if the regexp of the feature class/ code are correct
1537      */
1538     public boolean isRegexpCorrects() {
1539     	boolean ok = ImporterHelper.compileRegex(getAcceptRegExString()) != null;
1540     	if (!ok){
1541     		logger.error("regexp "+getAcceptRegExString()+"' is not correct");
1542     	} 
1543     	return ok;
1544     }
1545 
1546     /**
1547      * @return true if the config is Ok to process the import
1548      */
1549     public boolean isConfigCorrectForImport() {
1550     	boolean firstcondition =  isRegexpCorrects() && isGeonamesDownloadDirectoryAccessible() && isOpenStreetMapDownloadDirectoryAccessible() && isOpenStreetMapHouseNumberDownloadDirectoryAccessible()
1551     			&& isOpenStreetMapCitiesDirectoryAccessible() && isOpenStreetMapPoisDirectoryAccessible() && isQuattroshapesDirectoryAccessible();
1552     		if (isRetrieveFiles()){
1553     			return firstcondition && isAllFilesDownloadables();
1554     		} else {
1555     			return firstcondition;
1556     		}
1557     }
1558     
1559     
1560     public boolean isAllFilesDownloadables(){
1561     	//geonames
1562     	List<String> filenames ;
1563     	if(isGeonamesImporterEnabled()){
1564 	    	 filenames = getGeonamesDownloadFilesListFromOption();
1565 	    	for (String filename:filenames){
1566 	    		if (!checkUrl(getGeonamesDownloadURL()+filename)){
1567 	    			return false;
1568 	    		}
1569 	    	}
1570 	    	//zip
1571 	    	//because the zipcode importer is tolerant to non existing url we skip the tests
1572 	    	
1573     	}
1574     	
1575     	if(isOpenstreetmapHouseNumberImporterEnabled()){
1576 	    	//osm house number
1577 	    	filenames = getOpenStreetMapHouseNumberDownloadFilesListFromOption();
1578 	    	for (String filename:filenames){
1579 	    		if (!checkUrl(getOpenstreetMaphouseNumbersDownloadURL()+filename)){
1580 	    			return false;
1581 	    		}
1582 	    	}
1583     	}
1584     	
1585     	if(isOpenstreetmapImporterEnabled()){
1586     		//osmstreet
1587 	    	filenames = getOpenStreetMapDownloadFilesListFromOption();
1588 	    	for (String filename:filenames){
1589 	    		if (!checkUrl(getOpenstreetMapDownloadURL()+filename)){
1590 	    			return false;
1591 	    		}
1592 	    	}
1593 	    	//osm cities
1594 	    	filenames = getOpenStreetMapCitiesDownloadFilesListFromOption();
1595 	    	for (String filename:filenames){
1596 	    		if (!checkUrl(getOpenstreetMapCitiesDownloadURL()+filename)){
1597 	    			return false;
1598 	    		}
1599 	    	}
1600 	    	//osm poi
1601 	    	filenames = getOpenStreetMapPoisDownloadFilesListFromOption();
1602 	    	for (String filename:filenames){
1603 	    		if (!checkUrl(getOpenstreetMapPoisDownloadURL()+filename)){
1604 	    			return false;
1605 	    		}
1606 	    	}
1607 	    	}
1608     	if (quattroshapesImporterEnabled){
1609     		filenames = getQuattroshapesFilesDownloadFilesListFromOption();
1610     		for (String filename:filenames){
1611 	    		if (!checkUrl(getQuattroshapesDownloadURL()+filename)){
1612 	    			return false;
1613 	    		}
1614 	    	}
1615     	}
1616     	
1617     	
1618     	logger.info("All files are downloadables");
1619     	return true;
1620     }
1621    
1622     /**
1623      * @return the path to the file that give the information if the import is
1624      *         done or not
1625      */
1626     public String getAlreadyDoneFilePath() {
1627     	return getImporterMetadataDirectoryPath() + ALREADY_DONE_FILE_NAME;
1628     }
1629 
1630     /**
1631      * @return the path to the file that give the information if the import is
1632      *         done or not
1633      */
1634     public String getImporterMetadataDirectoryPath() {
1635     	return getGeonamesDir() + IMPORTER_METADATA_RELATIVE_PATH + File.separator;
1636     }
1637 
1638     /**
1639      * Create the importerMetadataDirectory
1640      * 
1641      * @return the path to the importerMetadataDirectory
1642      */
1643     public String createImporterMetadataDirIfItDoesnTExist() {
1644 	if (!isGeonamesDownloadDirectoryAccessible()) {
1645 	    if (!new File(getGeonamesDir()).mkdir()) {
1646 		throw new RuntimeException("the geonameDirectory doesn't exists and we can not create it ");
1647 	    }
1648 	}
1649 	String dirpath = getGeonamesDir() + IMPORTER_METADATA_RELATIVE_PATH + File.separator;
1650 	File directory = new File(dirpath);
1651 	if (!directory.exists()) {
1652 	    if (!directory.mkdir()) {
1653 		throw new RuntimeException("Can not create ImporterMetadataDirectory");
1654 	    }
1655 	}
1656 	return dirpath;
1657     }
1658 
1659     /**
1660      * Get the name of the file where the alternate names of features that are
1661      * not adm1, adm2, or country are
1662      * 
1663      * @see #setAlternateNameFeaturesFileName(String)
1664      * @return The name of the file
1665      */
1666     public String getAlternateNameFeaturesFileName() {
1667     	return alternateNameFeaturesFileName;
1668     }
1669 
1670     /**
1671      * Set the name of the file where the alternate names of features that are
1672      * not adm1, adm2, or country are
1673      * 
1674      * @see #getAlternateNameFeaturesFileName()
1675      * @param alternateNameFeaturesFileName
1676      *            The name of the file to set
1677      */
1678     @Required
1679     public void setAlternateNameFeaturesFileName(String alternateNameFeaturesFileName) {
1680     	this.alternateNameFeaturesFileName = alternateNameFeaturesFileName;
1681     }
1682 
1683     /**
1684      * Get the name of the file where the alternate names of adm with level 1
1685      * are
1686      * 
1687      * @see #setAlternateNameAdm1FileName(String)
1688      * @return The name of the file
1689      */
1690     public String getAlternateNameAdm1FileName() {
1691     	return alternateNameAdm1FileName;
1692     }
1693 
1694     /**
1695      * Set the name of the file where the alternate names of adm with level 1
1696      * are
1697      * 
1698      * @see #getAlternateNameAdm1FileName()
1699      * @param alternateNameAdm1FileName
1700      *            The name of the file to set
1701      */
1702     @Required
1703     public void setAlternateNameAdm1FileName(String alternateNameAdm1FileName) {
1704     	this.alternateNameAdm1FileName = alternateNameAdm1FileName;
1705     }
1706 
1707     /**
1708      * Get the name of the file where the alternate names of adm with level 2
1709      * are
1710      * 
1711      * @see #setAlternateNameAdm2FileName(String)
1712      * @return The name of the file
1713      */
1714     public String getAlternateNameAdm2FileName() {
1715     	return alternateNameAdm2FileName;
1716     }
1717 
1718     /**
1719      * Set the name of the file where the alternate names of adm with level 2
1720      * are
1721      * 
1722      * @see #getAlternateNameAdm2FileName()
1723      * @param alternateNameAdm2FileName
1724      *            The name of the file to set
1725      */
1726     @Required
1727     public void setAlternateNameAdm2FileName(String alternateNameAdm2FileName) {
1728     	this.alternateNameAdm2FileName = alternateNameAdm2FileName;
1729     }
1730 
1731     /**
1732      * Get the name of the file where the alternate names of countries are
1733      * 
1734      * @see #setAlternateNameCountryFileName(String)
1735      * @return The name of the file
1736      */
1737     public String getAlternateNameCountryFileName() {
1738     	return alternateNameCountryFileName;
1739     }
1740 
1741     /**
1742      * Set the name of the file where the alternate names of countries are
1743      * 
1744      * @see #getAlternateNameCountryFileName()
1745      * @param alternateNameCountryFileName
1746      *            The name of the file to set
1747      */
1748     @Required
1749     public void setAlternateNameCountryFileName(String alternateNameCountryFileName) {
1750     	this.alternateNameCountryFileName = alternateNameCountryFileName;
1751     }
1752 
1753     /**
1754      * if we search for the nearest city in geonames data to fill the is_in
1755      * field this increase the time of the importer but strongly increase the
1756      * relevance of the geocoder
1757      */
1758     public boolean isOpenStreetMapFillIsIn() {
1759     	return openStreetMapFillIsIn;
1760     }
1761 
1762     /**
1763      * @see #isOpenStreetMapFillIsIn()
1764      */
1765     public void setOpenStreetMapFillIsIn(boolean openStreetMapFillIsIn) {
1766     	this.openStreetMapFillIsIn = openStreetMapFillIsIn;
1767     	CommentedProperties.editPropertyFromClassPathRessource(PROPERTIES_CONFIG_FILE_CLASSPATH, OPENSTREETMAP_FILL_ISIN_FIELD_NAME, String.valueOf(openStreetMapFillIsIn));
1768     }
1769 
1770 
1771 	public boolean isRenameFilesAfterProcessing() {
1772 		return renameFilesAfterProcessing;
1773 	}
1774 
1775 	public void setRenameFilesAfterProcessing(boolean renameFilesAfterProcessing) {
1776 		this.renameFilesAfterProcessing = renameFilesAfterProcessing;
1777 	}
1778 
1779 }