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
|
package eu.etaxonomy.cdm.io.taxonx;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.HashMap;
|
13
|
import java.util.List;
|
14
|
import java.util.Map;
|
15
|
import java.util.Set;
|
16
|
|
17
|
import org.apache.log4j.Logger;
|
18
|
import org.jdom.Element;
|
19
|
import org.jdom.Namespace;
|
20
|
import org.springframework.stereotype.Component;
|
21
|
import org.springframework.transaction.TransactionStatus;
|
22
|
|
23
|
import eu.etaxonomy.cdm.api.service.ICommonService;
|
24
|
import eu.etaxonomy.cdm.api.service.INameService;
|
25
|
import eu.etaxonomy.cdm.api.service.ITaxonService;
|
26
|
import eu.etaxonomy.cdm.api.service.pager.Pager;
|
27
|
import eu.etaxonomy.cdm.common.CdmUtils;
|
28
|
import eu.etaxonomy.cdm.io.common.CdmIoBase;
|
29
|
import eu.etaxonomy.cdm.io.common.ICdmIO;
|
30
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator;
|
31
|
import eu.etaxonomy.cdm.model.agent.AgentBase;
|
32
|
import eu.etaxonomy.cdm.model.agent.Person;
|
33
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
34
|
import eu.etaxonomy.cdm.model.name.NameTypeDesignationStatus;
|
35
|
import eu.etaxonomy.cdm.model.name.NonViralName;
|
36
|
import eu.etaxonomy.cdm.model.name.Rank;
|
37
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
|
38
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
39
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
40
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
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
|
|
45
|
|
46
|
/**
|
47
|
* @author a.mueller
|
48
|
* @created 29.07.2008
|
49
|
* @version 1.0
|
50
|
*/
|
51
|
@Component
|
52
|
public class TaxonXNomenclatureImport extends CdmIoBase<TaxonXImportState> implements ICdmIO<TaxonXImportState> {
|
53
|
private static final Logger logger = Logger.getLogger(TaxonXNomenclatureImport.class);
|
54
|
|
55
|
@SuppressWarnings("unused")
|
56
|
private static int modCount = 10000;
|
57
|
|
58
|
public TaxonXNomenclatureImport(){
|
59
|
super();
|
60
|
}
|
61
|
|
62
|
@Override
|
63
|
public boolean doCheck(TaxonXImportState state){
|
64
|
boolean result = true;
|
65
|
logger.warn("Checking for Types not yet implemented");
|
66
|
//result &= checkArticlesWithoutJournal(bmiConfig);
|
67
|
//result &= checkPartOfJournal(bmiConfig);
|
68
|
|
69
|
return result;
|
70
|
}
|
71
|
|
72
|
@Override
|
73
|
public void doInvoke(TaxonXImportState state){
|
74
|
logger.info("start make Nomenclature ...");
|
75
|
TransactionStatus tx = startTransaction();
|
76
|
TaxonXImportConfigurator config = state.getConfig();
|
77
|
Element root = config.getSourceRoot();
|
78
|
Namespace nsTaxonx = root.getNamespace();
|
79
|
|
80
|
//for testing only
|
81
|
Taxon taxon = getTaxon(config);
|
82
|
boolean isChanged = false;
|
83
|
|
84
|
Element elTaxonBody = root.getChild("taxonxBody", nsTaxonx);
|
85
|
Element elTreatment = elTaxonBody.getChild("treatment", nsTaxonx);
|
86
|
Element elNomenclature = elTreatment.getChild("nomenclature", nsTaxonx);
|
87
|
|
88
|
//isChanged |= doCollectionEvent(txConfig, elNomenclature, nsTaxonx, taxon);
|
89
|
|
90
|
if (taxon != null && taxon.getName() != null && elNomenclature != null){
|
91
|
isChanged |= doNomenclaturalType(config, elNomenclature, nsTaxonx, taxon.getName());
|
92
|
List<Element> elSynonymyList = new ArrayList<Element>();
|
93
|
elSynonymyList.addAll(elNomenclature.getChildren("synonomy", nsTaxonx));
|
94
|
elSynonymyList.addAll(elNomenclature.getChildren("synonymy", nsTaxonx)); //wrong spelling in TaxonX-Schema
|
95
|
for (Element elSynonymy : elSynonymyList){
|
96
|
String synonymName = elSynonymy.getChildTextTrim("name");
|
97
|
if (elSynonymy.getChild("type", nsTaxonx) != null || elSynonymy.getChild("type_loc", nsTaxonx) != null){
|
98
|
Synonym synonym = getSynonym(config, taxon, synonymName);
|
99
|
if (synonym != null){
|
100
|
isChanged |= doNomenclaturalType(config, elSynonymy, nsTaxonx, synonym.getName());
|
101
|
}
|
102
|
}
|
103
|
}
|
104
|
}
|
105
|
|
106
|
|
107
|
if (isChanged){
|
108
|
getTaxonService().save(taxon);
|
109
|
}
|
110
|
commitTransaction(tx);
|
111
|
return;
|
112
|
}
|
113
|
|
114
|
private Synonym getSynonym(TaxonXImportConfigurator config, Taxon taxon, String synName){
|
115
|
Synonym result = null;
|
116
|
unlazySynonym(config, taxon);
|
117
|
Set<Synonym> synList = taxon.getSynonyms();
|
118
|
for (Synonym syn : synList){
|
119
|
TaxonNameBase<?,?> nameBase = syn.getName();
|
120
|
if (nameBase != null){
|
121
|
if (nameBase.isInstanceOf(NonViralName.class)){
|
122
|
NonViralName<?> nonViralName = nameBase.deproxy(nameBase, NonViralName.class);
|
123
|
if (nonViralName.getNameCache().equals(synName)){
|
124
|
return syn; //only first synonym is returned
|
125
|
}
|
126
|
}
|
127
|
}
|
128
|
}
|
129
|
logger.warn("Synonym ("+synName+ ")not found for taxon " + taxon.getTitleCache() + getBracketSourceName(config));
|
130
|
return result;
|
131
|
}
|
132
|
|
133
|
private Taxon getTaxon(TaxonXImportConfigurator config){
|
134
|
Taxon result;
|
135
|
// result = Taxon.NewInstance(BotanicalName.NewInstance(null), null);
|
136
|
//ICommonService commonService =config.getCdmAppController().getCommonService();
|
137
|
ICommonService commonService = getCommonService();
|
138
|
String originalSourceId = config.getOriginalSourceId();
|
139
|
String namespace = config.getOriginalSourceTaxonNamespace();
|
140
|
result = (Taxon)commonService.getSourcedObjectByIdInSource(Taxon.class, originalSourceId , namespace);
|
141
|
if (result == null){
|
142
|
logger.warn("Taxon (id: " + originalSourceId + ", namespace: " + namespace + ") could not be found");
|
143
|
}
|
144
|
return result;
|
145
|
}
|
146
|
|
147
|
/* (non-Javadoc)
|
148
|
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
|
149
|
*/
|
150
|
@Override
|
151
|
protected boolean isIgnore(TaxonXImportState state){
|
152
|
return ! state.getConfig().isDoTypes();
|
153
|
}
|
154
|
|
155
|
/**
|
156
|
*
|
157
|
* Reads the collection_event tag, creates the according data and stores it.
|
158
|
* TODO under work
|
159
|
* @param elNomenclature
|
160
|
* @param nsTaxonx
|
161
|
* @param taxonBase
|
162
|
* @return
|
163
|
*/
|
164
|
private boolean doNomenclaturalType(TaxonXImportConfigurator config, Element elNomenclature, Namespace nsTaxonx, TaxonNameBase taxonName){
|
165
|
boolean success = true;
|
166
|
if (taxonName == null){
|
167
|
logger.warn("taxonName is null");
|
168
|
return false;
|
169
|
}
|
170
|
if (elNomenclature == null){
|
171
|
logger.warn("elNomenclature is null");
|
172
|
return false;
|
173
|
}
|
174
|
|
175
|
|
176
|
Element elType = elNomenclature.getChild("type", nsTaxonx);
|
177
|
Element elTypeLoc = elNomenclature.getChild("type_loc", nsTaxonx);
|
178
|
|
179
|
if (elType != null || elTypeLoc != null){
|
180
|
unlazyTypeDesignation(config, taxonName);
|
181
|
|
182
|
if (taxonName.isInfraGeneric() || taxonName.isSupraGeneric() || taxonName.isGenus()){
|
183
|
success &= doNameType(elType, taxonName, config);
|
184
|
}else{
|
185
|
success &= doSpecimenType(config, elType, elTypeLoc, taxonName);
|
186
|
|
187
|
|
188
|
}
|
189
|
return success;
|
190
|
}
|
191
|
return false;
|
192
|
}
|
193
|
|
194
|
|
195
|
private boolean doSpecimenType(TaxonXImportConfigurator config, Element elType, Element elTypeLoc, TaxonNameBase taxonName){
|
196
|
Reference citation = null;
|
197
|
String citationMicroReference = null;
|
198
|
String originalNameString = null;
|
199
|
boolean isNotDesignated = true;
|
200
|
boolean addToAllHomotypicNames = true;
|
201
|
|
202
|
SimpleSpecimen simpleSpecimen = SimpleSpecimen.NewInstance();
|
203
|
//elType
|
204
|
if (elType != null){
|
205
|
doElType(elType, simpleSpecimen, config);
|
206
|
}//elType
|
207
|
|
208
|
//typeLoc
|
209
|
HashMap<DerivedUnit, SpecimenTypeDesignationStatus> typeLocMap = null;
|
210
|
if (elTypeLoc != null){
|
211
|
typeLocMap = doElTypeLoc(elTypeLoc, simpleSpecimen, taxonName, config);
|
212
|
}
|
213
|
if (typeLocMap != null && typeLocMap.size() >0){
|
214
|
for (DerivedUnit specimen : typeLocMap.keySet()){
|
215
|
SpecimenTypeDesignationStatus status = typeLocMap.get(specimen);
|
216
|
taxonName.addSpecimenTypeDesignation(specimen, status, citation, citationMicroReference, originalNameString, isNotDesignated, addToAllHomotypicNames);
|
217
|
}
|
218
|
}else{ // no type_loc
|
219
|
SpecimenTypeDesignationStatus status = null;
|
220
|
taxonName.addSpecimenTypeDesignation(simpleSpecimen.getSpecimen(), status, citation, citationMicroReference, originalNameString, isNotDesignated, addToAllHomotypicNames);
|
221
|
}
|
222
|
return true;
|
223
|
}
|
224
|
|
225
|
private boolean doElType(Element elType, SimpleSpecimen simpleSpecimen, TaxonXImportConfigurator config){
|
226
|
//type
|
227
|
String text = elType.getTextNormalize();
|
228
|
if (text.endsWith(";")){
|
229
|
text = text + " ";
|
230
|
}
|
231
|
String[] type = text.split(";");
|
232
|
if (type.length != 3 ){
|
233
|
if (text.equals("")){
|
234
|
logger.info("<nomenclature><type> is empty: " + getBracketSourceName(config));
|
235
|
}else{
|
236
|
logger.warn("<nomenclature><type> is of unsupported format: " + elType.getTextNormalize() + getBracketSourceName(config));
|
237
|
}
|
238
|
simpleSpecimen.setTitleCache(elType.getTextNormalize());
|
239
|
}else{
|
240
|
String strLocality = type[0].trim();
|
241
|
if (! "".equals(strLocality)){
|
242
|
// simpleSpecimen.setLocality(strLocality);
|
243
|
}
|
244
|
|
245
|
String strCollector = type[1].trim();
|
246
|
if (! "".equals(strCollector)){
|
247
|
AgentBase collector = Person.NewTitledInstance(strCollector);
|
248
|
// simpleSpecimen.setCollector(collector);
|
249
|
}
|
250
|
|
251
|
String strCollectorNumber = type[2].trim();
|
252
|
if (! "".equals(strCollectorNumber)){
|
253
|
// simpleSpecimen.setCollectorsNumber(strCollectorNumber);
|
254
|
}
|
255
|
|
256
|
String title = CdmUtils.concat(" ", new String[]{strLocality, strCollector, strCollectorNumber});
|
257
|
simpleSpecimen.setTitleCache(title);
|
258
|
}
|
259
|
return true;
|
260
|
}
|
261
|
|
262
|
private boolean doNameType(Element elType, TaxonNameBase taxonName, TaxonXImportConfigurator config){
|
263
|
boolean success = true;
|
264
|
//type
|
265
|
String text = elType.getTextNormalize();
|
266
|
logger.info("Type: " + text);
|
267
|
if (text.endsWith(";")){
|
268
|
text = text + " ";
|
269
|
}
|
270
|
String[] type = text.split(";");
|
271
|
if (type.length != 3 ){
|
272
|
if (text.equals("")){
|
273
|
logger.info("<nomenclature><type> is empty: " + getBracketSourceName(config));
|
274
|
}else{
|
275
|
logger.warn("<nomenclature><type> is of unsupported format: " + elType.getTextNormalize() + getBracketSourceName(config));
|
276
|
}
|
277
|
success = false;
|
278
|
}else{
|
279
|
String statusStr = type[0].trim();
|
280
|
String taxonNameStr = type[1].trim();
|
281
|
String authorStr = type[2].trim();
|
282
|
NameTypeDesignationStatus status = getNameTypeStatus(statusStr);
|
283
|
/*boolean isLectoType = getIsLectoType(statusStr);*/
|
284
|
|
285
|
// if (status == null){
|
286
|
// logger.warn("<nomenclature><type> is of unsupported format: " + elType.getTextNormalize() + getBracketSourceName(config));
|
287
|
// success = false;
|
288
|
// }else{
|
289
|
// TaxonNameBase childType = getChildrenNameType(taxonName, taxonNameStr, authorStr);
|
290
|
// if (childType != null){
|
291
|
// return doNameTypeDesignation(taxonName, childType, status);
|
292
|
// }else{
|
293
|
String[] epis = taxonNameStr.split(" ");
|
294
|
String uninomial = epis[0].trim();
|
295
|
String specEpi = epis[1].trim();
|
296
|
|
297
|
Pager<TaxonNameBase> nameTypes = getNameService().searchNames(uninomial, null, specEpi, null, Rank.SPECIES(), null, null, null, null);
|
298
|
|
299
|
List<NonViralName> result = new ArrayList<NonViralName>();
|
300
|
for (TaxonNameBase nt : nameTypes.getRecords()){
|
301
|
NonViralName nameType = CdmBase.deproxy(nt, NonViralName.class);
|
302
|
if (compareAuthorship(nameType, authorStr)){
|
303
|
result.add(nameType);
|
304
|
success &= doNameTypeDesignation(taxonName, nameType, status/*, isLectoType*/);
|
305
|
}else{
|
306
|
//TODO ?
|
307
|
}
|
308
|
}
|
309
|
if (result.size() > 1){
|
310
|
logger.warn("More than 1 name matches: " + text);
|
311
|
success = false;
|
312
|
}else if (result.size() == 0){
|
313
|
logger.warn("No name matches: " + text + "(" + config.getSourceNameString() + ")");
|
314
|
success = false;
|
315
|
}
|
316
|
// }
|
317
|
// }
|
318
|
}
|
319
|
return success;
|
320
|
}
|
321
|
|
322
|
|
323
|
private TaxonNameBase getChildrenNameType(TaxonNameBase name, String typeStr, String authorStr){
|
324
|
TaxonNameBase result = null;
|
325
|
Set<TaxonBase> list = name.getTaxonBases();
|
326
|
for (TaxonBase taxonBase : list){
|
327
|
Taxon taxon;
|
328
|
if (taxonBase.isInstanceOf(Taxon.class)){
|
329
|
taxon = CdmBase.deproxy(taxonBase, Taxon.class);
|
330
|
}else{
|
331
|
Synonym syn = CdmBase.deproxy(taxonBase, Synonym.class);
|
332
|
taxon = syn.getAcceptedTaxa().iterator().next();
|
333
|
}
|
334
|
Set<Taxon> children = taxon.getTaxonomicChildren();
|
335
|
for (Taxon child: children){
|
336
|
NonViralName childName = (CdmBase.deproxy(child.getName(), NonViralName.class));
|
337
|
if (childName.getNameCache().equals(typeStr)){
|
338
|
if (compareAuthorship(childName, authorStr)){
|
339
|
return childName;
|
340
|
}
|
341
|
}
|
342
|
}
|
343
|
}
|
344
|
return result;
|
345
|
}
|
346
|
|
347
|
private boolean compareAuthorship(NonViralName typeName, String authorStr){
|
348
|
boolean result = false;
|
349
|
authorStr = authorStr.replaceAll("\\s+and\\s+", "&");
|
350
|
authorStr = authorStr.replaceAll("\\s*", "");
|
351
|
authorStr = authorStr.replaceAll("\\.$", "");
|
352
|
String typeCache = typeName.getAuthorshipCache().replaceAll("\\s*", "");
|
353
|
typeCache = typeCache.replaceAll("\\.$", "");
|
354
|
if (authorStr.equals(typeCache)){
|
355
|
return true;
|
356
|
}else{
|
357
|
logger.info(" Authors different: " + authorStr + " <-> " + typeCache);
|
358
|
}
|
359
|
return result;
|
360
|
}
|
361
|
|
362
|
private NameTypeDesignationStatus getNameTypeStatus(String statusString){
|
363
|
//FIXME some types (not further defined types) do not exist yet
|
364
|
if (true){
|
365
|
return null;
|
366
|
}
|
367
|
if (statusString.trim().equalsIgnoreCase("Type")){
|
368
|
return NameTypeDesignationStatus.ORIGINAL_DESIGNATION();
|
369
|
}else if (statusString.trim().equalsIgnoreCase("Lectotype")){
|
370
|
return NameTypeDesignationStatus.LECTOTYPE();
|
371
|
}else if (statusString.trim().equalsIgnoreCase("Holotype")){
|
372
|
logger.warn("Holotype does not yet exist in CDM");
|
373
|
return NameTypeDesignationStatus.NOT_APPLICABLE();
|
374
|
}else if (statusString.trim().equalsIgnoreCase("paratype")){
|
375
|
logger.warn("paratype does not yet exist in CDM");
|
376
|
return NameTypeDesignationStatus.NOT_APPLICABLE();
|
377
|
}
|
378
|
else{
|
379
|
logger.warn("Status not recognized: " + statusString);
|
380
|
return null;
|
381
|
}
|
382
|
}
|
383
|
|
384
|
private boolean getIsLectoType(String statusString){
|
385
|
//FIXME may be deleted once getNameTypeStatus works finde
|
386
|
if (statusString.trim().equals("Lectotype")){
|
387
|
return true;
|
388
|
}else{
|
389
|
return false;
|
390
|
}
|
391
|
}
|
392
|
|
393
|
|
394
|
private boolean doNameTypeDesignation(TaxonNameBase name, TaxonNameBase type, NameTypeDesignationStatus status/*, boolean isLectoType*/){
|
395
|
Reference citation = null;
|
396
|
String citationMicroReference = null;
|
397
|
String originalNameString = null;
|
398
|
boolean addToAllHomotypicNames = true;
|
399
|
|
400
|
// name.addNameTypeDesignation(type, citation, citationMicroReference, originalNameString, status, addToAllHomotypicNames);
|
401
|
name.addNameTypeDesignation(type, citation, citationMicroReference, originalNameString,status, false, false, /*isLectoType, */false, addToAllHomotypicNames);
|
402
|
return true;
|
403
|
}
|
404
|
|
405
|
/**
|
406
|
* Reads the typeLoc element split in parts for eacht type (holo, iso,...)
|
407
|
* @param elTypeLoc
|
408
|
* @param simpleSpecimen
|
409
|
* @param taxonName
|
410
|
* @param config
|
411
|
* @return
|
412
|
*/
|
413
|
private HashMap<DerivedUnit, SpecimenTypeDesignationStatus> doElTypeLoc(Element elTypeLoc,
|
414
|
SimpleSpecimen simpleSpecimen,
|
415
|
TaxonNameBase<?,?> taxonName,
|
416
|
TaxonXImportConfigurator config){
|
417
|
|
418
|
HashMap<DerivedUnit, SpecimenTypeDesignationStatus> result = new HashMap<DerivedUnit, SpecimenTypeDesignationStatus>();
|
419
|
|
420
|
String typeLocFullString = elTypeLoc.getTextTrim();
|
421
|
typeLocFullString = typeLocFullString.replace("(", "").replace(")", "");
|
422
|
String[] typeLocStatusList = typeLocFullString.split(";");
|
423
|
|
424
|
DerivedUnit originalSpecimen = simpleSpecimen.getSpecimen();
|
425
|
|
426
|
|
427
|
for (String typeLocStatus : typeLocStatusList){
|
428
|
typeLocStatus = typeLocStatus.trim();
|
429
|
int pos = typeLocStatus.indexOf(" ");
|
430
|
if (pos == -1){
|
431
|
logger.warn("Unknown format or empty type_loc : '" +typeLocStatus + "'" + getBracketSourceName(config));
|
432
|
result.put(originalSpecimen, null);
|
433
|
}else{
|
434
|
String statusString = typeLocStatus.substring(0,pos);
|
435
|
SpecimenTypeDesignationStatus status = getStatusByStatusString(statusString.trim(), config);
|
436
|
//TODO
|
437
|
//String[] collectionStrings = typeLocStatus.substring(pos).split(",");
|
438
|
String tmpCollString = typeLocStatus.substring(pos).trim();
|
439
|
//for(String collectionString : collectionStrings){
|
440
|
if (tmpCollString.contains("typ")){
|
441
|
logger.warn("Is this really only a collection string? : " + tmpCollString + getBracketSourceName(config));
|
442
|
}
|
443
|
DerivedUnit specimen;
|
444
|
specimen = (DerivedUnit)originalSpecimen.clone();
|
445
|
String title = originalSpecimen.getTitleCache();
|
446
|
title = title + "(" + tmpCollString + ")";
|
447
|
specimen.setTitleCache(title, true );
|
448
|
result.put(specimen, status);
|
449
|
//}
|
450
|
}
|
451
|
}
|
452
|
|
453
|
return result;
|
454
|
}
|
455
|
|
456
|
/**
|
457
|
*
|
458
|
* Reads the collection_event tag, creates the according data and stores it.
|
459
|
* TODO under work
|
460
|
* @param elNomenclature
|
461
|
* @param nsTaxonx
|
462
|
* @param taxonBase
|
463
|
* @return
|
464
|
*/
|
465
|
private boolean doCollectionEvent(TaxonXImportConfigurator config, Element elNomenclature, Namespace nsTaxonx, TaxonBase taxonBase){
|
466
|
boolean result = false;
|
467
|
if (elNomenclature == null){
|
468
|
return false;
|
469
|
}
|
470
|
Element elCollectionEvent = elNomenclature.getChild("collection_event", nsTaxonx);
|
471
|
if (elCollectionEvent == null){
|
472
|
return result;
|
473
|
}
|
474
|
Element elLocality = elCollectionEvent.getChild("locality", nsTaxonx);
|
475
|
Element elType = elCollectionEvent.getChild("type", nsTaxonx);
|
476
|
Element elTypeLoc = elCollectionEvent.getChild("type_loc", nsTaxonx);
|
477
|
|
478
|
//locality
|
479
|
SimpleSpecimen simpleSpecimen = SimpleSpecimen.NewInstance();
|
480
|
String locality = elLocality.getTextNormalize();
|
481
|
if (! "".equals(locality)){
|
482
|
simpleSpecimen.setLocality(locality);
|
483
|
}
|
484
|
|
485
|
//type
|
486
|
String[] type = elType.getTextNormalize().split(" ");
|
487
|
if (type.length != 2 ){
|
488
|
logger.warn("<collecion_even><type> is of unsupported format: " + elType.getTextNormalize());
|
489
|
}else{
|
490
|
AgentBase collector = Person.NewTitledInstance(type[0]);
|
491
|
simpleSpecimen.setCollector(collector);
|
492
|
|
493
|
String collectorNumber = type[1];
|
494
|
simpleSpecimen.setCollectorsNumber(collectorNumber);
|
495
|
}
|
496
|
|
497
|
//typeLoc
|
498
|
String typeLocFullString = elTypeLoc.getTextTrim();
|
499
|
typeLocFullString = typeLocFullString.replace("(", "").replace(")", "");
|
500
|
String[] typeLocStatusList = typeLocFullString.split(";");
|
501
|
|
502
|
DerivedUnit originalSpecimen = simpleSpecimen.getSpecimen();
|
503
|
|
504
|
//TODO special character ?, �, !
|
505
|
|
506
|
for (String typeLocStatus : typeLocStatusList){
|
507
|
typeLocStatus = typeLocStatus.trim();
|
508
|
int pos = typeLocStatus.indexOf(" ");
|
509
|
if (pos == -1){
|
510
|
logger.warn("Unknown format: " + typeLocStatus);
|
511
|
}else{
|
512
|
String statusString = typeLocStatus.substring(0,pos);
|
513
|
SpecimenTypeDesignationStatus status = getStatusByStatusString(statusString.trim(), config);
|
514
|
String[] collectionStrings = typeLocStatus.substring(pos).split(",");
|
515
|
for(String collectionString : collectionStrings){
|
516
|
if (taxonBase != null){
|
517
|
TaxonNameBase<?, ?> taxonName = taxonBase.getName();
|
518
|
if (taxonName != null){
|
519
|
Reference citation = null;
|
520
|
String citationMicroReference = null;
|
521
|
String originalNameString = null;
|
522
|
boolean isNotDesignated = true;
|
523
|
boolean addToAllHomotypicNames = true;
|
524
|
DerivedUnit specimen = (DerivedUnit)originalSpecimen.clone();
|
525
|
unlazyTypeDesignation(config, taxonName);
|
526
|
taxonName.addSpecimenTypeDesignation(specimen, status, citation, citationMicroReference, originalNameString, isNotDesignated, addToAllHomotypicNames);
|
527
|
result = true;
|
528
|
}
|
529
|
}
|
530
|
}
|
531
|
}
|
532
|
}
|
533
|
return result;
|
534
|
}
|
535
|
|
536
|
|
537
|
private static Map<String, SpecimenTypeDesignationStatus> statusMap;
|
538
|
private static void fillTypeStatusMap(){
|
539
|
statusMap = new HashMap<String, SpecimenTypeDesignationStatus>();
|
540
|
statusMap.put("epitype", SpecimenTypeDesignationStatus.EPITYPE());
|
541
|
statusMap.put("holotype", SpecimenTypeDesignationStatus.HOLOTYPE());
|
542
|
statusMap.put("iconotype", SpecimenTypeDesignationStatus.ICONOTYPE());
|
543
|
statusMap.put("isotype", SpecimenTypeDesignationStatus.ISOTYPE());
|
544
|
statusMap.put("isoneotype", SpecimenTypeDesignationStatus.ISONEOTYPE());
|
545
|
statusMap.put("isosyntype", SpecimenTypeDesignationStatus.ISOSYNTYPE());
|
546
|
statusMap.put("isolectotype", SpecimenTypeDesignationStatus.ISOLECTOTYPE());
|
547
|
statusMap.put("lectotype", SpecimenTypeDesignationStatus.LECTOTYPE());
|
548
|
statusMap.put("syntype", SpecimenTypeDesignationStatus.SYNTYPE());
|
549
|
statusMap.put("paratype", SpecimenTypeDesignationStatus.PARATYPE());
|
550
|
statusMap.put("neotype", SpecimenTypeDesignationStatus.NEOTYPE());
|
551
|
statusMap.put("isoepitype", SpecimenTypeDesignationStatus.ISOEPITYPE());
|
552
|
statusMap.put("originalmaterial", SpecimenTypeDesignationStatus.ORIGINAL_MATERIAL());
|
553
|
statusMap.put("paralectotype", SpecimenTypeDesignationStatus.PARALECTOTYPE());
|
554
|
statusMap.put("paraneotype", SpecimenTypeDesignationStatus.PARANEOTYPE());
|
555
|
statusMap.put("phototype", SpecimenTypeDesignationStatus.PHOTOTYPE());
|
556
|
statusMap.put("secondsteplectotype", SpecimenTypeDesignationStatus.SECOND_STEP_LECTOTYPE());
|
557
|
statusMap.put("secondstepneotype", SpecimenTypeDesignationStatus.SECOND_STEP_NEOTYPE());
|
558
|
statusMap.put("type", null);
|
559
|
}
|
560
|
|
561
|
|
562
|
//TODO move to TypeDesignation class
|
563
|
/**
|
564
|
* Returns the typeDesignationStatus according to a type designation status string
|
565
|
* @param statusString
|
566
|
* @return TypeDesignationStatus
|
567
|
*/
|
568
|
private static SpecimenTypeDesignationStatus getStatusByStatusString(String statusString, TaxonXImportConfigurator config){
|
569
|
SpecimenTypeDesignationStatus result = null;
|
570
|
if (statusString == null || "".equals(statusString.trim())){
|
571
|
return null;
|
572
|
}
|
573
|
statusString = statusString.trim().toLowerCase();
|
574
|
statusString = statusString.replace("typi", "typus");
|
575
|
statusString = statusString.replace("typus", "type");
|
576
|
statusString = statusString.replace("types", "type");
|
577
|
statusString = statusString.toLowerCase();
|
578
|
|
579
|
if (statusMap == null){
|
580
|
fillTypeStatusMap();
|
581
|
}
|
582
|
result = statusMap.get(statusString);
|
583
|
if (statusString.equals("type")){
|
584
|
logger.info("No type designation type" + getBracketSourceName(config));
|
585
|
}else if (result == null){
|
586
|
logger.warn("Unknown type status string: " + statusString + getBracketSourceName(config));
|
587
|
}
|
588
|
return result;
|
589
|
}
|
590
|
|
591
|
|
592
|
/**
|
593
|
* TODO Preliminary to avoid laizy loading errors
|
594
|
*/
|
595
|
private void unlazyTypeDesignation(TaxonXImportConfigurator config, TaxonNameBase taxonNameBase){
|
596
|
TransactionStatus txStatus = startTransaction();
|
597
|
//INameService taxonNameService = config.getCdmAppController().getNameService();
|
598
|
INameService taxonNameService = getNameService();
|
599
|
|
600
|
taxonNameService.save(taxonNameBase);
|
601
|
Set<TaxonNameBase> typifiedNames = taxonNameBase.getHomotypicalGroup().getTypifiedNames();
|
602
|
for(TaxonNameBase typifiedName: typifiedNames){
|
603
|
typifiedName.getTypeDesignations().size();
|
604
|
}
|
605
|
//taxonNameService.saveTaxonName(taxonNameBase);
|
606
|
commitTransaction(txStatus);
|
607
|
}
|
608
|
|
609
|
/**
|
610
|
* TODO Preliminary to avoid laizy loading errors
|
611
|
*/
|
612
|
private void unlazySynonym(IImportConfigurator config, Taxon taxon){
|
613
|
TransactionStatus txStatus = startTransaction();
|
614
|
ITaxonService taxonService = getTaxonService();
|
615
|
taxonService.save(taxon);
|
616
|
Set<Synonym> synonyms = taxon.getSynonyms();
|
617
|
logger.debug(synonyms.size());
|
618
|
//taxonService.saveTaxon(taxon);
|
619
|
commitTransaction(txStatus);
|
620
|
}
|
621
|
|
622
|
private static String getBracketSourceName(TaxonXImportConfigurator config){
|
623
|
return "(" + config.getSourceNameString() + ")";
|
624
|
}
|
625
|
|
626
|
|
627
|
}
|