upper case for JoinTable WorkingSet_DescriptionBase
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / description / Distribution.java
index aafcc9c539315000d6f37e3f2424eca153bbc757..39c7161a8072324f1f5f1b3c06f055f3e4f20bbd 100644 (file)
@@ -9,9 +9,12 @@
 
 package eu.etaxonomy.cdm.model.description;
 
+import java.util.ArrayList;
+
 import javax.persistence.Entity;
 import javax.persistence.FetchType;
 import javax.persistence.ManyToOne;
+import javax.validation.constraints.NotNull;
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlElement;
@@ -21,13 +24,12 @@ 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.location.NamedArea;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.cdm.validation.Level2;
 
 /**
  * This class represents elementary distribution data for a {@link Taxon taxon}.
@@ -54,7 +56,7 @@ import eu.etaxonomy.cdm.model.taxon.Taxon;
 @Entity
 @Audited
 @Indexed(index = "eu.etaxonomy.cdm.model.description.DescriptionElementBase")
-public class Distribution extends DescriptionElementBase {
+public class Distribution extends DescriptionElementBase implements Cloneable {
        private static final long serialVersionUID = 8366462435651559730L;
        @SuppressWarnings("unused")
        private static final Logger logger = Logger.getLogger(Distribution.class);
@@ -63,12 +65,14 @@ public class Distribution extends DescriptionElementBase {
        @XmlIDREF
        @XmlSchemaType(name = "IDREF")
        @ManyToOne(fetch = FetchType.LAZY)
+       @NotNull(groups = Level2.class)
        private NamedArea area;
        
        @XmlElement(name = "PresenceAbsenceStatus")
        @XmlIDREF
        @XmlSchemaType(name = "IDREF")
        @ManyToOne(fetch = FetchType.LAZY)
+       @NotNull(groups = Level2.class)
        private PresenceAbsenceTermBase<?> status;
 
        
@@ -89,7 +93,7 @@ public class Distribution extends DescriptionElementBase {
         */
        public static Distribution NewInstance(){
                Distribution result = new Distribution();
-               result.setType(Feature.DISTRIBUTION());
+               result.setFeature(Feature.DISTRIBUTION());
                return result;
        }
 
@@ -109,8 +113,8 @@ public class Distribution extends DescriptionElementBase {
        }
        
        /** 
-        * Deprecated because {@link Feature feature} should always be {@link Feature#DISTRIBUTION() DISTRIBUTION}
-        * for all distribution instances.
+        * @deprecated Deprecated because {@link Feature feature} should always be {@link Feature#DISTRIBUTION() DISTRIBUTION}
+        * for all distribution instances and therefore it should not be changed.
         */
        /* (non-Javadoc)
         * @see eu.etaxonomy.cdm.model.description.DescriptionElementBase#setFeature(eu.etaxonomy.cdm.model.description.Feature)
@@ -146,5 +150,74 @@ public class Distribution extends DescriptionElementBase {
        public void setStatus(PresenceAbsenceTermBase<?> status){
                this.status = status;
        }
+       
+       /**
+        * Special equal method for building an sorted distribution tree
+        * @param dist
+        * @return
+        */
+       public boolean equalsForTree(Distribution dist){
+               boolean result = false;
+               //same area level and area label
+               if (this.getArea().getLabel().compareTo(dist.getArea().getLabel()) == 0 &&
+                               this.getArea().getLevel().getLabel().compareTo(dist.getArea().getLevel().getLabel()) == 0){
+                       result = true;
+               }
+               
+               return result;
+       }
+       
+       /**
+        * Special function for building the sorted distribution tree. The function returns true 
+        * if the sources of the two different objects are different
+        * @param dist
+        * @return
+        */
+       public boolean isDifferentSources(Distribution dist){
+               boolean result = false;
+               if(this.getSources().equals(dist.getSources())){
+                       result = true;
+               }
+               return result;
+       }
+       
+
+//*********************************** CLONE *****************************************/
+
+       /** 
+        * Clones <i>this</i> distribution. This is a shortcut that enables to create
+        * a new instance that differs only slightly from <i>this</i> distribution by
+        * modifying only some of the attributes.
+        * 
+        * @see eu.etaxonomy.cdm.model.description.DescriptionElementBase#clone()
+        * @see java.lang.Object#clone()
+        */
+       @Override
+       public Object clone() {
+
+               try {
+                       Distribution result = (Distribution)super.clone();
+                       
+                       return result;
+                       //no changes to: area, status
+               } catch (CloneNotSupportedException e) {
+                       logger.warn("Object does not implement cloneable");
+                       e.printStackTrace();
+                       return null;
+               }
+       }       
+
+// ************************* to String ***************************************************/    
+       
+       /**
+        * Implementation of the toString() function
+        */
+       public String toString(){
+               String result = "null";
+               if (this.area != null){                 
+                       result = area.getLabel().toString();
+               }
+               return result;
+       }
 
 }
\ No newline at end of file