Project

General

Profile

Download (23.2 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

    
10
package eu.etaxonomy.cdm.io.tcsxml.in;
11

    
12
import java.util.ArrayList;
13
import java.util.Collection;
14
import java.util.List;
15

    
16
import org.apache.commons.lang.StringUtils;
17
import org.apache.log4j.Logger;
18
import org.jdom.Element;
19
import org.jdom.Namespace;
20
import org.springframework.stereotype.Component;
21

    
22
import eu.etaxonomy.cdm.common.ResultWrapper;
23
import eu.etaxonomy.cdm.common.XmlHelp;
24
import eu.etaxonomy.cdm.io.common.ICdmIO;
25
import eu.etaxonomy.cdm.io.common.MapWrapper;
26
import eu.etaxonomy.cdm.io.tcsxml.TcsXmlTransformer;
27
import eu.etaxonomy.cdm.model.agent.Person;
28
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
29
import eu.etaxonomy.cdm.model.common.VerbatimTimePeriod;
30
import eu.etaxonomy.cdm.model.name.INonViralName;
31
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
32
import eu.etaxonomy.cdm.model.name.Rank;
33
import eu.etaxonomy.cdm.model.name.TaxonName;
34
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
35
import eu.etaxonomy.cdm.model.reference.Reference;
36
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
37
import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException;
38

    
39
@Component("tcsXmlTaxonNameIO")
40
public class TcsXmlTaxonNameImport extends TcsXmlImportBase implements ICdmIO<TcsXmlImportState> {
41

    
42
    private static final long serialVersionUID = -1978871518114999061L;
43
    private static final Logger logger = Logger.getLogger(TcsXmlTaxonNameImport.class);
44

    
45
	private static int modCount = 5000;
46

    
47
	public TcsXmlTaxonNameImport(){
48
		super();
49
	}
50

    
51
	@Override
52
	public boolean doCheck(TcsXmlImportState state){
53
		boolean result = true;
54
		logger.warn("BasionymRelations not yet implemented");
55
		logger.warn("Checking for TaxonNames not yet implemented");
56
		//result &= checkArticlesWithoutJournal(tcsConfig);
57
		//result &= checkPartOfJournal(tcsConfig);
58

    
59
		return result;
60
	}
61

    
62
	//@SuppressWarnings("unchecked")
63
	@Override
64
	public void doInvoke(TcsXmlImportState state){
65

    
66
		logger.info("start make TaxonNames ...");
67
		MapWrapper<Person> authorMap = (MapWrapper<Person>)state.getStore(ICdmIO.TEAM_STORE);
68
		MapWrapper<TaxonName> taxonNameMap = (MapWrapper<TaxonName>)state.getStore(ICdmIO.TAXONNAME_STORE);
69
		MapWrapper<Reference> referenceMap =  (MapWrapper<Reference>)state.getStore(ICdmIO.REFERENCE_STORE);
70

    
71
		ResultWrapper<Boolean> success = ResultWrapper.NewInstance(true);
72
		String childName;
73
		boolean obligatory;
74
		String idNamespace = "TaxonName";
75

    
76
		TcsXmlImportConfigurator config = state.getConfig();
77
		Element elDataSet = getDataSetElement(config);
78
		Namespace tcsNamespace = config.getTcsXmlNamespace();
79

    
80
		childName = "TaxonNames";
81
		obligatory = false;
82
		Element elTaxonNames = XmlHelp.getSingleChildElement(success, elDataSet, childName, tcsNamespace, obligatory);
83

    
84
		String tcsElementName = "TaxonName";
85
		List<Element> elTaxonNameList =  elTaxonNames == null ? new ArrayList<Element>() : (List<Element>)elTaxonNames.getChildren(tcsElementName, tcsNamespace);
86

    
87
		int i = 0;
88
		//for each taxonName
89
		for (Element elTaxonName : elTaxonNameList){
90
			if ((++i % modCount) == 0){ logger.info("Names handled: " + (i-1));}
91
			String strId = elTaxonName.getAttributeValue("id");
92
			/*List<String> elementList = new ArrayList<String>();
93

    
94
			//create TaxonName element
95
			String strId = elTaxonName.getAttributeValue("id");
96
			String strNomenclaturalCode = elTaxonName.getAttributeValue("nomenclaturalCode");
97

    
98
			childName = "Rank";
99
			obligatory = false;
100
			Element elRank = XmlHelp.getSingleChildElement(success, elTaxonName, childName, tcsNamespace, obligatory);
101
			Rank rank = null;
102
			if (elRank != null){
103
				rank = makeRank(elRank);
104
				if (rank == null){
105
					logger.warn("Unknown rank for" + strId);
106
				}
107
			}
108
			elementList.add(childName.toString());
109

    
110

    
111
			try {
112
				TaxonName nameBase;
113
				NomenclaturalCode nomCode = TcsXmlTransformer.nomCodeString2NomCode(strNomenclaturalCode);
114
				if (nomCode != null){
115
					nameBase = nomCode.getNewTaxonNameInstance(rank);
116
				}else{
117
					nameBase = TaxonNameFactory.NewNonViralInstance(rank);
118
				}
119
				childName = "Simple";
120
				obligatory = true;
121
				Element elSimple = XmlHelp.getSingleChildElement(success, elTaxonName, childName, tcsNamespace, obligatory);
122
				String simple = (elSimple == null)? "" : elSimple.getTextNormalize();
123
				nameBase.setTitleCache(simple, false);
124
				elementList.add(childName.toString());
125

    
126
				childName = "CanonicalName";
127
				obligatory = false;
128
				Element elCanonicalName = XmlHelp.getSingleChildElement(success, elTaxonName, childName, tcsNamespace, obligatory);
129
				makeCanonicalName(nameBase, elCanonicalName, taxonNameMap, success);
130
				elementList.add(childName.toString());
131

    
132
				childName = "CanonicalAuthorship";
133
				obligatory = false;
134
				Element elCanonicalAuthorship = XmlHelp.getSingleChildElement(success, elTaxonName, childName, tcsNamespace, obligatory);
135
				makeCanonicalAuthorship(nameBase, elCanonicalAuthorship, authorMap, success);
136
				elementList.add(childName.toString());
137

    
138
				childName = "PublishedIn";
139
				obligatory = false;
140
				Element elPublishedIn = XmlHelp.getSingleChildElement(success, elTaxonName, childName, tcsNamespace, obligatory);
141
				makePublishedIn(nameBase, elPublishedIn, referenceMap, success);
142
				elementList.add(childName.toString());
143

    
144
				childName = "Year";
145
				obligatory = false;
146
				Element elYear = XmlHelp.getSingleChildElement(success, elTaxonName, childName, tcsNamespace, obligatory);
147
				makeYear(nameBase, elYear, success);
148
				elementList.add(childName.toString());
149

    
150
				childName = "MicroReference";
151
				obligatory = false;
152
				Element elMicroReference = XmlHelp.getSingleChildElement(success, elTaxonName, childName, tcsNamespace, obligatory);
153
				makeMicroReference(nameBase, elMicroReference, success);
154
				elementList.add(childName.toString());
155

    
156
				childName = "Typification";
157
				obligatory = false;
158
				Element elTypification = XmlHelp.getSingleChildElement(success, elTaxonName, childName, tcsNamespace, obligatory);
159
				makeTypification(nameBase, elTypification, success);
160
				elementList.add(childName.toString());
161

    
162
				childName = "PublicationStatus";
163
				obligatory = false;
164
				Element elPublicationStatus = XmlHelp.getSingleChildElement(success, elTaxonName, childName, tcsNamespace, obligatory);
165
				makePublicationStatus(nameBase, elPublicationStatus, success);
166
				elementList.add(childName.toString());
167

    
168
				childName = "ProviderLink";
169
				obligatory = false;
170
				Element elProviderLink = XmlHelp.getSingleChildElement(success, elTaxonName, childName, tcsNamespace, obligatory);
171
				makeProviderLink(nameBase, elProviderLink, success);
172
				elementList.add(childName.toString());
173

    
174
				childName = "ProviderSpecificData";
175
				obligatory = false;
176
				Element elProviderSpecificData = XmlHelp.getSingleChildElement(success, elTaxonName, childName, tcsNamespace, obligatory);
177
				makeProviderSpecificData(nameBase, elProviderSpecificData, success);
178
				elementList.add(childName.toString());
179

    
180

    
181
				ImportHelper.setOriginalSource(nameBase, config.getSourceReference(), strId, idNamespace);
182
				if (strId != null){
183
					if (strId.matches("urn:lsid:ipni.org:.*:.*:.*")){
184
						strId = strId.substring(0,strId.lastIndexOf(":"));
185
					}
186
				}
187
				taxonNameMap.put(strId, nameBase);
188

    
189
			} catch (UnknownCdmTypeException e) {
190
				logger.warn("Name with id " + strId + " has unknown nomenclatural code.");
191
				success.setValue(false);
192
			}*/
193

    
194
			taxonNameMap.put(removeVersionOfRef(strId), handleTaxonNameElement(elTaxonName, success, state));
195
		}
196
		logger.info(i + " names handled");
197
		Collection<TaxonName> col = taxonNameMap.objects();
198
		getNameService().save(col);
199

    
200
		logger.info("end makeTaxonNames ...");
201
		if (!success.getValue()){
202
			state.setUnsuccessfull();
203
		}
204

    
205
		return;
206

    
207
	}
208

    
209
	/**
210
	 * Returns the rank represented by the rank element.<br>
211
	 * Returns <code>null</code> if the element is null.<br>
212
	 * Returns <code>null</code> if the code and the text are both either empty or do not exists.<br>
213
	 * Returns the rank represented by the code attribute, if the code attribute is not empty and could be resolved.<br>
214
	 * If the code could not be resolved it returns the rank represented most likely by the elements text.<br>
215
	 * Returns UNKNOWN_RANK if code attribute and element text could not be resolved.
216
	 * @param elRank tcs rank element
217
	 * @return
218
	 */
219
	protected static Rank makeRank(Element elRank){
220
		Rank result;
221
 		if (elRank == null){
222
			return null;
223
		}
224
		String strRankCode = elRank.getAttributeValue("code");
225
		String strRankString = elRank.getTextNormalize();
226
		if ( StringUtils.isBlank(strRankCode) && StringUtils.isBlank(strRankString)){
227
			return null;
228
		}
229

    
230
		Rank codeRank = null;
231
		try {
232
			codeRank = TcsXmlTransformer.rankCode2Rank(strRankCode);
233
		} catch (UnknownCdmTypeException e1) {
234
			codeRank = Rank.UNKNOWN_RANK();
235
		}
236
		Rank stringRank = null;
237
		try {
238
			boolean useUnknown = true;
239
			stringRank = TcsXmlTransformer.rankString2Rank(strRankString);
240
			//stringRank = Rank.getRankByNameOrIdInVoc(strRankString, useUnknown);
241
		} catch (UnknownCdmTypeException e1) {
242
			//does not happen because of useUnknown = true
243
		}
244

    
245
		//codeRank exists
246
		if ( (codeRank != null) && ! codeRank.equals(Rank.UNKNOWN_RANK())){
247
			result = codeRank;
248
			if (! codeRank.equals(stringRank) && ! stringRank.equals(Rank.UNKNOWN_RANK())){
249
				logger.warn("code rank and string rank are unequal. code: " + codeRank.getLabel() + " <-> string: " + stringRank.getLabel());
250
			}
251
		}
252
		//codeRank does not exist
253
		else{
254
			result = stringRank;
255
			logger.warn("string rank used, because code rank does not exist or was not recognized: " + strRankString );
256
		}
257
		return result;
258
	}
259

    
260
	public TaxonName handleTaxonNameElement(Element elTaxonName,  ResultWrapper<Boolean> success, TcsXmlImportState state){
261
		Namespace tcsNamespace = state.getConfig().getTcsXmlNamespace();
262
		MapWrapper<Person> authorMap = (MapWrapper<Person>)state.getStore(ICdmIO.TEAM_STORE);
263
		MapWrapper<TaxonName> taxonNameMap = (MapWrapper<TaxonName>)state.getStore(ICdmIO.TAXONNAME_STORE);
264
		MapWrapper<Reference> referenceMap =  (MapWrapper<Reference>)state.getStore(ICdmIO.REFERENCE_STORE);
265

    
266

    
267

    
268
		List<String> elementList = new ArrayList<>();
269
		String idNamespace = "TaxonName";
270
		//create TaxonName element
271
		String strId = elTaxonName.getAttributeValue("id");
272
		String strNomenclaturalCode = elTaxonName.getAttributeValue("nomenclaturalCode");
273
		//Content elTaxName = elTaxonName.getChild(name, ns);
274
		String childName = "Rank";
275
		boolean obligatory = false;
276
		Element elRank = XmlHelp.getSingleChildElement(success, elTaxonName, childName, tcsNamespace, obligatory);
277
		Rank rank = null;
278
		if (elRank != null){
279
			rank = TcsXmlTaxonNameImport.makeRank(elRank);
280
			if (rank == null){
281
				logger.warn("Unknown rank for" + strId);
282
			}
283
		}
284
		elementList.add(childName.toString());
285

    
286

    
287
		try {
288
			TaxonName nameBase;
289
			NomenclaturalCode nomCode = TcsXmlTransformer.nomCodeString2NomCode(strNomenclaturalCode);
290
			if (nomCode != null){
291
				nameBase = nomCode.getNewTaxonNameInstance(rank);
292
			}else{
293
				nameBase = TaxonNameFactory.NewNonViralInstance(rank);
294
			}
295
			childName = "Simple";
296
			obligatory = true;
297
			Element elSimple = XmlHelp.getSingleChildElement(success, elTaxonName, childName, tcsNamespace, obligatory);
298
			String simple = (elSimple == null)? "" : elSimple.getTextNormalize();
299
			nameBase.setTitleCache(simple, false);
300
			elementList.add(childName.toString());
301

    
302
			childName = "CanonicalName";
303
			obligatory = false;
304
			Element elCanonicalName = XmlHelp.getSingleChildElement(success, elTaxonName, childName, tcsNamespace, obligatory);
305
			makeCanonicalName(nameBase, elCanonicalName, taxonNameMap, success);
306
			elementList.add(childName.toString());
307

    
308
			childName = "CanonicalAuthorship";
309
			obligatory = false;
310
			Element elCanonicalAuthorship = XmlHelp.getSingleChildElement(success, elTaxonName, childName, tcsNamespace, obligatory);
311
			makeCanonicalAuthorship(nameBase, elCanonicalAuthorship, authorMap, success);
312
			elementList.add(childName.toString());
313

    
314
			childName = "PublishedIn";
315
			obligatory = false;
316
			Element elPublishedIn = XmlHelp.getSingleChildElement(success, elTaxonName, childName, tcsNamespace, obligatory);
317
			makePublishedIn(nameBase, elPublishedIn, referenceMap, success);
318
			elementList.add(childName.toString());
319

    
320
			childName = "Year";
321
			obligatory = false;
322
			Element elYear = XmlHelp.getSingleChildElement(success, elTaxonName, childName, tcsNamespace, obligatory);
323
			makeYear(nameBase, elYear, success);
324
			elementList.add(childName.toString());
325

    
326
			childName = "MicroReference";
327
			obligatory = false;
328
			Element elMicroReference = XmlHelp.getSingleChildElement(success, elTaxonName, childName, tcsNamespace, obligatory);
329
			makeMicroReference(nameBase, elMicroReference, success);
330
			elementList.add(childName.toString());
331

    
332
			childName = "Typification";
333
			obligatory = false;
334
			Element elTypification = XmlHelp.getSingleChildElement(success, elTaxonName, childName, tcsNamespace, obligatory);
335
			makeTypification(nameBase, elTypification, success);
336
			elementList.add(childName.toString());
337

    
338
			childName = "PublicationStatus";
339
			obligatory = false;
340
			Element elPublicationStatus = XmlHelp.getSingleChildElement(success, elTaxonName, childName, tcsNamespace, obligatory);
341
			makePublicationStatus(nameBase, elPublicationStatus, success);
342
			elementList.add(childName.toString());
343

    
344
			childName = "ProviderLink";
345
			obligatory = false;
346
			Element elProviderLink = XmlHelp.getSingleChildElement(success, elTaxonName, childName, tcsNamespace, obligatory);
347
			makeProviderLink(nameBase, elProviderLink, success);
348
			elementList.add(childName.toString());
349

    
350
			childName = "ProviderSpecificData";
351
			obligatory = false;
352
			Element elProviderSpecificData = XmlHelp.getSingleChildElement(success, elTaxonName, childName, tcsNamespace, obligatory);
353
			makeProviderSpecificData(nameBase, elProviderSpecificData, success, state);
354
			elementList.add(childName.toString());
355

    
356
			return nameBase;
357

    
358
		} catch (UnknownCdmTypeException e) {
359
			logger.warn("Name with id " + strId + " has unknown nomenclatural code.");
360
			success.setValue(false);
361
		}
362
		return null;
363
	}
364

    
365

    
366

    
367
	private void makeCanonicalAuthorship(TaxonName name, Element elCanonicalAuthorship, MapWrapper<Person> authorMap, ResultWrapper<Boolean> success){
368
		if (elCanonicalAuthorship != null){
369
			Namespace ns = elCanonicalAuthorship.getNamespace();
370

    
371
			if (name.isNonViral()){
372
				INonViralName nonViralName = name;
373

    
374
				String childName = "Simple";
375
				boolean obligatory = true;
376
				Element elSimple = XmlHelp.getSingleChildElement(success, elCanonicalAuthorship, childName, ns, obligatory);
377
				String simple = (elSimple == null)? "" : elSimple.getTextNormalize();
378
				//TODO
379
				//logger.warn("authorship cache cache protected not yet implemented");
380
				//nonViralName.setAuthorshipCache(simple, cacheProtected);
381

    
382
				childName = "Authorship";
383
				obligatory = false;
384
				Element elAuthorship = XmlHelp.getSingleChildElement(success, elCanonicalAuthorship, childName, ns, obligatory);
385
				TeamOrPersonBase author = makeNameCitation(elAuthorship, authorMap, success);
386
				nonViralName.setCombinationAuthorship(author);
387
				//setCombinationAuthorship(author);
388
				testNoMoreElements();
389

    
390
				childName = "BasionymAuthorship";
391
				obligatory = false;
392
				Element elBasionymAuthorship = XmlHelp.getSingleChildElement(success, elCanonicalAuthorship, childName, ns, obligatory);
393
				TeamOrPersonBase<?> basionymAuthor = makeNameCitation(elBasionymAuthorship, authorMap, success);
394
				nonViralName.setBasionymAuthorship(basionymAuthor);
395
				testNoMoreElements();
396

    
397
				childName = "CombinationAuthorship";
398
				obligatory = false;
399
				Element elCombinationAuthorship = XmlHelp.getSingleChildElement(success, elCanonicalAuthorship, childName, ns, obligatory);
400
				TeamOrPersonBase<?> combinationAuthor = makeNameCitation(elCombinationAuthorship, authorMap ,success);
401
				if (combinationAuthor != null){
402
					nonViralName.setCombinationAuthorship(combinationAuthor);
403
				}
404
				testNoMoreElements();
405

    
406
				if (elAuthorship != null && (elBasionymAuthorship != null || elCombinationAuthorship != null) ){
407
					logger.warn("Authorship and (BasionymAuthorship or CombinationAuthorship) must not exist at the same time in CanonicalAuthorship");
408
					success.setValue(false);
409
				}
410
			}
411
		}
412
	}
413

    
414
	private void makeMicroReference(TaxonName name, Element elMicroReference, ResultWrapper<Boolean> success){
415
		if (elMicroReference != null){
416
			String microReference = elMicroReference.getTextNormalize();
417
			name.setNomenclaturalMicroReference(microReference);
418
		}
419
	}
420

    
421
	private void makeCanonicalName(TaxonName name, Element elCanonicalName, MapWrapper<TaxonName> taxonNameMap, ResultWrapper<Boolean> success){
422
		boolean cacheProtected = false;
423

    
424
		if (elCanonicalName == null){
425
			return;
426
		}
427
		Namespace ns = elCanonicalName.getNamespace();
428

    
429
		String childName = "Simple";
430
		boolean obligatory = true;
431
		Element elSimple = XmlHelp.getSingleChildElement(success, elCanonicalName, childName, ns, obligatory);
432
		String simple = (elSimple == null)? "" : elSimple.getTextNormalize();
433
		name.setFullTitleCache(simple, cacheProtected);
434

    
435
		if (name.isNonViral()){
436
			INonViralName nonViralName = name;
437
			childName = "Uninomial";
438
			obligatory = false;
439
			Element elUninomial = XmlHelp.getSingleChildElement(success, elCanonicalName, childName, ns, obligatory);
440
			String uninomial = (elUninomial == null)? "" : elUninomial.getTextNormalize();
441
			if (StringUtils.isNotBlank(uninomial)){
442
				nonViralName.setGenusOrUninomial(uninomial);
443
				if (nonViralName.getRank() != null && nonViralName.getRank().isLower(Rank.GENUS())){  // TODO check
444
					logger.warn("Name " + simple + " lower then 'genus' but has a canonical name part 'Uninomial'.");
445
				}
446
			}
447
			testNoMoreElements();
448

    
449
			childName = "Genus";
450
			obligatory = false;
451
			Element elGenus = XmlHelp.getSingleChildElement(success, elCanonicalName, childName, ns, obligatory);
452
			if (elGenus != null){
453
				//TODO do Attributes reference
454
				makeGenusReferenceType(name, elGenus, taxonNameMap, success);
455
				String genus = elGenus.getTextNormalize();
456
				if (StringUtils.isNotBlank(genus)){
457
					nonViralName.setGenusOrUninomial(genus);
458
					if (nonViralName.getRank() != null &&  ! nonViralName.getRank().isLower(Rank.GENUS() )){  // TODO check
459
						logger.warn("Name " + simple + " is not lower then 'genus' but has canonical name part 'Genus'.");
460
					}
461
				}
462
			}
463

    
464
			childName = "InfragenericEpithet";
465
			obligatory = false;
466
			Element elInfrageneric = XmlHelp.getSingleChildElement(success, elCanonicalName, childName, ns, obligatory);
467
			String infraGenericEpithet = (elInfrageneric == null)? "" : elInfrageneric.getTextNormalize();
468
			if (! infraGenericEpithet.trim().equals("")){
469
				nonViralName.setInfraGenericEpithet(infraGenericEpithet);
470
				if (nonViralName.getRank() != null && ! name.getRank().isInfraGeneric()){
471
					logger.warn("Name " + simple + " is not infra generic but has canonical name part 'InfragenericEpithet'.");
472
				}
473
			}
474
			testNoMoreElements();
475

    
476
			childName = "SpecificEpithet";
477
			obligatory = false;
478
			Element elSpecificEpithet = XmlHelp.getSingleChildElement(success, elCanonicalName, childName, ns, obligatory);
479
			String specificEpithet = (elSpecificEpithet == null)? "" : elSpecificEpithet.getTextNormalize();
480
			if (! specificEpithet.trim().equals("")){
481
				nonViralName.setSpecificEpithet(specificEpithet);
482
				if (nonViralName.getRank() != null && name.getRank().isHigher(Rank.SPECIES()) ){
483
					logger.warn("Name " + simple + " is not species or below but has canonical name part 'SpecificEpithet'.");
484
				}
485
			}
486
			testNoMoreElements();
487

    
488
			childName = "InfraspecificEpithet";
489
			obligatory = false;
490
			Element elInfraspecificEpithet = XmlHelp.getSingleChildElement(success, elCanonicalName, childName, ns, obligatory);
491
			String infraspecificEpithet = (elInfraspecificEpithet == null)? "" : elInfraspecificEpithet.getTextNormalize();
492
			if (! infraspecificEpithet.trim().equals("")){
493
				nonViralName.setInfraSpecificEpithet(infraspecificEpithet);
494
				if (nonViralName.getRank() != null && ! name.isInfraSpecific() ){
495
					logger.warn("Name " + simple + " is not infraspecific but has canonical name part 'InfraspecificEpithet'.");
496
				}
497
			}
498
			testNoMoreElements();
499

    
500

    
501
		}else{ //ViralName
502
			//logger.warn("Non NonViralNames not yet supported by makeCanonicalName");
503
		}
504

    
505

    
506
		childName = "CultivarNameGroup";
507
		obligatory = false;
508
		Element elCultivarNameGroup = XmlHelp.getSingleChildElement(success, elCanonicalName, childName, ns, obligatory);
509
		String cultivarNameGroup = (elCultivarNameGroup == null)? "" : elCultivarNameGroup.getTextNormalize();
510
		if (! "".equals(cultivarNameGroup.trim())){
511
			if (name.isCultivar()){
512
				makeCultivarEpithet();
513
			}else{
514
				logger.warn("Non cultivar name has 'cultivar name group' element. Omitted");
515
			}
516
		}
517
		return;
518
	}
519

    
520
	private void makeCultivarEpithet(){
521
		//TODO
522
		//logger.warn("'makeCultivarName' Not yet implemented");
523
	}
524

    
525
	private void makeGenusReferenceType(TaxonName name, Element elGenus, MapWrapper<TaxonName> taxonNameMap, ResultWrapper<Boolean> success){
526
		if(name.isNonViral()){
527
			INonViralName nonViralName = name;
528
			if (elGenus != null){
529
			    INonViralName genusReferenceName;
530
				//TODO code
531
				Class<TaxonName> clazz = TaxonName.class;
532
				genusReferenceName = makeReferenceType(elGenus, clazz, taxonNameMap, success);
533
				genusReferenceName.setNameType(NomenclaturalCode.NonViral);
534
				//Genus is stored either in Genus part (if ref) or in titleCache (if plain text)
535
				String genus = genusReferenceName.getGenusOrUninomial()!= null ? genusReferenceName.getGenusOrUninomial(): genusReferenceName.getTitleCache();
536
				nonViralName.setGenusOrUninomial(genus);
537
			}else{
538
				logger.warn("Missing Genus information");
539
			}
540
		}else{
541
			//TODO   (can be changed if Viral Name also has Genus in future
542
			//logger.warn("Genus ref type for Viral Name not implemented yet");
543
		}
544

    
545
	}
546

    
547
	private void makePublishedIn(TaxonName name, Element elPublishedIn, MapWrapper<Reference> referenceMap, ResultWrapper<Boolean> success){
548
		if (elPublishedIn != null && name != null){
549
			Class<Reference> clazz = Reference.class;
550
			Reference ref = makeReferenceType(elPublishedIn, clazz, referenceMap, success);
551
			if (ref instanceof Reference){
552
				name.setNomenclaturalReference(ref);
553
			}else if (ref == null){
554
				logger.warn("Nomecl. reference could not be created for '" + name.getTitleCache() + "'");
555
			}else{
556
				logger.warn("Reference is not of type INomenclaturalReference and could not be added to the name " + name.getTitleCache());
557
			}
558
		}else if (name == null){
559
			logger.warn("TaxonName must not be 'null'");
560
			success.setValue(false);
561
		}
562
	}
563

    
564
	private void makeYear(TaxonName name, Element elYear, ResultWrapper<Boolean> success){
565
		if (elYear != null){
566
			String year = elYear.getTextNormalize();
567
			if (year != null){
568
    			if (name.isZoological()){
569
    				name.setPublicationYear(getIntegerYear(year));
570
    			}else{
571
    			    VerbatimTimePeriod period = VerbatimTimePeriod.NewVerbatimInstance(getIntegerYear(year));
572
    			    if (name.getNomenclaturalReference()!= null){
573
    			        name.getNomenclaturalReference().setDatePublished(period);
574
    			    } else{
575
    			        Reference nomRef = ReferenceFactory.newGeneric();
576
    			        nomRef.setDatePublished(period);
577
    			    }
578
    				logger.debug("Year can be set only for a zoological name, add the year to the nomenclatural reference.");
579
    			}
580
			}
581
		}
582
	}
583

    
584
}
(9-9/11)