2 * Copyright (C) 2016 Roland Haeder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.jcontacts.contact;
19 import java.util.Calendar;
20 import java.util.Date;
21 import java.util.Objects;
22 import javax.persistence.Basic;
23 import javax.persistence.CascadeType;
24 import javax.persistence.Column;
25 import javax.persistence.Entity;
26 import javax.persistence.EnumType;
27 import javax.persistence.Enumerated;
28 import javax.persistence.GeneratedValue;
29 import javax.persistence.GenerationType;
30 import javax.persistence.Id;
31 import javax.persistence.Index;
32 import javax.persistence.JoinColumn;
33 import javax.persistence.Lob;
34 import javax.persistence.OneToOne;
35 import javax.persistence.Table;
36 import javax.persistence.Temporal;
37 import javax.persistence.TemporalType;
38 import org.mxchange.jcontacts.contact.gender.Gender;
39 import org.mxchange.jcountry.data.Country;
40 import org.mxchange.jcountry.data.CountryData;
41 import org.mxchange.jphone.phonenumbers.cellphone.CellphoneNumber;
42 import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
43 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
44 import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
45 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
46 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
49 * A general contact class which serves as an entity.
51 * @author Roland Haeder<roland@mxchange.org>
54 @Entity (name = "contacts")
59 name = "contact_gender",
60 columnList = "contact_gender"
63 name = "contact_email_address",
65 columnList = "contact_email_address"
69 public class UserContact implements Contact {
74 private static final long serialVersionUID = 58_744_284_981_863L;
79 @Column (name = "contact_birthday")
80 @Temporal (TemporalType.DATE)
81 private Date contactBirthday;
86 @JoinColumn (name = "contact_cellphone_number_id", referencedColumnName = "cellphone_id", unique = true)
87 @OneToOne (targetEntity = CellphoneNumber.class, cascade = CascadeType.ALL)
88 private DialableCellphoneNumber contactCellphoneNumber;
93 @Basic (optional = false)
94 @Column (name = "contact_city", nullable = false, length = 100)
95 private String contactCity;
101 @Column (name = "contact_comment")
102 private String contactComment;
107 @JoinColumn (name = "contact_country_id", nullable = false, referencedColumnName = "country_id")
108 @OneToOne (targetEntity = CountryData.class, cascade = CascadeType.REFRESH, optional = false)
109 private Country contactCountry;
112 * When the contact has been created
114 @Basic (optional = false)
115 @Temporal (TemporalType.TIMESTAMP)
116 @Column (name = "contact_created", nullable = false)
117 private Calendar contactCreated;
122 @Basic (optional = false)
123 @Column (name = "contact_email_address", length = 100, nullable = false)
124 private String contactEmailAddress;
129 @Basic (optional = false)
130 @Column (name = "contact_family_name", length = 100, nullable = false)
131 private String contactFamilyName;
136 @JoinColumn (name = "contact_fax_number_id", referencedColumnName = "fax_id", unique = true)
137 @OneToOne (targetEntity = FaxNumber.class, cascade = CascadeType.ALL)
138 private DialableFaxNumber contactFaxNumber;
143 @Basic (optional = false)
144 @Column (name = "contact_first_name", length = 100, nullable = false)
145 private String contactFirstName;
150 @Basic (optional = false)
151 @Column (name = "contact_gender", nullable = false)
152 @Enumerated (EnumType.STRING)
153 private Gender contactGender;
158 @Basic (optional = false)
159 @Column (name = "contact_house_number", length = 5, nullable = false)
160 private Short contactHouseNumber;
166 @GeneratedValue (strategy = GenerationType.IDENTITY)
167 @Column (name = "contact_id", nullable = false, updatable = false)
168 private Long contactId;
171 * Flag whether this contact is user's own data
173 @Basic (optional = false)
174 @Column (name = "contact_own_contact", nullable = false)
175 private Boolean contactOwnContact;
180 @JoinColumn (name = "contact_phone_number_id", referencedColumnName = "phone_id", unique = true)
181 @OneToOne (targetEntity = LandLineNumber.class, cascade = CascadeType.ALL)
182 private DialableLandLineNumber contactPhoneNumber;
187 @Basic (optional = false)
188 @Column (name = "contact_street", nullable = false)
189 private String contactStreet;
192 * Title (Doctor, etc)
194 @Column (name = "contact_title")
195 private String contactTitle;
198 * When the contact has been updated
200 @Temporal (TemporalType.TIMESTAMP)
201 @Column (name = "contact_updated")
202 private Calendar contactUpdated;
207 @Basic (optional = false)
208 @Column (name = "contact_zip_code", nullable = false, length = 6)
209 private Integer contactZipCode;
212 * Default constructor
214 public UserContact () {
215 // Default is not user's own contact
216 this.contactOwnContact = Boolean.FALSE;
219 this.contactGender = Gender.UNKNOWN;
223 * Constructor for contactGender and names
225 * @param contactGender Gender instance
226 * @param contactFirstName First name
227 * @param contactFamilyName Family name
229 public UserContact (final Gender contactGender, final String contactFirstName, final String contactFamilyName) {
230 // Call default constructor
234 this.contactGender = contactGender;
235 this.contactFirstName = contactFirstName;
236 this.contactFamilyName = contactFamilyName;
240 public void copyAll (final Contact contact) {
243 this.setContactFirstName(contact.getContactFirstName());
244 this.setContactFamilyName(contact.getContactFamilyName());
245 this.setContactStreet(contact.getContactStreet());
246 this.setContactZipCode(contact.getContactZipCode());
247 this.setContactCity(contact.getContactCity());
248 this.setContactCountry(contact.getContactCountry());
250 // - phone, fax, email
251 this.setContactLandLineNumber(contact.getContactLandLineNumber());
252 this.setContactFaxNumber(contact.getContactFaxNumber());
253 this.setContactCellphoneNumber(contact.getContactCellphoneNumber());
256 this.setContactBirthday(contact.getContactBirthday());
257 this.setContactComment(contact.getContactComment());
258 this.setContactCreated(contact.getContactCreated());
259 this.setContactUpdated(contact.getContactUpdated());
263 public boolean equals (final Object object) {
265 if (!(object instanceof UserContact)) {
268 } else if (!(object instanceof Contact)) {
269 // Not correct interface
274 Contact contact = (Contact) object;
276 // Now test some data TODO Definedly needs improvement
277 return ((this.getContactGender().equals(contact.getContactGender())) &&
278 (this.getContactFirstName().toLowerCase().equals(contact.getContactFirstName().toLowerCase())) &&
279 (this.getContactFamilyName().toLowerCase().equals(contact.getContactFamilyName().toLowerCase())));
283 public int hashCode () {
284 // Validate contactGender instance
285 assert (this.getContactGender() instanceof Gender) : "gender is not set."; //NOI18N
288 hash = 79 * hash + Objects.hashCode(this.getContactFamilyName());
289 hash = 79 * hash + this.getContactGender().hashCode();
290 hash = 79 * hash + Objects.hashCode(this.getContactFirstName());
295 public Date getContactBirthday () {
296 return this.contactBirthday;
300 public void setContactBirthday (final Date contactBirthday) {
301 this.contactBirthday = contactBirthday;
305 public DialableCellphoneNumber getContactCellphoneNumber () {
306 return this.contactCellphoneNumber;
310 public void setContactCellphoneNumber (final DialableCellphoneNumber contactCellphoneNumber) {
311 this.contactCellphoneNumber = contactCellphoneNumber;
315 public String getContactCity () {
316 return this.contactCity;
320 public void setContactCity (final String contactCity) {
321 this.contactCity = contactCity;
325 public String getContactComment () {
326 return this.contactComment;
330 public void setContactComment (final String contactComment) {
331 this.contactComment = contactComment;
335 public Country getContactCountry () {
336 return this.contactCountry;
340 public void setContactCountry (final Country contactCountry) {
341 this.contactCountry = contactCountry;
345 public Calendar getContactCreated () {
346 return this.contactCreated;
350 public void setContactCreated (final Calendar contactCreated) {
351 this.contactCreated = contactCreated;
355 public String getContactEmailAddress () {
356 return this.contactEmailAddress;
360 public void setContactEmailAddress (final String contactEmailAddress) {
361 this.contactEmailAddress = contactEmailAddress;
365 public String getContactFamilyName () {
366 //* NOISY-DEBUG: */ this.getLogger().logTrace("CALLED!");
367 return this.contactFamilyName;
371 public void setContactFamilyName (final String contactFamilyName) {
372 this.contactFamilyName = contactFamilyName;
376 public DialableFaxNumber getContactFaxNumber () {
377 return this.contactFaxNumber;
381 public void setContactFaxNumber (final DialableFaxNumber contactFaxNumber) {
382 this.contactFaxNumber = contactFaxNumber;
386 public String getContactFirstName () {
387 return this.contactFirstName;
391 public void setContactFirstName (final String contactFirstName) {
392 this.contactFirstName = contactFirstName;
396 public Gender getContactGender () {
397 return this.contactGender;
401 public void setContactGender (final Gender contactGender) {
402 this.contactGender = contactGender;
406 public Short getContactHouseNumber () {
407 return this.contactHouseNumber;
411 public void setContactHouseNumber (final Short contactHouseNumber) {
412 this.contactHouseNumber = contactHouseNumber;
416 public Long getContactId () {
417 return this.contactId;
421 public void setContactId (final Long contactId) {
422 this.contactId = contactId;
426 public void setContactOwnContact (final Boolean contactOwnContact) {
427 this.contactOwnContact = contactOwnContact;
431 public DialableLandLineNumber getContactLandLineNumber () {
432 return this.contactPhoneNumber;
436 public void setContactLandLineNumber (final DialableLandLineNumber contactPhoneNumber) {
437 this.contactPhoneNumber = contactPhoneNumber;
441 public String getContactStreet () {
442 return this.contactStreet;
446 public void setContactStreet (final String contactStreet) {
447 this.contactStreet = contactStreet;
451 public String getContactTitle () {
452 return this.contactTitle;
456 public void setContactTitle (final String contactTitle) {
457 this.contactTitle = contactTitle;
461 public Calendar getContactUpdated () {
462 return this.contactUpdated;
466 public void setContactUpdated (final Calendar contactUpdated) {
467 this.contactUpdated = contactUpdated;
471 public Integer getContactZipCode () {
472 return this.contactZipCode;
476 public void setContactZipCode (final Integer contactZipCode) {
477 this.contactZipCode = contactZipCode;
481 public Boolean isOwnContact () {
482 return this.contactOwnContact;