import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import org.hibernate.search.annotations.Index;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.IndexedEmbedded;
+import org.joda.time.Partial;
import org.springframework.beans.factory.annotation.Configurable;
import eu.etaxonomy.cdm.model.common.TimePeriod;
+import eu.etaxonomy.cdm.model.common.User;
import eu.etaxonomy.cdm.strategy.cache.agent.PersonDefaultCacheStrategy;
import eu.etaxonomy.cdm.strategy.match.Match;
import eu.etaxonomy.cdm.strategy.match.MatchMode;
+import eu.etaxonomy.cdm.validation.annotation.NullOrNotEmpty;
/**
* This class represents human beings, living or dead.<BR>
"suffix",
"lifespan",
"institutionalMemberships"
- })
+})
@XmlRootElement(name = "Person")
@Entity
@Indexed(index = "eu.etaxonomy.cdm.model.agent.AgentBase")
@XmlElement(name = "Prefix")
@Field(index=Index.TOKENIZED)
+ @NullOrNotEmpty
+ @Size(max = 255)
private String prefix;
@XmlElement(name = "FirstName")
@Field(index=Index.TOKENIZED)
+ @NullOrNotEmpty
+ @Size(max = 255)
private String firstname;
@XmlElement(name = "LastName")
@Field(index=Index.TOKENIZED)
+ @NullOrNotEmpty
+ @Size(max = 255)
private String lastname;
@XmlElement(name = "Suffix")
@Field(index=Index.TOKENIZED)
+ @NullOrNotEmpty
+ @Size(max = 255)
private String suffix;
@XmlElement(name = "Lifespan")
@IndexedEmbedded
@Match(value=MatchMode.EQUAL_OR_ONE_NULL)
+ @NotNull
private TimePeriod lifespan = TimePeriod.NewInstance();
- @XmlElementWrapper(name = "InstitutionalMemberships")
+ @XmlElementWrapper(name = "InstitutionalMemberships", nillable = true)
@XmlElement(name = "InstitutionalMembership")
@OneToMany(fetch=FetchType.LAZY, mappedBy = "person")
@Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.DELETE})
- protected Set<InstitutionalMembership> institutionalMemberships = new HashSet<InstitutionalMembership>();
+ protected Set<InstitutionalMembership> institutionalMemberships;
/**
* Creates a new empty instance for a person whose existence is all what is known.
*/
public static Person NewTitledInstance(String titleCache){
Person result = new Person();
- result.setTitleCache(titleCache);
+ result.setTitleCache(titleCache, true);
return result;
}
public Person(String firstname, String lastname, String nomenclaturalTitel) {
this.setFirstname(firstname);
this.setLastname(lastname);
- System.err.println("before - Set nomenclatural Title");
+ logger.debug("before - Set nomenclatural Title");
this.setNomenclaturalTitle(nomenclaturalTitel);
- System.err.println("after - Set nomenclatural Title");
+ logger.debug("after - Set nomenclatural Title");
}
* @see InstitutionalMembership
*/
public Set<InstitutionalMembership> getInstitutionalMemberships(){
+ if(institutionalMemberships == null) {
+ this.institutionalMemberships = new HashSet<InstitutionalMembership>();
+ }
return this.institutionalMemberships;
}
protected void addInstitutionalMembership(InstitutionalMembership ims){
- this.institutionalMemberships.add(ims);
+ getInstitutionalMemberships().add(ims);
if (ims.getPerson() != this){
logger.warn("Institutional membership's person has to be changed for adding it to person: " + this);
ims.getPerson().removeInstitutionalMembership(ims);
public void removeInstitutionalMembership(InstitutionalMembership ims){
ims.setInstitute(null);
ims.setPerson(null);
- this.institutionalMemberships.remove(ims);
+ getInstitutionalMemberships().remove(ims);
}
/**
* @see eu.etaxonomy.cdm.model.common.TimePeriod
*/
public TimePeriod getLifespan(){
+ if(lifespan == null) {
+ this.lifespan = TimePeriod.NewInstance(new Partial(), new Partial());
+ }
return this.lifespan;
}
/**
// }
// return title;
// }
+
+//*********************** CLONE ********************************************************/
+
+ /**
+ * Clones <i>this</i> Person. This is a shortcut that enables to create
+ * a new instance that differs only slightly from <i>this</i> Person.
+ *
+ * @see eu.etaxonomy.cdm.model.media.IdentifiableMediaEntity#clone()
+ * @see java.lang.Object#clone()
+ */
+ @Override
+ public Object clone() {
+ try{
+ Person result = (Person)super.clone();
+ //no changes to firstname, lastname, lifespan, prefix, suffix
+ return result;
+ } catch (CloneNotSupportedException e){
+ logger.warn("Object does not implement cloneable");
+ e.printStackTrace();
+ return null;
+ }
+
+
+ }
}
\ No newline at end of file