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.redlist.gefaesspflanzen;
|
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
|
|
19
|
import org.apache.log4j.Logger;
|
20
|
import org.springframework.stereotype.Component;
|
21
|
|
22
|
import eu.etaxonomy.cdm.common.CdmUtils;
|
23
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
24
|
import eu.etaxonomy.cdm.io.common.DbImportBase;
|
25
|
import eu.etaxonomy.cdm.io.common.IPartitionedIO;
|
26
|
import eu.etaxonomy.cdm.io.common.ImportHelper;
|
27
|
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner;
|
28
|
import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException;
|
29
|
import eu.etaxonomy.cdm.model.agent.AgentBase;
|
30
|
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
|
31
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
32
|
import eu.etaxonomy.cdm.model.name.BotanicalName;
|
33
|
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
|
34
|
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
|
35
|
import eu.etaxonomy.cdm.model.name.NonViralName;
|
36
|
import eu.etaxonomy.cdm.model.name.Rank;
|
37
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
38
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
39
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
40
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
41
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
|
42
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
|
43
|
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
|
44
|
|
45
|
/**
|
46
|
*
|
47
|
* @author pplitzner
|
48
|
* @date Mar 1, 2016
|
49
|
*
|
50
|
*/
|
51
|
|
52
|
@Component
|
53
|
@SuppressWarnings("serial")
|
54
|
public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefaesspflanzenImportState, RedListGefaesspflanzenImportConfigurator> {
|
55
|
|
56
|
private static final Logger logger = Logger.getLogger(RedListGefaesspflanzenImportNames.class);
|
57
|
|
58
|
private static final String tableName = "Rote Liste Gefäßpflanzen";
|
59
|
|
60
|
private static final String pluralString = "names";
|
61
|
|
62
|
public RedListGefaesspflanzenImportNames() {
|
63
|
super(tableName, pluralString);
|
64
|
}
|
65
|
|
66
|
@Override
|
67
|
protected String getIdQuery(RedListGefaesspflanzenImportState state) {
|
68
|
return "SELECT NAMNR "
|
69
|
+ "FROM V_TAXATLAS_D20_EXPORT t "
|
70
|
+ " ORDER BY NAMNR";
|
71
|
}
|
72
|
|
73
|
@Override
|
74
|
protected String getRecordQuery(RedListGefaesspflanzenImportConfigurator config) {
|
75
|
String result = " SELECT * "
|
76
|
+ " FROM V_TAXATLAS_D20_EXPORT t "
|
77
|
+ " WHERE t.NAMNR IN (@IDSET)";
|
78
|
result = result.replace("@IDSET", IPartitionedIO.ID_LIST_TOKEN);
|
79
|
return result;
|
80
|
}
|
81
|
|
82
|
@Override
|
83
|
protected void doInvoke(RedListGefaesspflanzenImportState state) {
|
84
|
super.doInvoke(state);
|
85
|
}
|
86
|
|
87
|
|
88
|
@Override
|
89
|
public boolean doPartition(ResultSetPartitioner partitioner, RedListGefaesspflanzenImportState state) {
|
90
|
ResultSet rs = partitioner.getResultSet();
|
91
|
Set<TaxonNameBase> namesToSave = new HashSet<TaxonNameBase>();
|
92
|
Set<TaxonBase> taxaToSave = new HashSet<TaxonBase>();
|
93
|
try {
|
94
|
while (rs.next()){
|
95
|
makeSingleNameAndTaxon(state, rs, namesToSave, taxaToSave);
|
96
|
|
97
|
}
|
98
|
} catch (SQLException e) {
|
99
|
e.printStackTrace();
|
100
|
}
|
101
|
|
102
|
getNameService().saveOrUpdate(namesToSave);
|
103
|
getTaxonService().saveOrUpdate(taxaToSave);
|
104
|
return true;
|
105
|
}
|
106
|
|
107
|
private void makeSingleNameAndTaxon(RedListGefaesspflanzenImportState state, ResultSet rs, Set<TaxonNameBase> namesToSave, Set<TaxonBase> taxaToSave)
|
108
|
throws SQLException {
|
109
|
//cell values
|
110
|
long id = rs.getLong(RedListUtil.NAMNR);
|
111
|
String taxNameString = rs.getString(RedListUtil.TAXNAME);
|
112
|
String gueltString = rs.getString(RedListUtil.GUELT);
|
113
|
String rangString = rs.getString(RedListUtil.RANG);
|
114
|
String ep1String = rs.getString(RedListUtil.EPI1);
|
115
|
String ep2String = rs.getString(RedListUtil.EPI2);
|
116
|
String ep3String = rs.getString(RedListUtil.EPI3);
|
117
|
String nomZusatzString = rs.getString(RedListUtil.NOM_ZUSATZ);
|
118
|
String taxZusatzString = rs.getString(RedListUtil.TAX_ZUSATZ);
|
119
|
String zusatzString = rs.getString(RedListUtil.ZUSATZ);
|
120
|
String nonString = rs.getString(RedListUtil.NON);
|
121
|
String sensuString = rs.getString(RedListUtil.SENSU);
|
122
|
String authorKombString = rs.getString(RedListUtil.AUTOR_KOMB);
|
123
|
String authorBasiString = rs.getString(RedListUtil.AUTOR_BASI);
|
124
|
String hybString = rs.getString(RedListUtil.HYB);
|
125
|
String clTaxonString = rs.getString(RedListUtil.CL_TAXON);
|
126
|
String relationE = rs.getString(RedListUtil.E);
|
127
|
String relationW = rs.getString(RedListUtil.W);
|
128
|
String relationK = rs.getString(RedListUtil.K);
|
129
|
String relationAW = rs.getString(RedListUtil.AW);
|
130
|
String relationAO = rs.getString(RedListUtil.AO);
|
131
|
String relationR = rs.getString(RedListUtil.R);
|
132
|
String relationO = rs.getString(RedListUtil.O);
|
133
|
String relationS = rs.getString(RedListUtil.S);
|
134
|
|
135
|
//---NAME---
|
136
|
NonViralName name = importName(state, id, taxNameString, rangString, ep1String, ep2String, ep3String,
|
137
|
nomZusatzString, hybString, namesToSave);
|
138
|
|
139
|
|
140
|
//--- AUTHORS ---
|
141
|
importAuthors(state, rs, id, nomZusatzString, taxZusatzString, zusatzString, authorKombString,
|
142
|
authorBasiString, name);
|
143
|
|
144
|
//---TAXON---
|
145
|
TaxonBase taxonBase = importTaxon(id, taxNameString, gueltString, authorBasiString, hybString, name);
|
146
|
if(taxonBase==null){
|
147
|
RedListUtil.logMessage(id, "Taxon for name "+name+" could not be created.", logger);
|
148
|
return;
|
149
|
}
|
150
|
taxonBase.setSec(state.getConfig().getSourceReference());
|
151
|
|
152
|
//---CONCEPT RELATIONSHIPS---
|
153
|
/*check if taxon/synonym also exists in other classification
|
154
|
* 1. create new taxon with the same name (in that classification)
|
155
|
* 2. create concept relationship between both
|
156
|
*/
|
157
|
//checklist
|
158
|
if(CdmUtils.isNotBlank(clTaxonString) && !clTaxonString.trim().equals("-")){
|
159
|
cloneTaxon(taxonBase, name, TaxonRelationshipType.CONGRUENT_TO(), taxaToSave, id, RedListUtil.TAXON_CHECKLISTE_NAMESPACE, false, true, state);
|
160
|
}
|
161
|
//E, W, K, AW, AO, R, O, S
|
162
|
addConceptRelation(relationE, RedListUtil.CLASSIFICATION_NAMESPACE_E, taxonBase, name, taxaToSave, id, state);
|
163
|
addConceptRelation(relationW, RedListUtil.CLASSIFICATION_NAMESPACE_W, taxonBase, name, taxaToSave, id, state);
|
164
|
addConceptRelation(relationK, RedListUtil.CLASSIFICATION_NAMESPACE_K, taxonBase, name, taxaToSave, id, state);
|
165
|
addConceptRelation(relationAW, RedListUtil.CLASSIFICATION_NAMESPACE_AW, taxonBase, name, taxaToSave, id, state);
|
166
|
addConceptRelation(relationAO, RedListUtil.CLASSIFICATION_NAMESPACE_AO, taxonBase, name, taxaToSave, id, state);
|
167
|
addConceptRelation(relationR, RedListUtil.CLASSIFICATION_NAMESPACE_R, taxonBase, name, taxaToSave, id, state);
|
168
|
addConceptRelation(relationO, RedListUtil.CLASSIFICATION_NAMESPACE_O, taxonBase, name, taxaToSave, id, state);
|
169
|
addConceptRelation(relationS, RedListUtil.CLASSIFICATION_NAMESPACE_S, taxonBase, name, taxaToSave, id, state);
|
170
|
|
171
|
//NOTE: the source has to be added after cloning or otherwise the clone would also get the source
|
172
|
ImportHelper.setOriginalSource(taxonBase, state.getTransactionalSourceReference(), id, RedListUtil.TAXON_GESAMTLISTE_NAMESPACE);
|
173
|
taxaToSave.add(taxonBase);
|
174
|
}
|
175
|
|
176
|
private void addConceptRelation(String relationString, String classificationNamespace, TaxonBase taxonBase, TaxonNameBase name, Set<TaxonBase> taxaToSave, long id, RedListGefaesspflanzenImportState state){
|
177
|
if(CdmUtils.isNotBlank(relationString) && !relationString.equals(".")){
|
178
|
String substring = relationString.substring(relationString.length()-1, relationString.length());
|
179
|
TaxonRelationshipType taxonRelationshipTypeByKey = new RedListGefaesspflanzenTransformer().getTaxonRelationshipTypeByKey(substring);
|
180
|
if(taxonRelationshipTypeByKey==null){
|
181
|
RedListUtil.logMessage(id, "Could not interpret relationship "+relationString+" for taxon "+taxonBase.generateTitle(), logger);
|
182
|
}
|
183
|
//there is no type "included in" so we have to reverse the direction
|
184
|
if(substring.equals("<")){
|
185
|
cloneTaxon(taxonBase, name, taxonRelationshipTypeByKey, taxaToSave, id, classificationNamespace, true, false, state);
|
186
|
}
|
187
|
else{
|
188
|
cloneTaxon(taxonBase, name, taxonRelationshipTypeByKey, taxaToSave, id, classificationNamespace, false, false, state);
|
189
|
}
|
190
|
}
|
191
|
}
|
192
|
|
193
|
/**
|
194
|
* <b>NOTE:</b> the {@link TaxonRelationshipType} passed as parameter is
|
195
|
* directed <b>from the clone</b> to the taxon.<br>
|
196
|
* This can be changed with parameter <i>reverseRelation</i>
|
197
|
*/
|
198
|
private void cloneTaxon(TaxonBase taxonBase, TaxonNameBase name, TaxonRelationshipType relationFromCloneToTaxon, Set<TaxonBase> taxaToSave, long id, String sourceNameSpace, boolean reverseRelation, boolean doubtful, RedListGefaesspflanzenImportState state){
|
199
|
TaxonBase clone = (TaxonBase) taxonBase.clone();
|
200
|
clone.setName(name);
|
201
|
if(taxonBase.isInstanceOf(Taxon.class)){
|
202
|
TaxonRelationship taxonRelation;
|
203
|
if(reverseRelation){
|
204
|
taxonRelation = ((Taxon) taxonBase).addTaxonRelation((Taxon) clone, relationFromCloneToTaxon, null, null);
|
205
|
}
|
206
|
else {
|
207
|
taxonRelation = ((Taxon) clone).addTaxonRelation((Taxon) taxonBase, relationFromCloneToTaxon, null, null);
|
208
|
}
|
209
|
taxonRelation.setDoubtful(doubtful);
|
210
|
}
|
211
|
ImportHelper.setOriginalSource(clone, state.getTransactionalSourceReference(), id, sourceNameSpace);
|
212
|
taxaToSave.add(clone);
|
213
|
}
|
214
|
|
215
|
private TaxonBase importTaxon(long id, String taxNameString, String gueltString, String authorBasiString,
|
216
|
String hybString, NonViralName name) {
|
217
|
TaxonBase taxonBase = null;
|
218
|
if(authorBasiString.trim().contains(RedListUtil.AUCT)){
|
219
|
taxonBase = Taxon.NewInstance(name, null);
|
220
|
taxonBase.setAppendedPhrase(RedListUtil.AUCT);
|
221
|
}
|
222
|
else if(gueltString.equals(RedListUtil.GUELT_ACCEPTED_TAXON)){
|
223
|
taxonBase = Taxon.NewInstance(name, null);
|
224
|
}
|
225
|
else if(gueltString.equals(RedListUtil.GUELT_SYNONYM) || gueltString.equals(RedListUtil.GUELT_BASIONYM)){
|
226
|
taxonBase = Synonym.NewInstance(name, null);
|
227
|
}
|
228
|
else{
|
229
|
return null;
|
230
|
}
|
231
|
|
232
|
//check taxon name consistency
|
233
|
checkTaxonNameConsistency(id, taxNameString, hybString, taxonBase);
|
234
|
return taxonBase;
|
235
|
}
|
236
|
|
237
|
private void importAuthors(RedListGefaesspflanzenImportState state, ResultSet rs, long id, String nomZusatzString,
|
238
|
String taxZusatzString, String zusatzString, String authorKombString, String authorBasiString,
|
239
|
NonViralName name) throws SQLException {
|
240
|
//combination author
|
241
|
if(authorKombString.contains(RedListUtil.EX)){
|
242
|
//TODO: what happens with multiple ex authors??
|
243
|
String[] kombSplit = authorKombString.split(RedListUtil.EX);
|
244
|
if(kombSplit.length!=2){
|
245
|
RedListUtil.logMessage(id, "Multiple ex combination authors found", logger);
|
246
|
}
|
247
|
for (int i = 0; i < kombSplit.length; i++) {
|
248
|
if(i==0){
|
249
|
//first author is ex author
|
250
|
TeamOrPersonBase authorKomb = (TeamOrPersonBase) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, kombSplit[i]);
|
251
|
name.setExCombinationAuthorship(authorKomb);
|
252
|
}
|
253
|
else{
|
254
|
TeamOrPersonBase authorKomb = (TeamOrPersonBase) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, kombSplit[i]);
|
255
|
name.setCombinationAuthorship(authorKomb);
|
256
|
}
|
257
|
}
|
258
|
}
|
259
|
else if(authorKombString.trim().contains(RedListUtil.AUCT)){
|
260
|
RedListUtil.logMessage(id, "AUCT information in "+RedListUtil.AUTOR_KOMB+" column", logger);
|
261
|
}
|
262
|
else if(CdmUtils.isNotBlank(authorKombString)){
|
263
|
TeamOrPersonBase authorKomb = (TeamOrPersonBase) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, authorKombString);
|
264
|
name.setCombinationAuthorship(authorKomb);
|
265
|
}
|
266
|
//basionym author
|
267
|
if(authorBasiString.contains(RedListUtil.EX)){
|
268
|
String[] basiSplit = authorBasiString.split(RedListUtil.EX);
|
269
|
for (int i = 0; i < basiSplit.length; i++) {
|
270
|
if(basiSplit.length!=2){
|
271
|
RedListUtil.logMessage(id, "Multiple ex basionymn authors found", logger);
|
272
|
}
|
273
|
if(i==0){
|
274
|
TeamOrPersonBase authorBasi= (TeamOrPersonBase) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, basiSplit[i]);
|
275
|
if(CdmUtils.isBlank(authorKombString)){
|
276
|
name.setExCombinationAuthorship(authorBasi);
|
277
|
}
|
278
|
else{
|
279
|
name.setExBasionymAuthorship(authorBasi);
|
280
|
}
|
281
|
}
|
282
|
else{
|
283
|
TeamOrPersonBase authorBasi= (TeamOrPersonBase) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, basiSplit[i]);
|
284
|
if(CdmUtils.isBlank(authorKombString)){
|
285
|
name.setCombinationAuthorship(authorBasi);
|
286
|
}
|
287
|
else{
|
288
|
name.setBasionymAuthorship(authorBasi);
|
289
|
}
|
290
|
}
|
291
|
}
|
292
|
}
|
293
|
else if(CdmUtils.isNotBlank(authorBasiString)){
|
294
|
//this seems to be a convention in the source database: When there is only a single author then only the "AUTOR_BASI" column is used
|
295
|
TeamOrPersonBase authorBasi= (TeamOrPersonBase) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, authorBasiString);
|
296
|
if(CdmUtils.isBlank(authorKombString)){
|
297
|
name.setCombinationAuthorship(authorBasi);
|
298
|
}
|
299
|
else{
|
300
|
name.setBasionymAuthorship(authorBasi);
|
301
|
}
|
302
|
}
|
303
|
|
304
|
//check authorship consistency
|
305
|
String authorString = rs.getString(RedListUtil.AUTOR);
|
306
|
String authorshipCache = name.getAuthorshipCache();
|
307
|
checkAuthorShipConsistency(id, nomZusatzString, taxZusatzString, zusatzString, authorString, authorshipCache);
|
308
|
}
|
309
|
|
310
|
private NonViralName importName(RedListGefaesspflanzenImportState state, long id, String taxNameString,
|
311
|
String rangString, String ep1String, String ep2String, String ep3String, String nomZusatzString,
|
312
|
String hybString, Set<TaxonNameBase> namesToSave) {
|
313
|
if(CdmUtils.isBlank(taxNameString) && CdmUtils.isBlank(ep1String)){
|
314
|
RedListUtil.logMessage(id, "No name found!", logger);
|
315
|
}
|
316
|
|
317
|
Rank rank = makeRank(id, state, rangString);
|
318
|
NonViralName name = BotanicalName.NewInstance(rank);
|
319
|
|
320
|
//ep1 should always be present
|
321
|
if(CdmUtils.isBlank(ep1String)){
|
322
|
RedListUtil.logMessage(id, RedListUtil.EPI1+" is empty!", logger);
|
323
|
}
|
324
|
name.setGenusOrUninomial(ep1String);
|
325
|
if(CdmUtils.isNotBlank(ep2String)){
|
326
|
name.setSpecificEpithet(ep2String);
|
327
|
}
|
328
|
if(CdmUtils.isNotBlank(ep3String)){
|
329
|
name.setInfraSpecificEpithet(ep3String);
|
330
|
}
|
331
|
//nomenclatural status
|
332
|
if(CdmUtils.isNotBlank(nomZusatzString)){
|
333
|
NomenclaturalStatusType status = makeNomenclaturalStatus(id, state, nomZusatzString);
|
334
|
if(status!=null){
|
335
|
name.addStatus(NomenclaturalStatus.NewInstance(status));
|
336
|
}
|
337
|
}
|
338
|
//hybrid
|
339
|
if(CdmUtils.isNotBlank(hybString)){
|
340
|
if(hybString.equals(RedListUtil.HYB_X)){
|
341
|
name.setBinomHybrid(true);
|
342
|
}
|
343
|
else if(hybString.equals(RedListUtil.HYB_XF)){
|
344
|
name.setHybridFormula(true);
|
345
|
if(ep1String.contains(RedListUtil.HYB_SIGN)){
|
346
|
RedListUtil.logMessage(id, "EPI1 has hybrid signs but with flag: "+RedListUtil.HYB_XF, logger);
|
347
|
}
|
348
|
else if(ep2String.contains(RedListUtil.HYB_SIGN)){
|
349
|
String[] split = ep2String.split(RedListUtil.HYB_SIGN);
|
350
|
if(split.length!=2){
|
351
|
RedListUtil.logMessage(id, "Multiple hybrid signs found in "+ep2String, logger);
|
352
|
}
|
353
|
String hybridFormula1 = ep1String+" "+split[0].trim();
|
354
|
String hybridFormula2 = ep1String+" "+split[1].trim();
|
355
|
if(CdmUtils.isNotBlank(ep3String)){
|
356
|
hybridFormula1 += " "+ep3String;
|
357
|
hybridFormula2 += " "+ep3String;
|
358
|
}
|
359
|
String fullFormula = hybridFormula1+" "+RedListUtil.HYB_SIGN+" "+hybridFormula2;
|
360
|
name = NonViralNameParserImpl.NewInstance().parseFullName(fullFormula);
|
361
|
}
|
362
|
else if(ep3String.contains(RedListUtil.HYB_SIGN)){
|
363
|
String[] split = ep3String.split(RedListUtil.HYB_SIGN);
|
364
|
if(split.length!=2){
|
365
|
RedListUtil.logMessage(id, "Multiple hybrid signs found in "+ep3String, logger);
|
366
|
}
|
367
|
String hybridFormula1 = ep1String+" "+ep2String+" "+split[0];
|
368
|
String hybridFormula2 = ep1String+" "+ep2String+" "+split[1];
|
369
|
String fullFormula = hybridFormula1+" "+RedListUtil.HYB_SIGN+" "+hybridFormula2;
|
370
|
name = NonViralNameParserImpl.NewInstance().parseFullName(fullFormula);
|
371
|
}
|
372
|
}
|
373
|
}
|
374
|
//add source
|
375
|
ImportHelper.setOriginalSource(name, state.getTransactionalSourceReference(), id, RedListUtil.NAME_NAMESPACE);
|
376
|
|
377
|
namesToSave.add(name);
|
378
|
return name;
|
379
|
}
|
380
|
|
381
|
private void checkAuthorShipConsistency(long id, String nomZusatzString, String taxZusatzString,
|
382
|
String zusatzString, String authorString, String authorshipCache) {
|
383
|
if(CdmUtils.isNotBlank(zusatzString)){
|
384
|
authorString = authorString.replace(", "+zusatzString, "");
|
385
|
}
|
386
|
if(CdmUtils.isNotBlank(nomZusatzString)){
|
387
|
authorString = authorString.replace(", "+nomZusatzString, "");
|
388
|
}
|
389
|
if(CdmUtils.isNotBlank(taxZusatzString)){
|
390
|
authorString = authorString.replace(", "+taxZusatzString, "");
|
391
|
}
|
392
|
if(authorString.equals(RedListUtil.AUCT)){
|
393
|
authorString = "";
|
394
|
}
|
395
|
if(!authorString.equals(authorshipCache)){
|
396
|
RedListUtil.logMessage(id, "Authorship inconsistent! name.authorhshipCache <-> Column "+RedListUtil.AUTOR+": "+authorshipCache+" <-> "+authorString, logger);
|
397
|
}
|
398
|
}
|
399
|
|
400
|
private void checkTaxonNameConsistency(long id, String taxNameString, String hybString, TaxonBase taxonBase) {
|
401
|
if(hybString.equals(RedListUtil.HYB_XF)){
|
402
|
if(HibernateProxyHelper.deproxy(taxonBase.getName(),NonViralName.class).getHybridChildRelations().isEmpty()){
|
403
|
RedListUtil.logMessage(id, "Hybrid name but no hybrid child relations", logger);
|
404
|
return;
|
405
|
}
|
406
|
return;
|
407
|
}
|
408
|
|
409
|
|
410
|
String nameCache = HibernateProxyHelper.deproxy(taxonBase.getName(), NonViralName.class).getNameCache().trim();
|
411
|
|
412
|
if(taxNameString.endsWith("agg.")){
|
413
|
taxNameString = taxNameString.replace("agg.", "aggr.");
|
414
|
}
|
415
|
if(hybString.equals(RedListUtil.HYB_X)){
|
416
|
taxNameString = taxNameString.replace(RedListUtil.HYB_SIGN+" ", RedListUtil.HYB_SIGN);//hybrid sign has no space after it in titleCache for binomial hybrids
|
417
|
}
|
418
|
if(taxNameString.endsWith("- Gruppe")){
|
419
|
taxNameString.replaceAll("- Gruppe", "species group");
|
420
|
}
|
421
|
if(taxNameString.endsWith("- group")){
|
422
|
taxNameString.replaceAll("- group", "species group");
|
423
|
}
|
424
|
if(!taxNameString.trim().equals(nameCache)){
|
425
|
RedListUtil.logMessage(id, "Taxon name inconsistent! taxon.titleCache <-> Column "+RedListUtil.TAXNAME+": "+nameCache+" <-> "+taxNameString, logger);
|
426
|
}
|
427
|
}
|
428
|
|
429
|
private Rank makeRank(long id, RedListGefaesspflanzenImportState state, String rankStr) {
|
430
|
Rank rank = null;
|
431
|
try {
|
432
|
rank = state.getTransformer().getRankByKey(rankStr);
|
433
|
} catch (UndefinedTransformerMethodException e) {
|
434
|
e.printStackTrace();
|
435
|
}
|
436
|
if(rank==null){
|
437
|
RedListUtil.logMessage(id, rankStr+" could not be associated to a known rank.", logger);
|
438
|
}
|
439
|
return rank;
|
440
|
}
|
441
|
|
442
|
private NomenclaturalStatusType makeNomenclaturalStatus(long id, RedListGefaesspflanzenImportState state, String nomZusatzString) {
|
443
|
NomenclaturalStatusType status = null;
|
444
|
try {
|
445
|
status = state.getTransformer().getNomenclaturalStatusByKey(nomZusatzString);
|
446
|
} catch (UndefinedTransformerMethodException e) {
|
447
|
e.printStackTrace();
|
448
|
}
|
449
|
if(status==null){
|
450
|
RedListUtil.logMessage(id, nomZusatzString+" could not be associated to a known nomenclatural status.", logger);
|
451
|
}
|
452
|
return status;
|
453
|
}
|
454
|
|
455
|
|
456
|
|
457
|
@Override
|
458
|
public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs,
|
459
|
RedListGefaesspflanzenImportState state) {
|
460
|
Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<>();
|
461
|
Map<String, AgentBase<?>> authorMap = new HashMap<String, AgentBase<?>>();
|
462
|
|
463
|
try {
|
464
|
while (rs.next()){
|
465
|
String authorKombString = rs.getString(RedListUtil.AUTOR_KOMB);
|
466
|
|
467
|
if(authorKombString.contains(RedListUtil.EX)){
|
468
|
String[] kombSplit = authorKombString.split(RedListUtil.EX);
|
469
|
for (int i = 0; i < kombSplit.length; i++) {
|
470
|
if(!authorMap.containsKey(kombSplit[i])){
|
471
|
authorMap.put(kombSplit[i], getAgentService().load(state.getAuthorMap().get(kombSplit[i])));
|
472
|
}
|
473
|
}
|
474
|
}
|
475
|
else if(CdmUtils.isNotBlank(authorKombString) && !authorMap.containsKey(authorKombString)){
|
476
|
authorMap.put(authorKombString, getAgentService().load(state.getAuthorMap().get(authorKombString)));
|
477
|
}
|
478
|
|
479
|
String authorBasiString = rs.getString(RedListUtil.AUTOR_BASI);
|
480
|
//basionym author
|
481
|
if(authorBasiString.contains(RedListUtil.EX)){
|
482
|
String[] basiSplit = authorBasiString.split(RedListUtil.EX);
|
483
|
for (int i = 0; i < basiSplit.length; i++) {
|
484
|
if(!authorMap.containsKey(basiSplit[i])){
|
485
|
authorMap.put(basiSplit[i], getAgentService().load(state.getAuthorMap().get(basiSplit[i])));
|
486
|
}
|
487
|
}
|
488
|
}
|
489
|
else if(CdmUtils.isNotBlank(authorBasiString) && !authorMap.containsKey(authorBasiString)){
|
490
|
authorMap.put(authorBasiString, getAgentService().load(state.getAuthorMap().get(authorBasiString)));
|
491
|
}
|
492
|
}
|
493
|
} catch (SQLException e) {
|
494
|
e.printStackTrace();
|
495
|
}
|
496
|
result.put(RedListUtil.AUTHOR_NAMESPACE, authorMap);
|
497
|
|
498
|
return result;
|
499
|
}
|
500
|
|
501
|
@Override
|
502
|
protected boolean doCheck(RedListGefaesspflanzenImportState state) {
|
503
|
return false;
|
504
|
}
|
505
|
|
506
|
@Override
|
507
|
protected boolean isIgnore(RedListGefaesspflanzenImportState state) {
|
508
|
return false;
|
509
|
}
|
510
|
|
511
|
}
|