Added Cascade.MERGE for some, not all relationships where Cascade.SAVE_UPDATE exists...
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / agent / Team.java
index 44af5209a443ae2155a13f5d604c1f80a22a7d69..19e9728a702c202659b2e081f445732889e13331 100644 (file)
@@ -9,19 +9,32 @@
 
 package eu.etaxonomy.cdm.model.agent;
 
-import org.apache.log4j.Logger;
-
-import eu.etaxonomy.cdm.strategy.cache.agent.TeamDefaultCacheStrategy;
+import java.util.ArrayList;
+import java.util.List;
 
-import java.util.*;
-
-import javax.persistence.*;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.ManyToMany;
+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.XmlElementWrapper;
+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.annotations.IndexColumn;
+import org.hibernate.envers.Audited;
+import org.hibernate.search.annotations.Indexed;
+import org.springframework.beans.factory.annotation.Configurable;
+
+import eu.etaxonomy.cdm.strategy.cache.agent.TeamDefaultCacheStrategy;
+
 /**
  * This class represents teams of {@link Person persons}. A team exists either for itself
  * or is built with the list of (distinct) persons who belong to it.
@@ -46,10 +59,14 @@ import javax.xml.bind.annotation.XmlType;
        "protectedNomenclaturalTitleCache",
     "teamMembers"
 })
+@XmlRootElement
 @Entity
-public class Team extends TeamOrPersonBase {
-       
-       static Logger logger = Logger.getLogger(Team.class);
+@Indexed(index = "eu.etaxonomy.cdm.model.agent.AgentBase")
+@Audited
+@Configurable
+public class Team extends TeamOrPersonBase<Team> {
+       private static final long serialVersionUID = 97640416905934622L;
+       public static final Logger logger = Logger.getLogger(Team.class);
        
     @XmlElement(name = "ProtectedNomenclaturalTitleCache")
        private boolean protectedNomenclaturalTitleCache;
@@ -57,8 +74,12 @@ public class Team extends TeamOrPersonBase {
        //An abreviated name for the team (e. g. in case of nomenclatural authorteams). A non abreviated name for the team (e. g.
        //in case of some bibliographical references)
     @XmlElementWrapper(name = "TeamMembers")
-    @XmlElement(name = "Member")
-    //@XmlIDREF
+    @XmlElement(name = "TeamMember")
+    @XmlIDREF
+    @XmlSchemaType(name = "IDREF")
+    @IndexColumn(name="sortIndex", base = 0)
+       @ManyToMany(fetch = FetchType.LAZY)
+       @Cascade(CascadeType.SAVE_UPDATE)
        private List<Person> teamMembers = new ArrayList<Person>();
        
        
@@ -82,16 +103,9 @@ public class Team extends TeamOrPersonBase {
         * Returns the list of {@link Person members} belonging to <i>this</i> team. 
         * A person may be a member of several distinct teams. 
         */
-       @ManyToMany
        public List<Person> getTeamMembers(){
                return this.teamMembers;
        }
-       /** 
-        * @see     #getTeamMembers()
-        */
-       protected void setTeamMembers(List<Person> teamMembers){
-               this.teamMembers = teamMembers;
-       }
        
        /** 
         * Adds a new {@link Person person} to <i>this</i> team at the end of the members' list. 
@@ -146,10 +160,10 @@ public class Team extends TeamOrPersonBase {
         * 
         * @return  a string which identifies <i>this</i> team
         */
-       @Override
-       public String generateTitle() {
-               return cacheStrategy.getTitleCache(this);
-       }
+//     @Override
+//     public String generateTitle() {
+//             return cacheStrategy.getTitleCache(this);
+//     }
        
        
        /**
@@ -202,9 +216,4 @@ public class Team extends TeamOrPersonBase {
                this.nomenclaturalTitle = nomenclaturalTitle;
                this.protectedNomenclaturalTitleCache = protectedNomenclaturalTitleCache;
        }
-
-       
-       
-       
-
 }
\ No newline at end of file