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