Project

General

Profile

Download (22.8 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.name.INonViralName;
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
					if (nameBase.getNameCache().equals(synName)){
125
						return syn;  //only first synonym is returned
126
					}
127
				}
128
			}
129
		}
130
		logger.warn("Synonym ("+synName+ ")not found for taxon " + taxon.getTitleCache() + getBracketSourceName(config));
131
		return result;
132
	}
133

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

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

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

    
176

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

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

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

    
188

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

    
195

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

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

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

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

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

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

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

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

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

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

    
300
					List<INonViralName> result = new ArrayList<>();
301
					for (TaxonNameBase nt : nameTypes.getRecords()){
302
						if (compareAuthorship(nt, authorStr)){
303
							result.add(nt);
304
							success &= doNameTypeDesignation(taxonName, nt, 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
//				INonViralName childName = child.getName();
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(INonViralName 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
}
(6-6/7)