(no commit message)
authorAndreas Müller <a.mueller@bgbm.org>
Tue, 17 Jun 2008 12:26:46 +0000 (12:26 +0000)
committerAndreas Müller <a.mueller@bgbm.org>
Tue, 17 Jun 2008 12:26:46 +0000 (12:26 +0000)
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/IRelated.java
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/RelationshipBase.java
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/taxon/Taxon.java

index 3a29113db261d3ab71e8a83f52f63a4a64e1e43d..5f7e1f132758e866ceea8c3b0402b217176c7415 100644 (file)
@@ -18,4 +18,5 @@ public interface IRelated<T extends RelationshipBase> {
         * 
         */
        public UUID getUuid();
+       
 }
index 1bb41b455317e598da82a60e2b92ac8ceb783755..bcb8b8e45db9ae90660870afca730077fab2d987 100644 (file)
@@ -75,6 +75,7 @@ public abstract class RelationshipBase<FROM extends IRelated, TO extends IRelate
        protected void setRelatedTo(TO relatedTo) {
                this.relatedTo = relatedTo;
        }
+
        
 // TODO
 //     UUID toUuid; 
index 44b38515b08f788cded486842e7f9598fd543ef6..ac83ab08511e3cf5d5856c034cb3a2200f60db0d 100644 (file)
@@ -174,8 +174,19 @@ public class Taxon extends TaxonBase implements Iterable<Taxon>, IRelated<Relati
                if (rel.getType().equals(TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN()) && rel.getFromTaxon().equals(this)){
                        this.setTaxonomicParentCache(null);
                }
-               // TODO: remove in related taxon too?
+               //delete Relationship from other realted Taxon
+               Taxon fromTaxon = rel.getFromTaxon();
+               if (fromTaxon != null && fromTaxon != this){
+                       rel.setToTaxon(null);  //remove this Taxon from relationship
+                       fromTaxon.removeTaxonRelation(rel);
+               }
+               Taxon toTaxon = rel.getToTaxon();
+               if (toTaxon != null && toTaxon != this){
+                       rel.setFromTaxon(null); //remove this Taxon from relationship
+                       toTaxon.removeTaxonRelation(rel);
+               }
        }
+
        public void addTaxonRelation(TaxonRelationship rel) {
                if (rel!=null && rel.getType()!=null && !getTaxonRelations().contains(rel)){
                        if (rel.getFromTaxon().equals(this)){
@@ -198,6 +209,7 @@ public class Taxon extends TaxonBase implements Iterable<Taxon>, IRelated<Relati
        /* (non-Javadoc)
         * @see eu.etaxonomy.cdm.model.common.IRelated#addRelationship(eu.etaxonomy.cdm.model.common.RelationshipBase)
         */
+       @Deprecated //for inner use by RelationshipBase only
        public void addRelationship(RelationshipBase rel){
                if (rel instanceof TaxonRelationship){
                        addTaxonRelation((TaxonRelationship)rel);
@@ -208,7 +220,6 @@ public class Taxon extends TaxonBase implements Iterable<Taxon>, IRelated<Relati
                }
        }
        
-       
        public void addTaxonRelation(Taxon toTaxon, TaxonRelationshipType type, ReferenceBase citation, String microcitation) {
                TaxonRelationship rel = new TaxonRelationship(this, toTaxon, type, citation, microcitation);
        }
@@ -238,12 +249,23 @@ public class Taxon extends TaxonBase implements Iterable<Taxon>, IRelated<Relati
         * @param citation
         * @param microcitation 
         */
-       public void setTaxonomicParent(Taxon parent, ReferenceBase citation, String microcitation){
-               // TODO: remove previously existing parent relationship!!!
-               if (parent != null){
-                       addTaxonRelation(parent, TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN(),citation,microcitation);
+       public void setTaxonomicParent(Taxon newParent, ReferenceBase citation, String microcitation){
+               //remove previously existing parent relationship!!!
+               Taxon oldParent = this.getTaxonomicParent();
+               Set<TaxonRelationship> taxRels = this.getTaxonRelations();
+               for (TaxonRelationship taxRel : taxRels ){
+                       if (taxRel.getType().equals(TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN()) && taxRel.getToTaxon().equals(oldParent)){
+                               this.removeTaxonRelation(taxRel);
+                       }
+               }
+               //add new parent
+               if (newParent != null){
+                       addTaxonRelation(newParent, TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN(),citation,microcitation);
                }
        }
+       
+       
+       
 
        /**
         * @return