package eu.etaxonomy.cdm.model.agent;
import java.io.Serializable;
+import java.net.URI;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import org.hibernate.annotations.CascadeType;
import org.hibernate.envers.Audited;
-import eu.etaxonomy.cdm.model.location.Point;
import eu.etaxonomy.cdm.model.location.Country;
+import eu.etaxonomy.cdm.model.location.Point;
import eu.etaxonomy.cdm.strategy.merge.MergeException;
/**
private static final Logger logger = Logger.getLogger(Contact.class);
+ @XmlElementWrapper(name = "EmailAddresses", nillable = true)
+ @XmlElement(name = "EmailAddress")
+ @ElementCollection(fetch = FetchType.LAZY)
+ @Column(name = "contact_emailaddresses_element")
+ private List<String> emailAddresses;
+
+ @XmlElementWrapper(name = "URLs", nillable = true)
+ @XmlElement(name = "URL")
+ @XmlSchemaType(name = "anyURI")
+ @ElementCollection(fetch = FetchType.LAZY)
+ @Column(name = "contact_urls_element", length=330)
+ @Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.DELETE})
+ private List<String> urls = new ArrayList<String>();
+
+ @XmlElementWrapper(name = "PhoneNumbers", nillable = true)
+ @XmlElement(name = "PhoneNumber")
+ @ElementCollection(fetch = FetchType.LAZY)
+ @Column(name = "contact_phonenumbers_element")
+ @Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.DELETE})
+ private List<String> phoneNumbers;
+
+ @XmlElementWrapper(name = "FaxNumbers", nillable = true)
+ @XmlElement(name = "FaxNumber")
+ @ElementCollection(fetch = FetchType.LAZY)
+ @Column(name = "contact_faxnumbers_element")
+ private List<String> faxNumbers;
+
+ @XmlElementWrapper(name = "Addresses", nillable = true)
+ @XmlElement(name = "Address")
+ @OneToMany(fetch = FetchType.LAZY, orphanRemoval=true)
+ @Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE})
+ protected Set<Address> addresses;
+
+
public static Contact NewInstance() {
return new Contact();
}
*/
public static Contact NewInstance(String street, String postcode, String locality,
Country country, String pobox, String region,
- String email, String faxNumber, String phoneNumber, String url, Point location) {
+ String email, String faxNumber, String phoneNumber, URI url, Point location) {
Contact result = new Contact();
if (country != null || StringUtils.isNotBlank(locality) || StringUtils.isNotBlank(pobox) || StringUtils.isNotBlank(postcode) ||
StringUtils.isNotBlank(region) || StringUtils.isNotBlank(street) ){
public static Contact NewInstance(Set<Address> addresses, List<String> emailAdresses,
- List<String> faxNumbers, List<String> phoneNumbers, List<String> urls) {
+ List<String> faxNumbers, List<String> phoneNumbers, List<URI> urls) {
Contact result = new Contact();
if (addresses != null){
result.addresses = addresses;
result.phoneNumbers = phoneNumbers;
}
if (urls != null){
- result.urls = urls;
+ for (URI uri : urls){
+ result.urls.add(uri.toString());
+ }
}
return result;
}
public Contact() {
}
- @XmlElementWrapper(name = "EmailAddresses", nillable = true)
- @XmlElement(name = "EmailAddress")
- @ElementCollection(fetch = FetchType.LAZY)
- @Column(name = "contact_emailaddresses_element")
- private List<String> emailAddresses;
-
- @XmlElementWrapper(name = "URLs", nillable = true)
- @XmlElement(name = "URL")
- @XmlSchemaType(name = "anyURI")
- @ElementCollection(fetch = FetchType.LAZY)
- @Column(name = "contact_urls_element")
- private List<String> urls;
-
- @XmlElementWrapper(name = "PhoneNumbers", nillable = true)
- @XmlElement(name = "PhoneNumber")
- @ElementCollection(fetch = FetchType.LAZY)
- @Column(name = "contact_phonenumbers_element")
- private List<String> phoneNumbers;
-
- @XmlElementWrapper(name = "FaxNumbers", nillable = true)
- @XmlElement(name = "FaxNumber")
- @ElementCollection(fetch = FetchType.LAZY)
- @Column(name = "contact_faxnumbers_element")
- private List<String> faxNumbers;
-
- @XmlElementWrapper(name = "Addresses", nillable = true)
- @XmlElement(name = "Address")
- @OneToMany(fetch = FetchType.LAZY, orphanRemoval=true)
- @Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE})
- protected Set<Address> addresses;
-
public void merge(Contact contact2) throws MergeException{
if (contact2 != null){
}
}
- public void addAddress(String street, String postcode, String locality,
+ public Address addAddress(String street, String postcode, String locality,
Country country, String pobox, String region, Point location){
Address newAddress = Address.NewInstance(country, locality, pobox, postcode, region, street, location);
getAddresses().add(newAddress);
+ return newAddress;
}
/**
* Returns the list of strings representing the "Uniform Resource Locators" (urls)
* included in <i>this</i> contact.
*/
- public List<String> getUrls(){
- if(this.urls == null) {
- this.urls = new ArrayList<String>();
+ public List<URI> getUrls(){
+ List<URI> result = new ArrayList<URI>();
+ if(this.urls != null) {
+ for (String uri : this.urls){
+ result.add(URI.create(uri));
+ }
}
- return this.urls;
+ return result;
}
/**
* @see #getUrls()
*/
- public void addUrl(String url){
- getUrls().add(url);
+ public void addUrl(URI url){
+ this.urls.add(url.toString());
}
/**
* @param url the url of <i>this</i> contact which should be deleted
* @see #getUrls()
*/
- public void removeUrl(String url){
- getUrls().remove(url);
+ public void removeUrl(URI url){
+ this.urls.remove(url.toString());
}
/**