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