Project

General

Profile

Download (23.3 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.TimePeriod;
30
import eu.etaxonomy.cdm.model.name.CultivarPlantName;
31
import eu.etaxonomy.cdm.model.name.INonViralName;
32
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
33
import eu.etaxonomy.cdm.model.name.NonViralName;
34
import eu.etaxonomy.cdm.model.name.Rank;
35
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
36
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
37
import eu.etaxonomy.cdm.model.name.ZoologicalName;
38
import eu.etaxonomy.cdm.model.reference.Reference;
39
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
40
import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException;
41

    
42
@Component("tcsXmlTaxonNameIO")
43
public class TcsXmlTaxonNameImport extends TcsXmlImportBase implements ICdmIO<TcsXmlImportState> {
44
	private static final Logger logger = Logger.getLogger(TcsXmlTaxonNameImport.class);
45

    
46
	private static int modCount = 5000;
47

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

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

    
60
		return result;
61
	}
62

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

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

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

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

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

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

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

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

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

    
111

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

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

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

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

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

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

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

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

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

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

    
181

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

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

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

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

    
206
		return;
207

    
208
	}
209

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

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

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

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

    
267

    
268

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

    
287

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

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

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

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

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

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

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

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

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

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

    
357
			return nameBase;
358

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

    
366

    
367

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

    
372
			if (name instanceof NonViralName){
373
				INonViralName nonViralName = name;
374

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
501

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

    
506

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

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

    
526
	private void makeGenusReferenceType(TaxonNameBase name, Element elGenus, MapWrapper<TaxonNameBase> taxonNameMap, ResultWrapper<Boolean> success){
527
		if(name instanceof NonViralName){
528
			INonViralName nonViralName = name;
529
			if (elGenus != null){
530
			    INonViralName genusReferenceName;
531
				//TODO code
532
				Class<? extends NonViralName> clazz = NonViralName.class;
533
				genusReferenceName = makeReferenceType(elGenus, clazz, taxonNameMap, success);
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(TaxonNameBase 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(TaxonNameBase name, Element elYear, ResultWrapper<Boolean> success){
565
		if (elYear != null){
566
			String year = elYear.getTextNormalize();
567
			if (year != null){
568
    			if (name instanceof ZoologicalName){
569
    				((ZoologicalName)name).setPublicationYear(getIntegerYear(year));
570
    			}else{
571
    			    TimePeriod period = TimePeriod.NewInstance(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)