(no commit message)
[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 java.util.*;
20 import javax.persistence.*;
21
22 /**
23 * Allows to keep one {@link Institution institution} to which a {@link Person person} is affiliated.
24 * It includes time period of membership and role of the person
25 * in this institution. In case one person belongs to several institutions
26 * the corresponding number of instances 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 public InstitutionalMembership(Institution institute, Person person, TimePeriod period, String department,
47 String role) {
48 super();
49 this.period = period;
50 this.department = department;
51 this.role = role;
52 this.institute = institute;
53 this.person = person;
54 }
55
56 public Person getPerson() {
57 return person;
58 }
59 public void setPerson(Person newPerson) {
60 // Hibernate bidirectional cascade hack:
61 // http://opensource.atlassian.com/projects/hibernate/browse/HHH-1054
62 if(this.person == newPerson) return;
63 if (person != null) {
64 person.institutionalMemberships.remove(this);
65 }
66 if (newPerson!= null) {
67 newPerson.institutionalMemberships.add(this);
68 }
69 this.person = newPerson;
70 }
71
72
73 @Cascade({CascadeType.SAVE_UPDATE})
74 public Institution getInstitute(){
75 return this.institute;
76 }
77 public void setInstitute(Institution newInstitute){
78 this.institute = newInstitute;
79 }
80
81 public TimePeriod getPeriod(){
82 return this.period;
83 }
84
85 /**
86 *
87 * @param period period
88 */
89 public void setPeriod(TimePeriod period){
90 this.period = period;
91 }
92
93 public String getDepartment(){
94 return this.department;
95 }
96
97 /**
98 *
99 * @param department department
100 */
101 public void setDepartment(String department){
102 this.department = department;
103 }
104
105 public String getRole(){
106 return this.role;
107 }
108
109 /**
110 *
111 * @param role role
112 */
113 public void setRole(String role){
114 this.role = role;
115 }
116
117 }