#445: Added missing term vocabularies
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / agent / AgentBase.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 import java.util.List;
13 import java.util.Set;
14
15 import javax.persistence.Embedded;
16 import javax.persistence.Entity;
17 import javax.persistence.Transient;
18 import javax.xml.bind.annotation.XmlAccessType;
19 import javax.xml.bind.annotation.XmlAccessorType;
20 import javax.xml.bind.annotation.XmlElement;
21 import javax.xml.bind.annotation.XmlType;
22
23 import org.apache.log4j.Logger;
24 import org.hibernate.annotations.Index;
25 import org.hibernate.annotations.Table;
26 import org.hibernate.envers.Audited;
27
28 import eu.etaxonomy.cdm.model.location.Point;
29 import eu.etaxonomy.cdm.model.location.WaterbodyOrCountry;
30 import eu.etaxonomy.cdm.model.media.IdentifiableMediaEntity;
31 import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
32 import eu.etaxonomy.cdm.strategy.match.IMatchable;
33 import eu.etaxonomy.cdm.strategy.match.Match;
34 import eu.etaxonomy.cdm.strategy.match.MatchMode;
35 import eu.etaxonomy.cdm.strategy.merge.IMergable;
36 import eu.etaxonomy.cdm.strategy.merge.Merge;
37 import eu.etaxonomy.cdm.strategy.merge.MergeMode;
38
39 /**
40 * The upmost (abstract) class for agents such as persons, teams or institutions.
41 * An agent is a conscious entity which can take decisions, act and create
42 * according to its own knowledge and goals and which may be approached.
43 * Agents can be authors for nomenclatural or bibliographical references as well
44 * as creators of pictures or field collectors or administrators of collections.
45 *
46 * @author m.doering
47 * @version 1.0
48 * @created 08-Nov-2007 13:06:57
49 */
50 @XmlAccessorType(XmlAccessType.FIELD)
51 @XmlType(name = "Agent", propOrder = {
52 "contact"
53 })
54 @Entity
55 @Audited
56 @Table(appliesTo="AgentBase", indexes = { @Index(name = "agentTitleCacheIndex", columnNames = { "titleCache" }) })
57 public abstract class AgentBase<S extends IIdentifiableEntityCacheStrategy> extends IdentifiableMediaEntity<S> implements IMergable, IMatchable{
58 private static final long serialVersionUID = 7732768617469448829L;
59 @SuppressWarnings("unused")
60 private static final Logger logger = Logger.getLogger(AgentBase.class);
61
62 @XmlElement(name = "Contact")
63 @Embedded
64 @Merge(MergeMode.MERGE)
65 @Match(MatchMode.IGNORE)
66 private Contact contact;
67
68 /**
69 * Returns the {@link Contact contact} of <i>this</i> person.
70 * The contact contains several ways to approach <i>this</i> person.
71 *
72 * @see Contact
73 */
74 public Contact getContact(){
75 return this.contact;
76 }
77 /**
78 * @see #getContact()
79 */
80 public void setContact(Contact contact){
81 this.contact = contact;
82 }
83
84
85 /**
86 * Returns the existing contact, or if it does not exists a new contact.
87 * If <code>create</code> is true the new contact will be set as this agent's
88 * contact.
89 * @param create
90 * @return
91 */
92 @Transient
93 private Contact getNewOrExistingContact(boolean create){
94 if (contact != null){
95 return contact;
96 }else{
97 Contact newContact = Contact.NewInstance();
98 if (create){
99 contact = newContact;
100 }
101 return contact;
102 }
103 }
104
105
106 /**
107 * Adds a new address to this agent
108 * @param street
109 * @param postcode
110 * @param locality
111 * @param country
112 * @param pobox
113 * @param region
114 * @param location
115 * @see eu.etaxonomy.cdm.model.agent.Contact#addAddress(java.lang.String, java.lang.String, java.lang.String, eu.etaxonomy.cdm.model.location.WaterbodyOrCountry, java.lang.String, java.lang.String, eu.etaxonomy.cdm.model.location.Point)
116 */
117 public void addAddress(String street, String postcode, String locality,
118 WaterbodyOrCountry country, String pobox, String region,
119 Point location) {
120 getNewOrExistingContact(true).addAddress(street, postcode, locality, country, pobox, region,
121 location);
122 }
123 /**
124 * @param address
125 * @see eu.etaxonomy.cdm.model.agent.Contact#addAddress(eu.etaxonomy.cdm.model.agent.Address)
126 */
127 public void addAddress(Address address) {
128 getNewOrExistingContact(true).addAddress(address);
129 }
130 /**
131 * @param emailAddress
132 * @see eu.etaxonomy.cdm.model.agent.Contact#addEmailAddress(java.lang.String)
133 */
134 public void addEmailAddress(String emailAddress) {
135 getNewOrExistingContact(true).addEmailAddress(emailAddress);
136 }
137 /**
138 * @param faxNumber
139 * @see eu.etaxonomy.cdm.model.agent.Contact#addFaxNumber(java.lang.String)
140 */
141 public void addFaxNumber(String faxNumber) {
142 getNewOrExistingContact(true).addFaxNumber(faxNumber);
143 }
144 /**
145 * @param phoneNumber
146 * @see eu.etaxonomy.cdm.model.agent.Contact#addPhoneNumber(java.lang.String)
147 */
148 public void addPhoneNumber(String phoneNumber) {
149 getNewOrExistingContact(true).addPhoneNumber(phoneNumber);
150 }
151 /**
152 * @param url
153 * @see eu.etaxonomy.cdm.model.agent.Contact#addUrl(java.lang.String)
154 */
155 public void addUrl(String url) {
156 getNewOrExistingContact(true).addUrl(url);
157 }
158 /**
159 * @return
160 * @see eu.etaxonomy.cdm.model.agent.Contact#getAddresses()
161 */
162 @Transient
163 public Set<Address> getAddresses() {
164 return getNewOrExistingContact(false).getAddresses();
165 }
166 /**
167 * @return
168 * @see eu.etaxonomy.cdm.model.agent.Contact#getEmailAddresses()
169 */
170 @Transient
171 public List<String> getEmailAddresses() {
172 return getNewOrExistingContact(false).getEmailAddresses();
173 }
174 /**
175 * @return
176 * @see eu.etaxonomy.cdm.model.agent.Contact#getFaxNumbers()
177 */
178 @Transient
179 public List<String> getFaxNumbers() {
180 return getNewOrExistingContact(false).getFaxNumbers();
181 }
182 /**
183 * @return
184 * @see eu.etaxonomy.cdm.model.agent.Contact#getPhoneNumbers()
185 */
186 @Transient
187 public List<String> getPhoneNumbers() {
188 return getNewOrExistingContact(false).getPhoneNumbers();
189 }
190 /**
191 * @return
192 * @see eu.etaxonomy.cdm.model.agent.Contact#getUrls()
193 */
194 @Transient
195 public List<String> getUrls() {
196 return getNewOrExistingContact(false).getUrls();
197 }
198 /**
199 * @param address
200 * @see eu.etaxonomy.cdm.model.agent.Contact#removeAddress(eu.etaxonomy.cdm.model.agent.Address)
201 */
202 public void removeAddress(Address address) {
203 getNewOrExistingContact(false).removeAddress(address);
204 }
205 /**
206 * @param emailAddress
207 * @see eu.etaxonomy.cdm.model.agent.Contact#removeEmailAddress(java.lang.String)
208 */
209 public void removeEmailAddress(String emailAddress) {
210 getNewOrExistingContact(false).removeEmailAddress(emailAddress);
211 }
212 /**
213 * @param faxNumber
214 * @see eu.etaxonomy.cdm.model.agent.Contact#removeFaxNumber(java.lang.String)
215 */
216 public void removeFaxNumber(String faxNumber) {
217 getNewOrExistingContact(false).removeFaxNumber(faxNumber);
218 }
219 /**
220 * @param phoneNumber
221 * @see eu.etaxonomy.cdm.model.agent.Contact#removePhoneNumber(java.lang.String)
222 */
223 public void removePhoneNumber(String phoneNumber) {
224 getNewOrExistingContact(false).removePhoneNumber(phoneNumber);
225 }
226 /**
227 * @param url
228 * @see eu.etaxonomy.cdm.model.agent.Contact#removeUrl(java.lang.String)
229 */
230 public void removeUrl(String url) {
231 getNewOrExistingContact(false).removeUrl(url);
232 }
233
234
235
236
237 }