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;
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}.
})
@XmlRootElement(name = "Distribution")
@Entity
-public class Distribution extends DescriptionElementBase {
+@Audited
+@Indexed(index = "eu.etaxonomy.cdm.model.description.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);
@XmlElement(name = "NamedArea")
@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;
* The corresponding {@link Feature feature} is set to {@link Feature#DISTRIBUTION() DISTRIBUTION}.
*/
protected Distribution(){
- super(Feature.DISTRIBUTION());
+ super();
}
*/
public static Distribution NewInstance(){
Distribution result = new Distribution();
+ result.setFeature(Feature.DISTRIBUTION());
return result;
}
* @see #NewInstance()
*/
public static Distribution NewInstance(NamedArea area, PresenceAbsenceTermBase<?> status){
- Distribution result = new Distribution();
+ Distribution result = NewInstance();
result.setArea(area);
result.setStatus(status);
return result;
}
-
-
-
/**
- * 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)
/**
* Returns the {@link NamedArea named area} <i>this</i> distribution applies to.
*/
- @ManyToOne
- @Cascade({CascadeType.SAVE_UPDATE})
public NamedArea getArea(){
return this.area;
}
/**
* Returns the {@link PresenceAbsenceTermBase presence or absence term} for <i>this</i> distribution.
*/
- @ManyToOne
public PresenceAbsenceTermBase<?> getStatus(){
return this.status;
}
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