Project

General

Profile

Revision 3429c491

ID3429c4917a44f1f3acc2bec4b2cecb157d4d9b19
Parent 818cfd67
Child 223b2cd6

Added by Andreas Müller over 1 year ago

ref #2342 ref 6755 fix some issues in higherClassification handling in DwC-A export

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/out/DwcaTaxonExport.java
214 214
		record.setTaxonConceptId(taxonBase.getUuid());
215 215

  
216 216
		//Classification
217
		if (state.getConfig().isWithHigherClassification()
218
		        && taxonBase.isInstanceOf(Taxon.class)){
217
		if (state.getConfig().isWithHigherClassification()){
219 218
			//all classification and rank specific fields are meant to represent the classification
220
			Taxon taxon = CdmBase.deproxy(taxonBase, Taxon.class);
221
		    handleHigherClassification(state, record, taxon, classification);
219
		    handleHigherClassification(state, record, acceptedTaxon, classification);
222 220

  
223 221
			//... higher ranks
224
			handleUninomialOrGenus(record, name);
225
			if (name.getRank() != null &&  name.getRank().equals(Rank.SUBGENUS())){
226
				record.setSubgenus(name.getNameCache());
227
			}
222
//			handleUninomialOrGenus(record, name);
223
//			if (name.getRank() != null &&  name.getRank().equals(Rank.SUBGENUS())){
224
//				record.setSubgenus(name.getNameCache());
225
//			}
228 226
			//record.setSubgenus(name.getInfraGenericEpithet());
229 227
		}
230 228
		if (name.getRank() != null &&  (name.getRank().isSupraGeneric() || name.getRank().isGenus())){
......
314 312
        record.setOrder(nameOf(node.getAncestorOfRank(Rank.ORDER())));
315 313
        record.setFamily(nameOf(node.getAncestorOfRank(Rank.FAMILY())));
316 314
        record.setGenus(nameOf(node.getAncestorOfRank(Rank.GENUS())));
315
        record.setSubgenus(nameOf(node.getAncestorOfRank(Rank.SUBGENUS())));
317 316
        List<TaxonNode> ancestors = node.getAncestorList();
318 317
        String higherClassification = higherClassificationString(ancestors);
319 318
        record.setHigherClassification(higherClassification);
......
341 340
    private String nameOf(TaxonNode node) {
342 341
        if (node != null && node.getTaxon()!= null){
343 342
            Taxon taxon = node.getTaxon();
344
            if (taxon.getName()!= null){
345
                return taxon.getName().getTitleCache();
343
            TaxonName name = taxon.getName();
344
            if (name!= null){
345
                if (isNotBlank(name.getNameCache())){
346
                    return name.getNameCache();
347
                }else{
348
                    return name.getTitleCache();
349
                }
346 350
            }else{
347 351
                return taxon.getTitleCache();
348 352
            }
......
383 387
		}
384 388
	}
385 389

  
386
	/**
387
	 * @param record
388
	 * @param name
389
	 */
390
	private void handleUninomialOrGenus(DwcaTaxonRecord record, INonViralName name) {
391
		//epitheta
392
		String firstEpi = name.getGenusOrUninomial();
393
		if (StringUtils.isNotBlank(firstEpi)){
394
			Rank rank = name.getRank();
395
			if (rank != null){
396
				if (rank.isLower(Rank.GENUS())){
397
					record.setGenus(firstEpi);
398
				}else if (rank.equals(Rank.GENUS())){
399
					record.setGenus(firstEpi);
400
				}else if (rank.equals(Rank.KINGDOM())){
401
					record.setKingdom(firstEpi);
402
				}else if (rank.equals(Rank.PHYLUM())){
403
					record.setPhylum(firstEpi);
404
				}else if (rank.equals(Rank.CLASS())){
405
					record.setClazz(firstEpi);
406
				}else if (rank.equals(Rank.ORDER())){
407
					record.setOrder(firstEpi);
408
				}else if (rank.equals(Rank.FAMILY())){
409
					record.setFamily(firstEpi);
410
				}else{
411
					// !!!
412
					String message = "Rank not covered. Set uninomial as genus instead: " + rank.getLabel();
413
					logger.warn(message);
390
//	/**
391
//	 * @param record
392
//	 * @param name
393
//	 */
394
//	private void handleUninomialOrGenus(DwcaTaxonRecord record, INonViralName name) {
395
//		//epitheta
396
//		String firstEpi = name.getGenusOrUninomial();
397
//		if (StringUtils.isNotBlank(firstEpi)){
398
//			Rank rank = name.getRank();
399
//			if (rank != null){
400
//				if (rank.isLower(Rank.GENUS())){
414 401
//					record.setGenus(firstEpi);
415
				}
416

  
417
			}
418
		}
419
	}
402
//				}else if (rank.equals(Rank.GENUS())){
403
//					record.setGenus(firstEpi);
404
//				}else if (rank.equals(Rank.KINGDOM())){
405
//					record.setKingdom(firstEpi);
406
//				}else if (rank.equals(Rank.PHYLUM())){
407
//					record.setPhylum(firstEpi);
408
//				}else if (rank.equals(Rank.CLASS())){
409
//					record.setClazz(firstEpi);
410
//				}else if (rank.equals(Rank.ORDER())){
411
//					record.setOrder(firstEpi);
412
//				}else if (rank.equals(Rank.FAMILY())){
413
//					record.setFamily(firstEpi);
414
//				}else{
415
//					// !!!
416
//					String message = "Rank not covered. Set uninomial as genus instead: " + rank.getLabel();
417
//					logger.warn(message);
418
////					record.setGenus(firstEpi);
419
//				}
420
//
421
//			}
422
//		}
423
//	}
420 424

  
421 425

  
422 426
	/**
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/taxon/TaxonNode.java
831 831
    }
832 832

  
833 833
    /**
834
     * Retrieves the first ancestor of the given rank
834
     * Retrieves the first ancestor of the given rank. If any of the ancestors
835
     * has no taxon or has a rank > the given rank <code>null</code> is returned.
836
     * If <code>this</code> taxon is already of given rank this taxon is returned.
835 837
     * @param rank the rank the ancestor should have
836 838
     * @return the first found instance of a parent taxon node with the given rank
837 839
     */
......
841 843
            return null;
842 844
        }
843 845
        TaxonName name = CdmBase.deproxy(taxon.getName());
844
        if (name.getRank().isHigher(rank)){
845
        	return null;
846
        }
847
        if (name.getRank().equals(rank)){
848
        	return this;
846
        if (name != null && name.getRank() != null){
847
            if (name.getRank().isHigher(rank)){
848
                return null;
849
            }
850
            if (name.getRank().equals(rank)){
851
                return this;
852
            }
849 853
        }
850 854

  
851 855
        if(this.getParent() != null){

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)