1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
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.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.io.berlinModel.out;
|
10
|
|
11
|
import java.sql.SQLException;
|
12
|
import java.util.List;
|
13
|
|
14
|
import org.apache.log4j.Logger;
|
15
|
import org.springframework.stereotype.Component;
|
16
|
import org.springframework.transaction.TransactionStatus;
|
17
|
|
18
|
import eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer;
|
19
|
import eu.etaxonomy.cdm.io.berlinModel.out.mapper.CreatedAndNotesMapper;
|
20
|
import eu.etaxonomy.cdm.io.berlinModel.out.mapper.DbBooleanMapper;
|
21
|
import eu.etaxonomy.cdm.io.berlinModel.out.mapper.DbObjectMapper;
|
22
|
import eu.etaxonomy.cdm.io.berlinModel.out.mapper.DbStringMapper;
|
23
|
import eu.etaxonomy.cdm.io.berlinModel.out.mapper.IdMapper;
|
24
|
import eu.etaxonomy.cdm.io.berlinModel.out.mapper.MethodMapper;
|
25
|
import eu.etaxonomy.cdm.io.berlinModel.out.mapper.RefDetailMapper;
|
26
|
import eu.etaxonomy.cdm.io.common.IExportConfigurator;
|
27
|
import eu.etaxonomy.cdm.io.common.Source;
|
28
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
29
|
import eu.etaxonomy.cdm.model.name.NonViralName;
|
30
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
31
|
|
32
|
|
33
|
/**
|
34
|
* @author a.mueller
|
35
|
* @created 20.03.2008
|
36
|
* @version 1.0
|
37
|
*/
|
38
|
@Component
|
39
|
public class BerlinModelTaxonNameExport extends BerlinModelExportBase {
|
40
|
private static final Logger logger = Logger.getLogger(BerlinModelTaxonNameExport.class);
|
41
|
|
42
|
private static int modCount = 2500;
|
43
|
private static final String dbTableName = "Name";
|
44
|
private static final String pluralString = "TaxonNames";
|
45
|
private static final Class<? extends CdmBase> standardMethodParameter = NonViralName.class;
|
46
|
|
47
|
public BerlinModelTaxonNameExport(){
|
48
|
super();
|
49
|
}
|
50
|
|
51
|
/* (non-Javadoc)
|
52
|
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IImportConfigurator)
|
53
|
*/
|
54
|
@Override
|
55
|
protected boolean doCheck(IExportConfigurator config){
|
56
|
boolean result = true;
|
57
|
logger.warn("Checking for " + pluralString + " not yet implemented");
|
58
|
//result &= checkArticlesWithoutJournal(bmiConfig);
|
59
|
//result &= checkPartOfJournal(bmiConfig);
|
60
|
|
61
|
return result;
|
62
|
}
|
63
|
|
64
|
private BerlinModelExportMapping getMapping(){
|
65
|
String tableName = dbTableName;
|
66
|
BerlinModelExportMapping mapping = new BerlinModelExportMapping(tableName);
|
67
|
mapping.addMapper(IdMapper.NewInstance("NameId"));
|
68
|
mapping.addMapper(MethodMapper.NewInstance("RankFk", this));
|
69
|
mapping.addMapper(MethodMapper.NewInstance("SupraGenericName", this));
|
70
|
mapping.addMapper(MethodMapper.NewInstance("Genus", this));
|
71
|
mapping.addMapper(MethodMapper.NewInstance("NameCache", this));
|
72
|
mapping.addMapper(MethodMapper.NewInstance("FullNameCache", this));
|
73
|
mapping.addMapper(MethodMapper.NewInstance("PreliminaryFlag", this));
|
74
|
mapping.addMapper(DbStringMapper.NewInstance("infraGenericEpithet", "GenusSubDivisionEpi"));
|
75
|
mapping.addMapper(DbStringMapper.NewInstance("SpecificEpithet", "SpeciesEpi"));
|
76
|
mapping.addMapper(DbStringMapper.NewInstance("infraSpecificEpithet", "InfraSpeciesEpi"));
|
77
|
mapping.addMapper(DbStringMapper.NewInstance("appendedPhrase", "UnnamedNamePhrase"));
|
78
|
mapping.addMapper(DbBooleanMapper.NewInstance("isHybridFormula", "HybridFormulaFlag", false, false));
|
79
|
mapping.addMapper(DbBooleanMapper.NewInstance("isMonomHybrid", "MonomHybFlag", false, false));
|
80
|
mapping.addMapper(DbBooleanMapper.NewInstance("isBinomHybrid", "BinomHybFlag", false, false));
|
81
|
mapping.addMapper(DbBooleanMapper.NewInstance("isTrinomHybrid", "TrinomHybFlag", false, false));
|
82
|
mapping.addMapper(DbStringMapper.NewFacultativeInstance("cultivarName", "CultivarName"));
|
83
|
|
84
|
mapping.addMapper(DbObjectMapper.NewInstance("combinationAuthorTeam", "AuthorTeamFk"));
|
85
|
mapping.addMapper(DbObjectMapper.NewInstance("exCombinationAuthorTeam", "ExAuthorTeamFk"));
|
86
|
mapping.addMapper(DbObjectMapper.NewInstance("basionymAuthorTeam", "BasAuthorTeamFk"));
|
87
|
mapping.addMapper(DbObjectMapper.NewInstance("exBasionymAuthorTeam", "ExBasAuthorTeamFk"));
|
88
|
|
89
|
mapping.addMapper(DbObjectMapper.NewInstance("nomenclaturalReference", "NomRefFk"));
|
90
|
mapping.addMapper(RefDetailMapper.NewInstance("nomenclaturalMicroReference","nomenclaturalReference", "NomRefDetailFk"));
|
91
|
|
92
|
|
93
|
mapping.addMapper(CreatedAndNotesMapper.NewInstance(false));
|
94
|
//TODO
|
95
|
//CultivarGroupName
|
96
|
//NameSourceRefFk
|
97
|
// ,[Source_ACC]
|
98
|
|
99
|
//publicationYear
|
100
|
//originalPublicationYear
|
101
|
//breed
|
102
|
NonViralName<?> n = null;
|
103
|
//n.getNomenclaturalMicroReference()
|
104
|
return mapping;
|
105
|
}
|
106
|
|
107
|
protected boolean doInvoke(BerlinModelExportState<BerlinModelExportConfigurator> state){
|
108
|
try{
|
109
|
logger.info("start make "+pluralString+" ...");
|
110
|
boolean success = true ;
|
111
|
doDelete(state);
|
112
|
|
113
|
TransactionStatus txStatus = startTransaction(true);
|
114
|
|
115
|
List<TaxonNameBase> names = getNameService().list(100000000, 0);
|
116
|
|
117
|
BerlinModelExportMapping mapping = getMapping();
|
118
|
mapping.initialize(state);
|
119
|
|
120
|
int count = 0;
|
121
|
for (TaxonNameBase<?,?> name : names){
|
122
|
doCount(count++, modCount, pluralString);
|
123
|
success &= mapping.invoke(name);
|
124
|
//TODO rank = null or rank < genus and genusOrUninomial != null
|
125
|
}
|
126
|
commitTransaction(txStatus);
|
127
|
logger.info("end make " + pluralString+ " ...");
|
128
|
|
129
|
return success;
|
130
|
}catch(SQLException e){
|
131
|
e.printStackTrace();
|
132
|
logger.error(e.getMessage());
|
133
|
return false;
|
134
|
}
|
135
|
}
|
136
|
|
137
|
|
138
|
|
139
|
|
140
|
protected boolean doDelete(BerlinModelExportState<BerlinModelExportConfigurator> state){
|
141
|
BerlinModelExportConfigurator bmeConfig = state.getConfig();
|
142
|
|
143
|
String sql;
|
144
|
Source destination = bmeConfig.getDestination();
|
145
|
//RelPTaxon
|
146
|
sql = "DELETE FROM RelPTaxon";
|
147
|
destination.setQuery(sql);
|
148
|
destination.update(sql);
|
149
|
//Fact
|
150
|
sql = "DELETE FROM Fact";
|
151
|
destination.setQuery(sql);
|
152
|
destination.update(sql);
|
153
|
//PTaxon
|
154
|
sql = "DELETE FROM PTaxon";
|
155
|
destination.setQuery(sql);
|
156
|
destination.update(sql);
|
157
|
|
158
|
//NameHistory
|
159
|
sql = "DELETE FROM NameHistory";
|
160
|
destination.setQuery(sql);
|
161
|
destination.update(sql);
|
162
|
//RelName
|
163
|
sql = "DELETE FROM RelName";
|
164
|
destination.setQuery(sql);
|
165
|
destination.update(sql);
|
166
|
//NomStatusRel
|
167
|
sql = "DELETE FROM NomStatusRel";
|
168
|
destination.setQuery(sql);
|
169
|
destination.update(sql);
|
170
|
//Name
|
171
|
sql = "DELETE FROM Name";
|
172
|
destination.setQuery(sql);
|
173
|
destination.update(sql);
|
174
|
return true;
|
175
|
}
|
176
|
|
177
|
|
178
|
/* (non-Javadoc)
|
179
|
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
|
180
|
*/
|
181
|
protected boolean isIgnore(IExportConfigurator config){
|
182
|
return ! ((BerlinModelExportConfigurator)config).isDoTaxonNames();
|
183
|
}
|
184
|
|
185
|
//called by MethodMapper
|
186
|
@SuppressWarnings("unused")
|
187
|
private static Integer getRankFk(NonViralName<?> name){
|
188
|
return BerlinModelTransformer.rank2RankId(name.getRank());
|
189
|
}
|
190
|
|
191
|
//called by MethodMapper
|
192
|
@SuppressWarnings("unused")
|
193
|
private static String getSupraGenericName(NonViralName<?> name){
|
194
|
if (name.isSupraGeneric()){
|
195
|
return name.getGenusOrUninomial();
|
196
|
}else{
|
197
|
return null;
|
198
|
}
|
199
|
}
|
200
|
|
201
|
//called by MethodMapper
|
202
|
@SuppressWarnings("unused")
|
203
|
private static String getGenus(NonViralName<?> name){
|
204
|
if (! name.isSupraGeneric()){
|
205
|
return name.getGenusOrUninomial();
|
206
|
}else{
|
207
|
return null;
|
208
|
}
|
209
|
}
|
210
|
|
211
|
//called by MethodMapper
|
212
|
@SuppressWarnings("unused")
|
213
|
private static String getNameCache(NonViralName<?> name){
|
214
|
if (name.isProtectedNameCache()){
|
215
|
return name.getNameCache();
|
216
|
}else{
|
217
|
return null;
|
218
|
}
|
219
|
}
|
220
|
|
221
|
//called by MethodMapper
|
222
|
@SuppressWarnings("unused")
|
223
|
private static String getFullNameCache(NonViralName<?> name){
|
224
|
if (name.isProtectedTitleCache()){
|
225
|
return name.getTitleCache();
|
226
|
}else{
|
227
|
return null;
|
228
|
}
|
229
|
}
|
230
|
|
231
|
//called by MethodMapper
|
232
|
@SuppressWarnings("unused")
|
233
|
private static Boolean getPreliminaryFlag(NonViralName<?> name){
|
234
|
if (name.isProtectedTitleCache() || name.isProtectedNameCache()){
|
235
|
if (name.isProtectedTitleCache() && name.isProtectedNameCache()){
|
236
|
logger.warn("protectedTitleCache and protectedNameCache do not have the same value for name " + name.getTitleCache() + ". This can not be mapped appropriately to the Berlin Model ");
|
237
|
}
|
238
|
return true;
|
239
|
}else{
|
240
|
return false;
|
241
|
}
|
242
|
}
|
243
|
|
244
|
|
245
|
|
246
|
/* (non-Javadoc)
|
247
|
* @see eu.etaxonomy.cdm.io.berlinModel.out.BerlinModelExportBase#getStandardMethodParameter()
|
248
|
*/
|
249
|
@Override
|
250
|
public Class<? extends CdmBase> getStandardMethodParameter() {
|
251
|
return standardMethodParameter;
|
252
|
}
|
253
|
}
|