- 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);