Project

General

Profile

Download (23 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.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 long serialVersionUID = 796115831082828758L;
54

    
55
    private static final Logger logger = Logger.getLogger(TaxonXNomenclatureImport.class);
56

    
57
	@SuppressWarnings("unused")
58
	private static int modCount = 10000;
59

    
60
	public TaxonXNomenclatureImport(){
61
		super();
62
	}
63

    
64
	@Override
65
    public boolean doCheck(TaxonXImportState state){
66
		boolean result = true;
67
		logger.warn("Checking for Types not yet implemented");
68
		//result &= checkArticlesWithoutJournal(bmiConfig);
69
		//result &= checkPartOfJournal(bmiConfig);
70

    
71
		return result;
72
	}
73

    
74
	@Override
75
    public void doInvoke(TaxonXImportState state){
76
		logger.info("start make Nomenclature ...");
77
		TransactionStatus tx = startTransaction();
78
		TaxonXImportConfigurator config = state.getConfig();
79
		Element root = config.getSourceRoot();
80
		Namespace nsTaxonx = root.getNamespace();
81

    
82
		//for testing only
83
		Taxon taxon = getTaxon(config);
84
		boolean isChanged = false;
85

    
86
		Element elTaxonBody = root.getChild("taxonxBody", nsTaxonx);
87
		Element elTreatment = elTaxonBody.getChild("treatment", nsTaxonx);
88
		Element elNomenclature = elTreatment.getChild("nomenclature", nsTaxonx);
89

    
90
		//isChanged |= doCollectionEvent(txConfig, elNomenclature, nsTaxonx, taxon);
91

    
92
		if (taxon != null && taxon.getName() != null && elNomenclature != null){
93
			isChanged |= doNomenclaturalType(config, elNomenclature, nsTaxonx, taxon.getName());
94
			List<Element> elSynonymyList = new ArrayList<Element>();
95
			elSynonymyList.addAll(elNomenclature.getChildren("synonomy", nsTaxonx));
96
			elSynonymyList.addAll(elNomenclature.getChildren("synonymy", nsTaxonx)); //wrong spelling in TaxonX-Schema
97
			for (Element elSynonymy : elSynonymyList){
98
				String synonymName = elSynonymy.getChildTextTrim("name");
99
				if (elSynonymy.getChild("type", nsTaxonx) != null || elSynonymy.getChild("type_loc", nsTaxonx) != null){
100
					Synonym synonym = getSynonym(config, taxon, synonymName);
101
					if (synonym != null){
102
						isChanged |= doNomenclaturalType(config, elSynonymy, nsTaxonx, synonym.getName());
103
					}
104
				}
105
			}
106
		}
107

    
108

    
109
		if (isChanged){
110
			getTaxonService().save(taxon);
111
		}
112
		commitTransaction(tx);
113
		return;
114
	}
115

    
116
	private Synonym getSynonym(TaxonXImportConfigurator config, Taxon taxon, String synName){
117
		Synonym result = null;
118
		unlazySynonym(config, taxon);
119
		Set<Synonym> synList = taxon.getSynonyms();
120
		for (Synonym syn : synList){
121
			TaxonNameBase<?,?> nameBase = syn.getName();
122
			if (nameBase != null){
123
				if (nameBase.isInstanceOf(NonViralName.class)){
124
					NonViralName<?> nonViralName = nameBase.deproxy(nameBase, NonViralName.class);
125
					if (nonViralName.getNameCache().equals(synName)){
126
						return syn;  //only first synonym is returned
127
					}
128
				}
129
			}
130
		}
131
		logger.warn("Synonym ("+synName+ ")not found for taxon " + taxon.getTitleCache() + getBracketSourceName(config));
132
		return result;
133
	}
134

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

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

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

    
177

    
178
		Element elType = elNomenclature.getChild("type", nsTaxonx);
179
		Element elTypeLoc = elNomenclature.getChild("type_loc", nsTaxonx);
180

    
181
		if (elType != null || elTypeLoc != null){
182
			unlazyTypeDesignation(config, taxonName);
183

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

    
189

    
190
			}
191
			return success;
192
		}
193
		return false;
194
	}
195

    
196

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

    
204
		SimpleSpecimen simpleSpecimen = SimpleSpecimen.NewInstance();
205
		//elType
206
		if (elType != null){
207
			doElType(elType, simpleSpecimen, config);
208
		}//elType
209

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

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

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

    
253
			String strCollectorNumber = type[2].trim();
254
			if (! "".equals(strCollectorNumber)){
255
//				simpleSpecimen.setCollectorsNumber(strCollectorNumber);
256
			}
257

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

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

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

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

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

    
324

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

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

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

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

    
395

    
396
	private boolean doNameTypeDesignation(TaxonNameBase name, TaxonNameBase type, NameTypeDesignationStatus status/*, boolean isLectoType*/){
397
		Reference citation = null;
398
		String citationMicroReference = null;
399
		String originalNameString = null;
400
		boolean addToAllHomotypicNames = true;
401

    
402
//		name.addNameTypeDesignation(type, citation, citationMicroReference, originalNameString, status, addToAllHomotypicNames);
403
		name.addNameTypeDesignation(type, citation, citationMicroReference, originalNameString,status, false, false, /*isLectoType, */false, addToAllHomotypicNames);
404
		return true;
405
	}
406

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

    
420
		HashMap<DerivedUnit, SpecimenTypeDesignationStatus> result = new HashMap<DerivedUnit, SpecimenTypeDesignationStatus>();
421

    
422
		String typeLocFullString = elTypeLoc.getTextTrim();
423
		typeLocFullString = typeLocFullString.replace("(", "").replace(")", "");
424
		String[] typeLocStatusList = typeLocFullString.split(";");
425

    
426
		DerivedUnit originalSpecimen = simpleSpecimen.getSpecimen();
427

    
428

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

    
455
		return result;
456
	}
457

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

    
480
		//locality
481
		SimpleSpecimen simpleSpecimen = SimpleSpecimen.NewInstance();
482
		String locality = elLocality.getTextNormalize();
483
		if (! "".equals(locality)){
484
			simpleSpecimen.setLocality(locality);
485
		}
486

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

    
495
			String collectorNumber = type[1];
496
			simpleSpecimen.setCollectorsNumber(collectorNumber);
497
		}
498

    
499
		//typeLoc
500
		String typeLocFullString = elTypeLoc.getTextTrim();
501
		typeLocFullString = typeLocFullString.replace("(", "").replace(")", "");
502
		String[] typeLocStatusList = typeLocFullString.split(";");
503

    
504
		DerivedUnit originalSpecimen = simpleSpecimen.getSpecimen();
505

    
506
		//TODO special character ?, �, !
507

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

    
538

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

    
563

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

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

    
593

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

    
602
		taxonNameService.save(taxonNameBase);
603
		Set<TaxonNameBase> typifiedNames = taxonNameBase.getHomotypicalGroup().getTypifiedNames();
604
		for(TaxonNameBase typifiedName: typifiedNames){
605
			typifiedName.getTypeDesignations().size();
606
		}
607
		//taxonNameService.saveTaxonName(taxonNameBase);
608
		commitTransaction(txStatus);
609
	}
610

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

    
624
	private static String getBracketSourceName(TaxonXImportConfigurator config){
625
		return "(" + config.getSourceNameString() + ")";
626
	}
627

    
628

    
629
}
(6-6/7)