Revision 50818ab7
Added by Katja Luther over 8 years ago
app-import/src/main/java/eu/etaxonomy/cdm/app/wp6/palmae/PalmaeTaxonXImportActivator.java | ||
---|---|---|
1 | 1 |
/** |
2 | 2 |
* Copyright (C) 2007 EDIT |
3 |
* European Distributed Institute of Taxonomy
|
|
3 |
* European Distributed Institute of Taxonomy |
|
4 | 4 |
* http://www.e-taxonomy.eu |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
7 | 7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
8 | 8 |
*/ |
... | ... | |
23 | 23 |
import eu.etaxonomy.cdm.io.common.CdmDefaultImport; |
24 | 24 |
import eu.etaxonomy.cdm.io.common.IImportConfigurator; |
25 | 25 |
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK; |
26 |
import eu.etaxonomy.cdm.io.common.ImportResult; |
|
26 | 27 |
import eu.etaxonomy.cdm.io.taxonx.TaxonXImportConfigurator; |
27 | 28 |
|
28 | 29 |
/** |
... | ... | |
32 | 33 |
*/ |
33 | 34 |
public class PalmaeTaxonXImportActivator { |
34 | 35 |
private static final Logger logger = Logger.getLogger(PalmaeTaxonXImportActivator.class); |
35 |
|
|
36 |
|
|
36 | 37 |
//database validation status (create, update, validate ...) |
37 | 38 |
static DbSchemaValidation hbm2dll = DbSchemaValidation.UPDATE; |
38 | 39 |
//static final String tcsSource = TcsSources.taxonX_local(); |
39 | 40 |
//static File source = TcsSources.taxonX_localDir(); |
40 | 41 |
static File source = new File("target/classes/taxonX"); |
41 | 42 |
static ICdmDataSource cdmDestination = CdmDestinations.localH2Palmae(); |
42 |
|
|
43 |
|
|
43 | 44 |
//check - import |
44 | 45 |
static CHECK check = CHECK.IMPORT_WITHOUT_CHECK; |
45 |
|
|
46 |
|
|
46 | 47 |
static boolean doDescriptions = true; |
47 | 48 |
static boolean doNomenclature = true; |
48 | 49 |
static boolean doMods = true; |
49 |
|
|
50 |
|
|
51 |
public boolean runImport(){
|
|
52 |
boolean success = true;
|
|
50 |
|
|
51 |
|
|
52 |
public ImportResult runImport(){
|
|
53 |
ImportResult success = new ImportResult();
|
|
53 | 54 |
//make destination |
54 | 55 |
ICdmDataSource destination = cdmDestination; |
55 |
|
|
56 |
|
|
56 | 57 |
TaxonXImportConfigurator taxonXImportConfigurator = TaxonXImportConfigurator.NewInstance(null, destination); |
57 | 58 |
// invoke import |
58 | 59 |
CdmDefaultImport<IImportConfigurator> cdmImport = new CdmDefaultImport<IImportConfigurator>(); |
59 |
|
|
60 |
|
|
60 | 61 |
taxonXImportConfigurator.setDoFacts(doDescriptions); |
61 | 62 |
taxonXImportConfigurator.setDoTypes(doNomenclature); |
62 | 63 |
taxonXImportConfigurator.setDoMods(doMods); |
63 |
|
|
64 |
|
|
64 | 65 |
taxonXImportConfigurator.setCheck(check); |
65 | 66 |
taxonXImportConfigurator.setDbSchemaValidation(hbm2dll); |
66 | 67 |
|
67 | 68 |
cdmImport.startController(taxonXImportConfigurator, destination); |
68 |
|
|
69 |
|
|
69 | 70 |
//new Test().invoke(tcsImportConfigurator); |
70 | 71 |
if (source.isDirectory()){ |
71 | 72 |
makeDirectory(cdmImport, taxonXImportConfigurator, source); |
72 | 73 |
}else{ |
73 | 74 |
try { |
74 |
success &= importFile(cdmImport, taxonXImportConfigurator, source); |
|
75 |
success = importFile(cdmImport, taxonXImportConfigurator, source); |
|
76 |
|
|
75 | 77 |
} catch (URISyntaxException e) { |
76 |
success = false; |
|
78 |
success.setSuccess(false); |
|
79 |
success.addReport(e.getMessage().getBytes()); |
|
77 | 80 |
e.printStackTrace(); |
78 | 81 |
} |
79 | 82 |
} |
80 | 83 |
return success; |
81 | 84 |
} |
82 |
|
|
83 |
private boolean makeDirectory(CdmDefaultImport<IImportConfigurator> cdmImport, TaxonXImportConfigurator taxonXImportConfigurator, File source){
|
|
84 |
boolean success = true;
|
|
85 |
|
|
86 |
private ImportResult makeDirectory(CdmDefaultImport<IImportConfigurator> cdmImport, TaxonXImportConfigurator taxonXImportConfigurator, File source){
|
|
87 |
ImportResult success = new ImportResult();
|
|
85 | 88 |
int count = 0; |
86 | 89 |
for (File file : source.listFiles() ){ |
87 | 90 |
if (file.isFile()){ |
88 | 91 |
doCount(count++, 300, "Files"); |
89 | 92 |
try { |
90 |
success &= importFile(cdmImport, taxonXImportConfigurator, file);
|
|
93 |
success = importFile(cdmImport, taxonXImportConfigurator, file); |
|
91 | 94 |
} catch (URISyntaxException e) { |
92 |
success = false; |
|
95 |
success = new ImportResult(); |
|
96 |
success.setSuccess(false); |
|
97 |
success.addReport(e.getMessage().getBytes()); |
|
93 | 98 |
e.printStackTrace(); |
94 | 99 |
} |
95 | 100 |
}else{ |
... | ... | |
100 | 105 |
} |
101 | 106 |
return success; |
102 | 107 |
} |
103 |
|
|
104 |
private boolean importFile(CdmDefaultImport<IImportConfigurator> cdmImport,
|
|
108 |
|
|
109 |
private ImportResult importFile(CdmDefaultImport<IImportConfigurator> cdmImport,
|
|
105 | 110 |
TaxonXImportConfigurator config, File file) throws URISyntaxException{ |
106 |
boolean success = true;
|
|
111 |
ImportResult success ;
|
|
107 | 112 |
try{ |
108 | 113 |
URL url = file.toURI().toURL(); |
109 | 114 |
config.setSource(url.toURI()); |
... | ... | |
112 | 117 |
logger.debug(originalSourceId); |
113 | 118 |
config.setOriginalSourceId(originalSourceId); |
114 | 119 |
TransactionStatus tx = cdmImport.getCdmAppController().startTransaction(); |
115 |
success &= cdmImport.invoke(config);
|
|
116 |
cdmImport.getCdmAppController().commitTransaction(tx);
|
|
117 |
return success;
|
|
120 |
success = cdmImport.invoke(config); |
|
121 |
cdmImport.getCdmAppController().commitTransaction(tx); |
|
122 |
return success; |
|
118 | 123 |
} catch (MalformedURLException e) { |
119 | 124 |
logger.warn(e); |
120 |
return false; |
|
125 |
success = new ImportResult(); |
|
126 |
success.setSuccess(false); |
|
127 |
return success; |
|
121 | 128 |
} |
122 | 129 |
} |
123 |
|
|
130 |
|
|
124 | 131 |
protected void doCount(int count, int modCount, String pluralString){ |
125 | 132 |
if ((count % modCount ) == 0 && count!= 0 ){ logger.info(pluralString + " handled: " + (count));} |
126 | 133 |
} |
127 |
|
|
134 |
|
|
128 | 135 |
/** |
129 | 136 |
* @param args |
130 | 137 |
*/ |
131 | 138 |
public static void main(String[] args) { |
132 | 139 |
System.out.println("Start import from Source("+ source.toString() + ") ..."); |
133 |
|
|
140 |
|
|
134 | 141 |
PalmaeTaxonXImportActivator importer = new PalmaeTaxonXImportActivator(); |
135 |
|
|
142 |
|
|
136 | 143 |
importer.runImport(); |
137 |
|
|
138 |
|
|
144 |
|
|
145 |
|
|
139 | 146 |
System.out.println("End import from Source ("+ source.toString() + ")..."); |
140 | 147 |
} |
141 | 148 |
|
142 |
|
|
149 |
|
|
143 | 150 |
} |
Also available in: Unified diff
adapt the import classes to the new return type ImportResult