minor
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / description / FeatureTree.java
index 8acce085053565467c38138556e62fe0de1679e7..33f7d0e5fddac28c2951e9fdd34269c12f9f7183 100644 (file)
 package eu.etaxonomy.cdm.model.description;
 
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 import java.util.UUID;
 
 import javax.persistence.Entity;
 import javax.persistence.FetchType;
-import javax.persistence.ManyToOne;
 import javax.persistence.OneToOne;
 import javax.persistence.Transient;
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlIDREF;
 import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.XmlSchemaType;
 import javax.xml.bind.annotation.XmlType;
 
 import org.apache.log4j.Logger;
 import org.hibernate.annotations.Cascade;
 import org.hibernate.annotations.CascadeType;
 import org.hibernate.envers.Audited;
+import org.hibernate.search.annotations.Indexed;
 
 import eu.etaxonomy.cdm.model.common.TermBase;
 
@@ -48,7 +48,7 @@ import eu.etaxonomy.cdm.model.common.TermBase;
  * nothing in common with the possible hierarchical structure of features
  * depending on their grade of precision.  
  *  
- * @see                IdentificationKey
+ * @see                MediaKey
  * @author  m.doering
  * @version 1.0
  * @created 08-Nov-2007 13:06:16
@@ -60,20 +60,17 @@ import eu.etaxonomy.cdm.model.common.TermBase;
 })
 @XmlRootElement(name = "FeatureTree")
 @Entity
+@Indexed(index = "eu.etaxonomy.cdm.model.description.FeatureTree")
 @Audited
 public class FeatureTree extends TermBase {
-       /**
-        * 
-        */
        private static final long serialVersionUID = -6713834139003172735L;
-
        @SuppressWarnings("unused")
        private static final Logger logger = Logger.getLogger(FeatureTree.class);
        //private Set<FeatureNode> nodes = new HashSet<FeatureNode>();
        
        @XmlElement(name = "Root")
        @OneToOne(fetch = FetchType.LAZY)
-       @Cascade({CascadeType.SAVE_UPDATE})
+       @Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE})
        private FeatureNode root;
        
        @XmlElement(name = "IsDescriptionSeparated")
@@ -86,6 +83,7 @@ public class FeatureTree extends TermBase {
        protected FeatureTree() {
                super();
                root = FeatureNode.NewInstance();
+               root.setFeatureTree(this);
        }
 
        /** 
@@ -191,5 +189,17 @@ public class FeatureTree extends TermBase {
                result.addAll(root.getChildren());
                return result;
        }
-
+       
+       /**
+        * Computes a set of distinct features that are present in this feature tree
+        * 
+        * @return
+        */
+       @Transient
+       public Set<Feature> getDistinctFeatures(){
+               Set<Feature> features = new HashSet<Feature>();
+               
+               return root.getDistinctFeaturesRecursive(features);
+       }
+       
 }
\ No newline at end of file