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.annotation.PostConstruct;
23 import javax.persistence.Basic;
24 import javax.persistence.CascadeType;
25 import javax.persistence.Column;
26 import javax.persistence.Entity;
27 import javax.persistence.EnumType;
28 import javax.persistence.Enumerated;
29 import javax.persistence.GeneratedValue;
30 import javax.persistence.GenerationType;
31 import javax.persistence.Id;
32 import javax.persistence.Index;
33 import javax.persistence.JoinColumn;
34 import javax.persistence.Lob;
35 import javax.persistence.OneToOne;
36 import javax.persistence.Table;
37 import javax.persistence.Temporal;
38 import javax.persistence.TemporalType;
39 import org.mxchange.jcontacts.contact.gender.Gender;
40 import org.mxchange.jcountry.data.Country;
41 import org.mxchange.jcountry.data.CountryData;
42 import org.mxchange.jphone.phonenumbers.cellphone.CellphoneNumber;
43 import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
44 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
45 import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
46 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
47 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
50 * A general contact class which serves as an entity.
52 * @author Roland Haeder<roland@mxchange.org>
55 @Entity (name = "contacts")
60 name = "contact_gender",
61 columnList = "contact_gender"
64 name = "contact_email_address",
66 columnList = "contact_email_address"
70 public class UserContact implements Contact {
75 private static final long serialVersionUID = 58_744_284_981_863L;
80 @Column (name = "contact_birthday")
81 @Temporal (TemporalType.DATE)
82 private Date contactBirthday;
87 @JoinColumn (name = "contact_cellphone_number_id", referencedColumnName = "cellphone_id", unique = true)
88 @OneToOne (targetEntity = CellphoneNumber.class, cascade = CascadeType.ALL)
89 private DialableCellphoneNumber contactCellphoneNumber;
94 @Basic (optional = false)
95 @Column (name = "contact_city", nullable = false, length = 100)
96 private String contactCity;
102 @Column (name = "contact_comment")
103 private String contactComment;
108 @JoinColumn (name = "contact_country_id", nullable = false, referencedColumnName = "country_id")
109 @OneToOne (targetEntity = CountryData.class, cascade = CascadeType.REFRESH, optional = false)
110 private Country contactCountry;
113 * When the contact has been created
115 @Basic (optional = false)
116 @Temporal (TemporalType.TIMESTAMP)
117 @Column (name = "contact_created", nullable = false)
118 private Calendar contactCreated;
123 @Basic (optional = false)
124 @Column (name = "contact_email_address", length = 100, nullable = false)
125 private String contactEmailAddress;
130 @Basic (optional = false)
131 @Column (name = "contact_family_name", length = 100, nullable = false)
132 private String contactFamilyName;
137 @JoinColumn (name = "contact_fax_number_id", referencedColumnName = "fax_id", unique = true)
138 @OneToOne (targetEntity = FaxNumber.class, cascade = CascadeType.ALL)
139 private DialableFaxNumber contactFaxNumber;
144 @Basic (optional = false)
145 @Column (name = "contact_first_name", length = 100, nullable = false)
146 private String contactFirstName;
151 @Basic (optional = false)
152 @Column (name = "contact_gender", nullable = false)
153 @Enumerated (EnumType.STRING)
154 private Gender contactGender;
159 @Basic (optional = false)
160 @Column (name = "contact_house_number", length = 5, nullable = false)
161 private Short contactHouseNumber;
167 @GeneratedValue (strategy = GenerationType.IDENTITY)
168 @Column (name = "contact_id", length = 20, nullable = false, updatable = false)
169 private Long contactId;
172 * Flag whether this contact is user's own data
174 @Basic (optional = false)
175 @Column (name = "contact_own_contact", nullable = false)
176 private Boolean contactOwnContact;
181 @JoinColumn (name = "contact_phone_number_id", referencedColumnName = "phone_id", unique = true)
182 @OneToOne (targetEntity = LandLineNumber.class, cascade = CascadeType.ALL)
183 private DialableLandLineNumber contactPhoneNumber;
188 @Basic (optional = false)
189 @Column (name = "contact_street", nullable = false)
190 private String contactStreet;
193 * Title (Doctor, etc)
195 @Column (name = "contact_title")
196 private String contactTitle;
199 * When the contact has been updated
201 @Temporal (TemporalType.TIMESTAMP)
202 @Column (name = "contact_updated")
203 private Calendar contactUpdated;
208 @Basic (optional = false)
209 @Column (name = "contact_zip_code", nullable = false, length = 6)
210 private Integer contactZipCode;
213 * Constructor for contactGender and names
215 * @param contactGender Gender instance
216 * @param contactFirstName First name
217 * @param contactFamilyName Family name
219 public UserContact (final Gender contactGender, final String contactFirstName, final String contactFamilyName) {
220 // Call other constructor
224 this.contactGender = contactGender;
225 this.contactFirstName = contactFirstName;
226 this.contactFamilyName = contactFamilyName;
230 * Default constructor
232 public UserContact () {
233 // Default is not user's own contact
234 this.contactOwnContact = Boolean.FALSE;
238 public void copyAll (final Contact contact) {
241 this.setContactFirstName(contact.getContactFirstName());
242 this.setContactFamilyName(contact.getContactFamilyName());
243 this.setContactStreet(contact.getContactStreet());
244 this.setContactZipCode(contact.getContactZipCode());
245 this.setContactCity(contact.getContactCity());
246 this.setContactCountry(contact.getContactCountry());
248 // - phone, fax, email
249 this.setContactLandLineNumber(contact.getContactLandLineNumber());
250 this.setContactFaxNumber(contact.getContactFaxNumber());
251 this.setContactCellphoneNumber(contact.getContactCellphoneNumber());
254 this.setContactBirthday(contact.getContactBirthday());
255 this.setContactComment(contact.getContactComment());
256 this.setContactCreated(contact.getContactCreated());
257 this.setContactUpdated(contact.getContactUpdated());
261 public boolean equals (final Object object) {
263 if (!(object instanceof UserContact)) {
266 } else if (!(object instanceof Contact)) {
267 // Not correct interface
272 Contact contact = (Contact) object;
274 // Now test some data TODO Definedly needs improvement
275 return ((this.getContactGender().equals(contact.getContactGender())) &&
276 (this.getContactFirstName().toLowerCase().equals(contact.getContactFirstName().toLowerCase())) &&
277 (this.getContactFamilyName().toLowerCase().equals(contact.getContactFamilyName().toLowerCase())));
281 public int hashCode () {
282 // Validate contactGender instance
283 assert (this.getContactGender() instanceof Gender) : "gender is not set."; //NOI18N
286 hash = 79 * hash + Objects.hashCode(this.getContactFamilyName());
287 hash = 79 * hash + this.getContactGender().hashCode();
288 hash = 79 * hash + Objects.hashCode(this.getContactFirstName());
293 public Date getContactBirthday () {
294 return this.contactBirthday;
298 public void setContactBirthday (final Date contactBirthday) {
299 this.contactBirthday = contactBirthday;
303 public DialableCellphoneNumber getContactCellphoneNumber () {
304 return this.contactCellphoneNumber;
308 public void setContactCellphoneNumber (final DialableCellphoneNumber contactCellphoneNumber) {
309 this.contactCellphoneNumber = contactCellphoneNumber;
313 public String getContactCity () {
314 return this.contactCity;
318 public void setContactCity (final String contactCity) {
319 this.contactCity = contactCity;
323 public String getContactComment () {
324 return this.contactComment;
328 public void setContactComment (final String contactComment) {
329 this.contactComment = contactComment;
333 public Country getContactCountry () {
334 return this.contactCountry;
338 public void setContactCountry (final Country contactCountry) {
339 this.contactCountry = contactCountry;
343 public Calendar getContactCreated () {
344 return this.contactCreated;
348 public void setContactCreated (final Calendar contactCreated) {
349 this.contactCreated = contactCreated;
353 public String getContactEmailAddress () {
354 return this.contactEmailAddress;
358 public void setContactEmailAddress (final String contactEmailAddress) {
359 this.contactEmailAddress = contactEmailAddress;
363 public String getContactFamilyName () {
364 //* NOISY-DEBUG: */ this.getLogger().logTrace("CALLED!");
365 return this.contactFamilyName;
369 public void setContactFamilyName (final String contactFamilyName) {
370 this.contactFamilyName = contactFamilyName;
374 public DialableFaxNumber getContactFaxNumber () {
375 return this.contactFaxNumber;
379 public void setContactFaxNumber (final DialableFaxNumber contactFaxNumber) {
380 this.contactFaxNumber = contactFaxNumber;
384 public String getContactFirstName () {
385 return this.contactFirstName;
389 public void setContactFirstName (final String contactFirstName) {
390 this.contactFirstName = contactFirstName;
394 public Gender getContactGender () {
395 return this.contactGender;
399 public void setContactGender (final Gender contactGender) {
400 this.contactGender = contactGender;
404 public Short getContactHouseNumber () {
405 return this.contactHouseNumber;
409 public void setContactHouseNumber (final Short contactHouseNumber) {
410 this.contactHouseNumber = contactHouseNumber;
414 public Long getContactId () {
415 return this.contactId;
419 public void setContactId (final Long contactId) {
420 this.contactId = contactId;
424 public void setContactOwnContact (final Boolean contactOwnContact) {
425 this.contactOwnContact = contactOwnContact;
429 public DialableLandLineNumber getContactLandLineNumber () {
430 return this.contactPhoneNumber;
434 public void setContactLandLineNumber (final DialableLandLineNumber contactPhoneNumber) {
435 this.contactPhoneNumber = contactPhoneNumber;
439 public String getContactStreet () {
440 return this.contactStreet;
444 public void setContactStreet (final String contactStreet) {
445 this.contactStreet = contactStreet;
449 public String getContactTitle () {
450 return this.contactTitle;
454 public void setContactTitle (final String contactTitle) {
455 this.contactTitle = contactTitle;
459 public Calendar getContactUpdated () {
460 return this.contactUpdated;
464 public void setContactUpdated (final Calendar contactUpdated) {
465 this.contactUpdated = contactUpdated;
469 public Integer getContactZipCode () {
470 return this.contactZipCode;
474 public void setContactZipCode (final Integer contactZipCode) {
475 this.contactZipCode = contactZipCode;
479 * Initialization with fake contactGender UNKNOWN
482 public void init () {
483 // Fake contactGender
484 this.contactGender = Gender.UNKNOWN;
488 public Boolean isOwnContact () {
489 return this.contactOwnContact;