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