230b26e0f034e94225e0454b22184c3c470f5a22
[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
21 /**
22 * Allows to hold one {@link Institution institution} to which a {@link Person person} is affiliated.
23 * It includes {@link common.TimePeriod time period} of membership and role of the person
24 * in this institution. In case one person belongs to several institutions
25 * the corresponding number of instances of InstitutionalMembership
26 * have to be created.
27 *
28 * @author m.doering
29 * @version 1.0
30 * @created 08-Nov-2007 13:06:30
31 */
32 @Entity
33 public class InstitutionalMembership extends VersionableEntity {
34 static Logger logger = Logger.getLogger(InstitutionalMembership.class);
35 /*Time period a person belonged to the institution*/
36 private TimePeriod period;
37 //Department of the institution this person was working in
38 private String department;
39 //Role this person had in the institution
40 private String role;
41 //current institute the person belongs to
42 private Institution institute;
43 private Person person;
44
45
46 /**
47 * Class constructor using an {@link Institution institution}, a {@link Person person}, a {@link common.TimePeriod time period},
48 * a department name string and a role string.
49 *
50 * @param institute the institution in which the person is a member
51 * @param person the person who is a member of the institution
52 * @param period the time period during which the person belonged
53 * to the institution
54 * @param department the name string of the department (within the institution)
55 * this person is working in
56 * @param role the string which identifies the role played by the person
57 * in the institution (or in the department)
58 * @see Person
59 * @see Institution
60 */
61 public InstitutionalMembership(Institution institute, Person person, TimePeriod period, String department,
62 String role) {
63 super();
64 this.period = period;
65 this.department = department;
66 this.role = role;
67 this.institute = institute;
68 this.person = person;
69 }
70
71 /**
72 * Returns the {@link Person person} involved in this institutional membership.
73 *
74 * @see Person#institutionalMemberships
75 * @see Person#addInstitutionalMembership(Institution, TimePeriod, String, String)
76 */
77 public Person getPerson() {
78 return person;
79 }
80 /**
81 * Assigns a new {@link Person person} (replacing the actual one) to this institutional membership.
82 * This method also updates both sets of institutions
83 * the two persons (the new one and the substituted one) belong to.
84 *
85 * @param newPerson the new person to be included in this institutional membership
86 * @see #getPerson()
87 * @see Person#removeInstitutionalMembership(InstitutionalMembership)
88 */
89 public void setPerson(Person newPerson) {
90 // Hibernate bidirectional cascade hack:
91 // http://opensource.atlassian.com/projects/hibernate/browse/HHH-1054
92 if(this.person == newPerson) return;
93 if (person != null) {
94 person.institutionalMemberships.remove(this);
95 }
96 if (newPerson!= null) {
97 newPerson.institutionalMemberships.add(this);
98 }
99 this.person = newPerson;
100 }
101
102
103 /**
104 * Returns the {@link Institution institution} corresponding to this institutional membership.
105 */
106 @Cascade({CascadeType.SAVE_UPDATE})
107 public Institution getInstitute(){
108 return this.institute;
109 }
110 /**
111 * Assigns an new institution (replacing the actual one)
112 * to this institutional membership.
113 *
114 * @param newInstitute the new institution
115 * @see #getInstitute()
116 */
117 public void setInstitute(Institution newInstitute){
118 this.institute = newInstitute;
119 }
120
121 /**
122 * Returns the {@link common.TimePeriod time period} during which
123 * the {@link Person person} involved in this institutional membership belonged
124 * to the {@link Institution institution} also involved in it.
125 */
126 public TimePeriod getPeriod(){
127 return this.period;
128 }
129
130 /**
131 * @see #getPeriod()
132 */
133 public void setPeriod(TimePeriod period){
134 this.period = period;
135 }
136
137 /**
138 * Returns the string representing the name of the department (within
139 * the {@link Institution institution} involved in this institutional membership) to which
140 * the {@link Person person} belongs.
141 */
142 public String getDepartment(){
143 return this.department;
144 }
145
146 /**
147 * @see #getDepartment()
148 */
149 public void setDepartment(String department){
150 this.department = department;
151 }
152
153 /**
154 * Returns the string representing the role played by the {@link Person person} within
155 * the {@link Institution institution} (or within the department) involved
156 * in this institutional membership.
157 */
158 public String getRole(){
159 return this.role;
160 }
161
162 /**
163 * @see #getRole()
164 */
165 public void setRole(String role){
166 this.role = role;
167 }
168
169 }