Project

General

Profile

« Previous | Next » 

Revision 51171c9d

Added by Andreas Müller about 13 years ago

last updates for Taxon Excel Import and moving all success variables to state

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/common/CdmImportBase.java
589 589
	 * @return
590 590
	 */
591 591
	public TaxonDescription getTaxonDescription(Taxon taxon, boolean isImageGallery, boolean createNewIfNotExists) {
592
		Reference ref = null;
593
		return getTaxonDescription(taxon, ref, isImageGallery, createNewIfNotExists);
594
	}
595
	
596
	/**
597
	 * Like {@link #getTaxonDescription(Taxon, boolean, boolean)}
598
	 * Only matches a description if the given reference is a source of the description.<BR>
599
	 * If a new description is created the given reference will be added as a source.
600
	 * 
601
	 * @see #getTaxonDescription(Taxon, boolean, boolean)
602
	 */
603
	public TaxonDescription getTaxonDescription(Taxon taxon, Reference ref, boolean isImageGallery, boolean createNewIfNotExists) {
592 604
		TaxonDescription result = null;
593 605
		Set<TaxonDescription> descriptions= taxon.getDescriptions();
594 606
		for (TaxonDescription description : descriptions){
595 607
			if (description.isImageGallery() == isImageGallery){
596
				result = description;
597
				break;
608
				if (hasCorrespondingSource(ref, description)){
609
					result = description;
610
					break;
611
				}
598 612
			}
599 613
		}
600 614
		if (result == null && createNewIfNotExists){
601 615
			result = TaxonDescription.NewInstance(taxon);
602 616
			result.setImageGallery(isImageGallery);
617
			if (ref != null){
618
				result.addSource(null, null, ref, null);
619
			}
603 620
		}
604 621
		return result;
605 622
	}
623

  
624

  
625
	/**
626
	 * Returns true, if this description has a source with a citation equal to the given reference.
627
	 * Returns true if the given reference is null.
628
	 * @param ref
629
	 * @param description
630
	 */
631
	private boolean hasCorrespondingSource(Reference ref, TaxonDescription description) {
632
		if (ref != null){
633
			for (IdentifiableSource source : description.getSources()){
634
				if (ref.equals(source.getCitation())){
635
					return true;
636
				}
637
			}
638
			return false;
639
		}
640
		return true;
641
		
642
	}
606 643
	
607 644
	
608 645
	/**

Also available in: Unified diff