Project

General

Profile

Download (7.57 KB) Statistics
| Branch: | Tag: | Revision:
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.Index;
18
import javax.persistence.Table;
19
import javax.persistence.Transient;
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.XmlType;
24

    
25
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
26
import org.hibernate.annotations.Cascade;
27
import org.hibernate.annotations.CascadeType;
28
import org.hibernate.envers.Audited;
29

    
30
import eu.etaxonomy.cdm.common.URI;
31
import eu.etaxonomy.cdm.model.common.IIntextReferenceTarget;
32
import eu.etaxonomy.cdm.model.location.Country;
33
import eu.etaxonomy.cdm.model.location.Point;
34
import eu.etaxonomy.cdm.model.media.IdentifiableMediaEntity;
35
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
36
import eu.etaxonomy.cdm.strategy.match.IMatchable;
37
import eu.etaxonomy.cdm.strategy.match.Match;
38
import eu.etaxonomy.cdm.strategy.match.MatchMode;
39
import eu.etaxonomy.cdm.strategy.merge.IMergable;
40
import eu.etaxonomy.cdm.strategy.merge.Merge;
41
import eu.etaxonomy.cdm.strategy.merge.MergeMode;
42

    
43
/**
44
 * The upmost (abstract) class for agents such as persons, teams or institutions.
45
 * An agent is a conscious entity which can make decisions, act and create
46
 * according to its own knowledge and goals and which may be approached.
47
 * Agents can be authors for nomenclatural or bibliographical references as well
48
 * as creators of pictures or field collectors or administrators of collections.
49
 *
50
 * @author m.doering
51
 * @since 08-Nov-2007 13:06:57
52
 */
53
@XmlAccessorType(XmlAccessType.FIELD)
54
@XmlType(name = "AgentBase", propOrder = {
55
		"contact"
56
})
57
@Entity
58
@Audited
59
@Table(name="AgentBase", indexes = { @Index(name = "agentTitleCacheIndex", columnList = "titleCache") })
60
public abstract class AgentBase<S extends IIdentifiableEntityCacheStrategy<? extends AgentBase<S>>>
61
        extends IdentifiableMediaEntity<S>
62
        implements IMergable, IMatchable, IIntextReferenceTarget{
63

    
64
	private static final long serialVersionUID = 7732768617469448829L;
65
	@SuppressWarnings("unused")
66
	private static final Logger logger = LogManager.getLogger(AgentBase.class);
67

    
68
	@XmlElement(name = "Contact")
69
    @Embedded
70
    @Merge(MergeMode.MERGE)
71
    @Match(MatchMode.IGNORE)
72
    @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE, CascadeType.DELETE})
73
	private Contact contact = new Contact();
74

    
75
	/**
76
	 * Returns the {@link Contact contact} of <i>this</i> person.
77
	 * The contact contains several ways to approach <i>this</i> person.
78
	 *
79
	 * @see 	Contact
80
	 */
81
	public Contact getContact(){
82
		return this.contact;
83
	}
84
	/**
85
	 * @see  #getContact()
86
	 */
87
	public void setContact(Contact contact){
88
		this.contact = contact;
89
	}
90

    
91

    
92
	/**
93
	 * Returns the existing contact, or if it does not exists a new contact.
94
	 * If <code>create</code> is true the new contact will be set as this agent's
95
	 * contact.
96
	 * @param create
97
	 * @return
98
	 */
99
	@Transient
100
	private Contact getNewOrExistingContact(boolean create){
101
		if (contact != null){
102
			return contact;
103
		}else{
104
			Contact newContact = Contact.NewInstance();
105
			if (create){
106
				contact = newContact;
107
				this.setContact(contact);
108
			}
109
			return contact;
110
		}
111
	}
112

    
113

    
114
	/**
115
	 * Adds a new address to this agent
116
	 * @param street
117
	 * @param postcode
118
	 * @param locality
119
	 * @param country
120
	 * @param pobox
121
	 * @param region
122
	 * @param location
123
	 * @see eu.etaxonomy.cdm.model.agent.Contact#addAddress(java.lang.String, java.lang.String, java.lang.String, eu.etaxonomy.cdm.model.location.Country, java.lang.String, java.lang.String, eu.etaxonomy.cdm.model.location.Point)
124
	 */
125
	public Address addAddress(String street, String postcode, String locality,
126
			Country country, String pobox, String region,
127
			Point location) {
128
		return getNewOrExistingContact(true).addAddress(street, postcode, locality, country, pobox, region,
129
				location);
130
	}
131
	/**
132
	 * @param address
133
	 * @see eu.etaxonomy.cdm.model.agent.Contact#addAddress(eu.etaxonomy.cdm.model.agent.Address)
134
	 */
135
	public void addAddress(Address address) {
136
		getNewOrExistingContact(true).addAddress(address);
137
	}
138
	/**
139
	 * @param emailAddress
140
	 * @see eu.etaxonomy.cdm.model.agent.Contact#addEmailAddress(java.lang.String)
141
	 */
142
	public void addEmailAddress(String emailAddress) {
143
		getNewOrExistingContact(true).addEmailAddress(emailAddress);
144
	}
145
	/**
146
	 * @param faxNumber
147
	 * @see eu.etaxonomy.cdm.model.agent.Contact#addFaxNumber(java.lang.String)
148
	 */
149
	public void addFaxNumber(String faxNumber) {
150
		getNewOrExistingContact(true).addFaxNumber(faxNumber);
151
	}
152
	/**
153
	 * @param phoneNumber
154
	 * @see eu.etaxonomy.cdm.model.agent.Contact#addPhoneNumber(java.lang.String)
155
	 */
156
	public void addPhoneNumber(String phoneNumber) {
157
		getNewOrExistingContact(true).addPhoneNumber(phoneNumber);
158
	}
159
	/**
160
	 * @param url
161
	 * @see eu.etaxonomy.cdm.model.agent.Contact#addUrl(java.lang.String)
162
	 */
163
	public void addUrl(URI url) {
164
		getNewOrExistingContact(true).addUrl(url);
165
	}
166
	/**
167
	 * @return
168
	 * @see eu.etaxonomy.cdm.model.agent.Contact#getAddresses()
169
	 */
170
	@Transient
171
	public Set<Address> getAddresses() {
172
		return getNewOrExistingContact(false).getAddresses();
173
	}
174
	/**
175
	 * @return
176
	 * @see eu.etaxonomy.cdm.model.agent.Contact#getEmailAddresses()
177
	 */
178
	@Transient
179
	public List<String> getEmailAddresses() {
180
		return getNewOrExistingContact(false).getEmailAddresses();
181
	}
182
	/**
183
	 * @return
184
	 * @see eu.etaxonomy.cdm.model.agent.Contact#getFaxNumbers()
185
	 */
186
	@Transient
187
	public List<String> getFaxNumbers() {
188
		return getNewOrExistingContact(false).getFaxNumbers();
189
	}
190
	/**
191
	 * @return
192
	 * @see eu.etaxonomy.cdm.model.agent.Contact#getPhoneNumbers()
193
	 */
194
	@Transient
195
	public List<String> getPhoneNumbers() {
196
		return getNewOrExistingContact(false).getPhoneNumbers();
197
	}
198
	/**
199
	 * @return
200
	 * @see eu.etaxonomy.cdm.model.agent.Contact#getUrls()
201
	 */
202
	@Transient
203
	public List<String> getUrls() {
204
		return getNewOrExistingContact(false).getUrls();
205
	}
206
	/**
207
	 * @param address
208
	 * @see eu.etaxonomy.cdm.model.agent.Contact#removeAddress(eu.etaxonomy.cdm.model.agent.Address)
209
	 */
210
	public void removeAddress(Address address) {
211
		getNewOrExistingContact(false).removeAddress(address);
212
	}
213
	/**
214
	 * @param emailAddress
215
	 * @see eu.etaxonomy.cdm.model.agent.Contact#removeEmailAddress(java.lang.String)
216
	 */
217
	public void removeEmailAddress(String emailAddress) {
218
		getNewOrExistingContact(false).removeEmailAddress(emailAddress);
219
	}
220
	/**
221
	 * @param faxNumber
222
	 * @see eu.etaxonomy.cdm.model.agent.Contact#removeFaxNumber(java.lang.String)
223
	 */
224
	public void removeFaxNumber(String faxNumber) {
225
		getNewOrExistingContact(false).removeFaxNumber(faxNumber);
226
	}
227
	/**
228
	 * @param phoneNumber
229
	 * @see eu.etaxonomy.cdm.model.agent.Contact#removePhoneNumber(java.lang.String)
230
	 */
231
	public void removePhoneNumber(String phoneNumber) {
232
		getNewOrExistingContact(false).removePhoneNumber(phoneNumber);
233
	}
234
	/**
235
	 * @param url
236
	 * @see eu.etaxonomy.cdm.model.agent.Contact#removeUrl(java.lang.String)
237
	 */
238
	public void removeUrl(URI url) {
239
		getNewOrExistingContact(false).removeUrl(url);
240
	}
241

    
242
    @Override
243
    public AgentBase<S> clone() throws CloneNotSupportedException {
244
        AgentBase<S> result = (AgentBase<S>)super.clone();
245

    
246
        result.setContact(this.contact == null ? null : this.contact.clone());
247
        //nothing to do: contact
248
        return result;
249
    }
250

    
251
}
(2-2/12)