Store sample data set in DB
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / agent / InstitutionalMembership.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9
10 package eu.etaxonomy.cdm.model.agent;
11
12
13 import eu.etaxonomy.cdm.model.common.TimePeriod;
14 import eu.etaxonomy.cdm.model.common.VersionableEntity;
15 import org.apache.log4j.Logger;
16 import org.hibernate.annotations.Cascade;
17 import org.hibernate.annotations.CascadeType;
18
19 import javax.persistence.*;
20 import javax.xml.bind.annotation.XmlAccessType;
21 import javax.xml.bind.annotation.XmlAccessorType;
22 import javax.xml.bind.annotation.XmlElement;
23 import javax.xml.bind.annotation.XmlIDREF;
24 import javax.xml.bind.annotation.XmlRootElement;
25 import javax.xml.bind.annotation.XmlSchemaType;
26 import javax.xml.bind.annotation.XmlType;
27 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
28
29 /**
30 * Allows to hold one {@link Institution institution} to which a {@link Person person} is affiliated.
31 * It includes {@link common.TimePeriod time period} of membership and role of the person
32 * in this institution. In case one person belongs to several institutions
33 * the corresponding number of instances of InstitutionalMembership
34 * have to be created.
35 *
36 * @author m.doering
37 * @version 1.0
38 * @created 08-Nov-2007 13:06:30
39 */
40 @XmlAccessorType(XmlAccessType.FIELD)
41 @XmlType(name = "", propOrder = {
42 "period",
43 "department",
44 "role",
45 "institute",
46 "person"
47 })
48 @XmlRootElement(name = "InstitutionalMembership")
49 @Entity
50 public class InstitutionalMembership extends VersionableEntity {
51
52 static Logger logger = Logger.getLogger(InstitutionalMembership.class);
53
54 /*Time period a person belonged to the institution*/
55 @XmlElement(name = "Period")
56 //@XmlJavaTypeAdapter(IntervalAdapter.class)
57 private TimePeriod period;
58
59 //Department of the institution this person was working in
60 @XmlElement(name = "Department")
61 private String department;
62
63 //Role this person had in the institution
64 @XmlElement(name = "Role")
65 private String role;
66
67 //current institute the person belongs to
68 @XmlElement(name = "Institution", required = true)
69 @XmlIDREF
70 @XmlSchemaType(name = "IDREF")
71 private Institution institute;
72
73 @XmlElement(name = "Person", required = true)
74 @XmlIDREF
75 @XmlSchemaType(name = "IDREF")
76 private Person person;
77
78 public static InstitutionalMembership NewInstance() {
79 InstitutionalMembership mship = new InstitutionalMembership();
80 return mship;
81 }
82
83 public InstitutionalMembership() {
84 super();
85 }
86
87 /**
88 * Class constructor using an {@link Institution institution}, a {@link Person person}, a {@link common.TimePeriod time period},
89 * a department name string and a role string.
90 *
91 * @param institute the institution in which the person is a member
92 * @param person the person who is a member of the institution
93 * @param period the time period during which the person belonged
94 * to the institution
95 * @param department the name string of the department (within the institution)
96 * this person is working in
97 * @param role the string which identifies the role played by the person
98 * in the institution (or in the department)
99 * @see Person
100 * @see Institution
101 */
102 public InstitutionalMembership(Institution institute, Person person, TimePeriod period, String department,
103 String role) {
104 super();
105 this.period = period;
106 this.department = department;
107 this.role = role;
108 this.institute = institute;
109 this.person = person;
110 }
111
112 /**
113 * Returns the {@link Person person} involved in this institutional membership.
114 *
115 * @see Person#institutionalMemberships
116 * @see Person#addInstitutionalMembership(Institution, TimePeriod, String, String)
117 */
118 public Person getPerson() {
119 return person;
120 }
121 /**
122 * Assigns a new {@link Person person} (replacing the actual one) to this institutional membership.
123 * This method also updates both sets of institutions
124 * the two persons (the new one and the substituted one) belong to.
125 *
126 * @param newPerson the new person to be included in this institutional membership
127 * @see #getPerson()
128 * @see Person#removeInstitutionalMembership(InstitutionalMembership)
129 */
130 protected void setPerson(Person newPerson) {
131 this.person = newPerson;
132 }
133
134
135 /**
136 * Returns the {@link Institution institution} corresponding to this institutional membership.
137 */
138 @Cascade({CascadeType.SAVE_UPDATE})
139 public Institution getInstitute(){
140 return this.institute;
141 }
142 /**
143 * Assigns an new institution (replacing the actual one)
144 * to this institutional membership.
145 *
146 * @param newInstitute the new institution
147 * @see #getInstitute()
148 */
149 public void setInstitute(Institution newInstitute){
150 this.institute = newInstitute;
151 }
152
153 /**
154 * Returns the {@link common.TimePeriod time period} during which
155 * the {@link Person person} involved in this institutional membership belonged
156 * to the {@link Institution institution} also involved in it.
157 */
158 public TimePeriod getPeriod(){
159 return this.period;
160 }
161
162 /**
163 * @see #getPeriod()
164 */
165 public void setPeriod(TimePeriod period){
166 this.period = period;
167 }
168
169 /**
170 * Returns the string representing the name of the department (within
171 * the {@link Institution institution} involved in this institutional membership) to which
172 * the {@link Person person} belongs.
173 */
174 public String getDepartment(){
175 return this.department;
176 }
177
178 /**
179 * @see #getDepartment()
180 */
181 public void setDepartment(String department){
182 this.department = department;
183 }
184
185 /**
186 * Returns the string representing the role played by the {@link Person person} within
187 * the {@link Institution institution} (or within the department) involved
188 * in this institutional membership.
189 */
190 public String getRole(){
191 return this.role;
192 }
193
194 /**
195 * @see #getRole()
196 */
197 public void setRole(String role){
198 this.role = role;
199 }
200
201 }