package eu.etaxonomy.cdm.model.agent;
-import eu.etaxonomy.cdm.model.common.TimePeriod;
-import eu.etaxonomy.cdm.model.common.VersionableEntity;
-import org.apache.log4j.Logger;
-import org.hibernate.annotations.Cascade;
-import org.hibernate.annotations.CascadeType;
-
-import javax.persistence.*;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.ManyToOne;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
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 eu.etaxonomy.cdm.model.common.TimePeriod;
+import eu.etaxonomy.cdm.model.common.VersionableEntity;
+
/**
* This class allows to hold one {@link Institution institution} to which a {@link Person person}
* is affiliated. It includes {@link eu.etaxonomy.cdm.model.common.TimePeriod time period} of membership and role of
})
@XmlRootElement(name = "InstitutionalMembership")
@Entity
-//@Audited
-public class InstitutionalMembership extends VersionableEntity {
+@Audited
+public class InstitutionalMembership extends VersionableEntity implements Cloneable{
private static final long serialVersionUID = -800814712134999042L;
public static final Logger logger = Logger.getLogger(InstitutionalMembership.class);
/*Time period a person belonged to the institution*/
@XmlElement(name = "Period")
- //@XmlJavaTypeAdapter(IntervalAdapter.class)
- private TimePeriod period;
+ private TimePeriod period = TimePeriod.NewInstance();
//Department of the institution this person was working in
@XmlElement(name = "Department")
@XmlElement(name = "Institution", required = true)
@XmlIDREF
@XmlSchemaType(name = "IDREF")
+ @ManyToOne(fetch = FetchType.LAZY)
+ @Cascade(CascadeType.SAVE_UPDATE)
private Institution institute;
@XmlElement(name = "Person", required = true)
@XmlIDREF
@XmlSchemaType(name = "IDREF")
+ @ManyToOne(fetch = FetchType.LAZY)
+ @Cascade(CascadeType.SAVE_UPDATE)
private Person person;
public static InstitutionalMembership NewInstance() {
return mship;
}
- public InstitutionalMembership() {
+ protected InstitutionalMembership() {
super();
}
/**
* Class constructor using an {@link Institution institution}, a {@link Person person}, a {@link common.TimePeriod time period},
* a department name string and a role string.
+ * Adds this membership to the persons memberships.
*
* @param institute the institution in which the person is a member
* @param person the person who is a member of the institution
this.role = role;
this.institute = institute;
this.person = person;
+ person.addInstitutionalMembership(this);
}
/**
* @see Person#institutionalMemberships
* @see Person#addInstitutionalMembership(Institution, TimePeriod, String, String)
*/
- @ManyToOne(fetch = FetchType.LAZY)
- @Cascade({CascadeType.SAVE_UPDATE})
public Person getPerson() {
return person;
}
- /**
+
+ /**
* Assigns a new {@link Person person} (replacing the actual one) to <i>this</i> institutional membership.
* This method also updates both sets of institutions
- * the two persons (the new one and the substituted one) belong to.
+ * the two persons (the new one and the substituted one) belong to.
*
* @param newPerson the new person to be included in <i>this</i> institutional membership
* @see #getPerson()
* @see Person#removeInstitutionalMembership(InstitutionalMembership)
*/
- protected void setPerson(Person newPerson) {
- this.person = newPerson;
+ protected void setPerson(Person person) {
+ this.person = person;
}
-
/**
* Returns the {@link Institution institution} corresponding to <i>this</i> institutional membership.
*/
- @Cascade({CascadeType.SAVE_UPDATE})
- @ManyToOne(fetch = FetchType.LAZY)
public Institution getInstitute(){
return this.institute;
}
public void setRole(String role){
this.role = role;
}
-
+
+//*********************** CLONE ********************************************************/
+
+ /**
+ * Clones <i>this</i> InstitutionalMembership. This is a shortcut that enables to create
+ * a new instance that differs only slightly from <i>this</i> InstitutionalMembership.
+ *
+ * @see eu.etaxonomy.cdm.model.common.VersionableEntity
+ * @see java.lang.Object#clone()
+ */
+ @Override
+ public Object clone() {
+ try{
+ InstitutionalMembership result = (InstitutionalMembership) super.clone();
+ //no changes to department, institute, period, person, role
+ return result;
+ }catch (CloneNotSupportedException e){
+ logger.warn("Object does not implement cloneable");
+ e.printStackTrace();
+ return null;
+ }
+ }
}
\ No newline at end of file