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.NamedQueries;
35 import javax.persistence.NamedQuery;
36 import javax.persistence.OneToOne;
37 import javax.persistence.Table;
38 import javax.persistence.Temporal;
39 import javax.persistence.TemporalType;
40 import org.mxchange.jcontacts.contact.gender.Gender;
41 import org.mxchange.jcountry.data.Country;
42 import org.mxchange.jcountry.data.CountryData;
43 import org.mxchange.jphone.phonenumbers.cellphone.CellphoneNumber;
44 import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
45 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
46 import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
47 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
48 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
51 * A general contact class which serves as an entity.
53 * @author Roland Haeder<roland@mxchange.org>
56 @Entity (name = "contacts")
61 name = "contact_gender",
62 columnList = "contact_gender"
65 name = "contact_email_address",
67 columnList = "contact_email_address"
73 @NamedQuery (name = "AllContactsByCellphone", query = "SELECT c FROM contacts AS c WHERE c.contactCellphoneNumber = :cellPhone ORDER BY c.contactId ASC"),
74 @NamedQuery (name = "SearchContactById", query = "SELECT c FROM contacts AS c WHERE c.contactId = :contactId")
77 public class UserContact implements Contact {
82 private static final long serialVersionUID = 58_744_284_981_863L;
87 @Column (name = "contact_birthday")
88 @Temporal (TemporalType.DATE)
89 private Date contactBirthday;
94 @JoinColumn (name = "contact_cellphone_number_id", referencedColumnName = "cellphone_id", unique = true)
95 @OneToOne (targetEntity = CellphoneNumber.class, cascade = CascadeType.ALL)
96 private DialableCellphoneNumber contactCellphoneNumber;
101 @Basic (optional = false)
102 @Column (name = "contact_city", nullable = false, length = 100)
103 private String contactCity;
109 @Column (name = "contact_comment")
110 private String contactComment;
115 @JoinColumn (name = "contact_country_id", nullable = false, referencedColumnName = "country_id")
116 @OneToOne (targetEntity = CountryData.class, cascade = CascadeType.REFRESH, optional = false)
117 private Country contactCountry;
120 * When the contact has been created
122 @Basic (optional = false)
123 @Temporal (TemporalType.TIMESTAMP)
124 @Column (name = "contact_created", nullable = false)
125 private Calendar contactCreated;
130 @Basic (optional = false)
131 @Column (name = "contact_email_address", length = 100, nullable = false)
132 private String contactEmailAddress;
137 @Basic (optional = false)
138 @Column (name = "contact_family_name", length = 100, nullable = false)
139 private String contactFamilyName;
144 @JoinColumn (name = "contact_fax_number_id", referencedColumnName = "fax_id", unique = true)
145 @OneToOne (targetEntity = FaxNumber.class, cascade = CascadeType.ALL)
146 private DialableFaxNumber contactFaxNumber;
151 @Basic (optional = false)
152 @Column (name = "contact_first_name", length = 100, nullable = false)
153 private String contactFirstName;
158 @Basic (optional = false)
159 @Column (name = "contact_gender", nullable = false)
160 @Enumerated (EnumType.STRING)
161 private Gender contactGender;
166 @Basic (optional = false)
167 @Column (name = "contact_house_number", length = 5, nullable = false)
168 private Short contactHouseNumber;
174 @GeneratedValue (strategy = GenerationType.IDENTITY)
175 @Column (name = "contact_id", nullable = false, updatable = false)
176 private Long contactId;
179 * Flag whether this contact is user's own data
181 @Basic (optional = false)
182 @Column (name = "contact_own_contact", nullable = false)
183 private Boolean contactOwnContact;
188 @JoinColumn (name = "contact_phone_number_id", referencedColumnName = "phone_id", unique = true)
189 @OneToOne (targetEntity = LandLineNumber.class, cascade = CascadeType.ALL)
190 private DialableLandLineNumber contactPhoneNumber;
195 @Basic (optional = false)
196 @Column (name = "contact_street", nullable = false)
197 private String contactStreet;
200 * Title (Doctor, etc)
202 @Column (name = "contact_title")
203 private String contactTitle;
206 * When the contact has been updated
208 @Temporal (TemporalType.TIMESTAMP)
209 @Column (name = "contact_updated")
210 private Calendar contactUpdated;
215 @Basic (optional = false)
216 @Column (name = "contact_zip_code", nullable = false, length = 6)
217 private Integer contactZipCode;
220 * Default constructor
222 public UserContact () {
223 // Default is not user's own contact
224 this.contactOwnContact = Boolean.FALSE;
227 this.contactGender = Gender.UNKNOWN;
231 * Constructor for contactGender and names
233 * @param contactGender Gender instance
234 * @param contactFirstName First name
235 * @param contactFamilyName Family name
237 public UserContact (final Gender contactGender, final String contactFirstName, final String contactFamilyName) {
238 // Call default constructor
242 this.contactGender = contactGender;
243 this.contactFirstName = contactFirstName;
244 this.contactFamilyName = contactFamilyName;
248 public void copyAll (final Contact contact) {
251 this.setContactFirstName(contact.getContactFirstName());
252 this.setContactFamilyName(contact.getContactFamilyName());
253 this.setContactStreet(contact.getContactStreet());
254 this.setContactZipCode(contact.getContactZipCode());
255 this.setContactCity(contact.getContactCity());
256 this.setContactCountry(contact.getContactCountry());
258 // - phone, fax, email
259 this.setContactLandLineNumber(contact.getContactLandLineNumber());
260 this.setContactFaxNumber(contact.getContactFaxNumber());
261 this.setContactCellphoneNumber(contact.getContactCellphoneNumber());
264 this.setContactBirthday(contact.getContactBirthday());
265 this.setContactComment(contact.getContactComment());
266 this.setContactCreated(contact.getContactCreated());
267 this.setContactUpdated(contact.getContactUpdated());
271 public boolean equals (final Object object) {
273 if (!(object instanceof UserContact)) {
276 } else if (!(object instanceof Contact)) {
277 // Not correct interface
282 Contact contact = (Contact) object;
284 // Now test some data TODO Definedly needs improvement
285 return ((this.getContactGender().equals(contact.getContactGender())) &&
286 (this.getContactFirstName().toLowerCase().equals(contact.getContactFirstName().toLowerCase())) &&
287 (this.getContactFamilyName().toLowerCase().equals(contact.getContactFamilyName().toLowerCase())));
291 public int hashCode () {
292 // Validate contactGender instance
293 assert (this.getContactGender() instanceof Gender) : "gender is not set."; //NOI18N
296 hash = 79 * hash + Objects.hashCode(this.getContactFamilyName());
297 hash = 79 * hash + this.getContactGender().hashCode();
298 hash = 79 * hash + Objects.hashCode(this.getContactFirstName());
303 public Date getContactBirthday () {
304 return this.contactBirthday;
308 public void setContactBirthday (final Date contactBirthday) {
309 this.contactBirthday = contactBirthday;
313 public DialableCellphoneNumber getContactCellphoneNumber () {
314 return this.contactCellphoneNumber;
318 public void setContactCellphoneNumber (final DialableCellphoneNumber contactCellphoneNumber) {
319 this.contactCellphoneNumber = contactCellphoneNumber;
323 public String getContactCity () {
324 return this.contactCity;
328 public void setContactCity (final String contactCity) {
329 this.contactCity = contactCity;
333 public String getContactComment () {
334 return this.contactComment;
338 public void setContactComment (final String contactComment) {
339 this.contactComment = contactComment;
343 public Country getContactCountry () {
344 return this.contactCountry;
348 public void setContactCountry (final Country contactCountry) {
349 this.contactCountry = contactCountry;
353 public Calendar getContactCreated () {
354 return this.contactCreated;
358 public void setContactCreated (final Calendar contactCreated) {
359 this.contactCreated = contactCreated;
363 public String getContactEmailAddress () {
364 return this.contactEmailAddress;
368 public void setContactEmailAddress (final String contactEmailAddress) {
369 this.contactEmailAddress = contactEmailAddress;
373 public String getContactFamilyName () {
374 //* NOISY-DEBUG: */ this.getLogger().logTrace("CALLED!");
375 return this.contactFamilyName;
379 public void setContactFamilyName (final String contactFamilyName) {
380 this.contactFamilyName = contactFamilyName;
384 public DialableFaxNumber getContactFaxNumber () {
385 return this.contactFaxNumber;
389 public void setContactFaxNumber (final DialableFaxNumber contactFaxNumber) {
390 this.contactFaxNumber = contactFaxNumber;
394 public String getContactFirstName () {
395 return this.contactFirstName;
399 public void setContactFirstName (final String contactFirstName) {
400 this.contactFirstName = contactFirstName;
404 public Gender getContactGender () {
405 return this.contactGender;
409 public void setContactGender (final Gender contactGender) {
410 this.contactGender = contactGender;
414 public Short getContactHouseNumber () {
415 return this.contactHouseNumber;
419 public void setContactHouseNumber (final Short contactHouseNumber) {
420 this.contactHouseNumber = contactHouseNumber;
424 public Long getContactId () {
425 return this.contactId;
429 public void setContactId (final Long contactId) {
430 this.contactId = contactId;
434 public void setContactOwnContact (final Boolean contactOwnContact) {
435 this.contactOwnContact = contactOwnContact;
439 public DialableLandLineNumber getContactLandLineNumber () {
440 return this.contactPhoneNumber;
444 public void setContactLandLineNumber (final DialableLandLineNumber contactPhoneNumber) {
445 this.contactPhoneNumber = contactPhoneNumber;
449 public String getContactStreet () {
450 return this.contactStreet;
454 public void setContactStreet (final String contactStreet) {
455 this.contactStreet = contactStreet;
459 public String getContactTitle () {
460 return this.contactTitle;
464 public void setContactTitle (final String contactTitle) {
465 this.contactTitle = contactTitle;
469 public Calendar getContactUpdated () {
470 return this.contactUpdated;
474 public void setContactUpdated (final Calendar contactUpdated) {
475 this.contactUpdated = contactUpdated;
479 public Integer getContactZipCode () {
480 return this.contactZipCode;
484 public void setContactZipCode (final Integer contactZipCode) {
485 this.contactZipCode = contactZipCode;
489 public Boolean isOwnContact () {
490 return this.contactOwnContact;