Project

General

Profile

« Previous | Next » 

Revision 48014773

Added by Andreas Müller almost 9 years ago

Rename NonViralName authorteams to authorship #4968

View differences:

cdm-eflora/src/main/java/eu/etaxonomy/cdm/io/eflora/EfloraTaxonImport.java
5 5
*
6 6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/ 
8
*/
9 9

  
10 10
package eu.etaxonomy.cdm.io.eflora;
11 11

  
......
92 92
	private static final Logger logger = Logger.getLogger(EfloraTaxonImport.class);
93 93

  
94 94
	private static int modCount = 30000;
95
	private NonViralNameParserImpl parser = new NonViralNameParserImpl();
95
	private final NonViralNameParserImpl parser = new NonViralNameParserImpl();
96 96

  
97 97
	public EfloraTaxonImport(){
98 98
		super();
99 99
	}
100
	
101
	
100

  
101

  
102 102
	@Override
103 103
	public boolean doCheck(EfloraImportState state){
104 104
		boolean result = true;
105 105
		return result;
106 106
	}
107
	
108
	//TODO make part of state, but state is renewed when invoking the import a second time 
107

  
108
	//TODO make part of state, but state is renewed when invoking the import a second time
109 109
	private UnmatchedLeads unmatchedLeads;
110
	
110

  
111 111
	@Override
112 112
	public void doInvoke(EfloraImportState state){
113 113
		logger.info("start make Taxa ...");
114
		
114

  
115 115
		//FIXME reset state
116 116
		state.putTree(null, null);
117 117
//		UnmatchedLeads unmatchedLeads = state.getOpenKeys();
......
119 119
			unmatchedLeads = UnmatchedLeads.NewInstance();
120 120
		}
121 121
		state.setUnmatchedLeads(unmatchedLeads);
122
		
122

  
123 123
		TransactionStatus tx = startTransaction();
124 124
		unmatchedLeads.saveToSession(getPolytomousKeyNodeService());
125
		
126
		
125

  
126

  
127 127
		//TODO generally do not store the reference object in the config
128 128
		Reference sourceReference = state.getConfig().getSourceReference();
129 129
		getReferenceService().saveOrUpdate(sourceReference);
130
		
130

  
131 131
		Set<TaxonBase> taxaToSave = new HashSet<TaxonBase>();
132 132
		ResultWrapper<Boolean> success = ResultWrapper.NewInstance(true);
133 133

  
134 134
		Element elbody= getBodyElement(state.getConfig());
135 135
		List<Element> elTaxonList = elbody.getChildren();
136
		
136

  
137 137
		int i = 0;
138
		
138

  
139 139
		Set<String> unhandledTitleClassess = new HashSet<String>();
140 140
		Set<String> unhandledNomeclatureChildren = new HashSet<String>();
141 141
		Set<String> unhandledDescriptionChildren = new HashSet<String>();
142
		
142

  
143 143
		Taxon lastTaxon = getLastTaxon(state);
144
		
144

  
145 145
		//for each taxon
146 146
		for (Element elTaxon : elTaxonList){
147 147
			try {
......
149 149
				if (! elTaxon.getName().equalsIgnoreCase("taxon")){
150 150
					logger.warn("body has element other than 'taxon'");
151 151
				}
152
				
152

  
153 153
				BotanicalName botanicalName = BotanicalName.NewInstance(Rank.SPECIES());
154 154
				Taxon taxon = Taxon.NewInstance(botanicalName, state.getConfig().getSourceReference());
155
				
155

  
156 156
				handleTaxonAttributes(elTaxon, taxon, state);
157 157

  
158
				
158

  
159 159
				List<Element> children = elTaxon.getChildren();
160 160
				handleTaxonElement(state, unhandledTitleClassess, unhandledNomeclatureChildren,	unhandledDescriptionChildren, taxon, children);
161 161
				handleTaxonRelation(state, taxon, lastTaxon);
162 162
				lastTaxon = taxon;
163 163
				taxaToSave.add(taxon);
164 164
				state.getConfig().setLastTaxonUuid(lastTaxon.getUuid());
165
				
165

  
166 166
			} catch (Exception e) {
167 167
				logger.warn("Exception occurred in Sapindacea taxon import: " + e);
168 168
				e.printStackTrace();
169 169
			}
170
			
170

  
171 171
		}
172
		
172

  
173 173
		System.out.println(state.getUnmatchedLeads().toString());
174 174
		logger.warn("There are taxa with attributes 'excluded' and 'dubious'");
175
		
175

  
176 176
		logger.info("Children for nomenclature are: " + unhandledNomeclatureChildren);
177 177
		logger.info("Children for description are: " + unhandledDescriptionChildren);
178 178
		logger.info("Children for homotypes are: " + unhandledHomotypeChildren);
179 179
		logger.info("Children for nom are: " + unhandledNomChildren);
180
		
181
		
180

  
181

  
182 182
		//invokeRelations(source, cdmApp, deleteAll, taxonMap, referenceMap);
183 183
		logger.info(i + " taxa handled. Saving ...");
184 184
		getTaxonService().saveOrUpdate(taxaToSave);
185 185
		getFeatureTreeService().saveOrUpdateFeatureNodesAll(state.getFeatureNodesToSave());
186 186
		state.getFeatureNodesToSave().clear();
187 187
		commitTransaction(tx);
188
		
188

  
189 189
		logger.info("end makeTaxa ...");
190 190
		logger.info("start makeKey ...");
191 191
//		invokeDoKey(state);
192 192
		logger.info("end makeKey ...");
193
		
193

  
194 194
		if (! success.getValue()){
195 195
			state.setUnsuccessfull();
196 196
		}
......
235 235

  
236 236
//	private void invokeDoKey(SapindaceaeImportState state) {
237 237
//		TransactionStatus tx = startTransaction();
238
//		
238
//
239 239
//		Set<FeatureNode> nodesToSave = new HashSet<FeatureNode>();
240 240
//		ITaxonService taxonService = getTaxonService();
241 241
//		ResultWrapper<Boolean> success = ResultWrapper.NewInstance(true);
242 242
//
243 243
//		Element elbody= getBodyElement(state.getConfig());
244 244
//		List<Element> elTaxonList = elbody.getChildren();
245
//		
245
//
246 246
//		int i = 0;
247
//		
247
//
248 248
//		//for each taxon
249 249
//		for (Element elTaxon : elTaxonList){
250 250
//			if ((i++ % modCount) == 0 && i > 1){ logger.info("Taxa handled: " + (i-1));}
251 251
//			if (! elTaxon.getName().equalsIgnoreCase("taxon")){
252 252
//				continue;
253 253
//			}
254
//			
254
//
255 255
//			List<Element> children = elTaxon.getChildren("key");
256 256
//			for (Element element : children){
257 257
//				handleKeys(state, element, null);
......
259 259
//			nodesToSave.add(taxon);
260 260
//
261 261
//		}
262
//		
262
//
263 263
//	}
264 264

  
265 265

  
......
268 268
		AnnotatableEntity lastEntity = null;
269 269
		for (Element element : children){
270 270
			String elName = element.getName();
271
			
271

  
272 272
			if (elName.equalsIgnoreCase("title")){
273 273
				handleTitle(state, element, taxon, unhandledTitleClassess);
274 274
				lastEntity = null;
......
304 304
			}
305 305
		}
306 306
	}
307
	
308
	
307

  
308

  
309 309
	private void handleVernaculars(EfloraImportState state, Element elVernacular, Taxon taxon) {
310 310
		verifyNoAttribute(elVernacular);
311 311
		verifyNoChildren(elVernacular, false);
......
330 330
		if (matcher.find()){
331 331
			String dialect = singleDialect.substring(matcher.start(), matcher.end());
332 332
			dialect = dialect.replace("(dial. ", "").replace(")", "");
333
			
333

  
334 334
			Language language = null;
335 335
			try {
336 336
				language = this.getLanguage(state, state.getTransformer().getLanguageUuid(dialect), dialect, dialect, dialect);
337 337
			} catch (UndefinedTransformerMethodException e) {
338 338
				logger.error(e.getMessage());
339 339
			}
340
			
340

  
341 341
			String commonNames = singleDialect.substring(0, matcher.start());
342 342
			String[] splitNames = commonNames.split(",");
343 343
			for (String commonNameString : splitNames){
......
354 354
	private void handleReferences(EfloraImportState state, Element elReferences, Taxon taxon, AnnotatableEntity lastEntity) {
355 355
		verifyNoAttribute(elReferences);
356 356
		verifyNoChildren(elReferences, true);
357
		String refString = elReferences.getTextNormalize(); 
357
		String refString = elReferences.getTextNormalize();
358 358
		if (lastEntity == null){
359 359
			logger.warn("No last entity defined: " + refString);
360 360
			return;
361 361
		}
362
		
362

  
363 363
		Annotation annotation = Annotation.NewInstance(refString, AnnotationType.EDITORIAL(), Language.DEFAULT());
364 364
		lastEntity.addAnnotation(annotation);
365 365
	}
......
367 367

  
368 368
	private PolytomousKey handleKeys(EfloraImportState state, Element elKey, Taxon taxon) {
369 369
		UnmatchedLeads openKeys = state.getUnmatchedLeads();
370
		
370

  
371 371
		//title
372 372
		String title = makeKeyTitle(elKey);
373
		
373

  
374 374
		//key
375 375
		PolytomousKey key = PolytomousKey.NewTitledInstance(title);
376
		
376

  
377 377
		//TODO add covered taxa etc.
378 378
		verifyNoAttribute(elKey);
379
		
379

  
380 380
		//notes
381 381
		makeKeyNotes(elKey, key);
382
		
382

  
383 383
		//keycouplets
384 384
		List<Element> keychoices = new ArrayList<Element>();
385 385
		keychoices.addAll(elKey.getChildren("keycouplet"));
386 386
		keychoices.addAll(elKey.getChildren("keychoice"));
387
		
388
		
387

  
388

  
389 389
		for (Element elKeychoice : keychoices){
390 390
			handleKeyChoices(state, openKeys, key, elKeychoice, taxon);
391 391
			elKey.removeContent(elKeychoice);
392 392
		}
393
		
393

  
394 394
		//
395 395
		verifyNoChildren(elKey);
396 396
		logger.info("Unmatched leads after key handling:" + openKeys.toString());
397
		
397

  
398 398

  
399 399
		if (state.getConfig().isDoPrintKeys()){
400 400
			key.print(System.err);
......
410 410
	 * @param openKeys
411 411
	 * @param key
412 412
	 * @param elKeychoice
413
	 * @param taxon 
413
	 * @param taxon
414 414
	 */
415 415
	private void handleKeyChoices(EfloraImportState state, UnmatchedLeads openKeys, PolytomousKey key, Element elKeychoice, Taxon taxon) {
416
		
416

  
417 417
		//char Attribute
418
		//TODO it's still unclear if char is a feature and needs to be a new attribute 
418
		//TODO it's still unclear if char is a feature and needs to be a new attribute
419 419
		//or if it is handled as question. Therefore both cases are handled but feature
420 420
		//is finally not yet set
421 421
		KeyStatement question = handleKeychoiceChar(state, elKeychoice);
422 422
		Feature feature = handleKeychoiceCharAsFeature(state, elKeychoice);
423
		
423

  
424 424
		//lead
425 425
		List<PolytomousKeyNode> childNodes = handleKeychoiceLeads(state, key, elKeychoice, taxon, question, feature);
426
		
426

  
427 427
		//num -> match with unmatched leads
428 428
		handleKeychoiceNum(openKeys, key, elKeychoice, childNodes);
429 429

  
......
454 454
				key.getRoot().addChild(childNode);
455 455
			}
456 456
		}
457
		
457

  
458 458
		elKeychoice.removeAttribute("num");
459 459
	}
460 460

  
......
495 495
		}
496 496
		return statement;
497 497
	}
498
	
498

  
499 499
	/**
500 500
	 * @param state
501 501
	 * @param elKeychoice
......
519 519
		//needs to be discussed on model side
520 520
		node.setQuestion(question);
521 521
//		node.setFeature(feature);
522
		
522

  
523 523
		//text
524 524
		String text = handleLeadText(elLead, node);
525
		
525

  
526 526
		//num
527 527
		handleLeadNum(elLead, text);
528
		
528

  
529 529
		//goto
530 530
		handleLeadGoto(state, key, elLead, taxon, node);
531
		
531

  
532 532
		//others
533 533
		verifyNoAttribute(elLead);
534
		
534

  
535 535
		return node;
536 536
	}
537 537

  
......
613 613
		String strGenusName = CdmBase.deproxy(taxon.getName(), NonViralName.class).getGenusOrUninomial();
614 614
		strGoto = strGoto.replaceAll("\\([^\\(\\)]*\\)", "");  //replace all brackets
615 615
		strGoto = strGoto.replaceAll("\\s+", " "); //replace multiple whitespaces by exactly one whitespace
616
		
617
		strGoto = strGoto.trim();  
616

  
617
		strGoto = strGoto.trim();
618 618
		String[] split = strGoto.split("\\s");
619 619
		for (int i = 0; i<split.length; i++){
620 620
			String single = split[i];
......
647 647
		if (! single.matches("[A-Z]\\.?")) {
648 648
			return false;
649 649
		}else if (single.length() == 0 || strGenusName == null || strGenusName.length() == 0){
650
			return false; 
650
			return false;
651 651
		}else{
652 652
			return single.charAt(0) == strGenusName.charAt(0);
653 653
		}
......
702 702
		String chromosomesPart = getChromosomesPart(value);
703 703
		String references = value.replace(chromosomesPart, "").trim();
704 704
		chromosomesPart = chromosomesPart.replace(":", "").trim();
705
		return addDescriptionElement(state, taxon, chromosomesPart, chromosomeFeature, references);	
705
		return addDescriptionElement(state, taxon, chromosomesPart, chromosomeFeature, references);
706 706
	}
707 707

  
708 708

  
709 709
	/**
710
	 * @param ref 
711
	 * @param string 
710
	 * @param ref
711
	 * @param string
712 712
	 * @return
713 713
	 */
714 714
	private void makeOriginalSourceReferences(ISourceable sourcable, String splitter, String refAll) {
......
719 719
			String refDetail = parseReferenceYearAndDetail(ref);
720 720
			sourcable.addSource(OriginalSourceType.PrimaryTaxonomicSource, null, null, ref, refDetail);
721 721
		}
722
		
723
		
722

  
723

  
724 724
//TODO use regex instead
725 725
/*		String detailResult = null;
726 726
		String titleToParse = ref.getTitleCache();
......
729 729
		String reYear = "\\([1-2]{1}[0-9]{3}\\)";
730 730
		String reYearPeriod = reYear + "(-" + reYear + ")+";
731 731
		String reDetail = "\\.{1,10}$";
732
*/		
732
*/
733 733
	}
734 734

  
735 735

  
......
820 820
		value = replaceStart(value, "Uses");
821 821
		Feature feature = Feature.USES();
822 822
		return addDescriptionElement(state, taxon, value, feature, null);
823
		
823

  
824 824
	}
825 825

  
826 826

  
......
897 897
	 * @param state
898 898
	 * @param element
899 899
	 * @param taxon
900
	 * @param unhandledNomeclatureChildren 
900
	 * @param unhandledNomeclatureChildren
901 901
	 */
902 902
	private void handleNomenclature(EfloraImportState state, Element elNomenclature, Taxon taxon, Set<String> unhandledChildren) {
903 903
		verifyNoAttribute(elNomenclature);
904
		
904

  
905 905
		List<Element> elements = elNomenclature.getChildren();
906 906
		for (Element element : elements){
907 907
			if (element.getName().equals("homotypes")){
......
912 912
				unhandledChildren.add(element.getName());
913 913
			}
914 914
		}
915
		
915

  
916 916
	}
917 917

  
918 918

  
......
935 935
	 */
936 936
	private void handleHomotypes(EfloraImportState state, Element elHomotypes, Taxon taxon) {
937 937
		verifyNoAttribute(elHomotypes);
938
		
938

  
939 939
		List<Element> elements = elHomotypes.getChildren();
940 940
		HomotypicalGroup homotypicalGroup = null;
941 941
		for (Element element : elements){
......
945 945
				unhandledHomotypeChildren.add(element.getName());
946 946
			}
947 947
		}
948
		
948

  
949 949
	}
950 950

  
951 951
	private static Set<String> unhandledNomChildren = new HashSet<String>();
......
957 957
	 */
958 958
	private HomotypicalGroup handleNom(EfloraImportState state, Element elNom, Taxon taxon, HomotypicalGroup homotypicalGroup) {
959 959
		List<Attribute> attributes = elNom.getAttributes();
960
		
960

  
961 961
		boolean taxonBaseClassType = false;
962 962
		for (Attribute attribute : attributes){
963 963
			if (! attribute.getName().equalsIgnoreCase("class")){
......
975 975
				}else{
976 976
					logger.warn("Unhandled class value for nom: " + classValue);
977 977
				}
978
				
978

  
979 979
			}
980 980
		}
981
		
981

  
982 982
		List<Element> elements = elNom.getChildren();
983 983
		for (Element element : elements){
984 984
			if (element.getName().equals("name") || element.getName().equals("homonym") ){
......
989 989
				unhandledNomChildren.add(element.getName());
990 990
			}
991 991
		}
992
		
992

  
993 993
		return homotypicalGroup;
994
		
994

  
995 995
	}
996 996

  
997 997
	/**
998 998
	 * @param state
999 999
	 * @param elNom
1000 1000
	 * @param taxon
1001
	 * @param homotypicalGroup 
1001
	 * @param homotypicalGroup
1002 1002
	 */
1003 1003
	protected void handleTypeRef(EfloraImportState state, Element elNom, Taxon taxon, HomotypicalGroup homotypicalGroup) {
1004 1004
		verifyNoChildren(elNom);
1005 1005
		String typeRef = elNom.getTextNormalize();
1006 1006
		typeRef = removeStartingTypeRefMinus(typeRef);
1007
		
1007

  
1008 1008
		String[] split = typeRef.split(":");
1009 1009
		if (split.length < 2){
1010 1010
			logger.warn("typeRef has no ':' : " + typeRef);
......
1014 1014
			StringBuffer typeType = new StringBuffer(split[0]);
1015 1015
			String typeText = split[1].trim();
1016 1016
			TypeDesignationBase typeDesignation = getTypeDesignationAndReference(typeType);
1017
			
1017

  
1018 1018
			//Name Type Desitnations
1019 1019
			if (typeDesignation instanceof NameTypeDesignation){
1020 1020
				makeNameTypeDesignations(typeType, typeText, typeDesignation);
......
1154 1154
	private HomotypicalGroup handleNomTaxon(EfloraImportState state, Element elNom, Taxon taxon, HomotypicalGroup homotypicalGroup, boolean isSynonym) {
1155 1155
		NonViralName name = makeName(taxon, homotypicalGroup, isSynonym);
1156 1156
		String num = null;
1157
		
1157

  
1158 1158
		boolean hasGenusInfo = false;
1159 1159
		TeamOrPersonBase lastTeam = null;
1160
		
1160

  
1161 1161
		//genus
1162 1162
		List<Element> elGenus = XmlHelp.getAttributedChildListWithValue(elNom, "name", "class", "genus");
1163 1163
		if (elGenus.size() > 0){
......
1169 1169
		List<Element> elInfraRank = XmlHelp.getAttributedChildListWithValue(elNom, "name", "class", "infrank");
1170 1170
		Rank infraRank = null;
1171 1171
		infraRank = handleInfRank(name, elInfraRank, infraRank);
1172
		
1172

  
1173 1173
		//get left over elements
1174 1174
		List<Element> elements = elNom.getChildren();
1175 1175
		elements.removeAll(elInfraRank);
1176
		
1176

  
1177 1177
		for (Element element : elements){
1178 1178
			if (element.getName().equals("name")){
1179 1179
				String classValue = element.getAttributeValue("class");
......
1230 1230
				unhandledNomChildren.add(element.getName());
1231 1231
			}
1232 1232
		}
1233
		
1233

  
1234 1234
		//handle key
1235 1235
		if (! isSynonym){
1236 1236
			String taxonString = name.getNameCache();
1237
			//try to find matching lead nodes 
1237
			//try to find matching lead nodes
1238 1238
			UnmatchedLeadsKey leadsKey = UnmatchedLeadsKey.NewInstance(num, taxonString);
1239 1239
			Set<PolytomousKeyNode> matchingNodes = handleMatchingNodes(state, taxon, leadsKey);
1240 1240
			//same without using the num
......
1246 1246
				logger.warn("Taxon has num but no matching nodes exist: " + num+ ", Key: " + leadsKey.toString());
1247 1247
			}
1248 1248
		}
1249
		
1249

  
1250 1250
		//test nom element has no text
1251 1251
		if (StringUtils.isNotBlank(elNom.getTextNormalize().replace("—", "").replace("\u002d","").replace("\u2013", ""))){
1252 1252
			String strElNom = elNom.getTextNormalize();
......
1257 1257
			//System.out.println(CharUtils.unicodeEscaped(c));
1258 1258
			logger.warn("Nom tag has text: " + strElNom);
1259 1259
		}
1260
		
1260

  
1261 1261
		return name.getHomotypicalGroup();
1262 1262
	}
1263 1263

  
......
1273 1273
	}
1274 1274

  
1275 1275

  
1276
	//merge with handleNomTaxon	
1276
	//merge with handleNomTaxon
1277 1277
	private void handleHomonym(EfloraImportState state, Element elHomonym, NonViralName upperName) {
1278 1278
		verifyNoAttribute(elHomonym);
1279
		
1279

  
1280 1280
		//hommonym name
1281 1281
		BotanicalName homonymName = BotanicalName.NewInstance(upperName.getRank());
1282 1282
		homonymName.setGenusOrUninomial(upperName.getGenusOrUninomial());
......
1304 1304
			}
1305 1305
		}
1306 1306
		//TODO verify other information
1307
		
1307

  
1308 1308

  
1309 1309
		//rel
1310 1310
		boolean homonymIsLater = false;
......
1326 1326
		}else{
1327 1327
			upperName.addRelationshipToName(homonymName, relType, null);
1328 1328
		}
1329
		
1329

  
1330 1330
	}
1331 1331

  
1332 1332

  
......
1362 1362
	protected TeamOrPersonBase handleNameUsage(Taxon taxon, NonViralName<?> name, String referenceTitle, TeamOrPersonBase lastTeam) {
1363 1363
		Reference<?> ref = ReferenceFactory.newGeneric();
1364 1364
		referenceTitle = removeStartingSymbols(referenceTitle, ref);
1365
		
1365

  
1366 1366
		ref.setTitleCache(referenceTitle, true);
1367 1367
		String microReference = parseReferenceYearAndDetail(ref);
1368 1368
		TeamOrPersonBase<?> team = getReferenceAuthor(ref);
......
1371 1371
			team = lastTeam;
1372 1372
		}
1373 1373
		ref.setAuthorship(team);
1374
		
1374

  
1375 1375
		TaxonDescription description = getDescription(taxon);
1376 1376
		TextData textData = TextData.NewInstance(Feature.CITATION());
1377 1377
		textData.addSource(OriginalSourceType.PrimaryTaxonomicSource, null, null, ref, microReference, name, null);
......
1405 1405
			ref.setType(ReferenceType.Book);
1406 1406
			return;
1407 1407
		}
1408
		
1408

  
1409 1409
		title = title.substring(3);
1410 1410
		//in reference
1411 1411
		//no ,
......
1435 1435
			book.setDatePublished(ref.getDatePublished());
1436 1436
			ref.setTitle(null);
1437 1437
			ref.setInBook(book);
1438
		}		
1438
		}
1439 1439
	}
1440 1440

  
1441 1441

  
......
1467 1467
			//no author is given
1468 1468
			return null;
1469 1469
		}
1470
		
1470

  
1471 1471
		//,-references
1472 1472
		split = (referenceTitle).split(",\\s*[A-Z]");
1473 1473
		if (split.length > 1){
......
1495 1495
			return detail;
1496 1496
		}
1497 1497

  
1498
		
1498

  
1499 1499
		//non RE
1500 1500
		String reNon = "(\\s|,)non\\s";
1501 1501
		Pattern patReference = Pattern.compile(reNon);
......
1503 1503
		if (matcher.find()){
1504 1504
			int start = matcher.start();
1505 1505
			int end = matcher.end();
1506
			
1506

  
1507 1507
			if (detail != null){
1508 1508
				logger.warn("Unhandled non part: " + detail.substring(start));
1509 1509
				return detail;
1510 1510
			}
1511
			
1511

  
1512 1512
			result = detail.substring(0, start);
1513 1513

  
1514 1514
			//homonym string
1515 1515
			String homonymString = detail.substring(end);
1516
			
1516

  
1517 1517
			//hommonym name
1518 1518
			BotanicalName homonymName = BotanicalName.NewInstance(name.getRank());
1519 1519
			homonymName.setGenusOrUninomial(name.getGenusOrUninomial());
......
1529 1529
			homonymNomRef.setAuthorship(team);
1530 1530
			homonymNomRef.setTitle("");
1531 1531
			homonymNomRef.setProtectedTitleCache(false);
1532
			
1532

  
1533 1533
			//rel
1534 1534
			boolean homonymIsLater = false;
1535 1535
			NameRelationshipType relType = NameRelationshipType.LATER_HOMONYM();
......
1545 1545
			}else{
1546 1546
				name.addRelationshipToName(homonymName, relType, null);
1547 1547
			}
1548
			
1548

  
1549 1549
		}else{
1550 1550
			return detail;
1551 1551
		}
......
1566 1566
		name.setNomenclaturalReference(nomRef);
1567 1567
		microReference = parseHomonym(microReference, name);
1568 1568
		name.setNomenclaturalMicroReference(microReference);
1569
		TeamOrPersonBase  team = (TeamOrPersonBase)name.getCombinationAuthorTeam();
1569
		TeamOrPersonBase  team = name.getCombinationAuthorship();
1570 1570
		if (team == null){
1571 1571
			logger.warn("Name has nom. ref. but no author team. Name: " + name.getTitleCache() + ", Nom.Ref.: " + value);
1572 1572
		}else{
......
1581 1581
			strAuthor = strAuthor.substring(0, strAuthor.length() -1);
1582 1582
		}
1583 1583
		TeamOrPersonBase[] team = getTeam(strAuthor);
1584
		if (name.getCombinationAuthorTeam() != null && overwrite == false){
1584
		if (name.getCombinationAuthorship() != null && overwrite == false){
1585 1585
			logger.warn("Try to write combination author for a name that already has a combination author. Neglected.");
1586 1586
		}else{
1587
			name.setCombinationAuthorTeam(team[0]);
1588
			name.setExCombinationAuthorTeam(team[1]);
1587
			name.setCombinationAuthorship(team[0]);
1588
			name.setExCombinationAuthorship(team[1]);
1589 1589
		}
1590
		
1591
		
1590

  
1591

  
1592 1592
	}
1593 1593

  
1594 1594

  
......
1699 1699
			logger.warn("Brackets are missing for original combination author " + strAuthor);
1700 1700
		}
1701 1701
		TeamOrPersonBase[] basionymTeam = getTeam(strAuthor);
1702
		if (name.getBasionymAuthorTeam() != null && overwrite == false){
1702
		if (name.getBasionymAuthorship() != null && overwrite == false){
1703 1703
			logger.warn("Try to write basionym author for a name that already has a basionym author. Neglected.");
1704 1704
		}else{
1705
			name.setBasionymAuthorTeam(basionymTeam[0]);
1706
			name.setExBasionymAuthorTeam(basionymTeam[1]);
1705
			name.setBasionymAuthorship(basionymTeam[0]);
1706
			name.setExBasionymAuthorship(basionymTeam[1]);
1707 1707

  
1708 1708
		}
1709 1709
	}
1710 1710

  
1711
	private Map<String, UUID> teamMap = new HashMap<String, UUID>();
1711
	private final Map<String, UUID> teamMap = new HashMap<String, UUID>();
1712 1712
	/**
1713 1713
	 * @param elAuthors
1714 1714
	 * @param name
1715
	 * @param elNom 
1715
	 * @param elNom
1716 1716
	 */
1717 1717
	private void handleNameAuthors(Element elAuthor, NonViralName name) {
1718
		if (name.getCombinationAuthorTeam() != null){
1718
		if (name.getCombinationAuthorship() != null){
1719 1719
			logger.warn("Name already has a combination author. Name: " +  name.getTitleCache() + ", Author: " + elAuthor.getTextNormalize());
1720 1720
		}
1721 1721
		String strAuthor = elAuthor.getValue().trim();
......
1726 1726
			logger.warn("Author has brackets. Basionym authors should be handled in separate tags: " + strAuthor);
1727 1727
		}
1728 1728
		TeamOrPersonBase[] team = getTeam(strAuthor);
1729
		name.setCombinationAuthorTeam(team[0]);
1730
		name.setExCombinationAuthorTeam(team[1]);
1729
		name.setCombinationAuthorship(team[0]);
1730
		name.setExCombinationAuthorship(team[1]);
1731 1731
	}
1732 1732

  
1733 1733

  
......
1740 1740
		String[] split = strAuthor.split(" ex ");
1741 1741
		String strBaseAuthor = null;
1742 1742
		String strExAuthor = null;
1743
		
1743

  
1744 1744
		if (split.length == 2){
1745
			strBaseAuthor = split[1]; 
1746
			strExAuthor = split[0];	
1745
			strBaseAuthor = split[1];
1746
			strExAuthor = split[0];
1747 1747
		}else if (split.length == 1){
1748 1748
			strBaseAuthor = split[0];
1749 1749
		}else{
......
1761 1761
				result[1].setTitleCache(strExAuthor, true);
1762 1762
				teamMap.put(strExAuthor, result[1].getUuid());
1763 1763
			}
1764
		
1765
		}	
1764

  
1765
		}
1766 1766
		return result;
1767 1767
	}
1768 1768

  
......
1807 1807

  
1808 1808
	private void handleDescription(EfloraImportState state, Element elDescription, Taxon taxon, Set<String> unhandledChildren) {
1809 1809
		verifyNoAttribute(elDescription);
1810
		
1810

  
1811 1811
		List<Element> elements = elDescription.getChildren();
1812 1812
		for (Element element : elements){
1813 1813
			if (element.getName().equalsIgnoreCase("char")){
......
1816 1816
				logger.warn("Unhandled description child: " + element.getName());
1817 1817
			}
1818 1818
		}
1819
		
1819

  
1820 1820
	}
1821
	
1822
	
1821

  
1822

  
1823 1823
	/**
1824 1824
	 * @param state
1825 1825
	 * @param element
......
1839 1839
					String value = element.getValue();
1840 1840
					addDescriptionElement(state, taxon, value, feature, null);
1841 1841
				}
1842
				
1842

  
1843 1843
			}
1844 1844
		}
1845
		
1845

  
1846 1846
		List<Element> elements = element.getChildren();
1847 1847
		if (! elements.isEmpty()){
1848 1848
			logger.warn("Char has unhandled children");
......
1867 1867

  
1868 1868
	/**
1869 1869
	 * @param classValue
1870
	 * @param state 
1870
	 * @param state
1871 1871
	 * @return
1872
	 * @throws UndefinedTransformerMethodException 
1872
	 * @throws UndefinedTransformerMethodException
1873 1873
	 */
1874 1874
	private Feature getFeature(String classValue, EfloraImportState state) {
1875 1875
		UUID uuid;
......
1896 1896
	 * @param state
1897 1897
	 * @param element
1898 1898
	 * @param taxon
1899
	 * @param unhandledTitleClassess 
1899
	 * @param unhandledTitleClassess
1900 1900
	 */
1901 1901
	private void handleTitle(EfloraImportState state, Element element, Taxon taxon, Set<String> unhandledTitleClassess) {
1902 1902
		// attributes
......
1947 1947
		UUID uuidTitle = EfloraTransformer.uuidTitle;
1948 1948
		ExtensionType titleExtension = this.getExtensionType(state, uuidTitle, "title", "title", "title");
1949 1949
		taxon.addExtension(element.getTextNormalize(), titleExtension);
1950
		
1950

  
1951 1951
	}
1952 1952

  
1953 1953

  
1954 1954
	/**
1955 1955
	 * @param value
1956
	 * @param taxonNameBase 
1956
	 * @param taxonNameBase
1957 1957
	 */
1958 1958
	private void handleSubGenus(String value, TaxonNameBase taxonNameBase) {
1959 1959
		String name = value.replace("Subgenus", "").trim();
1960 1960
		((NonViralName)taxonNameBase).setInfraGenericEpithet(name);
1961 1961
	}
1962
	
1962

  
1963 1963
	/**
1964 1964
	 * @param value
1965
	 * @param taxonNameBase 
1965
	 * @param taxonNameBase
1966 1966
	 */
1967 1967
	private void handleSection(String value, TaxonNameBase taxonNameBase) {
1968 1968
		String name = value.replace("Section", "").trim();
1969 1969
		((NonViralName)taxonNameBase).setInfraGenericEpithet(name);
1970 1970
	}
1971
	
1971

  
1972 1972
	/**
1973 1973
	 * @param value
1974
	 * @param taxonNameBase 
1974
	 * @param taxonNameBase
1975 1975
	 */
1976 1976
	private void handleSpecies(String value, TaxonNameBase taxonNameBase) {
1977 1977
		//do nothing
1978 1978
	}
1979
	
1979

  
1980 1980
	/**
1981 1981
	 * @param value
1982
	 * @param taxonNameBase 
1982
	 * @param taxonNameBase
1983 1983
	 */
1984 1984
	private void handleVariety(String value, TaxonNameBase taxonNameBase) {
1985 1985
		//do nothing
1986 1986
	}
1987
	
1987

  
1988 1988
	/**
1989 1989
	 * @param value
1990
	 * @param taxonNameBase 
1990
	 * @param taxonNameBase
1991 1991
	 */
1992 1992
	private void handleSubSpecies(String value, TaxonNameBase taxonNameBase) {
1993 1993
		//do nothing
1994 1994
	}
1995 1995

  
1996
	
1997
	private Pattern rexGenusAuthor = Pattern.compile("(\\[|\\().*(\\]|\\))");
1998
	
1996

  
1997
	private final Pattern rexGenusAuthor = Pattern.compile("(\\[|\\().*(\\]|\\))");
1998

  
1999 1999
	/**
2000 2000
	 * @param value
2001
	 * @param taxonNameBase 
2001
	 * @param taxonNameBase
2002 2002
	 */
2003 2003
	protected void handleGenus(String value, TaxonNameBase taxonName) {
2004 2004
		Matcher matcher = rexGenusAuthor.matcher(value);
......
2011 2011
			Credit credit = Credit.NewInstance(team, null);
2012 2012
			taxonName.addCredit(credit);
2013 2013
//			NonViralName nvn = (NonViralName)taxonName;
2014
//			nvn.setCombinationAuthorTeam(team);
2014
//			nvn.setCombinationAuthorship(team);
2015 2015
//			nvn.setGenusOrUninomial(genus);
2016 2016
		}else{
2017 2017
			logger.info("No Author match for " + value);
2018 2018
		}
2019 2019
	}
2020
	
2020

  
2021 2021

  
2022 2022
	/**
2023 2023
	 * @param taxon
2024 2024
	 * @param lastTaxon
2025 2025
	 */
2026 2026
	private void handleTaxonRelation(EfloraImportState state, Taxon taxon, Taxon lastTaxon) {
2027
		
2027

  
2028 2028
		Classification tree = getTree(state);
2029 2029
		if (lastTaxon == null){
2030 2030
			tree.addChildTaxon(taxon, null, null);
......
2059 2059

  
2060 2060
	/**
2061 2061
	 * @param state
2062
	 * @return 
2062
	 * @return
2063 2063
	 */
2064 2064
	private Classification getTree(EfloraImportState state) {
2065 2065
		Classification result = state.getTree(null);
......
2090 2090

  
2091 2091

  
2092 2092
	/**
2093
	 * @param state 
2093
	 * @param state
2094 2094
	 * @param taxon
2095 2095
	 * @param value
2096 2096
	 * @param feature
2097
	 * @return 
2097
	 * @return
2098 2098
	 */
2099 2099
	private TextData addDescriptionElement(EfloraImportState state, Taxon taxon, String value, Feature feature, String references) {
2100 2100
		TextData textData = TextData.NewInstance(feature);
......
2135 2135
			logger.warn(element.getName() + " has unhandled attributes: " + attributes.get(0).getValue() + "..." );
2136 2136
		}
2137 2137
	}
2138
	
2138

  
2139 2139
	/**
2140 2140
	 * @param elNomenclature
2141 2141
	 */
2142 2142
	protected void verifyNoChildren(Element element) {
2143 2143
		verifyNoChildren(element, false);
2144 2144
	}
2145
	
2145

  
2146 2146
	/**
2147 2147
	 * @param elNomenclature
2148 2148
	 */
......
2160 2160
			}
2161 2161
		}
2162 2162
	}
2163
	
2164
	
2163

  
2164

  
2165 2165

  
2166 2166
	/**
2167 2167
	 * Parses the nomenclatural status from the references titleCache. If a nomenclatural status
2168
	 * exists it is added to the name and the nom. status part of the references title cache is 
2168
	 * exists it is added to the name and the nom. status part of the references title cache is
2169 2169
	 * removed. Requires protected title cache.
2170 2170
	 * @param ref
2171 2171
	 * @param nonViralName
2172 2172
	 */
2173 2173
	protected void parseNomStatus(Reference ref, NonViralName nonViralName) {
2174 2174
		String titleToParse = ref.getTitleCache();
2175
		
2175

  
2176 2176
		String noStatusTitle = parser.parseNomStatus(titleToParse, nonViralName, true);
2177 2177
		if (! noStatusTitle.equals(titleToParse)){
2178 2178
			ref.setTitleCache(noStatusTitle, true);
2179 2179
		}
2180 2180
	}
2181 2181

  
2182
	
2182

  
2183 2183
	/**
2184 2184
	 * Extracts the date published part and returns micro reference
2185 2185
	 * @param ref
......
2194 2194
		String oneMonth = "(Feb.|Dec.|March|June|July)";
2195 2195
		String reYear = oneMonth + "?\\s?[1-2]\\s?[0-9]\\s?[0-9]\\s?[0-9]\\s?";
2196 2196
		String secondYear = "(\\s?[1-2]\\s?[0-9])?\\s?[0-9]\\s?[0-9]\\s?";
2197
		
2197

  
2198 2198
		String reYearPeriod = "\\(" + reYear + "(\\-" + secondYear + ")?\\)";
2199 2199
		String reDetail = "\\.{1,10}$";
2200
		
2200

  
2201 2201
		//pattern for the whole string
2202 2202
		Pattern patReference = Pattern.compile(/*reReference +*/ reYearPeriod /*+ reDetail */);
2203 2203
		Matcher matcher = patReference.matcher(titleToParse);
2204 2204
		if (matcher.find()){
2205 2205
			int start = matcher.start();
2206 2206
			int end = matcher.end();
2207
			
2207

  
2208 2208
			//title and other information precedes the year part
2209 2209
			String title = titleToParse.substring(0, start).trim();
2210 2210
			//detail follows the year part
2211 2211
			String detail = titleToParse.substring(end).trim();
2212
			
2212

  
2213 2213
			//time period
2214 2214
			String strPeriod = matcher.group().trim();
2215 2215
			strPeriod = strPeriod.substring(1, strPeriod.length()-1);   //remove brackets
......
2222 2222
				strPeriod = strPeriod.substring(0, end) + " " + strPeriod.substring(end);
2223 2223
				startMonth = getMonth(strPeriod.substring(0, end));
2224 2224
			}
2225
			
2225

  
2226 2226
			TimePeriod datePublished = TimePeriodParser.parseString(strPeriod);
2227 2227
			if (startMonth != null){
2228 2228
				datePublished.setStartMonth(startMonth);
......
2238 2238
			logger.warn("Could not parse reference: " +  titleToParse);
2239 2239
		}
2240 2240
		return detailResult;
2241
		
2241

  
2242 2242
	}
2243 2243

  
2244
	
2245
	
2244

  
2245

  
2246 2246
	private Integer getMonth(String month) {
2247 2247
		if (month.startsWith("Jan")){
2248 2248
			return 1;
......
2278 2278
	/* (non-Javadoc)
2279 2279
	 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
2280 2280
	 */
2281
	protected boolean isIgnore(EfloraImportState state){
2281
	@Override
2282
    protected boolean isIgnore(EfloraImportState state){
2282 2283
		return ! state.getConfig().isDoTaxa();
2283 2284
	}
2284 2285

  

Also available in: Unified diff