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