Project

General

Profile

Revision e5605065

IDe5605065d74f6e654ef2190a0c6f7294bd52fe7e
Parent 9f1aa368
Child 4fb554ff

Added by Andreas Müller almost 3 years ago

ref #6089 Remove all calls and methods for taxonomicChildrenCount and taxonomicParentCache

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/taxonx/TaxonXNomenclatureImport.java
50 50
 */
51 51
@Component
52 52
public class TaxonXNomenclatureImport extends CdmIoBase<TaxonXImportState> implements ICdmIO<TaxonXImportState> {
53
	private static final Logger logger = Logger.getLogger(TaxonXNomenclatureImport.class);
53
    private static final long serialVersionUID = 796115831082828758L;
54

  
55
    private static final Logger logger = Logger.getLogger(TaxonXNomenclatureImport.class);
54 56

  
55 57
	@SuppressWarnings("unused")
56 58
	private static int modCount = 10000;
......
320 322
	}
321 323

  
322 324

  
323
	private TaxonNameBase getChildrenNameType(TaxonNameBase name, String typeStr, String authorStr){
324
		TaxonNameBase result = null;
325
		Set<TaxonBase> list = name.getTaxonBases();
326
		for (TaxonBase taxonBase : list){
327
			Taxon taxon;
328
			if (taxonBase.isInstanceOf(Taxon.class)){
329
				taxon = CdmBase.deproxy(taxonBase, Taxon.class);
330
			}else{
331
				Synonym syn = CdmBase.deproxy(taxonBase, Synonym.class);
332
				taxon = syn.getAcceptedTaxa().iterator().next();
333
			}
334
			Set<Taxon> children = taxon.getTaxonomicChildren();
335
			for (Taxon child: children){
336
				NonViralName childName = (CdmBase.deproxy(child.getName(), NonViralName.class));
337
				if (childName.getNameCache().equals(typeStr)){
338
					if (compareAuthorship(childName, authorStr)){
339
						return childName;
340
					}
341
				}
342
			}
343
		}
344
		return result;
345
	}
325
//	private TaxonNameBase getChildrenNameType(TaxonNameBase name, String typeStr, String authorStr){
326
//		TaxonNameBase result = null;
327
//		Set<TaxonBase> list = name.getTaxonBases();
328
//		for (TaxonBase taxonBase : list){
329
//			Taxon taxon;
330
//			if (taxonBase.isInstanceOf(Taxon.class)){
331
//				taxon = CdmBase.deproxy(taxonBase, Taxon.class);
332
//			}else{
333
//				Synonym syn = CdmBase.deproxy(taxonBase, Synonym.class);
334
//				taxon = syn.getAcceptedTaxa().iterator().next();
335
//			}
336
//			Set<Taxon> children = taxon.getTaxonomicChildren();
337
//			for (Taxon child: children){
338
//				NonViralName childName = (CdmBase.deproxy(child.getName(), NonViralName.class));
339
//				if (childName.getNameCache().equals(typeStr)){
340
//					if (compareAuthorship(childName, authorStr)){
341
//						return childName;
342
//					}
343
//				}
344
//			}
345
//		}
346
//		return result;
347
//	}
346 348

  
347 349
	private boolean compareAuthorship(NonViralName typeName, String authorStr){
348 350
		 boolean result = false;
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/taxon/Taxon.java
615 615
        this.relationsFromThisTaxon.remove(rel);
616 616
        Taxon fromTaxon = rel.getFromTaxon();
617 617
        Taxon toTaxon = rel.getToTaxon();
618
        // check if this removes the taxonomical parent. If so, also remove shortcut to the higher taxon
619
        if (rel.getType().equals(TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN()) ){
620
            if (fromTaxon != null && fromTaxon.equals(this)){
621
                this.taxonomicParentCache = null;
622
            }else if (toTaxon != null && toTaxon.equals(this)){
623
                this.setTaxonomicChildrenCount(computeTaxonomicChildrenCount());
624
            }
625
        }
618

  
626 619
        //delete Relationship from other related Taxon
627 620
        if (fromTaxon != this){
628 621
            rel.setToTaxon(null);  //remove this Taxon from relationship
......
672 665
                    if (toTaxon!=null){
673 666
                        toTaxon.addTaxonRelation(rel);
674 667
                    }
675
                    // check if this sets the taxonomical parent. If so, remember a shortcut to this taxon
676
                    if (rel.getType().equals(TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN()) && toTaxon!=null ){
677
                        this.taxonomicParentCache = toTaxon;
678
                    }
679 668
                }else if (this.equals(toTaxon)){
680 669
                    relationsToThisTaxon.add(rel);
681 670
                    // also add relation to other taxon object
682 671
                    if (fromTaxon!=null){
683 672
                        fromTaxon.addTaxonRelation(rel);
684 673
                    }
685
                    if (rel.getType().equals(TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN()) && fromTaxon!=null ){
686
                        this.taxonomicChildrenCount++;
687
                    }
688

  
689 674
                }
690 675
            }else if (toTaxon == null || fromTaxon == null){
691 676
                if (toTaxon == null){
......
694 679
                    if (fromTaxon!= null){
695 680
                        fromTaxon.addTaxonRelation(rel);
696 681
                    }
697
                    if (rel.getType().equals(TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN()) && fromTaxon!=null ){
698
                        this.taxonomicChildrenCount++;
699
                    }
700 682
                }else if (fromTaxon == null && toTaxon != null){
701 683
                    fromTaxon = this;
702 684
                    relationsFromThisTaxon.add(rel);
703
                    if (toTaxon!=null){
704
                        toTaxon.addTaxonRelation(rel);
705
                    }
706
                    if (rel.getType().equals(TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN()) && toTaxon!=null ){
707
                        this.taxonomicParentCache = toTaxon;
708
                    }
685
                    toTaxon.addTaxonRelation(rel);
709 686
                }
710 687
            }
711 688
        }
712 689
    }
713 690

  
714
    /* (non-Javadoc)
715
     * @see eu.etaxonomy.cdm.model.common.IRelated#addRelationship(eu.etaxonomy.cdm.model.common.RelationshipBase)
716
     */
691

  
717 692
    @Override
718 693
    @Deprecated //for inner use by RelationshipBase only
719 694
    public void addRelationship(RelationshipBase rel){
......
807 782
    }
808 783

  
809 784
    /**
810
     * Creates a new {@link TaxonRelationship taxon relationship} (with {@link TaxonRelationshipType taxon relationship type}
811
     * "taxonomically included in") instance where <i>this</i> taxon plays the target
812
     * role (parent) and adds it to the set of
813
     * {@link #getRelationsToThisTaxon() "taxon relationships to"} belonging to <i>this</i> taxon.
814
     * The taxon relationship will also be added to the set of
815
     * {@link #getRelationsFromThisTaxon() "taxon relationships from"} belonging to the second taxon
816
     * (child) involved in the created relationship.<P>
817
     * Since the taxon relationship concerns the modifications
818
     * of the number of {@link #getTaxonomicChildrenCount() childrens} for <i>this</i> taxon and
819
     * of the {@link #getTaxonomicParent() parent taxon} for the child taxon will be stored.
820
     * The {@link name.Rank rank} of the taxon name used as a parent taxon must be higher
821
     * than the rank of the taxon name used as a child taxon.
822
     *
823
     * @param child			the taxon which plays the source role (child) in the new taxon relationship
824
     * @param citation		the reference source for the new taxon relationship
825
     * @param microcitation	the string with the details describing the exact localisation within the reference
826
     * @see    	   			#setTaxonomicParent(Taxon, Reference, String)
827
     * @see    	   			#addTaxonRelation(Taxon, TaxonRelationshipType, Reference, String)
828
     * @see    	   			#addTaxonRelation(TaxonRelationship)
829
     * @see    	   			#getTaxonRelations()
830
     * @see    	   			#getRelationsFromThisTaxon()
831
     * @see    	   			#getRelationsToThisTaxon()
832
     * @see    	   			#getTaxonomicParent()
833
     * @see    	   			#getTaxonomicChildrenCount()
834
     */
835
    @Deprecated //will be removed in future versions. Use Classification/TaxonNode instead
836
    public void addTaxonomicChild(Taxon child, Reference citation, String microcitation){
837
        if (child == null){
838
            throw new NullPointerException("Child Taxon is 'null'");
839
        }else{
840
            child.setTaxonomicParent(this, citation, microcitation);
841
        }
842
    }
843

  
844
    /**
845
     * Removes one {@link TaxonRelationship taxon relationship} with {@link TaxonRelationshipType taxon relationship type}
846
     * "taxonomically included in" and with the given child taxon playing the
847
     * source role from the set of {@link #getRelationsToThisTaxon() "taxon relationships to"} belonging
848
     * to <i>this</i> taxon. The taxon relationship will also be removed from the set
849
     * of {@link #getRelationsFromThisTaxon() "taxon relationships from"} belonging to the child taxon.
850
     * Furthermore the inherited RelatedFrom and RelatedTo attributes of the
851
     * taxon relationship will be nullified.<P>
852
     * Since the taxon relationship concerns the classification modifications
853
     * of the number of {@link #getTaxonomicChildrenCount() childrens} for <i>this</i> taxon and
854
     * of the {@link #getTaxonomicParent() parent taxon} for the child taxon will be stored.
855
     *
856
     * @param  child	the taxon playing the source role in the relationship to be removed
857
     * @see    	    	#removeTaxonRelation(TaxonRelationship)
858
     * @see    			#getRelationsToThisTaxon()
859
     * @see    			#getRelationsFromThisTaxon()
860
     * @see    	    	#getTaxonomicParent()
861
     * @see    	    	#getTaxonomicChildrenCount()
862
     * @see    			eu.etaxonomy.cdm.model.common.RelationshipBase#getRelatedFrom()
863
     * @see    			eu.etaxonomy.cdm.model.common.RelationshipBase#getRelatedTo()
864
     *
865
     */
866
    @Deprecated //will be removed in future versions. Use classification/TaxonNode instead
867
    public void removeTaxonomicChild(Taxon child){
868
        Set<TaxonRelationship> taxRels = this.getTaxonRelations();
869
        for (TaxonRelationship taxRel : taxRels ){
870
            if (taxRel.getType().equals(TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN())
871
                && taxRel.getFromTaxon().equals(child)){
872
                this.removeTaxonRelation(taxRel);
873
            }
874
        }
875
    }
876

  
877
    /**
878
     * Returns the taxon which is the next higher taxon (parent) of <i>this</i> taxon
879
     * within the classification and which is stored in the
880
     * TaxonomicParentCache attribute. Each taxon can have only one parent taxon.
881
     * The child taxon and the parent taxon play the source respectively the
882
     * target role in one {@link TaxonRelationship taxon relationship} with
883
     * {@link TaxonRelationshipType taxon relationship type} "taxonomically included in".
884
     * The {@link name.Rank rank} of the taxon name used as a parent taxon must be higher
885
     * than the rank of the taxon name used as a child taxon.
886
     *
887
     * @see  #setTaxonomicParent(Taxon, Reference, String)
888
     * @see  #getTaxonomicChildren()
889
     * @see  #getTaxonomicChildrenCount()
890
     * @see  #getRelationsFromThisTaxon()
891
     */
892
    @Deprecated //will be removed in future versions. Use Classification/TaxonNode instead
893
    public Taxon getTaxonomicParent() {
894
        return this.taxonomicParentCache;
895
    }
896

  
897
    /**
898
     * Sets the taxononomic parent of <i>this</i> taxon to null.
899
     * Note that this method does not handle taxonomic relationships.
900
     */
901
    @Deprecated //will be removed in future versions. Use Classification/TaxonNode instead
902
    public void nullifyTaxonomicParent() {
903
        this.taxonomicParentCache = null;
904
    }
905

  
906
    /**
907
     * Replaces both the taxonomic parent cache with the given new parent taxon
908
     * and the corresponding taxon relationship with a new {@link TaxonRelationship taxon relationship}
909
     * (with {@link TaxonRelationshipType taxon relationship type} "taxonomically included in") instance.
910
     * In the new taxon relationship <i>this</i> taxon plays the source role (child).
911
     * This method creates and adds the new taxon relationship to the set of
912
     * {@link #getRelationsFromThisTaxon() "taxon relationships from"} belonging to <i>this</i> taxon.
913
     * The taxon relationship will also be added to the set of
914
     * {@link #getRelationsToThisTaxon() "taxon relationships to"} belonging to the second taxon
915
     * (parent) involved in the new relationship.<P>
916
     * Since the taxon relationship concerns the classification modifications
917
     * of the {@link #getTaxonomicParent() parent taxon} for <i>this</i> taxon and of the number of
918
     * {@link #getTaxonomicChildrenCount() childrens} for the child taxon will be stored.
919
     *
920
     * @param newParent		the taxon which plays the target role (parent) in the new taxon relationship
921
     * @param citation		the reference source for the new taxon relationship
922
     * @param microcitation	the string with the details describing the exact localisation within the reference
923
     * @see    	   			#removeTaxonRelation(TaxonRelationship)
924
     * @see    	   			#getTaxonomicParent()
925
     * @see    	   			#addTaxonRelation(Taxon, TaxonRelationshipType, Reference, String)
926
     * @see    	   			#addTaxonRelation(TaxonRelationship)
927
     * @see    	   			#getTaxonRelations()
928
     * @see    	   			#getRelationsFromThisTaxon()
929
     * @see    	   			#getRelationsToThisTaxon()
930
     * @see    	   			#getTaxonomicChildrenCount()
931
     */
932
    @Deprecated //will be removed in future versions. Use Classification/TaxonNode instead
933
    public void setTaxonomicParent(Taxon newParent, Reference citation, String microcitation){
934
        //remove previously existing parent relationship!!!
935
        Taxon oldParent = this.getTaxonomicParent();
936
        Set<TaxonRelationship> taxRels = this.getTaxonRelations();
937
        for (TaxonRelationship taxRel : taxRels ){
938
            if (taxRel.getType().equals(TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN()) && taxRel.getToTaxon().equals(oldParent)){
939
                this.removeTaxonRelation(taxRel);
940
            }
941
        }
942
        //add new parent
943
        if (newParent != null){
944
            addTaxonRelation(newParent, TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN(),citation,microcitation);
945
        }
946
    }
947

  
948
    /**
949
     * Returns the set of taxa which have <i>this</i> taxon as next higher taxon
950
     * (parent) within the classification. Each taxon can have several child
951
     * taxa. The child taxon and the parent taxon play the source respectively
952
     * the target role in one {@link TaxonRelationship taxon relationship} with
953
     * {@link TaxonRelationshipType taxon relationship type} "taxonomically included in".
954
     * The {@link name.Rank rank} of the taxon name used as a parent taxon must be higher
955
     * than the rank of the taxon name used as a child taxon.
956
     *
957
     * @see  #getTaxonomicParent()
958
     * @see  #addTaxonomicChild(Taxon, Reference, String)
959
     * @see  #getTaxonomicChildrenCount()
960
     * @see  #getRelationsToThisTaxon()
961
     */
962
    @Transient
963
    @Deprecated //will be removed in future versions. Use Classification/TaxonNode instead
964
    public Set<Taxon> getTaxonomicChildren() {
965
        Set<Taxon> taxa = new HashSet<Taxon>();
966
        Set<TaxonRelationship> rels = this.getRelationsToThisTaxon();
967
        for (TaxonRelationship rel: rels){
968
            TaxonRelationshipType tt = rel.getType();
969
            TaxonRelationshipType incl = TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN();
970
            if (tt.equals(incl)){
971
                taxa.add(rel.getFromTaxon());
972
            }
973
        }
974
        return taxa;
975
    }
976

  
977
    /**
978
     * Returns the number of taxa which have <i>this</i> taxon as next higher taxon
979
     * (parent) within the classification and the number of which is stored in
980
     * the TaxonomicChildrenCount attribute. Each taxon can have several child
981
     * taxa. The child taxon and the parent taxon play the source respectively
982
     * the target role in one {@link TaxonRelationship taxon relationship} with
983
     * {@link TaxonRelationshipType taxon relationship type} "taxonomically included in".
984
     * The {@link name.Rank rank} of the taxon name used as a parent taxon must be higher
985
     * than the rank of the taxon name used as a child taxon.
986
     *
987
     * @see  #getTaxonomicChildren()
988
     * @see  #getRelationsToThisTaxon()
989
     */
990
    @Deprecated //will be removed in future versions. Use Classification/TaxonNode instead
991
    public int getTaxonomicChildrenCount(){
992
        return taxonomicChildrenCount;
993
    }
994

  
995
    /**
996
     * @see  #getTaxonomicChildrenCount()
997
     */
998
    @Deprecated //will be removed in future versions. Use Classification/TaxonNode instead
999
    public void setTaxonomicChildrenCount(int taxonomicChildrenCount) {
1000
        this.taxonomicChildrenCount = taxonomicChildrenCount;
1001
    }
1002

  
1003
    /**
1004
     * Returns the boolean value indicating whether <i>this</i> taxon has at least one
1005
     * taxonomic child taxon within the classification (true) or not (false).
1006
     *
1007
     * @see  #getTaxonomicChildrenCount()
1008
     * @see  #getTaxonomicChildren()
1009
     */
1010
    @Deprecated //will be removed in future versions. Use Classification/TaxonNode instead
1011
    @Transient
1012
    public boolean hasTaxonomicChildren(){
1013
        return this.taxonomicChildrenCount > 0;
1014
    }
1015

  
1016
    @Deprecated //will be removed in future versions. Use Classification/TaxonNode instead
1017
    private int computeTaxonomicChildrenCount(){
1018
        int count = 0;
1019
        for (TaxonRelationship rel: this.getRelationsToThisTaxon()){
1020
            if (rel.getType().equals(TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN())){
1021
                count++;
1022
            }
1023
        }
1024
        return count;
1025
    }
1026

  
1027

  
1028
    /**
1029 785
     * Returns the boolean value indicating whether <i>this</i> taxon is a misaplication
1030 786
     * (misapplied name) for at least one other taxon.
1031 787
     */
cdmlib-model/src/test/java/eu/etaxonomy/cdm/datagenerator/TaxonGenerator.java
9 9

  
10 10
package eu.etaxonomy.cdm.datagenerator;
11 11

  
12
import java.util.Random;
13

  
14 12
import eu.etaxonomy.cdm.model.agent.Person;
15 13
import eu.etaxonomy.cdm.model.common.Language;
16 14
import eu.etaxonomy.cdm.model.common.LanguageString;
......
19 17
import eu.etaxonomy.cdm.model.description.TextData;
20 18
import eu.etaxonomy.cdm.model.name.BotanicalName;
21 19
import eu.etaxonomy.cdm.model.name.Rank;
22
//import eu.etaxonomy.cdm.model.reference.Book;
23
//import eu.etaxonomy.cdm.model.reference.Database;
24 20
import eu.etaxonomy.cdm.model.reference.Reference;
25 21
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
26 22
import eu.etaxonomy.cdm.model.taxon.Synonym;
......
38 34
	private static String[] epitheta = {"vulgaris", "magdalena", "officinalis", "alba", "negra", "communa", "alpina", "rotundifolia", "greutheriana", "helventica", "allemania", "franca"};
39 35
	private static String[] ranks = {"subsp", "var", "f"};
40 36

  
41
	private Random rnd = new Random();
42

  
43 37
	public static Taxon getTestTaxon(){
44 38
		Person deCandolle = Person.NewInstance();
45 39
		deCandolle.setTitleCache("DC.", true);
......
71 65
        botSpecies.setCombinationAuthorship(Person.NewInstance());
72 66
        botSpecies.getCombinationAuthorship().setNomenclaturalTitle("Pau");
73 67
        Taxon childTaxon = Taxon.NewInstance(botSpecies, sec);
74
        childTaxon.setTaxonomicParent(genusTaxon, citationRef, "456");
68
//        childTaxon.setTaxonomicParent(genusTaxon, citationRef, "456");
75 69

  
76 70
        //homotypic synonym of childTaxon1
77 71
        BotanicalName botSpecies4= BotanicalName.NewInstance(Rank.SPECIES());
......
91 85
        botSpecies2.setCombinationAuthorship(Person.NewInstance());
92 86
        botSpecies2.getCombinationAuthorship().setNomenclaturalTitle("Zahn");
93 87
        Taxon childTaxon2 = Taxon.NewInstance(botSpecies2, sec);
94
        childTaxon2.setTaxonomicParent(genusTaxon, citationRef, "499");
88
//        childTaxon2.setTaxonomicParent(genusTaxon, citationRef, "499");
95 89

  
96 90
        //heterotypic synonym of childTaxon2
97 91
        BotanicalName botSpecies3= BotanicalName.NewInstance(Rank.SPECIES());
cdmlib-model/src/test/java/eu/etaxonomy/cdm/model/taxon/TaxonTest.java
38 38
import eu.etaxonomy.cdm.test.unit.EntityTestBase;
39 39

  
40 40
public class TaxonTest extends EntityTestBase {
41
	private static final Logger logger = Logger.getLogger(TaxonTest.class);
42

  
41
	@SuppressWarnings("unused")
42
    private static final Logger logger = Logger.getLogger(TaxonTest.class);
43 43

  
44 44
	private Reference sec;
45 45
	private Reference misSec;
......
85 85
//		newTree.addParentChild(rootT, child1, sec, "p.998");
86 86
//		newTree.addParentChild(rootT, child2, sec, "p.987");
87 87

  
88
		rootT.addTaxonomicChild(child1, sec, "p.998");
89
		rootT.addTaxonomicChild(child2, sec, "p.987");
90 88
		// synonymy
91 89
		syn1=Synonym.NewInstance(name1,sec);
92 90
		syn2=Synonym.NewInstance(name2,sec);
......
105 103
	}
106 104

  
107 105
	@Test
108
	public void testAddTaxonomicChild() {
109

  
110
		rootT.addTaxonomicChild(freeT, null, null);
111
		Assert.assertEquals(Integer.valueOf(3), Integer.valueOf(rootT.getTaxonomicChildren().size()));
112
	}
113

  
114
	@Test
115
	public void testGetTaxonomicParent() {
116
		assertEquals(rootT, child2.getTaxonomicParent());
117
	}
118

  
119
	@Test
120
	public void testSetTaxonomicParent() {
121
		child2.setTaxonomicParent(child1, null, null);
122
		assertEquals(child1, child2.getTaxonomicParent());
123
	}
124

  
125
	@Test
126
	public void testGetTaxonomicChildren() {
127
		Set<Taxon> kids=rootT.getTaxonomicChildren();
128
		assertTrue(kids.size()==2 && kids.contains(child1) && kids.contains(child2));
129
	}
130

  
131
	@Test
132
	public void testHasTaxonomicChildren() {
133
		assertFalse(child2.hasTaxonomicChildren());
134
		assertTrue(rootT.hasTaxonomicChildren());
135
		rootT.removeTaxonomicChild(child1);
136
		assertTrue(rootT.hasTaxonomicChildren());
137
		rootT.removeTaxonomicChild(child2);
138
		assertFalse(rootT.hasTaxonomicChildren());
139
	}
140

  
141
	@Test
142
	public void testGetTaxonomicChildrenCount() {
143
		assertEquals(0, child2.getTaxonomicChildrenCount());
144
		assertEquals(2, rootT.getTaxonomicChildrenCount());
145
		rootT.removeTaxonomicChild(child1);
146
		assertEquals(1, rootT.getTaxonomicChildrenCount());
147
		rootT.removeTaxonomicChild(child2);
148
		assertEquals(0, rootT.getTaxonomicChildrenCount());
149
	}
150

  
151
	@Test
152 106
	public void testIsMisappliedName() {
153 107
		assertFalse(child2.isMisapplication());
154 108
		assertFalse(rootT.isMisapplication());
......
190 144
	}
191 145

  
192 146
	/**
193
	 * Test method for {@link eu.etaxonomy.cdm.model.taxon.Taxon#getDescriptions()}.
194
	 */
195
	@Test
196
	public void testGetDescriptions() {
197
		logger.warn("Not yet implemented");
198
	}
199

  
200
	/**
201
	 * Test method for {@link eu.etaxonomy.cdm.model.taxon.Taxon#setDescriptions(java.util.Set)}.
202
	 */
203
	@Test
204
	public void testSetDescriptions() {
205
		logger.warn("Not yet implemented");
206
	}
207

  
208
	/**
209
	 * Test method for {@link eu.etaxonomy.cdm.model.taxon.Taxon#addDescription(eu.etaxonomy.cdm.model.description.TaxonDescription)}.
210
	 */
211
	@Test
212
	public void testAddDescription() {
213
		logger.warn("Not yet implemented");
214
	}
215

  
216
	/**
217
	 * Test method for {@link eu.etaxonomy.cdm.model.taxon.Taxon#removeDescription(eu.etaxonomy.cdm.model.description.TaxonDescription)}.
218
	 */
219
	@Test
220
	public void testRemoveDescription() {
221
		logger.warn("Not yet implemented");
222
	}
223

  
224
	/**
225
	 * Test method for {@link eu.etaxonomy.cdm.model.taxon.Taxon#getSynonymRelations()}.
226
	 */
227
	@Test
228
	public void testGetSynonymRelations() {
229
		logger.warn("Not yet implemented");
230
	}
231

  
232
	/**
233
	 * Test method for {@link eu.etaxonomy.cdm.model.taxon.Taxon#setSynonymRelations(java.util.Set)}.
234
	 */
235
	@Test
236
	public void testSetSynonymRelations() {
237
		logger.warn("Not yet implemented");
238
	}
239

  
240
	/**
241
	 * Test method for {@link eu.etaxonomy.cdm.model.taxon.Taxon#addSynonymRelation(eu.etaxonomy.cdm.model.taxon.SynonymRelationship)}.
242
	 */
243
	@Test
244
	public void testAddSynonymRelation() {
245
		logger.warn("Not yet implemented");
246
	}
247

  
248
	/**
249
	 * Test method for {@link eu.etaxonomy.cdm.model.taxon.Taxon#removeSynonymRelation(eu.etaxonomy.cdm.model.taxon.SynonymRelationship)}.
250
	 */
251
	@Test
252
	public void testRemoveSynonymRelation() {
253
		logger.warn("Not yet implemented");
254
	}
255

  
256
	/**
257
	 * Test method for {@link eu.etaxonomy.cdm.model.taxon.Taxon#getRelationsFromThisTaxon()}.
258
	 */
259
	@Test
260
	public void testGetRelationsFromThisTaxon() {
261
		logger.warn("Not yet implemented");
262
	}
263

  
264
	/**
265
	 * Test method for {@link eu.etaxonomy.cdm.model.taxon.Taxon#setRelationsFromThisTaxon(java.util.Set)}.
266
	 */
267
	@Test
268
	public void testSetRelationsFromThisTaxon() {
269
		logger.warn("Not yet implemented");
270
	}
271

  
272
	/**
273
	 * Test method for {@link eu.etaxonomy.cdm.model.taxon.Taxon#getRelationsToThisTaxon()}.
274
	 */
275
	@Test
276
	public void testGetRelationsToThisTaxon() {
277
		logger.warn("Not yet implemented");
278
	}
279

  
280
	/**
281
	 * Test method for {@link eu.etaxonomy.cdm.model.taxon.Taxon#setRelationsToThisTaxon(java.util.Set)}.
282
	 */
283
	@Test
284
	public void testSetRelationsToThisTaxon() {
285
		logger.warn("Not yet implemented");
286
	}
287

  
288
	/**
289 147
	 * Test method for {@link eu.etaxonomy.cdm.model.taxon.Taxon#getTaxonRelations()}.
290 148
	 */
291 149
	@Test
......
326 184
		assertEquals("There should be exactly one taxon relationships", 1, taxon.getTaxonRelations().size());
327 185
	}
328 186

  
329
	/**
330
	 * Test method for {@link eu.etaxonomy.cdm.model.taxon.Taxon#addRelationship(eu.etaxonomy.cdm.model.common.RelationshipBase)}.
331
	 */
332
	@Test
333
	public void testAddRelationship() {
334
		logger.warn("Not yet implemented");
335
	}
336

  
337
	/**
338
	 * Test method for {@link eu.etaxonomy.cdm.model.taxon.Taxon#addTaxonRelation(eu.etaxonomy.cdm.model.taxon.Taxon, eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType, eu.etaxonomy.cdm.model.reference.Reference, java.lang.String)}.
339
	 */
340
	@Test
341
	public void testAddTaxonRelationTaxonTaxonRelationshipTypeReferenceBaseString() {
342
		logger.warn("Not yet implemented");
343
	}
344

  
345
	/**
346
	 * Test method for {@link eu.etaxonomy.cdm.model.taxon.Taxon#addMisappliedName(eu.etaxonomy.cdm.model.taxon.Taxon, eu.etaxonomy.cdm.model.reference.Reference, java.lang.String)}.
347
	 */
348
	@Test
349
	public void testAddMisappliedName() {
350
		logger.warn("Not yet implemented");
351
	}
352

  
353

  
354
	/**
355
	 * Test method for {@link eu.etaxonomy.cdm.model.taxon.Taxon#hasSynonyms()}.
356
	 */
357
	@Test
358
	public void testHasSynonyms() {
359
		logger.warn("Not yet implemented");
360
	}
361

  
362
	/**
363
	 * Test method for {@link eu.etaxonomy.cdm.model.taxon.Taxon#getMisappliedNames()}.
364
	 */
365
	@Test
366
	public void testGetMisappliedNames() {
367
		logger.warn("Not yet implemented");
368
	}
369

  
370

  
371
	/**
372
	 * Test method for {@link eu.etaxonomy.cdm.model.taxon.Taxon#getSynonymsSortedByType()}.
373
	 */
374
	@Test
375
	public void testGetSynonymsSortedByType() {
376
		logger.warn("Not yet implemented");
377
	}
378

  
379
	/**
380
	 * Test method for {@link eu.etaxonomy.cdm.model.taxon.Taxon#addSynonym(eu.etaxonomy.cdm.model.taxon.Synonym, eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType)}.
381
	 */
382
	@Test
383
	public void testAddSynonymSynonymSynonymRelationshipType() {
384
		logger.warn("Not yet implemented");
385
	}
386

  
387
	/**
388
	 * Test method for {@link eu.etaxonomy.cdm.model.taxon.Taxon#addSynonym(eu.etaxonomy.cdm.model.taxon.Synonym, eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType, eu.etaxonomy.cdm.model.reference.Reference, java.lang.String)}.
389
	 */
390
	@Test
391
	public void testAddSynonymSynonymSynonymRelationshipTypeReferenceBaseString() {
392
		logger.warn("Not yet implemented");
393
	}
394

  
395
	/**
396
	 * Test method for {@link eu.etaxonomy.cdm.model.taxon.Taxon#addSynonymName(eu.etaxonomy.cdm.model.name.TaxonNameBase, eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType)}.
397
	 */
398
	@Test
399
	public void testAddSynonymNameTaxonNameBaseSynonymRelationshipType() {
400
		logger.warn("Not yet implemented");
401
	}
402

  
403
	/**
404
	 * Test method for {@link eu.etaxonomy.cdm.model.taxon.Taxon#addSynonymName(eu.etaxonomy.cdm.model.name.TaxonNameBase, eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType, eu.etaxonomy.cdm.model.reference.Reference, java.lang.String)}.
405
	 */
406
	@Test
407
	public void testAddSynonymNameTaxonNameBaseSynonymRelationshipTypeReferenceBaseString() {
408
		logger.warn("Not yet implemented");
409
	}
410

  
411
	/**
412
	 * Test method for {@link eu.etaxonomy.cdm.model.taxon.Taxon#addHeterotypicSynonymName(eu.etaxonomy.cdm.model.name.TaxonNameBase)}.
413
	 */
414
	@Test
415
	public void testAddHeterotypicSynonymNameTaxonNameBase() {
416
		logger.warn("Not yet implemented");
417
	}
418

  
419
	/**
420
	 * Test method for {@link eu.etaxonomy.cdm.model.taxon.Taxon#addHeterotypicSynonymName(eu.etaxonomy.cdm.model.name.TaxonNameBase, eu.etaxonomy.cdm.model.name.HomotypicalGroup, eu.etaxonomy.cdm.model.reference.Reference, java.lang.String)}.
421
	 */
422
	@Test
423
	public void testAddHeterotypicSynonymNameTaxonNameBaseHomotypicalGroupReferenceBaseString() {
424
		logger.warn("Not yet implemented");
425
	}
426

  
427
	/**
428
	 * Test method for {@link eu.etaxonomy.cdm.model.taxon.Taxon#addHomotypicSynonymName(eu.etaxonomy.cdm.model.name.TaxonNameBase, eu.etaxonomy.cdm.model.reference.Reference, java.lang.String)}.
429
	 */
430
	@Test
431
	public void testAddHomotypicSynonymName() {
432
		logger.warn("Not yet implemented");
433
	}
434

  
435
	/**
436
	 * Test method for {@link eu.etaxonomy.cdm.model.taxon.Taxon#addHomotypicSynonym(eu.etaxonomy.cdm.model.taxon.Synonym, eu.etaxonomy.cdm.model.reference.Reference, java.lang.String)}.
437
	 */
438
	@Test
439
	public void testAddHomotypicSynonym() {
440
		logger.warn("Not yet implemented");
441
	}
442

  
443
	/**
444
	 * Test method for {@link eu.etaxonomy.cdm.model.taxon.Taxon#removeSynonym(eu.etaxonomy.cdm.model.taxon.Synonym)}.
445
	 */
446
	@Test
447
	public void testRemoveSynonym() {
448
		logger.warn("Not yet implemented");
449
	}
450

  
451
	/**
452
	 * Test method for {@link eu.etaxonomy.cdm.model.taxon.Taxon#iterator()}.
453
	 */
454
	@Test
455
	public void testIterator() {
456
		logger.warn("Not yet implemented");
457
	}
458

  
459
	/**
460
	 * Test method for {@link eu.etaxonomy.cdm.model.taxon.Taxon#getHomotypicSynonymsByHomotypicGroup()}.
461
	 */
462
	@Test
463
	public void testGetHomotypicSynonymsByHomotypicGroup() {
464
		logger.warn("Not yet implemented");
465
	}
466

  
467
	/**
468
	 * Test method for {@link eu.etaxonomy.cdm.model.taxon.Taxon#getHomotypicSynonymsByHomotypicRelationship()}.
469
	 */
470
	@Test
471
	public void testGetHomotypicSynonymsByHomotypicRelationship() {
472
		logger.warn("Not yet implemented");
473
	}
474

  
475
	/**
476
	 * Test method for {@link eu.etaxonomy.cdm.model.taxon.Taxon#getHomotypicSynonymyGroups()}.
477
	 */
478
	@Test
479
	public void testGetHomotypicSynonymyGroups() {
480
		logger.warn("Not yet implemented");
481
	}
482

  
483
	/**
484
	 * Test method for {@link eu.etaxonomy.cdm.model.taxon.Taxon#getHeterotypicSynonymyGroups()}.
485
	 */
486
	@Test
487
	public void testGetHeterotypicSynonymyGroups() {
488
		logger.warn("Not yet implemented");
489
	}
490

  
491 187

  
492 188
	@Test
493 189
	public void testAddRemoveSynonymInSameGroup(){
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/taxon/TaxonDaoHibernateImpl.java
66 66
import eu.etaxonomy.cdm.persistence.dao.name.ITaxonNameDao;
67 67
import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonDao;
68 68
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
69
import eu.etaxonomy.cdm.persistence.fetch.CdmFetch;
70 69
import eu.etaxonomy.cdm.persistence.query.MatchMode;
71 70
import eu.etaxonomy.cdm.persistence.query.OrderHint;
72 71

  
......
98 97
//        this.alternativeSpellingSuggestionParser = alternativeSpellingSuggestionParser;
99 98
//    }
100 99

  
101
    @Override
102
    public List<Taxon> getRootTaxa(Reference sec) {
103
        return getRootTaxa(sec, CdmFetch.FETCH_CHILDTAXA(), true, false);
104
    }
105

  
106
    @Override
107
    public List<Taxon> getRootTaxa(Rank rank, Reference sec, CdmFetch cdmFetch, Boolean onlyWithChildren, Boolean withMisapplications, List<String> propertyPaths) {
108
        checkNotInPriorView("TaxonDaoHibernateImpl.getRootTaxa(Rank rank, Reference sec, CdmFetch cdmFetch, Boolean onlyWithChildren, Boolean withMisapplications)");
109
        if (onlyWithChildren == null){
110
            onlyWithChildren = true;
111
        }
112
        if (withMisapplications == null){
113
            withMisapplications = true;
114
        }
115
        if (cdmFetch == null){
116
            cdmFetch = CdmFetch.NO_FETCH();
117
        }
118

  
119
        Criteria crit = getSession().createCriteria(Taxon.class);
120

  
121
        crit.setFetchMode("name", FetchMode.JOIN);
122
        crit.createAlias("name", "name");
123

  
124
        if (rank != null) {
125
            crit.add(Restrictions.eq("name.rank", rank));
126
        }else{
127
            crit.add(Restrictions.isNull("taxonomicParentCache"));
128
        }
129

  
130
        if (sec != null){
131
            crit.add(Restrictions.eq("sec", sec) );
132
        }
133

  
134
        if (! cdmFetch.includes(CdmFetch.FETCH_CHILDTAXA())){
135
            logger.info("Not fetching child taxa");
136
            //TODO overwrite LAZY (SELECT) does not work (bug in hibernate?)
137
            crit.setFetchMode("relationsToThisTaxon.fromTaxon", FetchMode.LAZY);
138
        }
139

  
140
        List<Taxon> results = new ArrayList<Taxon>();
141
        @SuppressWarnings("unchecked")
142
        List<Taxon> taxa = crit.list();
143
        for(Taxon taxon : taxa){
144

  
145

  
146
            //childTaxa
147
            //TODO create restriction instead
148
            // (a) not using cache fields
149
            /*Hibernate.initialize(taxon.getRelationsFromThisTaxon());
150
            if (onlyWithChildren == false || taxon.getRelationsFromThisTaxon().size() > 0){
151
                if (withMisapplications == true || ! taxon.isMisappliedName()){
152
                    defaultBeanInitializer.initialize(taxon, propertyPaths);
153
                    results.add(taxon);
154
                }
155
            }*/
156
            // (b) using cache fields
157
            if (onlyWithChildren == false || taxon.hasTaxonomicChildren()){
158
                if (withMisapplications == true || ! taxon.isMisapplication()){
159
                    defaultBeanInitializer.initialize(taxon, propertyPaths);
160
                    results.add(taxon);
161
                }
162
            }
163
        }
164
        return results;
165
    }
166

  
167
    @Override
168
    public List<Taxon> getRootTaxa(Reference sec, CdmFetch cdmFetch, Boolean onlyWithChildren, Boolean withMisapplications) {
169
        return getRootTaxa(null, sec, cdmFetch, onlyWithChildren, withMisapplications, null);
170
    }
171 100

  
172 101
    @Override
173 102
    public List<TaxonBase> getTaxaByName(String queryString, Reference sec) {
......
979 908
            for (Iterator<TaxonRelationship> iterator = ((Taxon)taxonBase).getRelationsFromThisTaxon().iterator(); iterator.hasNext();){
980 909
                TaxonRelationship relationFromThisTaxon = iterator.next();
981 910

  
982
                // decrease children count of taxonomic parent by one
983
                if (relationFromThisTaxon.getType().equals(TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN())) {
984
                    Taxon toTaxon = relationFromThisTaxon.getToTaxon(); // parent
985
                    if (toTaxon != null) {
986
                        toTaxon.setTaxonomicChildrenCount(toTaxon.getTaxonomicChildrenCount() - 1);
987
                    }
988
                }
989 911
            }
990 912
        }
991 913

  
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/taxon/ITaxonDao.java
36 36
import eu.etaxonomy.cdm.persistence.dao.common.ITitledDao;
37 37
import eu.etaxonomy.cdm.persistence.dao.initializer.IBeanInitializer;
38 38
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
39
import eu.etaxonomy.cdm.persistence.fetch.CdmFetch;
40 39
import eu.etaxonomy.cdm.persistence.query.MatchMode;
41 40
import eu.etaxonomy.cdm.persistence.query.OrderHint;
42 41

  
......
225 224
    MatchMode matchMode, Set<NamedArea> namedAreas, Integer pageSize,
226 225
    Integer pageNumber, List<String> propertyPaths);
227 226

  
228

  
229
    /**
230
     * Computes all Taxon instances that do not have a taxonomic parent and has at least one child.
231
     * @return The List<Taxon> of root taxa.
232
     * @deprecated obsolete when using classification
233
     */
234
    @Deprecated
235
    public List<Taxon> getRootTaxa(Reference sec);
236

  
237

  
238
    /**
239
     * Computes all Taxon instances that do not have a taxonomic parent.
240
     * @param sec The concept reference that the taxon belongs to
241
     * @param cdmFetch not used yet !! TODO
242
     * @param onlyWithChildren if true only taxa are returned that have taxonomic children. <Br>Default: true.
243
     * @param withMisaplications if false only taxa are returned that have no isMisappliedNameFor relationship.
244
     * <Br>Default: true.
245
     * @return The List<Taxon> of root taxa.
246
     * @deprecated obsolete when using classification
247
     */
248
    @Deprecated
249
    public List<Taxon> getRootTaxa(Reference sec, CdmFetch cdmFetch, Boolean onlyWithChildren, Boolean withMisapplications);
250

  
251

  
252 227
    /**
253
     * Computes all Taxon instances which name is of a certain Rank.
254
     *
255
     * @param rank
256
     *            The rank of the taxon name
257
     * @param sec
258
     *            The concept reference that the taxon belongs to
259
     * @param cdmFetch
260
     *            not used yet !! TODO
261
     * @param onlyWithChildren
262
     *            if true only taxa are returned that have taxonomic children. <Br>
263
     *            Default: true.
264
     * @param withMisaplications
265
     *            if false only taxa are returned that have no
266
     *            isMisappliedNameFor relationship.
267
     * @param propertyPaths
268
     *            properties to be initialized, For detailed description and
269
     *            examples <b>please refer to:</b>
270
     *            {@link IBeanInitializer#initialize(Object, List)}. <Br>
271
     *            Default: true.
272
     * @return The List<Taxon> of root taxa.
273
     * @deprecated obsolete when using classification
274
     */
275
    @Deprecated
276
    public List<Taxon>
277
    getRootTaxa(Rank rank, Reference sec, CdmFetch cdmFetch, Boolean onlyWithChildren, Boolean withMisapplications, List<String> propertyPaths);
278

  
279
        /**
280 228
     * TODO necessary?
281 229
     * @param pagesize max maximum number of returned taxa
282 230
     * @param page page to start, with 0 being first page
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/persistence/dao/hibernate/taxon/TaxonDaoHibernateImplTest.java
13 13
import static org.junit.Assert.assertFalse;
14 14
import static org.junit.Assert.assertNotNull;
15 15
import static org.junit.Assert.assertNull;
16
import static org.junit.Assert.assertSame;
17 16
import static org.junit.Assert.assertTrue;
18 17
import static org.junit.Assert.fail;
19 18

  
......
43 42
import eu.etaxonomy.cdm.model.common.MarkerType;
44 43
import eu.etaxonomy.cdm.model.location.NamedArea;
45 44
import eu.etaxonomy.cdm.model.name.NonViralName;
46
import eu.etaxonomy.cdm.model.name.Rank;
47 45
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
48 46
import eu.etaxonomy.cdm.model.reference.Reference;
49 47
import eu.etaxonomy.cdm.model.taxon.Classification;
......
64 62
import eu.etaxonomy.cdm.persistence.dao.taxon.IClassificationDao;
65 63
import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonDao;
66 64
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
67
import eu.etaxonomy.cdm.persistence.fetch.CdmFetch;
68 65
import eu.etaxonomy.cdm.persistence.query.GroupByCount;
69 66
import eu.etaxonomy.cdm.persistence.query.GroupByDate;
70 67
import eu.etaxonomy.cdm.persistence.query.Grouping;
......
163 160
    }
164 161

  
165 162
    /**
166
     * Test method for
167
     * {@link eu.etaxonomy.cdm.persistence.dao.hibernate.taxon.TaxonDaoHibernateImpl#getRootTaxa(eu.etaxonomy.cdm.model.reference.Reference)}
168
     * .
169
     */
170
    @Test
171
    @DataSet
172
    public void testGetRootTaxa() {
173
        Reference sec1 = referenceDao.findById(1);
174
        assert sec1 != null : "sec1 must exist";
175
        Reference sec2 = referenceDao.findById(2);
176
        assert sec2 != null : "sec2 must exist";
177

  
178
        List<Taxon> rootTaxa = taxonDao.getRootTaxa(sec1);
179
        assertNotNull("getRootTaxa should return a List", rootTaxa);
180
        assertFalse("The list should not be empty", rootTaxa.isEmpty());
181
        assertEquals("There should be one root taxon", 1, rootTaxa.size());
182

  
183
        rootTaxa = taxonDao.getRootTaxa(sec1, CdmFetch.FETCH_CHILDTAXA(), true, false);
184
        assertNotNull("getRootTaxa should return a List", rootTaxa);
185
        assertFalse("The list should not be empty", rootTaxa.isEmpty());
186
        assertEquals("There should be one root taxon", 1, rootTaxa.size());
187

  
188
        rootTaxa = taxonDao.getRootTaxa(Rank.GENUS(), sec1, CdmFetch.FETCH_CHILDTAXA(), true, false, null);
189
        assertNotNull("getRootTaxa should return a List", rootTaxa);
190
        assertFalse("The list should not be empty", rootTaxa.isEmpty());
191
        assertEquals("There should be one root taxon", 1, rootTaxa.size());
192

  
193
        rootTaxa = taxonDao.getRootTaxa(Rank.FAMILY(), sec2, CdmFetch.FETCH_CHILDTAXA(), true, false, null);
194
        if (logger.isDebugEnabled()) {
195
            logger.debug("Root taxa rank Family (" + rootTaxa.size() + "):");
196
            for (Taxon taxon : rootTaxa) {
197
                logger.debug(taxon.getTitleCache());
198
            }
199
        }
200
        assertEquals("There should be one root taxon rank Family", 1, rootTaxa.size());
201
        rootTaxa = taxonDao.getRootTaxa(Rank.GENUS(), sec2, CdmFetch.FETCH_CHILDTAXA(), true, false, null);
202
        assertNotNull("getRootTaxa should return a List", rootTaxa);
203
        assertFalse("The list should not be empty", rootTaxa.isEmpty());
204
        if (logger.isDebugEnabled()) {
205
            logger.debug("Root taxa rank Genus (" + rootTaxa.size() + "):");
206
            for (Taxon taxon : rootTaxa) {
207
                logger.debug(taxon.getTitleCache());
208
            }
209
        }
210
        assertEquals("There should be 22 root taxa rank Genus", 22, rootTaxa.size());
211

  
212
        rootTaxa = taxonDao.getRootTaxa(Rank.SPECIES(), sec2, CdmFetch.FETCH_CHILDTAXA(), true, false, null);
213
        if (logger.isDebugEnabled()) {
214
            logger.debug("Root taxa rank Species (" + rootTaxa.size() + "):");
215
            for (Taxon taxon : rootTaxa) {
216
                logger.debug(taxon.getTitleCache());
217
            }
218
        }
219
        assertEquals("There should be 4 root taxa rank Species", 3, rootTaxa.size());
220
    }
221

  
222
    /**
223 163
     * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.taxon.TaxonDaoHibernateImpl#getTaxaByName(java.lang.String, eu.etaxonomy.cdm.model.reference.Reference)}.
224 164
     */
225 165
    @Test
......
791 731
    }
792 732

  
793 733
    @Test
794
    @DataSet
795
    public void testDeleteWithChildren() {
796
        Taxon taxonWithChildren = (Taxon)taxonDao.findByUuid(mimas);
797
        assert taxonWithChildren != null : "taxon must exist";
798
        assertEquals(taxonWithChildren.getTaxonomicChildrenCount(), 2);
799
        Taxon parent = (Taxon)taxonDao.findByUuid(sphingidae);
800
        assertSame(taxonWithChildren.getTaxonomicParent(), parent);
801
        assertEquals(parent.getTaxonomicChildrenCount(), 204);
802
        taxonDao.delete(taxonWithChildren);
803
        assertEquals(parent.getTaxonomicChildrenCount(), 203);
804
    }
805

  
806
    @Test
807 734
    @DataSet("TaxonDaoHibernateImplTest.testFindDeleted.xml")
808 735
    public void testFindDeleted() {
809 736
        TaxonBase<?> taxon = taxonDao.findByUuid(acherontia);
......
929 856
        Taxon taxon = (Taxon)taxonDao.findByUuid(acherontiaLachesis);
930 857
        assert taxon != null : "taxon cannot be null";
931 858

  
932
        assertEquals("getTaxonomicChildrenCount should return 1 in this view",1,taxon.getTaxonomicChildrenCount());
933
        assertEquals("getRelationsToThisTaxon should contain 1 TaxonRelationship in this view",1,taxon.getRelationsToThisTaxon().size());
859
       assertEquals("getRelationsToThisTaxon should contain 1 TaxonRelationship in this view",1,taxon.getRelationsToThisTaxon().size());
934 860
    }
935 861

  
936 862
    @Test
......
940 866
        Taxon taxon = (Taxon)taxonDao.findByUuid(acherontiaLachesis);
941 867
        assert taxon != null : "taxon cannot be null";
942 868

  
943
        assertEquals("getTaxonomicChildrenCount should return 0 in this view",0,taxon.getTaxonomicChildrenCount());
944 869
        assertTrue("getRelationsToThisTaxon should contain 0 TaxonRelationship in this view",taxon.getRelationsToThisTaxon().isEmpty());
945 870
    }
946 871

  
cdmlib-remote/src/test/java/eu/etaxonomy/cdm/remote/dto/assembler/lsid/AssemblerTest.java
126 126
        for(int i = 0; i < 10; i++) {
127 127
            Taxon child = Taxon.NewInstance(name, (Reference)sec);
128 128
            child.setLsid(new LSID("urn:lsid:example.org:taxonconcepts:" + (2 + i )));
129
            taxon.addTaxonomicChild(child, null,null);
129
//            taxon.addTaxonomicChild(child, null,null);
130 130
        }
131 131

  
132 132

  
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/ITaxonService.java
35 35
import eu.etaxonomy.cdm.model.common.DefinedTerm;
36 36
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
37 37
import eu.etaxonomy.cdm.model.common.Language;
38
import eu.etaxonomy.cdm.model.common.OrderedTermVocabulary;
39 38
import eu.etaxonomy.cdm.model.common.RelationshipBase;
40 39
import eu.etaxonomy.cdm.model.common.RelationshipBase.Direction;
41 40
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
......
59 58
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
60 59
import eu.etaxonomy.cdm.persistence.dao.initializer.IBeanInitializer;
61 60
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
62
import eu.etaxonomy.cdm.persistence.fetch.CdmFetch;
63 61
import eu.etaxonomy.cdm.persistence.query.MatchMode;
64 62
import eu.etaxonomy.cdm.persistence.query.OrderHint;
65 63

  
......
67 65
public interface ITaxonService extends IIdentifiableEntityService<TaxonBase>{
68 66

  
69 67
    /**
70
     * Computes all Taxon instances that do not have a taxonomic parent.
71
     * @param sec The concept reference that the taxon belongs to
72
     *
73
     * @param onlyWithChildren if true only taxa are returned that have taxonomic children. <Br>Default: true.
74
     * @return The List<Taxon> of root taxa.
75
     * @deprecated obsolete when using classification
76
     */
77
    @Deprecated
78
    public List<Taxon> getRootTaxa(Reference sec, CdmFetch cdmFetch, boolean onlyWithChildren);
79

  
80
    /**
81
     * Computes all Taxon instances which name is of a certain Rank.
82
     * @param rank The rank of the taxon name
83
     * @param sec The concept reference that the taxon belongs to
84
     * @param onlyWithChildren if true only taxa are returned that have taxonomic children. <Br>Default: true.
85
     * @param withMisapplications if false taxa that have at least one misapplied name relationship in which they are
86
     * the misapplied name are not returned.<Br>Default: true.
87
     * @param propertyPaths
88
     *            properties to be initialized, For detailed description and
89
     *            examples <b>please refer to:</b>
90
     *            {@link IBeanInitializer#initialize(Object, List)}. <Br>
91
     *            Default: true.
92
     * @return The List<Taxon> of root taxa.
93
     * @deprecated obsolete when using classification
94
     */
95
    @Deprecated
96
    public List<Taxon> getRootTaxa(Rank rank, Reference sec, boolean onlyWithChildren, boolean withMisapplications, List<String> propertyPaths);
97

  
98
    /**
99 68
     * Computes all relationships.
100 69
     * @param limit
101 70
     * @param start
......
105 74
    public List<RelationshipBase> getAllRelationships(int limit, int start);
106 75

  
107 76
    /**
108
     * Returns TaxonRelationshipType vocabulary
109
     * @return
110
     * @deprecated use TermService#getVocabulary(VocabularyType) instead
111
     */
112
    @Deprecated
113
    public OrderedTermVocabulary<TaxonRelationshipType> getTaxonRelationshipTypeVocabulary();
114

  
115
    /**
116 77
     * Returns a list of taxa that matches the name string and the sec reference
117 78
     * @param name the name string to search for
118 79
     * @param sec the taxons sec reference
......
215 176
  public 	Synonym changeRelatedTaxonToSynonym(Taxon fromTaxon, Taxon toTaxon,
216 177
             TaxonRelationshipType oldRelationshipType,
217 178
            SynonymRelationshipType synonymRelationshipType) throws DataChangeNoRollbackException;
218
    /**
219
     * Deletes all synonym relationships of a given synonym. If taxon is given
220
     * only those relationships to the taxon are deleted.
221
     *
222
     * @param syn
223
     *            the synonym
224
     * @param taxon
225
     * @return
226
     * @deprecated This method must no longer being used since the
227
     *             SynonymRelationship is annotated at the {@link Taxon} and at
228
     *             the {@link Synonym} with <code>orphanDelete=true</code>. Just
229
     *             remove the from and to entities from the relationship and
230
     *             hibernate will care for the deletion. Using this method can cause
231
     *             <code>StaleStateException</code> (see http://dev.e-taxonomy.eu/trac/ticket/3797)
232
     *
233
     */
234
    @Deprecated
235
    public long deleteSynonymRelationships(Synonym syn, Taxon taxon);
236

  
237 179

  
238 180
    /**
239 181
     * Changes the homotypic group of a synonym into the new homotypic group.
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/TaxonServiceImpl.java
75 75
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
76 76
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
77 77
import eu.etaxonomy.cdm.model.common.Language;
78
import eu.etaxonomy.cdm.model.common.OrderedTermVocabulary;
79 78
import eu.etaxonomy.cdm.model.common.OriginalSourceType;
80 79
import eu.etaxonomy.cdm.model.common.RelationshipBase;
81 80
import eu.etaxonomy.cdm.model.common.RelationshipBase.Direction;
......
123 122
import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonDao;
124 123
import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonNodeDao;
125 124
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
126
import eu.etaxonomy.cdm.persistence.fetch.CdmFetch;
127 125
import eu.etaxonomy.cdm.persistence.query.MatchMode;
128 126
import eu.etaxonomy.cdm.persistence.query.OrderHint;
129 127
import eu.etaxonomy.cdm.persistence.query.OrderHint.SortOrder;
......
198 196
        return dao.getTaxaByName(name, sec);
199 197
    }
200 198

  
201
    /**
202
     * FIXME Candidate for harmonization
203
     * merge with getRootTaxa(Reference sec, ..., ...)
204
     *  (non-Javadoc)
205
     * @see eu.etaxonomy.cdm.api.service.ITaxonService#getRootTaxa(eu.etaxonomy.cdm.model.reference.Reference, boolean)
206
     */
207
    @Override
208
    public List<Taxon> getRootTaxa(Reference sec, CdmFetch cdmFetch, boolean onlyWithChildren) {
209
        if (cdmFetch == null){
210
            cdmFetch = CdmFetch.NO_FETCH();
211
        }
212
        return dao.getRootTaxa(sec, cdmFetch, onlyWithChildren, false);
213
    }
214

  
215
    @Override
216
    public List<Taxon> getRootTaxa(Rank rank, Reference sec, boolean onlyWithChildren,boolean withMisapplications, List<String> propertyPaths) {
217
        return dao.getRootTaxa(rank, sec, null, onlyWithChildren, withMisapplications, propertyPaths);
218
    }
219

  
220 199
    @Override
221 200
    public List<RelationshipBase> getAllRelationships(int limit, int start){
222 201
        return dao.getAllRelationships(limit, start);
223 202
    }
224 203

  
225
    /**
226
     * FIXME Candidate for harmonization
227
     * is this the same as termService.getVocabulary(VocabularyEnum.TaxonRelationshipType) ?
228
     */
229
    @Override
230
    @Deprecated
231
    public OrderedTermVocabulary<TaxonRelationshipType> getTaxonRelationshipTypeVocabulary() {
232

  
233
        String taxonRelTypeVocabularyId = "15db0cf7-7afc-4a86-a7d4-221c73b0c9ac";
234
        UUID uuid = UUID.fromString(taxonRelTypeVocabularyId);
235
        OrderedTermVocabulary<TaxonRelationshipType> taxonRelTypeVocabulary =
236
            (OrderedTermVocabulary)orderedVocabularyDao.findByUuid(uuid);
237
        return taxonRelTypeVocabulary;
238
    }
239

  
240 204
    @Override
241 205
    @Transactional(readOnly = false)
242 206
    public UpdateResult swapSynonymAndAcceptedTaxon(Synonym synonym, Taxon acceptedTaxon){
......
1352 1316
    }
1353 1317

  
1354 1318
    @Override
1355
    public long deleteSynonymRelationships(Synonym syn, Taxon taxon) {
1356
        return dao.deleteSynonymRelationships(syn, taxon);
1357
    }
1358

  
1359
    @Override
1360 1319
    public long deleteSynonymRelationships(Synonym syn) {
1361 1320
        return dao.deleteSynonymRelationships(syn, null);
1362 1321
    }
cdmlib-services/src/test/java/eu/etaxonomy/cdm/test/function/TestService.java
23 23
import eu.etaxonomy.cdm.api.service.DeleteResult;
24 24
import eu.etaxonomy.cdm.api.service.IDescriptionService;
25 25
import eu.etaxonomy.cdm.api.service.ITaxonService;
26
import eu.etaxonomy.cdm.api.service.ITermService;
27 26
import eu.etaxonomy.cdm.database.DbSchemaValidation;
28 27
import eu.etaxonomy.cdm.model.agent.Person;
29 28
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
......
40 39
import eu.etaxonomy.cdm.model.taxon.Synonym;
41 40
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
42 41
import eu.etaxonomy.cdm.model.taxon.Taxon;
43
import eu.etaxonomy.cdm.persistence.fetch.CdmFetch;
44 42

  
45 43

  
46 44

  
......
82 80

  
83 81
 		Taxon parentTaxon = Taxon.NewInstance(zn, sec);
84 82
		parentTaxon.setUuid(TEST_TAXON_UUID);
85
		parentTaxon.addTaxonomicChild(childTaxon, sec, null);
83
//		parentTaxon.addTaxonomicChild(childTaxon, sec, null);
86 84

  
87 85

  
88 86
		// test
......
105 103
		}
106 104
	}
107 105

  
108
	public void testRootTaxa(){
109
		// load Name list
110
		logger.info("Load existing names from db...");
111
		List<TaxonNameBase> tnList = appCtr.getNameService().list(null,1000, 0,null,null);
112
		for (TaxonNameBase tn2: tnList){
113
			logger.info("Title: "+ tn2.getTitleCache() + " UUID: " + tn2.getUuid()+";");
114
		}
115

  
116
		// load Root taxa
117
		logger.info("Load taxon from db...");
118
		List<Taxon> taxa = appCtr.getTaxonService().getRootTaxa(null, CdmFetch.NO_FETCH(), false);
119
		for (Taxon rt: taxa){
120
			logger.info("Root taxon: "+ rt.toString());
121
			for (Taxon child: rt.getTaxonomicChildren()){
122
				logger.info("Child: "+ child.toString());
123
				logger.info("  Child.higherTaxon: "+ child.getTaxonomicParent().toString());
124
				for (Synonym synonym: child.getSynonyms()){
125
					logger.info("  Child synonyms: "+ synonym.toString());
126
				}
127
			}
128
		}
129
	}
130

  
131
	public void testTermApi(){
132
		ITermService ts = appCtr.getTermService();
133
		//DefinedTermBase dt = ts.getTermByUri("e9f8cdb7-6819-44e8-95d3-e2d0690c3523");
134
		//logger.warn(dt.toString());
135
		//TODO: fix ts.listTerms(0,100)
136
//		List<DefinedTermBase> dts = ts.listTerms(0,100);
137
//		int i = 0;
138
//		for (DefinedTermBase d: dts){
139
//			i++;
140
//			if (i > 10) break;
141
//			logger.info(d.toString());
142
//		}
143
	}
144

  
145 106
	public void testDeleteTaxa(){
146 107
		ITaxonService taxonService = appCtr.getTaxonService();
147 108
		TaxonNameBase<?,?> taxonName = BotanicalName.NewInstance(Rank.SPECIES());
......
192 153
		Reference ref = ReferenceFactory.newJournal();
193 154
		Taxon parent = Taxon.NewInstance(taxonName, ref);
194 155
		Taxon child = Taxon.NewInstance(taxonName, null);
195
		parent.addTaxonomicChild(child, null, null);
156
//		parent.addTaxonomicChild(child, null, null);
196 157

  
197 158
		logger.info("Save taxon ...");
198 159
		UUID uuidTaxon1 = taxonService.save(parent).getUuid();

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)