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.log4j.Logger;
|
21
|
import org.springframework.stereotype.Component;
|
22
|
|
23
|
import eu.etaxonomy.cdm.common.CdmUtils;
|
24
|
import eu.etaxonomy.cdm.database.update.DatabaseTypeNotSupportedException;
|
25
|
import eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer;
|
26
|
import eu.etaxonomy.cdm.io.berlinModel.in.validation.BerlinModelTaxonNameImportValidator;
|
27
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator;
|
28
|
import eu.etaxonomy.cdm.io.common.IOValidator;
|
29
|
import eu.etaxonomy.cdm.io.common.ImportHelper;
|
30
|
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner;
|
31
|
import eu.etaxonomy.cdm.io.common.Source;
|
32
|
import eu.etaxonomy.cdm.model.agent.Person;
|
33
|
import eu.etaxonomy.cdm.model.agent.Team;
|
34
|
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
|
35
|
import eu.etaxonomy.cdm.model.common.Annotation;
|
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
|
* @since 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 epithet was imported. May be wrong");
|
209
|
success = false;
|
210
|
}
|
211
|
|
212
|
//epithets
|
213
|
if (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 (isNotBlank(sourceAcc)){
|
256
|
ExtensionType sourceAccExtensionType = getExtensionType(state, SOURCE_ACC_UUID, "Source_Acc","Source_Acc","Source_Acc");
|
257
|
Extension.NewInstance(taxonName, sourceAcc, sourceAccExtensionType);
|
258
|
}
|
259
|
}
|
260
|
|
261
|
//created, notes
|
262
|
boolean excludeUpdated = true;
|
263
|
boolean excludeNotes = true;
|
264
|
success &= doIdCreatedUpdatedNotes(state, taxonName, rs, nameId, NAMESPACE, excludeUpdated, excludeNotes);
|
265
|
handleNameNotes(state, taxonName, rs, nameId);
|
266
|
|
267
|
//NonViralName
|
268
|
if (taxonName.isNonViral()){
|
269
|
INonViralName nonViralName = taxonName;
|
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 (taxonName.isZoological()){
|
287
|
IZoologicalName zooName = taxonName;
|
288
|
makeZoologialName(rs, zooName, nameId);
|
289
|
}
|
290
|
//botanicalName
|
291
|
else if (taxonName.isBotanical()){
|
292
|
IBotanicalName botName = taxonName;
|
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
|
taxonName.setTitleCache(fullNameCache, true);
|
303
|
taxonName.setFullTitleCache(taxonName.getFullTitleCache(), true);
|
304
|
if (taxonName.isNonViral()){
|
305
|
INonViralName nvn = taxonName;
|
306
|
nvn.setNameCache(nameCache, true);
|
307
|
nvn.setAuthorshipCache(nvn.getAuthorshipCache(), true);
|
308
|
}
|
309
|
}
|
310
|
namesToSave.add(taxonName);
|
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
|
/**
|
332
|
* @param state
|
333
|
* @param taxonName
|
334
|
* @param rs
|
335
|
* @param nameId
|
336
|
* @throws SQLException
|
337
|
*/
|
338
|
private void handleNameNotes(BerlinModelImportState state, TaxonName taxonName, ResultSet rs, int nameId) throws SQLException {
|
339
|
String notesOrig = rs.getString("notes");
|
340
|
String notes = filterNotes(notesOrig, nameId);
|
341
|
boolean isParentalSpecies = state.getConfig().isEuroMed() && isPostulatedParentalSpeciesNote(notes);
|
342
|
if (isNotBlank(notes) && taxonName != null && !isParentalSpecies ){
|
343
|
String notesString = String.valueOf(notes);
|
344
|
if (notesString.length() > 65530 ){
|
345
|
notesString = notesString.substring(0, 65530) + "...";
|
346
|
logger.warn("Notes string is longer than 65530 and was truncated: " + taxonName);
|
347
|
}
|
348
|
Annotation notesAnnotation = Annotation.NewInstance(notesString, Language.DEFAULT());
|
349
|
//notesAnnotation.setAnnotationType(AnnotationType.EDITORIAL());
|
350
|
//notes.setCommentator(bmiConfig.getCommentator());
|
351
|
taxonName.addAnnotation(notesAnnotation);
|
352
|
}
|
353
|
|
354
|
}
|
355
|
|
356
|
private static final String MCL = "MCL\\s?[0-9]{1,3}(\\-[0-9]{1,4}(\\-[0-9]{1,4}(\\-[0-9]{1,4}(\\-[0-9]{1,3})?)?)?)?";
|
357
|
/**
|
358
|
* @param notes
|
359
|
*/
|
360
|
protected static String filterNotes(String notes, int nameId) {
|
361
|
String result;
|
362
|
if (isBlank(notes)){
|
363
|
result = null;
|
364
|
}else if (notes.matches("Acc:.*")){
|
365
|
if (notes.matches("Acc: .*\\$$") || (notes.matches("Acc: .*"+MCL))){
|
366
|
result = null;
|
367
|
}else if (notes.matches("Acc: .*(\\$|"+MCL+")\\s*\\{.*\\}")){
|
368
|
notes = notes.substring(notes.indexOf("{")+1, notes.length()-1);
|
369
|
result = notes;
|
370
|
}else if (notes.matches("Acc: .*(\\$|"+MCL+")\\s*\\[.*\\]")){
|
371
|
notes = notes.substring(notes.indexOf("[")+1, notes.length()-1);
|
372
|
result = notes;
|
373
|
}else{
|
374
|
logger.warn("Name id: " + nameId + ". Namenote: " + notes);
|
375
|
result = notes;
|
376
|
}
|
377
|
}else if (notes.matches("Syn:.*")){
|
378
|
if (notes.matches("Syn: .*\\$$") || (notes.matches("Syn: .*"+MCL))){
|
379
|
result = null;
|
380
|
}else if (notes.matches("Syn: .*(\\$|"+MCL+")\\s*\\{.*\\}")){
|
381
|
notes = notes.substring(notes.indexOf("{")+1, notes.length()-1);
|
382
|
result = notes;
|
383
|
}else if (notes.matches("Syn: .*(\\$|"+MCL+")\\s*\\[.*\\]")){
|
384
|
notes = notes.substring(notes.indexOf("[")+1, notes.length()-1);
|
385
|
result = notes;
|
386
|
}else{
|
387
|
logger.warn("Name id: " + nameId + ". Namenote: " + notes);
|
388
|
result = notes;
|
389
|
}
|
390
|
}else{
|
391
|
result = notes;
|
392
|
}
|
393
|
return result;
|
394
|
}
|
395
|
|
396
|
|
397
|
/**
|
398
|
* @param nameNotes
|
399
|
* @return
|
400
|
*/
|
401
|
protected static boolean isPostulatedParentalSpeciesNote(String nameNotes) {
|
402
|
if (nameNotes == null){
|
403
|
return false;
|
404
|
}else{
|
405
|
return nameNotes.matches(".*<>.*");
|
406
|
}
|
407
|
}
|
408
|
|
409
|
|
410
|
private Rank handleProlesAndRaceSublusus(BerlinModelImportState state, ResultSet rs, Rank rank) throws SQLException {
|
411
|
Rank result;
|
412
|
String rankAbbrev = rs.getString("RankAbbrev");
|
413
|
// String rankStr = rs.getString("Rank");
|
414
|
if (CdmUtils.nullSafeEqual(rankAbbrev, "prol.") ){
|
415
|
result = Rank.PROLES();
|
416
|
}else if(CdmUtils.nullSafeEqual(rankAbbrev, "race")){
|
417
|
result = Rank.RACE();
|
418
|
}else if(CdmUtils.nullSafeEqual(rankAbbrev, "sublusus")){
|
419
|
result = Rank.SUBLUSUS();
|
420
|
}else{
|
421
|
result = rank;
|
422
|
logger.warn("Unhandled rank: " + rankAbbrev);
|
423
|
}
|
424
|
return result;
|
425
|
}
|
426
|
|
427
|
@Override
|
428
|
public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs, BerlinModelImportState state) {
|
429
|
String nameSpace;
|
430
|
Class<?> cdmClass;
|
431
|
Set<String> idSet;
|
432
|
|
433
|
Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<Object, Map<String, ? extends CdmBase>>();
|
434
|
|
435
|
try{
|
436
|
Set<String> teamIdSet = new HashSet<String>();
|
437
|
Set<String> referenceIdSet = new HashSet<String>();
|
438
|
Set<String> refDetailIdSet = new HashSet<String>();
|
439
|
while (rs.next()){
|
440
|
handleForeignKey(rs, teamIdSet, "AuthorTeamFk");
|
441
|
handleForeignKey(rs, teamIdSet, "ExAuthorTeamFk");
|
442
|
handleForeignKey(rs, teamIdSet, "BasAuthorTeamFk");
|
443
|
handleForeignKey(rs, teamIdSet, "ExBasAuthorTeamFk");
|
444
|
handleForeignKey(rs, referenceIdSet, "nomRefFk");
|
445
|
handleForeignKey(rs, refDetailIdSet, "nomRefDetailFk");
|
446
|
}
|
447
|
|
448
|
//team map
|
449
|
nameSpace = BerlinModelAuthorTeamImport.NAMESPACE;
|
450
|
cdmClass = Team.class;
|
451
|
idSet = teamIdSet;
|
452
|
Map<String, Person> teamMap = (Map<String, Person>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
|
453
|
result.put(nameSpace, teamMap);
|
454
|
|
455
|
//reference map
|
456
|
nameSpace = BerlinModelReferenceImport.REFERENCE_NAMESPACE;
|
457
|
cdmClass = Reference.class;
|
458
|
idSet = referenceIdSet;
|
459
|
Map<String, Reference> referenceMap = (Map<String, Reference>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
|
460
|
result.put(nameSpace, referenceMap);
|
461
|
|
462
|
//refDetail map
|
463
|
nameSpace = BerlinModelRefDetailImport.REFDETAIL_NAMESPACE;
|
464
|
cdmClass = Reference.class;
|
465
|
idSet = refDetailIdSet;
|
466
|
Map<String, Reference> refDetailMap= (Map<String, Reference>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
|
467
|
result.put(nameSpace, refDetailMap);
|
468
|
|
469
|
} catch (SQLException e) {
|
470
|
throw new RuntimeException(e);
|
471
|
}
|
472
|
return result;
|
473
|
}
|
474
|
|
475
|
private boolean makeZoologialName(ResultSet rs, IZoologicalName zooName, int nameId)
|
476
|
throws SQLException{
|
477
|
boolean success = true;
|
478
|
//publicationYear
|
479
|
String authorTeamYear = rs.getString("authorTeamYear");
|
480
|
try {
|
481
|
if (! "".equals(CdmUtils.Nz(authorTeamYear).trim())){
|
482
|
Integer publicationYear = Integer.valueOf(authorTeamYear.trim());
|
483
|
zooName.setPublicationYear(publicationYear);
|
484
|
}
|
485
|
} catch (NumberFormatException e) {
|
486
|
logger.warn("authorTeamYear could not be parsed for taxonName: "+ nameId);
|
487
|
}
|
488
|
//original publication year
|
489
|
String basAuthorTeamYear = rs.getString("basAuthorTeamYear");
|
490
|
try {
|
491
|
if (! "".equals(CdmUtils.Nz(basAuthorTeamYear).trim())){
|
492
|
Integer OriginalPublicationYear = Integer.valueOf(basAuthorTeamYear.trim());
|
493
|
zooName.setOriginalPublicationYear(OriginalPublicationYear);
|
494
|
}
|
495
|
} catch (NumberFormatException e) {
|
496
|
logger.warn("basAuthorTeamYear could not be parsed for taxonName: "+ nameId);
|
497
|
}
|
498
|
return success;
|
499
|
}
|
500
|
|
501
|
private boolean makeBotanicalNamePart(ResultSet rs, IBotanicalName botanicalName)throws SQLException{
|
502
|
boolean success = true;
|
503
|
String dbAttrName;
|
504
|
String cdmAttrName;
|
505
|
|
506
|
dbAttrName = "HybridFormulaFlag";
|
507
|
cdmAttrName = "isHybridFormula";
|
508
|
success &= ImportHelper.addBooleanValue(rs, botanicalName, dbAttrName, cdmAttrName);
|
509
|
|
510
|
dbAttrName = "MonomHybFlag";
|
511
|
cdmAttrName = "isMonomHybrid";
|
512
|
success &= ImportHelper.addBooleanValue(rs, botanicalName, dbAttrName, cdmAttrName);
|
513
|
|
514
|
dbAttrName = "BinomHybFlag";
|
515
|
cdmAttrName = "isBinomHybrid";
|
516
|
success &= ImportHelper.addBooleanValue(rs, botanicalName, dbAttrName, cdmAttrName);
|
517
|
|
518
|
dbAttrName = "TrinomHybFlag";
|
519
|
cdmAttrName = "isTrinomHybrid";
|
520
|
success &= ImportHelper.addBooleanValue(rs, botanicalName, dbAttrName, cdmAttrName);
|
521
|
|
522
|
try {
|
523
|
String strCultivarGroupName = rs.getString("CultivarGroupName");
|
524
|
String strCultivarName = rs.getString("CultivarName");
|
525
|
if (botanicalName.isCultivar()){
|
526
|
ICultivarPlantName cultivarName = (ICultivarPlantName)botanicalName;
|
527
|
String concatCultivarName = CdmUtils.concat("-", strCultivarName, strCultivarGroupName);
|
528
|
if (isNotBlank(strCultivarGroupName) && isNotBlank(strCultivarName)){
|
529
|
logger.warn("CDM does not support cultivarGroupName and CultivarName together: " + concatCultivarName);
|
530
|
}
|
531
|
cultivarName.setCultivarName(strCultivarGroupName);
|
532
|
}
|
533
|
} catch (SQLException e) {
|
534
|
throw e;
|
535
|
}
|
536
|
return success;
|
537
|
}
|
538
|
|
539
|
|
540
|
private boolean makeNomenclaturalReference(IImportConfigurator config, TaxonName taxonNameBase,
|
541
|
int nameId, ResultSet rs, ResultSetPartitioner partitioner) throws SQLException{
|
542
|
Map<String, Reference> refMap = partitioner.getObjectMap(BerlinModelReferenceImport.REFERENCE_NAMESPACE);
|
543
|
Map<String, Reference> refDetailMap = partitioner.getObjectMap(BerlinModelRefDetailImport.REFDETAIL_NAMESPACE);
|
544
|
|
545
|
Object nomRefFkObj = rs.getObject("NomRefFk");
|
546
|
Object nomRefDetailFkObj = rs.getObject("NomRefDetailFk");
|
547
|
boolean refDetailPrelim = rs.getBoolean("RefDetailPrelim");
|
548
|
|
549
|
boolean success = true;
|
550
|
//nomenclatural Reference
|
551
|
if (refMap != null){
|
552
|
if (nomRefFkObj != null){
|
553
|
String nomRefFk = String.valueOf(nomRefFkObj);
|
554
|
String nomRefDetailFk = String.valueOf(nomRefDetailFkObj);
|
555
|
//get nomRef
|
556
|
Reference nomReference =
|
557
|
getReferenceFromMaps(refDetailMap, refMap, nomRefDetailFk, nomRefFk);
|
558
|
|
559
|
|
560
|
//setNomRef
|
561
|
if (nomReference == null ){
|
562
|
//TODO
|
563
|
if (! config.isIgnoreNull()){
|
564
|
logger.warn("Nomenclatural reference (nomRefFk = " + nomRefFk + ") for TaxonName (nameId = " + nameId + ")"+
|
565
|
" was not found in reference store. Nomenclatural reference was not set!!");
|
566
|
}
|
567
|
}else{
|
568
|
if (! INomenclaturalReference.class.isAssignableFrom(nomReference.getClass())){
|
569
|
logger.warn("Nomenclatural reference (nomRefFk = " + nomRefFk + ") for TaxonName (nameId = " + nameId + ")"+
|
570
|
" is not assignable from INomenclaturalReference. (Class = " + nomReference.getClass()+ ")");
|
571
|
}
|
572
|
nomReference.setNomenclaturallyRelevant(true);
|
573
|
taxonNameBase.setNomenclaturalReference(nomReference);
|
574
|
}
|
575
|
}
|
576
|
}
|
577
|
return success;
|
578
|
}
|
579
|
|
580
|
private static TeamOrPersonBase getAuthorTeam(Map<String, Team> teamMap, Object teamIdObject, int nameId, BerlinModelImportConfigurator bmiConfig){
|
581
|
if (teamIdObject == null){
|
582
|
return null;
|
583
|
}else {
|
584
|
String teamId = String.valueOf(teamIdObject);
|
585
|
TeamOrPersonBase author = teamMap.get(teamId);
|
586
|
if (author == null){
|
587
|
//TODO
|
588
|
if (!bmiConfig.isIgnoreNull() && ! (teamId.equals(0) && bmiConfig.isIgnore0AuthorTeam()) ){
|
589
|
logger.warn("AuthorTeam (teamId = " + teamId + ") for TaxonName (nameId = " + nameId + ")"+
|
590
|
" was not found in authorTeam store. Relation was not set!!");}
|
591
|
return null;
|
592
|
}else{
|
593
|
return author;
|
594
|
}
|
595
|
}
|
596
|
}
|
597
|
|
598
|
@Override
|
599
|
protected boolean doCheck(BerlinModelImportState state){
|
600
|
IOValidator<BerlinModelImportState> validator = new BerlinModelTaxonNameImportValidator();
|
601
|
return validator.validate(state);
|
602
|
}
|
603
|
|
604
|
@Override
|
605
|
protected boolean isIgnore(BerlinModelImportState state){
|
606
|
return ! state.getConfig().isDoTaxonNames();
|
607
|
}
|
608
|
|
609
|
|
610
|
|
611
|
|
612
|
|
613
|
|
614
|
//FOR FUTURE USE , DONT DELETE
|
615
|
// new CdmStringMapper("nameId", "nameId"),
|
616
|
// new CdmStringMapper("rankFk", "rankFk"),
|
617
|
// new CdmStringMapper("nameCache", "nameCache"),
|
618
|
// new CdmStringMapper("unnamedNamePhrase", "unnamedNamePhrase"),
|
619
|
// new CdmStringMapper("fullNameCache", "fullNameCache"),
|
620
|
// new CdmStringMapper("preliminaryFlag", "preliminaryFlag"),
|
621
|
// new CdmStringMapper("supragenericName", "supragenericName"),
|
622
|
// new CdmStringMapper("genus", "genus"),
|
623
|
// new CdmStringMapper("genusSubdivisionEpi", "genusSubdivisionEpi"),
|
624
|
// new CdmStringMapper("speciesEpi", "speciesEpi"),
|
625
|
// new CdmStringMapper("infraSpeciesEpi", "infraSpeciesEpi"),
|
626
|
// new CdmStringMapper("authorTeamFk", "authorTeamFk"),
|
627
|
// new CdmStringMapper("exAuthorTeamFk", "exAuthorTeamFk"),
|
628
|
// new CdmStringMapper("basAuthorTeamFk", "basAuthorTeamFk"),
|
629
|
// new CdmStringMapper("exBasAuthorTeamFk", "exBasAuthorTeamFk"),
|
630
|
// new CdmStringMapper("hybridFormulaFlag", "hybridFormulaFlag"),
|
631
|
// new CdmStringMapper("monomHybFlag", "monomHybFlag"),
|
632
|
// new CdmStringMapper("binomHybFlag", "binomHybFlag"),
|
633
|
// new CdmStringMapper("trinomHybFlag", "trinomHybFlag"),
|
634
|
// new CdmStringMapper("cultivarGroupName", "cultivarGroupName"),
|
635
|
// new CdmStringMapper("cultivarName", "cultivarName"),
|
636
|
// new CdmStringMapper("nomRefFk", "nomRefFk"),
|
637
|
// new CdmStringMapper("nomRefDetailFk", "nomRefDetailFk"),
|
638
|
// new CdmStringMapper("nameSourceRefFk", "nameSourceRefFk"),
|
639
|
// new CdmStringMapper("source_Acc", "source_Acc"),
|
640
|
// new CdmStringMapper("created_When", "created_When"),
|
641
|
// new CdmStringMapper("created_Who", "created_Who"),
|
642
|
// new CdmStringMapper("notes", "notes"),
|
643
|
// new CdmStringMapper("parsingComments", "parsingComments"),
|
644
|
// new CdmStringMapper("oldNomRefFk", "oldNomRefFk"),
|
645
|
// new CdmStringMapper("oldNomRefDetailFk", "oldNomRefDetailFk"),
|
646
|
// new CdmStringMapper("updated_Who", "updated_Who"),
|
647
|
// new CdmStringMapper("orthoProjection", "orthoProjection"),
|
648
|
|
649
|
|
650
|
}
|