2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.app
.wp6
.palmae
;
13 import java
.net
.MalformedURLException
;
16 import org
.apache
.log4j
.Logger
;
17 import org
.springframework
.transaction
.TransactionStatus
;
19 import eu
.etaxonomy
.cdm
.app
.common
.CdmDestinations
;
20 import eu
.etaxonomy
.cdm
.database
.DbSchemaValidation
;
21 import eu
.etaxonomy
.cdm
.database
.ICdmDataSource
;
22 import eu
.etaxonomy
.cdm
.io
.common
.CdmDefaultImport
;
23 import eu
.etaxonomy
.cdm
.io
.common
.IImportConfigurator
;
24 import eu
.etaxonomy
.cdm
.io
.common
.IImportConfigurator
.CHECK
;
25 import eu
.etaxonomy
.cdm
.io
.taxonx
.TaxonXImportConfigurator
;
32 public class PalmaeTaxonXImportActivator
{
33 private static final Logger logger
= Logger
.getLogger(PalmaeTaxonXImportActivator
.class);
35 //database validation status (create, update, validate ...)
36 static DbSchemaValidation hbm2dll
= DbSchemaValidation
.UPDATE
;
37 //static final String tcsSource = TcsSources.taxonX_local();
38 //static File source = TcsSources.taxonX_localDir();
39 static File source
= new File("target/classes/taxonX");
40 static ICdmDataSource cdmDestination
= CdmDestinations
.localH2Palmae();
43 static CHECK check
= CHECK
.IMPORT_WITHOUT_CHECK
;
45 static boolean doDescriptions
= true;
46 static boolean doNomenclature
= true;
47 static boolean doMods
= true;
50 public boolean runImport(){
51 boolean success
= true;
53 ICdmDataSource destination
= cdmDestination
;
55 TaxonXImportConfigurator taxonXImportConfigurator
= TaxonXImportConfigurator
.NewInstance("", destination
);
57 CdmDefaultImport
<IImportConfigurator
> cdmImport
= new CdmDefaultImport
<IImportConfigurator
>();
59 taxonXImportConfigurator
.setDoFacts(doDescriptions
);
60 taxonXImportConfigurator
.setDoTypes(doNomenclature
);
61 taxonXImportConfigurator
.setDoMods(doMods
);
63 taxonXImportConfigurator
.setCheck(check
);
64 taxonXImportConfigurator
.setDbSchemaValidation(hbm2dll
);
66 cdmImport
.startController(taxonXImportConfigurator
, destination
);
68 //new Test().invoke(tcsImportConfigurator);
69 if (source
.isDirectory()){
70 makeDirectory(cdmImport
, taxonXImportConfigurator
, source
);
72 success
&= importFile(cdmImport
, taxonXImportConfigurator
, source
);
77 private boolean makeDirectory(CdmDefaultImport
<IImportConfigurator
> cdmImport
, TaxonXImportConfigurator taxonXImportConfigurator
, File source
){
78 boolean success
= true;
80 for (File file
: source
.listFiles() ){
82 doCount(count
++, 300, "Files");
83 success
&= importFile(cdmImport
, taxonXImportConfigurator
, file
);
85 if (! file
.getName().startsWith(".")){
86 makeDirectory(cdmImport
, taxonXImportConfigurator
, file
);
93 private boolean importFile(CdmDefaultImport
<IImportConfigurator
> cdmImport
,
94 TaxonXImportConfigurator config
, File file
){
95 boolean success
= true;
97 URL url
= file
.toURI().toURL();
98 config
.setSource(url
.toString());
99 String originalSourceId
= file
.getName();
100 originalSourceId
=originalSourceId
.replace(".xml", "");
101 logger
.debug(originalSourceId
);
102 config
.setOriginalSourceId(originalSourceId
);
103 TransactionStatus tx
= cdmImport
.getCdmAppController().startTransaction();
104 success
&= cdmImport
.invoke(config
);
105 cdmImport
.getCdmAppController().commitTransaction(tx
);
107 } catch (MalformedURLException e
) {
113 protected void doCount(int count
, int modCount
, String pluralString
){
114 if ((count
% modCount
) == 0 && count
!= 0 ){ logger
.info(pluralString
+ " handled: " + (count
));}
120 public static void main(String
[] args
) {
121 System
.out
.println("Start import from Source("+ source
.toString() + ") ...");
123 PalmaeTaxonXImportActivator importer
= new PalmaeTaxonXImportActivator();
125 importer
.runImport();
128 System
.out
.println("End import from Source ("+ source
.toString() + ")...");