1
|
package eu.etaxonomy.cdm.io.berlinModel;
|
2
|
|
3
|
import org.apache.log4j.Logger;
|
4
|
import org.springframework.stereotype.Service;
|
5
|
|
6
|
import eu.etaxonomy.cdm.api.application.CdmApplicationController;
|
7
|
import eu.etaxonomy.cdm.database.DataSourceNotFoundException;
|
8
|
import eu.etaxonomy.cdm.io.source.Source;
|
9
|
import eu.etaxonomy.cdm.model.agent.Team;
|
10
|
import eu.etaxonomy.cdm.model.common.init.TermNotFoundException;
|
11
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
12
|
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
|
13
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
14
|
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelImportConfigurator.DO_REFERENCES.*;
|
15
|
|
16
|
@Service
|
17
|
public class BerlinModelImport {
|
18
|
private static final Logger logger = Logger.getLogger(BerlinModelImport.class);
|
19
|
|
20
|
//Constants
|
21
|
//final boolean OBLIGATORY = true;
|
22
|
//final boolean FACULTATIVE = false;
|
23
|
final int modCount = 1000;
|
24
|
|
25
|
|
26
|
//Hashmaps for Joins
|
27
|
//OLD: private Map<Integer, UUID> referenceMap = new HashMap<Integer, UUID>();
|
28
|
private MapWrapper<Team> authorStore= new MapWrapper<Team>(null);
|
29
|
private MapWrapper<ReferenceBase> referenceStore= new MapWrapper<ReferenceBase>(null);
|
30
|
private MapWrapper<TaxonNameBase> taxonNameStore = new MapWrapper<TaxonNameBase>(null);
|
31
|
private MapWrapper<TaxonBase> taxonStore = new MapWrapper<TaxonBase>(null);
|
32
|
|
33
|
|
34
|
/**
|
35
|
* Executes the whole
|
36
|
*/
|
37
|
public boolean doImport(BerlinModelImportConfigurator bmiConfig){
|
38
|
CdmApplicationController cdmApp;
|
39
|
if (bmiConfig == null){
|
40
|
logger.warn("BerlinModelImportConfiguration is null");
|
41
|
return false;
|
42
|
}else if (! bmiConfig.isValid()){
|
43
|
logger.warn("BerlinModelImportConfiguration is not valid");
|
44
|
return false;
|
45
|
}
|
46
|
try {
|
47
|
cdmApp = CdmApplicationController.NewInstance(bmiConfig.getDestination(), bmiConfig.getDbSchemaValidation());
|
48
|
} catch (DataSourceNotFoundException e) {
|
49
|
logger.warn("could not connect to destination database");
|
50
|
return false;
|
51
|
}catch (TermNotFoundException e) {
|
52
|
logger.warn("could not find needed term in destination datasource");
|
53
|
return false;
|
54
|
}
|
55
|
Source source = bmiConfig.getSource();
|
56
|
ReferenceBase sourceReference = bmiConfig.getSourceReference();
|
57
|
System.out.println("Start import from BerlinModel ("+ bmiConfig.getSource().getDatabase() + ") to Cdm (" + cdmApp.getDatabaseService().getUrl() + ") ...");
|
58
|
|
59
|
|
60
|
//Authors
|
61
|
if (bmiConfig.isDoAuthors()){
|
62
|
if (! BerlinModelAuthorIO.invoke(bmiConfig, cdmApp, authorStore)){
|
63
|
logger.warn("No Authors imported");
|
64
|
return false;
|
65
|
}
|
66
|
}else{
|
67
|
authorStore = null;
|
68
|
}
|
69
|
|
70
|
//References
|
71
|
if (bmiConfig.getDoReferences() != NONE){
|
72
|
if (! BerlinModelReferenceIO.invoke(bmiConfig, cdmApp, referenceStore, authorStore)){
|
73
|
return false;
|
74
|
}
|
75
|
}else{
|
76
|
logger.warn("No References imported");
|
77
|
referenceStore = null;
|
78
|
}
|
79
|
|
80
|
//TaxonNames
|
81
|
if (bmiConfig.isDoTaxonNames()){
|
82
|
if (! BerlinModelTaxonNameIO.invoke(bmiConfig, cdmApp, taxonNameStore, referenceStore, authorStore)){
|
83
|
//return false;
|
84
|
}
|
85
|
}else{
|
86
|
logger.warn("No TaxonNames imported");
|
87
|
taxonNameStore = null;
|
88
|
}
|
89
|
|
90
|
|
91
|
//make and save RelNames
|
92
|
if(bmiConfig.isDoRelNames()){
|
93
|
if (! BerlinModelTaxonNameIO.invokeRelations(bmiConfig, cdmApp, taxonNameStore, referenceStore)){
|
94
|
return false;
|
95
|
}
|
96
|
}else{
|
97
|
logger.warn("No RelPTaxa imported");
|
98
|
}
|
99
|
|
100
|
//TODO NomStatus
|
101
|
//TODO Types
|
102
|
|
103
|
//make and save Taxa
|
104
|
if(bmiConfig.isDoTaxa()){
|
105
|
if (! BerlinModelTaxonIO.invoke(bmiConfig, cdmApp, taxonStore, taxonNameStore, referenceStore)){
|
106
|
return false;
|
107
|
}
|
108
|
}else{
|
109
|
logger.warn("No Taxa imported");
|
110
|
taxonNameStore = null;
|
111
|
}
|
112
|
|
113
|
//make and save RelPTaxa
|
114
|
if(bmiConfig.isDoRelTaxa()){
|
115
|
if (! BerlinModelTaxonIO.invokeRelations(bmiConfig, cdmApp, taxonStore, referenceStore)){
|
116
|
return false;
|
117
|
}
|
118
|
}else{
|
119
|
logger.warn("No RelPTaxa imported");
|
120
|
}
|
121
|
|
122
|
//make and save Facts
|
123
|
if(bmiConfig.isDoFacts()){
|
124
|
if (! BerlinModelFactsIO.invoke(bmiConfig, cdmApp, taxonStore, referenceStore)){
|
125
|
return false;
|
126
|
}
|
127
|
}else{
|
128
|
logger.warn("No Facts imported");
|
129
|
}
|
130
|
|
131
|
//return
|
132
|
System.out.println("End import from BerlinModel ("+ source.getDatabase() + ") to Cdm (" + cdmApp.getDatabaseService().getUrl() + ") ...");
|
133
|
return true;
|
134
|
}
|
135
|
|
136
|
|
137
|
}
|