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
|
|
10
|
package eu.etaxonomy.cdm.io.berlinModel.in;
|
11
|
|
12
|
import java.sql.ResultSet;
|
13
|
import java.sql.SQLException;
|
14
|
import java.util.HashMap;
|
15
|
import java.util.HashSet;
|
16
|
import java.util.Map;
|
17
|
import java.util.Set;
|
18
|
import java.util.UUID;
|
19
|
|
20
|
import org.apache.commons.lang.StringUtils;
|
21
|
import org.apache.log4j.Logger;
|
22
|
import org.springframework.stereotype.Component;
|
23
|
|
24
|
import eu.etaxonomy.cdm.common.CdmUtils;
|
25
|
import eu.etaxonomy.cdm.database.update.DatabaseTypeNotSupportedException;
|
26
|
import eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer;
|
27
|
import eu.etaxonomy.cdm.io.berlinModel.in.validation.BerlinModelTaxonNameImportValidator;
|
28
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator;
|
29
|
import eu.etaxonomy.cdm.io.common.IOValidator;
|
30
|
import eu.etaxonomy.cdm.io.common.ImportHelper;
|
31
|
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner;
|
32
|
import eu.etaxonomy.cdm.io.common.Source;
|
33
|
import eu.etaxonomy.cdm.model.agent.Person;
|
34
|
import eu.etaxonomy.cdm.model.agent.Team;
|
35
|
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
|
36
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
37
|
import eu.etaxonomy.cdm.model.common.Extension;
|
38
|
import eu.etaxonomy.cdm.model.common.ExtensionType;
|
39
|
import eu.etaxonomy.cdm.model.common.Language;
|
40
|
import eu.etaxonomy.cdm.model.common.Representation;
|
41
|
import eu.etaxonomy.cdm.model.name.BotanicalName;
|
42
|
import eu.etaxonomy.cdm.model.name.CultivarPlantName;
|
43
|
import eu.etaxonomy.cdm.model.name.NonViralName;
|
44
|
import eu.etaxonomy.cdm.model.name.Rank;
|
45
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
46
|
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
47
|
import eu.etaxonomy.cdm.model.name.ZoologicalName;
|
48
|
import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;
|
49
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
50
|
import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException;
|
51
|
|
52
|
/**
|
53
|
* @author a.mueller
|
54
|
* @created 20.03.2008
|
55
|
* @version 1.0
|
56
|
*/
|
57
|
@Component
|
58
|
public class BerlinModelTaxonNameImport extends BerlinModelImportBase {
|
59
|
private static final boolean BLANK_TO_NULL = true;
|
60
|
|
61
|
private static final Logger logger = Logger.getLogger(BerlinModelTaxonNameImport.class);
|
62
|
|
63
|
public static final String NAMESPACE = "TaxonName";
|
64
|
|
65
|
public static final UUID SOURCE_ACC_UUID = UUID.fromString("c3959b4f-d876-4b7a-a739-9260f4cafd1c");
|
66
|
|
67
|
private static int modCount = 5000;
|
68
|
private static final String pluralString = "TaxonNames";
|
69
|
private static final String dbTableName = "Name";
|
70
|
|
71
|
|
72
|
public BerlinModelTaxonNameImport(){
|
73
|
super(dbTableName, pluralString);
|
74
|
}
|
75
|
|
76
|
|
77
|
@Override
|
78
|
protected String getIdQuery(BerlinModelImportState state) {
|
79
|
if (state.getConfig().getNameIdTable()==null ){
|
80
|
return super.getIdQuery(state);
|
81
|
}else{
|
82
|
return "SELECT nameId FROM " + state.getConfig().getNameIdTable() + "";
|
83
|
}
|
84
|
}
|
85
|
|
86
|
@Override
|
87
|
protected String getRecordQuery(BerlinModelImportConfigurator config) {
|
88
|
Source source = config.getSource();
|
89
|
|
90
|
String facultativCols = "";
|
91
|
String strFacTable = "RefDetail";
|
92
|
String strFacColumn = "IdInSource";
|
93
|
String strColAlias = null;
|
94
|
if (checkSqlServerColumnExists(source, strFacTable, strFacColumn)){
|
95
|
facultativCols += ", " + strFacTable + "." + strFacColumn ;
|
96
|
if (! CdmUtils.Nz(strColAlias).equals("") ){
|
97
|
facultativCols += " AS " + strColAlias;
|
98
|
}
|
99
|
}
|
100
|
|
101
|
String strRecordQuery =
|
102
|
"SELECT Name.* , RefDetail.RefDetailId, RefDetail.RefFk, " +
|
103
|
" RefDetail.FullRefCache, RefDetail.FullNomRefCache, RefDetail.PreliminaryFlag AS RefDetailPrelim, RefDetail.Details, " +
|
104
|
" RefDetail.SecondarySources, Rank.RankAbbrev, Rank.Rank " +
|
105
|
facultativCols +
|
106
|
" FROM Name LEFT OUTER JOIN RefDetail ON Name.NomRefDetailFk = RefDetail.RefDetailId AND " +
|
107
|
" Name.NomRefFk = RefDetail.RefFk " +
|
108
|
" LEFT OUTER JOIN Rank ON Name.RankFk = Rank.rankID " +
|
109
|
" WHERE name.nameId IN ("+ID_LIST_TOKEN+") ";
|
110
|
//strQuery += " AND RefDetail.PreliminaryFlag = 1 ";
|
111
|
//strQuery += " AND Name.Created_When > '03.03.2004' ";
|
112
|
return strRecordQuery + "";
|
113
|
}
|
114
|
|
115
|
|
116
|
|
117
|
@Override
|
118
|
protected void doInvoke(BerlinModelImportState state) {
|
119
|
//update rank labels if necessary
|
120
|
String strAbbrev = state.getConfig().getInfrGenericRankAbbrev();
|
121
|
Rank rank = Rank.INFRAGENERICTAXON();
|
122
|
testRankAbbrev(strAbbrev, rank);
|
123
|
|
124
|
strAbbrev = state.getConfig().getInfrSpecificRankAbbrev();
|
125
|
rank = Rank.INFRASPECIFICTAXON();
|
126
|
testRankAbbrev(strAbbrev, rank);
|
127
|
|
128
|
super.doInvoke(state);
|
129
|
}
|
130
|
|
131
|
private void testRankAbbrev(String strAbbrev, Rank rank) {
|
132
|
if (strAbbrev != null){
|
133
|
Representation rep = rank.getRepresentation(Language.ENGLISH());
|
134
|
rep.setAbbreviatedLabel(strAbbrev);
|
135
|
getTermService().saveOrUpdate(rank);
|
136
|
}
|
137
|
}
|
138
|
|
139
|
@Override
|
140
|
public boolean doPartition(ResultSetPartitioner partitioner, BerlinModelImportState state) {
|
141
|
String dbAttrName;
|
142
|
String cdmAttrName;
|
143
|
boolean success = true ;
|
144
|
BerlinModelImportConfigurator config = state.getConfig();
|
145
|
Set<TaxonNameBase> namesToSave = new HashSet<TaxonNameBase>();
|
146
|
Map<String, Team> teamMap = partitioner.getObjectMap(BerlinModelAuthorTeamImport.NAMESPACE);
|
147
|
|
148
|
ResultSet rs = partitioner.getResultSet();
|
149
|
|
150
|
try {
|
151
|
int i = 0;
|
152
|
//for each reference
|
153
|
while (rs.next()){
|
154
|
|
155
|
if ((i++ % modCount) == 0 && i != 1 ){ logger.info("Names handled: " + (i-1));}
|
156
|
|
157
|
//create TaxonName element
|
158
|
int nameId = rs.getInt("nameId");
|
159
|
Object authorFk = rs.getObject("AuthorTeamFk");
|
160
|
Object exAuthorFk = rs.getObject("ExAuthorTeamFk");
|
161
|
Object basAuthorFk = rs.getObject("BasAuthorTeamFk");
|
162
|
Object exBasAuthorFk = rs.getObject("ExBasAuthorTeamFk");
|
163
|
String strCultivarGroupName = rs.getString("CultivarGroupName");
|
164
|
String strCultivarName = rs.getString("CultivarName");
|
165
|
String nameCache = rs.getString("NameCache");
|
166
|
String fullNameCache = rs.getString("FullNameCache");
|
167
|
String uuid = null;
|
168
|
if (resultSetHasColumn(rs,"UUID")){
|
169
|
uuid = rs.getString("UUID");
|
170
|
}
|
171
|
|
172
|
try {
|
173
|
|
174
|
//define rank
|
175
|
boolean useUnknownRank = true;
|
176
|
Rank rank = BerlinModelTransformer.rankId2Rank(rs, useUnknownRank, config.isSwitchSpeciesGroup());
|
177
|
|
178
|
boolean allowInfraSpecTaxonRank = state.getConfig().isAllowInfraSpecTaxonRank() ;
|
179
|
if (rank == null || rank.equals(Rank.UNKNOWN_RANK()) || (rank.equals(Rank.INFRASPECIFICTAXON()) && ! allowInfraSpecTaxonRank)){
|
180
|
rank = handleProlesAndRaceSublusus(state, rs, rank);
|
181
|
}
|
182
|
|
183
|
if (rank.getId() == 0){
|
184
|
getTermService().save(rank);
|
185
|
logger.warn("Rank did not yet exist: " + rank.getTitleCache());
|
186
|
}
|
187
|
|
188
|
//create TaxonNameBase
|
189
|
TaxonNameBase<?,?> taxonNameBase;
|
190
|
if (config.getNomenclaturalCode() != null){
|
191
|
taxonNameBase = config.getNomenclaturalCode().getNewTaxonNameInstance(rank);
|
192
|
//check cultivar
|
193
|
if (taxonNameBase instanceof BotanicalName){
|
194
|
if (isNotBlank(strCultivarGroupName) && isNotBlank(strCultivarName)){
|
195
|
taxonNameBase = TaxonNameFactory.NewCultivarInstance(rank);
|
196
|
}
|
197
|
}
|
198
|
}else{
|
199
|
taxonNameBase = TaxonNameFactory.NewNonViralInstance(rank);
|
200
|
}
|
201
|
if (uuid != null){
|
202
|
taxonNameBase.setUuid(UUID.fromString(uuid));
|
203
|
}
|
204
|
|
205
|
if (rank == null){
|
206
|
//TODO rank should never be null or a more sophisticated algorithm has to be implemented for genus/supraGenericName
|
207
|
logger.warn("Rank is null. Genus epethiton was imported. May be wrong");
|
208
|
success = false;
|
209
|
}
|
210
|
|
211
|
//epithets
|
212
|
if (rank != null && rank.isSupraGeneric()){
|
213
|
dbAttrName = "supraGenericName";
|
214
|
}else{
|
215
|
dbAttrName = "genus";
|
216
|
}
|
217
|
cdmAttrName = "genusOrUninomial";
|
218
|
success &= ImportHelper.addStringValue(rs, taxonNameBase, dbAttrName, cdmAttrName, BLANK_TO_NULL);
|
219
|
|
220
|
dbAttrName = "genusSubdivisionEpi";
|
221
|
cdmAttrName = "infraGenericEpithet";
|
222
|
success &= ImportHelper.addStringValue(rs, taxonNameBase, dbAttrName, cdmAttrName, BLANK_TO_NULL);
|
223
|
|
224
|
dbAttrName = "speciesEpi";
|
225
|
cdmAttrName = "specificEpithet";
|
226
|
success &= ImportHelper.addStringValue(rs, taxonNameBase, dbAttrName, cdmAttrName, BLANK_TO_NULL);
|
227
|
|
228
|
|
229
|
dbAttrName = "infraSpeciesEpi";
|
230
|
cdmAttrName = "infraSpecificEpithet";
|
231
|
success &= ImportHelper.addStringValue(rs, taxonNameBase, dbAttrName, cdmAttrName, BLANK_TO_NULL);
|
232
|
|
233
|
dbAttrName = "unnamedNamePhrase";
|
234
|
cdmAttrName = "appendedPhrase";
|
235
|
success &= ImportHelper.addStringValue(rs, taxonNameBase, dbAttrName, cdmAttrName, BLANK_TO_NULL);
|
236
|
|
237
|
//Details
|
238
|
dbAttrName = "details";
|
239
|
cdmAttrName = "nomenclaturalMicroReference";
|
240
|
success &= ImportHelper.addStringValue(rs, taxonNameBase, dbAttrName, cdmAttrName, BLANK_TO_NULL);
|
241
|
|
242
|
//nomRef
|
243
|
success &= makeNomenclaturalReference(config, taxonNameBase, nameId, rs, partitioner);
|
244
|
|
245
|
//Source_Acc
|
246
|
boolean colExists = true;
|
247
|
try {
|
248
|
colExists = state.getConfig().getSource().checkColumnExists("Name", "Source_Acc");
|
249
|
} catch (DatabaseTypeNotSupportedException e) {
|
250
|
logger.debug("Source does not support 'checkColumnExists'");
|
251
|
}
|
252
|
if (colExists){
|
253
|
String sourceAcc = rs.getString("Source_Acc");
|
254
|
if (StringUtils.isNotBlank(sourceAcc)){
|
255
|
ExtensionType sourceAccExtensionType = getExtensionType(state, SOURCE_ACC_UUID, "Source_Acc","Source_Acc","Source_Acc");
|
256
|
Extension datesExtension = Extension.NewInstance(taxonNameBase, sourceAcc, sourceAccExtensionType);
|
257
|
}
|
258
|
}
|
259
|
|
260
|
//created, notes
|
261
|
boolean excludeUpdated = true;
|
262
|
success &= doIdCreatedUpdatedNotes(state, taxonNameBase, rs, nameId, NAMESPACE, excludeUpdated, false);
|
263
|
|
264
|
//NonViralName
|
265
|
if (taxonNameBase instanceof NonViralName){
|
266
|
NonViralName<?> nonViralName = (NonViralName<?>)taxonNameBase;
|
267
|
|
268
|
//authorTeams
|
269
|
if (teamMap != null ){
|
270
|
nonViralName.setCombinationAuthorship(getAuthorTeam(teamMap, authorFk, nameId, config));
|
271
|
nonViralName.setExCombinationAuthorship(getAuthorTeam(teamMap, exAuthorFk, nameId, config));
|
272
|
nonViralName.setBasionymAuthorship(getAuthorTeam(teamMap, basAuthorFk, nameId, config));
|
273
|
nonViralName.setExBasionymAuthorship(getAuthorTeam(teamMap, exBasAuthorFk, nameId, config));
|
274
|
}else{
|
275
|
logger.warn("TeamMap is null");
|
276
|
success = false;
|
277
|
}
|
278
|
}//nonviralName
|
279
|
|
280
|
|
281
|
|
282
|
//zoologicalName
|
283
|
if (taxonNameBase instanceof ZoologicalName){
|
284
|
ZoologicalName zooName = (ZoologicalName)taxonNameBase;
|
285
|
makeZoologialName(rs, zooName, nameId);
|
286
|
}
|
287
|
//botanicalName
|
288
|
else if (taxonNameBase instanceof BotanicalName){
|
289
|
BotanicalName botName = (BotanicalName)taxonNameBase;
|
290
|
success &= makeBotanicalNamePart(rs, botName) ;
|
291
|
|
292
|
}
|
293
|
|
294
|
// dbAttrName = "preliminaryFlag";
|
295
|
Boolean preliminaryFlag = rs.getBoolean("PreliminaryFlag");
|
296
|
Boolean hybridFormulaFlag = rs.getBoolean("HybridFormulaFlag"); //hybrid flag does not lead to cache update in Berlin Model
|
297
|
if (preliminaryFlag == true || hybridFormulaFlag == true){
|
298
|
//Computes all caches and sets
|
299
|
taxonNameBase.setTitleCache(fullNameCache, true);
|
300
|
taxonNameBase.setFullTitleCache(taxonNameBase.getFullTitleCache(), true);
|
301
|
if (taxonNameBase instanceof NonViralName){
|
302
|
NonViralName<?> nvn = (NonViralName<?>)taxonNameBase;
|
303
|
nvn.setNameCache(nameCache, true);
|
304
|
nvn.setAuthorshipCache(nvn.getAuthorshipCache(), true);
|
305
|
}
|
306
|
}
|
307
|
namesToSave.add(taxonNameBase);
|
308
|
|
309
|
}
|
310
|
catch (UnknownCdmTypeException e) {
|
311
|
logger.warn("Name with id " + nameId + " has unknown rankId " + " and could not be saved.");
|
312
|
success = false;
|
313
|
}
|
314
|
|
315
|
} //while rs.hasNext()
|
316
|
} catch (SQLException e) {
|
317
|
logger.error("SQLException:" + e);
|
318
|
return false;
|
319
|
}
|
320
|
|
321
|
|
322
|
// logger.info( i + " names handled");
|
323
|
getNameService().save(namesToSave);
|
324
|
return success;
|
325
|
}
|
326
|
|
327
|
|
328
|
private Rank handleProlesAndRaceSublusus(BerlinModelImportState state, ResultSet rs, Rank rank) throws SQLException {
|
329
|
Rank result;
|
330
|
String rankAbbrev = rs.getString("RankAbbrev");
|
331
|
// String rankStr = rs.getString("Rank");
|
332
|
if (CdmUtils.nullSafeEqual(rankAbbrev, "prol.") ){
|
333
|
result = Rank.PROLES();
|
334
|
}else if(CdmUtils.nullSafeEqual(rankAbbrev, "race")){
|
335
|
result = Rank.RACE();
|
336
|
}else if(CdmUtils.nullSafeEqual(rankAbbrev, "sublusus")){
|
337
|
result = Rank.SUBLUSUS();
|
338
|
}else{
|
339
|
result = rank;
|
340
|
logger.warn("Unhandled rank: " + rankAbbrev);
|
341
|
}
|
342
|
return result;
|
343
|
}
|
344
|
|
345
|
@Override
|
346
|
public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs, BerlinModelImportState state) {
|
347
|
String nameSpace;
|
348
|
Class<?> cdmClass;
|
349
|
Set<String> idSet;
|
350
|
|
351
|
Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<Object, Map<String, ? extends CdmBase>>();
|
352
|
|
353
|
try{
|
354
|
Set<String> teamIdSet = new HashSet<String>();
|
355
|
Set<String> referenceIdSet = new HashSet<String>();
|
356
|
Set<String> refDetailIdSet = new HashSet<String>();
|
357
|
while (rs.next()){
|
358
|
handleForeignKey(rs, teamIdSet, "AuthorTeamFk");
|
359
|
handleForeignKey(rs, teamIdSet, "ExAuthorTeamFk");
|
360
|
handleForeignKey(rs, teamIdSet, "BasAuthorTeamFk");
|
361
|
handleForeignKey(rs, teamIdSet, "ExBasAuthorTeamFk");
|
362
|
handleForeignKey(rs, referenceIdSet, "nomRefFk");
|
363
|
handleForeignKey(rs, refDetailIdSet, "nomRefDetailFk");
|
364
|
}
|
365
|
|
366
|
//team map
|
367
|
nameSpace = BerlinModelAuthorTeamImport.NAMESPACE;
|
368
|
cdmClass = Team.class;
|
369
|
idSet = teamIdSet;
|
370
|
Map<String, Person> teamMap = (Map<String, Person>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
|
371
|
result.put(nameSpace, teamMap);
|
372
|
|
373
|
//reference map
|
374
|
nameSpace = BerlinModelReferenceImport.REFERENCE_NAMESPACE;
|
375
|
cdmClass = Reference.class;
|
376
|
idSet = referenceIdSet;
|
377
|
Map<String, Reference> referenceMap = (Map<String, Reference>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
|
378
|
result.put(nameSpace, referenceMap);
|
379
|
|
380
|
//refDetail map
|
381
|
nameSpace = BerlinModelRefDetailImport.REFDETAIL_NAMESPACE;
|
382
|
cdmClass = Reference.class;
|
383
|
idSet = refDetailIdSet;
|
384
|
Map<String, Reference> refDetailMap= (Map<String, Reference>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
|
385
|
result.put(nameSpace, refDetailMap);
|
386
|
|
387
|
} catch (SQLException e) {
|
388
|
throw new RuntimeException(e);
|
389
|
}
|
390
|
return result;
|
391
|
}
|
392
|
|
393
|
private boolean makeZoologialName(ResultSet rs, ZoologicalName zooName, int nameId)
|
394
|
throws SQLException{
|
395
|
boolean success = true;
|
396
|
//publicationYear
|
397
|
String authorTeamYear = rs.getString("authorTeamYear");
|
398
|
try {
|
399
|
if (! "".equals(CdmUtils.Nz(authorTeamYear).trim())){
|
400
|
Integer publicationYear = Integer.valueOf(authorTeamYear.trim());
|
401
|
zooName.setPublicationYear(publicationYear);
|
402
|
}
|
403
|
} catch (NumberFormatException e) {
|
404
|
logger.warn("authorTeamYear could not be parsed for taxonName: "+ nameId);
|
405
|
}
|
406
|
//original publication year
|
407
|
String basAuthorTeamYear = rs.getString("basAuthorTeamYear");
|
408
|
try {
|
409
|
if (! "".equals(CdmUtils.Nz(basAuthorTeamYear).trim())){
|
410
|
Integer OriginalPublicationYear = Integer.valueOf(basAuthorTeamYear.trim());
|
411
|
zooName.setOriginalPublicationYear(OriginalPublicationYear);
|
412
|
}
|
413
|
} catch (NumberFormatException e) {
|
414
|
logger.warn("basAuthorTeamYear could not be parsed for taxonName: "+ nameId);
|
415
|
}
|
416
|
return success;
|
417
|
}
|
418
|
|
419
|
private boolean makeBotanicalNamePart(ResultSet rs, BotanicalName botanicalName)throws SQLException{
|
420
|
boolean success = true;
|
421
|
String dbAttrName;
|
422
|
String cdmAttrName;
|
423
|
|
424
|
dbAttrName = "HybridFormulaFlag";
|
425
|
cdmAttrName = "isHybridFormula";
|
426
|
success &= ImportHelper.addBooleanValue(rs, botanicalName, dbAttrName, cdmAttrName);
|
427
|
|
428
|
dbAttrName = "MonomHybFlag";
|
429
|
cdmAttrName = "isMonomHybrid";
|
430
|
success &= ImportHelper.addBooleanValue(rs, botanicalName, dbAttrName, cdmAttrName);
|
431
|
|
432
|
dbAttrName = "BinomHybFlag";
|
433
|
cdmAttrName = "isBinomHybrid";
|
434
|
success &= ImportHelper.addBooleanValue(rs, botanicalName, dbAttrName, cdmAttrName);
|
435
|
|
436
|
dbAttrName = "TrinomHybFlag";
|
437
|
cdmAttrName = "isTrinomHybrid";
|
438
|
success &= ImportHelper.addBooleanValue(rs, botanicalName, dbAttrName, cdmAttrName);
|
439
|
|
440
|
try {
|
441
|
String strCultivarGroupName = rs.getString("CultivarGroupName");
|
442
|
String strCultivarName = rs.getString("CultivarName");
|
443
|
if (botanicalName instanceof CultivarPlantName){
|
444
|
CultivarPlantName cultivarName = (CultivarPlantName)botanicalName;
|
445
|
String concatCultivarName = CdmUtils.concat("-", strCultivarName, strCultivarGroupName);
|
446
|
if (CdmUtils.isNotEmpty(strCultivarGroupName) && CdmUtils.isNotEmpty(strCultivarName)){
|
447
|
logger.warn("CDM does not support cultivarGroupName and CultivarName together: " + concatCultivarName);
|
448
|
}
|
449
|
cultivarName.setCultivarName(strCultivarGroupName);
|
450
|
}
|
451
|
} catch (SQLException e) {
|
452
|
throw e;
|
453
|
}
|
454
|
return success;
|
455
|
}
|
456
|
|
457
|
|
458
|
private boolean makeNomenclaturalReference(IImportConfigurator config, TaxonNameBase taxonNameBase,
|
459
|
int nameId, ResultSet rs, ResultSetPartitioner partitioner) throws SQLException{
|
460
|
Map<String, Reference> refMap = partitioner.getObjectMap(BerlinModelReferenceImport.REFERENCE_NAMESPACE);
|
461
|
Map<String, Reference> refDetailMap = partitioner.getObjectMap(BerlinModelRefDetailImport.REFDETAIL_NAMESPACE);
|
462
|
|
463
|
Object nomRefFkObj = rs.getObject("NomRefFk");
|
464
|
Object nomRefDetailFkObj = rs.getObject("NomRefDetailFk");
|
465
|
boolean refDetailPrelim = rs.getBoolean("RefDetailPrelim");
|
466
|
|
467
|
boolean success = true;
|
468
|
//nomenclatural Reference
|
469
|
if (refMap != null){
|
470
|
if (nomRefFkObj != null){
|
471
|
String nomRefFk = String.valueOf(nomRefFkObj);
|
472
|
String nomRefDetailFk = String.valueOf(nomRefDetailFkObj);
|
473
|
//get nomRef
|
474
|
Reference nomReference =
|
475
|
getReferenceFromMaps(refDetailMap, refMap, nomRefDetailFk, nomRefFk);
|
476
|
|
477
|
|
478
|
//setNomRef
|
479
|
if (nomReference == null ){
|
480
|
//TODO
|
481
|
if (! config.isIgnoreNull()){
|
482
|
logger.warn("Nomenclatural reference (nomRefFk = " + nomRefFk + ") for TaxonName (nameId = " + nameId + ")"+
|
483
|
" was not found in reference store. Nomenclatural reference was not set!!");
|
484
|
}
|
485
|
}else{
|
486
|
if (! INomenclaturalReference.class.isAssignableFrom(nomReference.getClass())){
|
487
|
logger.warn("Nomenclatural reference (nomRefFk = " + nomRefFk + ") for TaxonName (nameId = " + nameId + ")"+
|
488
|
" is not assignable from INomenclaturalReference. (Class = " + nomReference.getClass()+ ")");
|
489
|
}
|
490
|
nomReference.setNomenclaturallyRelevant(true);
|
491
|
taxonNameBase.setNomenclaturalReference(nomReference);
|
492
|
}
|
493
|
}
|
494
|
}
|
495
|
return success;
|
496
|
}
|
497
|
|
498
|
private static TeamOrPersonBase getAuthorTeam(Map<String, Team> teamMap, Object teamIdObject, int nameId, BerlinModelImportConfigurator bmiConfig){
|
499
|
if (teamIdObject == null){
|
500
|
return null;
|
501
|
}else {
|
502
|
String teamId = String.valueOf(teamIdObject);
|
503
|
TeamOrPersonBase author = teamMap.get(teamId);
|
504
|
if (author == null){
|
505
|
//TODO
|
506
|
if (!bmiConfig.isIgnoreNull() && ! (teamId.equals(0) && bmiConfig.isIgnore0AuthorTeam()) ){
|
507
|
logger.warn("AuthorTeam (teamId = " + teamId + ") for TaxonName (nameId = " + nameId + ")"+
|
508
|
" was not found in authorTeam store. Relation was not set!!");}
|
509
|
return null;
|
510
|
}else{
|
511
|
return author;
|
512
|
}
|
513
|
}
|
514
|
}
|
515
|
|
516
|
@Override
|
517
|
protected boolean doCheck(BerlinModelImportState state){
|
518
|
IOValidator<BerlinModelImportState> validator = new BerlinModelTaxonNameImportValidator();
|
519
|
return validator.validate(state);
|
520
|
}
|
521
|
|
522
|
@Override
|
523
|
protected boolean isIgnore(BerlinModelImportState state){
|
524
|
return ! state.getConfig().isDoTaxonNames();
|
525
|
}
|
526
|
|
527
|
|
528
|
|
529
|
|
530
|
|
531
|
|
532
|
//FOR FUTURE USE , DONT DELETE
|
533
|
// new CdmStringMapper("nameId", "nameId"),
|
534
|
// new CdmStringMapper("rankFk", "rankFk"),
|
535
|
// new CdmStringMapper("nameCache", "nameCache"),
|
536
|
// new CdmStringMapper("unnamedNamePhrase", "unnamedNamePhrase"),
|
537
|
// new CdmStringMapper("fullNameCache", "fullNameCache"),
|
538
|
// new CdmStringMapper("preliminaryFlag", "preliminaryFlag"),
|
539
|
// new CdmStringMapper("supragenericName", "supragenericName"),
|
540
|
// new CdmStringMapper("genus", "genus"),
|
541
|
// new CdmStringMapper("genusSubdivisionEpi", "genusSubdivisionEpi"),
|
542
|
// new CdmStringMapper("speciesEpi", "speciesEpi"),
|
543
|
// new CdmStringMapper("infraSpeciesEpi", "infraSpeciesEpi"),
|
544
|
// new CdmStringMapper("authorTeamFk", "authorTeamFk"),
|
545
|
// new CdmStringMapper("exAuthorTeamFk", "exAuthorTeamFk"),
|
546
|
// new CdmStringMapper("basAuthorTeamFk", "basAuthorTeamFk"),
|
547
|
// new CdmStringMapper("exBasAuthorTeamFk", "exBasAuthorTeamFk"),
|
548
|
// new CdmStringMapper("hybridFormulaFlag", "hybridFormulaFlag"),
|
549
|
// new CdmStringMapper("monomHybFlag", "monomHybFlag"),
|
550
|
// new CdmStringMapper("binomHybFlag", "binomHybFlag"),
|
551
|
// new CdmStringMapper("trinomHybFlag", "trinomHybFlag"),
|
552
|
// new CdmStringMapper("cultivarGroupName", "cultivarGroupName"),
|
553
|
// new CdmStringMapper("cultivarName", "cultivarName"),
|
554
|
// new CdmStringMapper("nomRefFk", "nomRefFk"),
|
555
|
// new CdmStringMapper("nomRefDetailFk", "nomRefDetailFk"),
|
556
|
// new CdmStringMapper("nameSourceRefFk", "nameSourceRefFk"),
|
557
|
// new CdmStringMapper("source_Acc", "source_Acc"),
|
558
|
// new CdmStringMapper("created_When", "created_When"),
|
559
|
// new CdmStringMapper("created_Who", "created_Who"),
|
560
|
// new CdmStringMapper("notes", "notes"),
|
561
|
// new CdmStringMapper("parsingComments", "parsingComments"),
|
562
|
// new CdmStringMapper("oldNomRefFk", "oldNomRefFk"),
|
563
|
// new CdmStringMapper("oldNomRefDetailFk", "oldNomRefDetailFk"),
|
564
|
// new CdmStringMapper("updated_Who", "updated_Who"),
|
565
|
// new CdmStringMapper("orthoProjection", "orthoProjection"),
|
566
|
|
567
|
|
568
|
}
|