Project

General

Profile

Download (22.7 KB) Statistics
| Branch: | Tag: | Revision:
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.CdmImportBase;
29
import eu.etaxonomy.cdm.io.common.IImportConfigurator;
30
import eu.etaxonomy.cdm.model.agent.AgentBase;
31
import eu.etaxonomy.cdm.model.agent.Person;
32
import eu.etaxonomy.cdm.model.name.INonViralName;
33
import eu.etaxonomy.cdm.model.name.NameTypeDesignationStatus;
34
import eu.etaxonomy.cdm.model.name.Rank;
35
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
36
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
37
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
38
import eu.etaxonomy.cdm.model.reference.Reference;
39
import eu.etaxonomy.cdm.model.taxon.Synonym;
40
import eu.etaxonomy.cdm.model.taxon.Taxon;
41
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
42

    
43

    
44
/**
45
 * @author a.mueller
46
 * @created 29.07.2008
47
 */
48
@Component
49
public class TaxonXNomenclatureImport
50
        extends CdmImportBase<TaxonXImportConfigurator, TaxonXImportState>  {
51

    
52
    private static final long serialVersionUID = 796115831082828758L;
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.isNonViral()){
122
					if (nameBase.getNameCache().equals(synName)){
123
						return syn;  //only first synonym is returned
124
					}
125
				}
126
			}
127
		}
128
		logger.warn("Synonym ("+synName+ ")not found for taxon " + taxon.getTitleCache() + getBracketSourceName(config));
129
		return result;
130
	}
131

    
132
	private Taxon getTaxon(TaxonXImportConfigurator config){
133
		Taxon result;
134
//		result =  Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(null), null);
135
		//ICommonService commonService =config.getCdmAppController().getCommonService();
136
		ICommonService commonService = getCommonService();
137
		String originalSourceId = config.getOriginalSourceId();
138
		String namespace = config.getOriginalSourceTaxonNamespace();
139
		result = (Taxon)commonService.getSourcedObjectByIdInSource(Taxon.class, originalSourceId , namespace);
140
		if (result == null){
141
			logger.warn("Taxon (id: " + originalSourceId + ", namespace: " + namespace + ") could not be found");
142
		}
143
		return result;
144
	}
145

    
146
	/* (non-Javadoc)
147
	 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
148
	 */
149
	@Override
150
    protected boolean isIgnore(TaxonXImportState state){
151
		return ! state.getConfig().isDoTypes();
152
	}
153

    
154
	/**
155
	 *
156
	 * Reads the collection_event tag, creates the according data and stores it.
157
	 * TODO under work
158
	 * @param elNomenclature
159
	 * @param nsTaxonx
160
	 * @param taxonBase
161
	 * @return
162
	 */
163
	private boolean doNomenclaturalType(TaxonXImportConfigurator config, Element elNomenclature, Namespace nsTaxonx, TaxonNameBase taxonName){
164
		boolean success = true;
165
		if (taxonName == null){
166
			logger.warn("taxonName is null");
167
			return false;
168
		}
169
		if (elNomenclature == null){
170
			logger.warn("elNomenclature is null");
171
			return false;
172
		}
173

    
174

    
175
		Element elType = elNomenclature.getChild("type", nsTaxonx);
176
		Element elTypeLoc = elNomenclature.getChild("type_loc", nsTaxonx);
177

    
178
		if (elType != null || elTypeLoc != null){
179
			unlazyTypeDesignation(config, taxonName);
180

    
181
			if (taxonName.isInfraGeneric() || taxonName.isSupraGeneric() || taxonName.isGenus()){
182
				success &= doNameType(elType, taxonName, config);
183
			}else{
184
				success &= doSpecimenType(config, elType, elTypeLoc, taxonName);
185

    
186

    
187
			}
188
			return success;
189
		}
190
		return false;
191
	}
192

    
193

    
194
	private boolean doSpecimenType(TaxonXImportConfigurator config, Element elType, Element elTypeLoc, TaxonNameBase taxonName){
195
		Reference citation = null;
196
		String citationMicroReference = null;
197
		String originalNameString = null;
198
		boolean isNotDesignated = true;
199
		boolean addToAllHomotypicNames = true;
200

    
201
		SimpleSpecimen simpleSpecimen = SimpleSpecimen.NewInstance();
202
		//elType
203
		if (elType != null){
204
			doElType(elType, simpleSpecimen, config);
205
		}//elType
206

    
207
		//typeLoc
208
		HashMap<DerivedUnit, SpecimenTypeDesignationStatus> typeLocMap = null;
209
		if (elTypeLoc != null){
210
			typeLocMap = doElTypeLoc(elTypeLoc, simpleSpecimen, taxonName, config);
211
		}
212
		if (typeLocMap != null && typeLocMap.size() >0){
213
			for (DerivedUnit specimen : typeLocMap.keySet()){
214
				SpecimenTypeDesignationStatus status = typeLocMap.get(specimen);
215
				taxonName.addSpecimenTypeDesignation(specimen, status, citation, citationMicroReference, originalNameString, isNotDesignated, addToAllHomotypicNames);
216
			}
217
		}else{ // no type_loc
218
			SpecimenTypeDesignationStatus status = null;
219
			taxonName.addSpecimenTypeDesignation(simpleSpecimen.getSpecimen(), status, citation, citationMicroReference, originalNameString, isNotDesignated, addToAllHomotypicNames);
220
		}
221
		return true;
222
	}
223

    
224
	private boolean doElType(Element elType, SimpleSpecimen simpleSpecimen, TaxonXImportConfigurator config){
225
		//type
226
		String text = elType.getTextNormalize();
227
		if (text.endsWith(";")){
228
			text = text + " ";
229
		}
230
		String[] type = text.split(";");
231
		if (type.length != 3 ){
232
			if (text.equals("")){
233
				logger.info("<nomenclature><type> is empty: " + getBracketSourceName(config));
234
			}else{
235
				logger.warn("<nomenclature><type> is of unsupported format: " + elType.getTextNormalize() + getBracketSourceName(config));
236
			}
237
			simpleSpecimen.setTitleCache(elType.getTextNormalize());
238
		}else{
239
			String strLocality = type[0].trim();
240
			if (! "".equals(strLocality)){
241
//				simpleSpecimen.setLocality(strLocality);
242
			}
243

    
244
			String strCollector = type[1].trim();
245
			if (! "".equals(strCollector)){
246
				AgentBase collector = Person.NewTitledInstance(strCollector);
247
//				simpleSpecimen.setCollector(collector);
248
			}
249

    
250
			String strCollectorNumber = type[2].trim();
251
			if (! "".equals(strCollectorNumber)){
252
//				simpleSpecimen.setCollectorsNumber(strCollectorNumber);
253
			}
254

    
255
			String title = CdmUtils.concat(" ", new String[]{strLocality, strCollector, strCollectorNumber});
256
			simpleSpecimen.setTitleCache(title);
257
		}
258
		return true;
259
	}
260

    
261
	private boolean doNameType(Element elType, TaxonNameBase taxonName, TaxonXImportConfigurator config){
262
		boolean success = true;
263
		//type
264
		String text = elType.getTextNormalize();
265
		logger.info("Type: " + text);
266
		if (text.endsWith(";")){
267
			text = text + " ";
268
		}
269
		String[] type = text.split(";");
270
		if (type.length != 3 ){
271
			if (text.equals("")){
272
				logger.info("<nomenclature><type> is empty: " + getBracketSourceName(config));
273
			}else{
274
				logger.warn("<nomenclature><type> is of unsupported format: " + elType.getTextNormalize() + getBracketSourceName(config));
275
			}
276
			success = false;
277
		}else{
278
			String statusStr = type[0].trim();
279
			String taxonNameStr = type[1].trim();
280
			String authorStr = type[2].trim();
281
			NameTypeDesignationStatus status = getNameTypeStatus(statusStr);
282
			/*boolean isLectoType = getIsLectoType(statusStr);*/
283

    
284
//			if (status == null){
285
//				logger.warn("<nomenclature><type> is of unsupported format: " + elType.getTextNormalize() + getBracketSourceName(config));
286
//				success = false;
287
//			}else{
288
//				TaxonNameBase childType = getChildrenNameType(taxonName, taxonNameStr, authorStr);
289
//				if (childType != null){
290
//					return doNameTypeDesignation(taxonName, childType, status);
291
//				}else{
292
					String[] epis = taxonNameStr.split(" ");
293
					String uninomial = epis[0].trim();
294
					String specEpi = epis[1].trim();
295

    
296
					Pager<TaxonNameBase> nameTypes = getNameService().searchNames(uninomial, null, specEpi, null, Rank.SPECIES(), null, null, null, null);
297

    
298
					List<INonViralName> result = new ArrayList<>();
299
					for (TaxonNameBase nt : nameTypes.getRecords()){
300
						if (compareAuthorship(nt, authorStr)){
301
							result.add(nt);
302
							success &= doNameTypeDesignation(taxonName, nt, status/*, isLectoType*/);
303
						}else{
304
							//TODO ?
305
						}
306
					}
307
					if (result.size() > 1){
308
						logger.warn("More than 1 name matches: " + text);
309
						success = false;
310
					}else if (result.size() == 0){
311
						logger.warn("No name matches: " + text + "(" + config.getSourceNameString() + ")");
312
						success = false;
313
					}
314
//				}
315
//			}
316
		}
317
		return success;
318
	}
319

    
320

    
321
//	private TaxonNameBase getChildrenNameType(TaxonNameBase name, String typeStr, String authorStr){
322
//		TaxonNameBase result = null;
323
//		Set<TaxonBase> list = name.getTaxonBases();
324
//		for (TaxonBase taxonBase : list){
325
//			Taxon taxon;
326
//			if (taxonBase.isInstanceOf(Taxon.class)){
327
//				taxon = CdmBase.deproxy(taxonBase, Taxon.class);
328
//			}else{
329
//				Synonym syn = CdmBase.deproxy(taxonBase, Synonym.class);
330
//				taxon = syn.getAcceptedTaxa().iterator().next();
331
//			}
332
//			Set<Taxon> children = taxon.getTaxonomicChildren();
333
//			for (Taxon child: children){
334
//				INonViralName childName = child.getName();
335
//				if (childName.getNameCache().equals(typeStr)){
336
//					if (compareAuthorship(childName, authorStr)){
337
//						return childName;
338
//					}
339
//				}
340
//			}
341
//		}
342
//		return result;
343
//	}
344

    
345
	private boolean compareAuthorship(INonViralName typeName, String authorStr){
346
		 boolean result = false;
347
		 authorStr = authorStr.replaceAll("\\s+and\\s+", "&");
348
		 authorStr = authorStr.replaceAll("\\s*", "");
349
		 authorStr = authorStr.replaceAll("\\.$", "");
350
		 String typeCache = typeName.getAuthorshipCache().replaceAll("\\s*", "");
351
		 typeCache = typeCache.replaceAll("\\.$", "");
352
		 if (authorStr.equals(typeCache)){
353
			 return true;
354
		 }else{
355
			 logger.info("   Authors different: " + authorStr + " <-> " + typeCache);
356
		 }
357
		 return result;
358
	}
359

    
360
	private NameTypeDesignationStatus getNameTypeStatus(String statusString){
361
		//FIXME some types (not further defined types) do not exist yet
362
		if (true){
363
			return null;
364
		}
365
		if (statusString.trim().equalsIgnoreCase("Type")){
366
			return NameTypeDesignationStatus.ORIGINAL_DESIGNATION();
367
		}else if (statusString.trim().equalsIgnoreCase("Lectotype")){
368
			return NameTypeDesignationStatus.LECTOTYPE();
369
		}else if (statusString.trim().equalsIgnoreCase("Holotype")){
370
			logger.warn("Holotype does not yet exist in CDM");
371
			return NameTypeDesignationStatus.NOT_APPLICABLE();
372
		}else if (statusString.trim().equalsIgnoreCase("paratype")){
373
			logger.warn("paratype does not yet exist in CDM");
374
			return NameTypeDesignationStatus.NOT_APPLICABLE();
375
		}
376
		else{
377
			logger.warn("Status not recognized: " + statusString);
378
			return null;
379
		}
380
	}
381

    
382
	private boolean getIsLectoType(String statusString){
383
		//FIXME may be deleted once getNameTypeStatus works finde
384
		if (statusString.trim().equals("Lectotype")){
385
			return true;
386
		}else{
387
			return false;
388
		}
389
	}
390

    
391

    
392
	private boolean doNameTypeDesignation(TaxonNameBase name, TaxonNameBase type, NameTypeDesignationStatus status/*, boolean isLectoType*/){
393
		Reference citation = null;
394
		String citationMicroReference = null;
395
		String originalNameString = null;
396
		boolean addToAllHomotypicNames = true;
397

    
398
//		name.addNameTypeDesignation(type, citation, citationMicroReference, originalNameString, status, addToAllHomotypicNames);
399
		name.addNameTypeDesignation(type, citation, citationMicroReference, originalNameString,status, false, false, /*isLectoType, */false, addToAllHomotypicNames);
400
		return true;
401
	}
402

    
403
	/**
404
	 * Reads the typeLoc element split in parts for eacht type (holo, iso,...)
405
	 * @param elTypeLoc
406
	 * @param simpleSpecimen
407
	 * @param taxonName
408
	 * @param config
409
	 * @return
410
	 */
411
	private HashMap<DerivedUnit, SpecimenTypeDesignationStatus> doElTypeLoc(Element elTypeLoc,
412
			SimpleSpecimen simpleSpecimen,
413
			TaxonNameBase<?,?> taxonName,
414
			TaxonXImportConfigurator config){
415

    
416
		HashMap<DerivedUnit, SpecimenTypeDesignationStatus> result = new HashMap<DerivedUnit, SpecimenTypeDesignationStatus>();
417

    
418
		String typeLocFullString = elTypeLoc.getTextTrim();
419
		typeLocFullString = typeLocFullString.replace("(", "").replace(")", "");
420
		String[] typeLocStatusList = typeLocFullString.split(";");
421

    
422
		DerivedUnit originalSpecimen = simpleSpecimen.getSpecimen();
423

    
424

    
425
		for (String typeLocStatus : typeLocStatusList){
426
			typeLocStatus = typeLocStatus.trim();
427
			int pos = typeLocStatus.indexOf(" ");
428
			if (pos == -1){
429
				logger.warn("Unknown format or empty type_loc : '" +typeLocStatus + "'" + getBracketSourceName(config));
430
				result.put(originalSpecimen, null);
431
			}else{
432
				String statusString = typeLocStatus.substring(0,pos);
433
				SpecimenTypeDesignationStatus status = getStatusByStatusString(statusString.trim(), config);
434
				//TODO
435
				//String[] collectionStrings = typeLocStatus.substring(pos).split(",");
436
				String tmpCollString = typeLocStatus.substring(pos).trim();
437
				//for(String collectionString : collectionStrings){
438
					if (tmpCollString.contains("typ")){
439
						logger.warn("Is this really only a collection string? : "  + tmpCollString + getBracketSourceName(config));
440
					}
441
					DerivedUnit specimen;
442
					specimen = (DerivedUnit)originalSpecimen.clone();
443
					String title = originalSpecimen.getTitleCache();
444
					title = title + "(" + tmpCollString + ")";
445
					specimen.setTitleCache(title, true );
446
					result.put(specimen, status);
447
				//}
448
			}
449
		}
450

    
451
		return result;
452
	}
453

    
454
	/**
455
	 *
456
	 * Reads the collection_event tag, creates the according data and stores it.
457
	 * TODO under work
458
	 * @param elNomenclature
459
	 * @param nsTaxonx
460
	 * @param taxonBase
461
	 * @return
462
	 */
463
	private boolean doCollectionEvent(TaxonXImportConfigurator config, Element elNomenclature, Namespace nsTaxonx, TaxonBase taxonBase){
464
		boolean result = false;
465
		if (elNomenclature == null){
466
			return false;
467
		}
468
		Element elCollectionEvent = elNomenclature.getChild("collection_event", nsTaxonx);
469
		if (elCollectionEvent == null){
470
			return result;
471
		}
472
		Element elLocality = elCollectionEvent.getChild("locality", nsTaxonx);
473
		Element elType = elCollectionEvent.getChild("type", nsTaxonx);
474
		Element elTypeLoc = elCollectionEvent.getChild("type_loc", nsTaxonx);
475

    
476
		//locality
477
		SimpleSpecimen simpleSpecimen = SimpleSpecimen.NewInstance();
478
		String locality = elLocality.getTextNormalize();
479
		if (! "".equals(locality)){
480
			simpleSpecimen.setLocality(locality);
481
		}
482

    
483
		//type
484
		String[] type = elType.getTextNormalize().split(" ");
485
		if (type.length != 2 ){
486
			logger.warn("<collecion_even><type> is of unsupported format: " + elType.getTextNormalize());
487
		}else{
488
			AgentBase collector = Person.NewTitledInstance(type[0]);
489
			simpleSpecimen.setCollector(collector);
490

    
491
			String collectorNumber = type[1];
492
			simpleSpecimen.setCollectorsNumber(collectorNumber);
493
		}
494

    
495
		//typeLoc
496
		String typeLocFullString = elTypeLoc.getTextTrim();
497
		typeLocFullString = typeLocFullString.replace("(", "").replace(")", "");
498
		String[] typeLocStatusList = typeLocFullString.split(";");
499

    
500
		DerivedUnit originalSpecimen = simpleSpecimen.getSpecimen();
501

    
502
		//TODO special character ?, �, !
503

    
504
		for (String typeLocStatus : typeLocStatusList){
505
			typeLocStatus = typeLocStatus.trim();
506
			int pos = typeLocStatus.indexOf(" ");
507
			if (pos == -1){
508
				logger.warn("Unknown format: " + typeLocStatus);
509
			}else{
510
				String statusString = typeLocStatus.substring(0,pos);
511
				SpecimenTypeDesignationStatus status = getStatusByStatusString(statusString.trim(), config);
512
				String[] collectionStrings = typeLocStatus.substring(pos).split(",");
513
				for(String collectionString : collectionStrings){
514
					if (taxonBase != null){
515
						TaxonNameBase<?, ?> taxonName = taxonBase.getName();
516
						if (taxonName != null){
517
							Reference citation = null;
518
							String citationMicroReference = null;
519
							String originalNameString = null;
520
							boolean isNotDesignated = true;
521
							boolean addToAllHomotypicNames = true;
522
							DerivedUnit specimen = (DerivedUnit)originalSpecimen.clone();
523
							unlazyTypeDesignation(config, taxonName);
524
							taxonName.addSpecimenTypeDesignation(specimen, status, citation, citationMicroReference, originalNameString, isNotDesignated, addToAllHomotypicNames);
525
							result = true;
526
						}
527
					}
528
				}
529
			}
530
		}
531
		return result;
532
	}
533

    
534

    
535
	private static Map<String, SpecimenTypeDesignationStatus> statusMap;
536
	private static void fillTypeStatusMap(){
537
		statusMap = new HashMap<String, SpecimenTypeDesignationStatus>();
538
		statusMap.put("epitype", SpecimenTypeDesignationStatus.EPITYPE());
539
		statusMap.put("holotype", SpecimenTypeDesignationStatus.HOLOTYPE());
540
		statusMap.put("iconotype", SpecimenTypeDesignationStatus.ICONOTYPE());
541
		statusMap.put("isotype", SpecimenTypeDesignationStatus.ISOTYPE());
542
		statusMap.put("isoneotype", SpecimenTypeDesignationStatus.ISONEOTYPE());
543
		statusMap.put("isosyntype", SpecimenTypeDesignationStatus.ISOSYNTYPE());
544
		statusMap.put("isolectotype", SpecimenTypeDesignationStatus.ISOLECTOTYPE());
545
		statusMap.put("lectotype", SpecimenTypeDesignationStatus.LECTOTYPE());
546
		statusMap.put("syntype", SpecimenTypeDesignationStatus.SYNTYPE());
547
		statusMap.put("paratype", SpecimenTypeDesignationStatus.PARATYPE());
548
		statusMap.put("neotype", SpecimenTypeDesignationStatus.NEOTYPE());
549
		statusMap.put("isoepitype", SpecimenTypeDesignationStatus.ISOEPITYPE());
550
		statusMap.put("originalmaterial", SpecimenTypeDesignationStatus.ORIGINAL_MATERIAL());
551
		statusMap.put("paralectotype", SpecimenTypeDesignationStatus.PARALECTOTYPE());
552
		statusMap.put("paraneotype", SpecimenTypeDesignationStatus.PARANEOTYPE());
553
		statusMap.put("phototype", SpecimenTypeDesignationStatus.PHOTOTYPE());
554
		statusMap.put("secondsteplectotype", SpecimenTypeDesignationStatus.SECOND_STEP_LECTOTYPE());
555
		statusMap.put("secondstepneotype", SpecimenTypeDesignationStatus.SECOND_STEP_NEOTYPE());
556
		statusMap.put("type", null);
557
	}
558

    
559

    
560
	//TODO move to TypeDesignation class
561
	/**
562
	 * Returns the typeDesignationStatus according to a type designation status string
563
	 * @param statusString
564
	 * @return TypeDesignationStatus
565
	 */
566
	private static SpecimenTypeDesignationStatus getStatusByStatusString(String statusString, TaxonXImportConfigurator config){
567
		SpecimenTypeDesignationStatus result = null;
568
		if (statusString == null || "".equals(statusString.trim())){
569
			return null;
570
		}
571
		statusString = statusString.trim().toLowerCase();
572
		statusString = statusString.replace("typi", "typus");
573
		statusString = statusString.replace("typus", "type");
574
		statusString = statusString.replace("types", "type");
575
		statusString = statusString.toLowerCase();
576

    
577
		if (statusMap == null){
578
			fillTypeStatusMap();
579
		}
580
		result = statusMap.get(statusString);
581
		if (statusString.equals("type")){
582
			logger.info("No type designation type" + getBracketSourceName(config));
583
		}else if (result == null){
584
			logger.warn("Unknown type status string: " + statusString + getBracketSourceName(config));
585
		}
586
		return result;
587
	}
588

    
589

    
590
	/**
591
	 * TODO Preliminary to avoid laizy loading errors
592
	 */
593
	private void unlazyTypeDesignation(TaxonXImportConfigurator config, TaxonNameBase taxonNameBase){
594
		TransactionStatus txStatus = startTransaction();
595
		//INameService taxonNameService = config.getCdmAppController().getNameService();
596
		INameService taxonNameService = getNameService();
597

    
598
		taxonNameService.save(taxonNameBase);
599
		Set<TaxonNameBase> typifiedNames = taxonNameBase.getHomotypicalGroup().getTypifiedNames();
600
		for(TaxonNameBase typifiedName: typifiedNames){
601
			typifiedName.getTypeDesignations().size();
602
		}
603
		//taxonNameService.saveTaxonName(taxonNameBase);
604
		commitTransaction(txStatus);
605
	}
606

    
607
	/**
608
	 * TODO Preliminary to avoid laizy loading errors
609
	 */
610
	private void unlazySynonym(IImportConfigurator config, Taxon taxon){
611
		TransactionStatus txStatus = startTransaction();
612
		ITaxonService taxonService = getTaxonService();
613
		taxonService.save(taxon);
614
		Set<Synonym> synonyms = taxon.getSynonyms();
615
		logger.debug(synonyms.size());
616
		//taxonService.saveTaxon(taxon);
617
		commitTransaction(txStatus);
618
	}
619

    
620
	private static String getBracketSourceName(TaxonXImportConfigurator config){
621
		return "(" + config.getSourceNameString() + ")";
622
	}
623

    
624

    
625
}
(6-6/7)