]> git.mxchange.org Git - jcontacts-core.git/blob - src/org/mxchange/jcontacts/model/contact/UserContact.java
Continued:
[jcontacts-core.git] / src / org / mxchange / jcontacts / model / contact / UserContact.java
1 /*
2  * Copyright (C) 2016, 2017 Roland Häder
3  *
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.
8  *
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.
13  *
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/>.
16  */
17 package org.mxchange.jcontacts.model.contact;
18
19 import java.util.Date;
20 import java.util.Objects;
21 import javax.persistence.Basic;
22 import javax.persistence.CascadeType;
23 import javax.persistence.Column;
24 import javax.persistence.Entity;
25 import javax.persistence.EnumType;
26 import javax.persistence.Enumerated;
27 import javax.persistence.GeneratedValue;
28 import javax.persistence.GenerationType;
29 import javax.persistence.Id;
30 import javax.persistence.Index;
31 import javax.persistence.JoinColumn;
32 import javax.persistence.Lob;
33 import javax.persistence.NamedQueries;
34 import javax.persistence.NamedQuery;
35 import javax.persistence.OneToOne;
36 import javax.persistence.Table;
37 import javax.persistence.Temporal;
38 import javax.persistence.TemporalType;
39 import javax.persistence.Transient;
40 import org.mxchange.jcontacts.model.contact.title.PersonalTitle;
41 import org.mxchange.jcountry.model.data.Country;
42 import org.mxchange.jcountry.model.data.CountryData;
43 import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
44 import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber;
45 import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
46 import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumber;
47 import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
48 import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumber;
49
50 /**
51  * A general contact class which serves as an entity.
52  * <p>
53  * @author Roland Häder<roland@mxchange.org>
54  * @version 0.0
55  */
56 @Entity (name = "contacts")
57 @Table (
58                 name = "contacts",
59                 indexes = {
60                         @Index (
61                                         name = "contact_personal_title",
62                                         columnList = "contact_personal_title"
63                         )
64                 }
65 )
66 @NamedQueries (
67                 {
68                         @NamedQuery (name = "AllContacts", query = "SELECT c FROM contacts AS c ORDER BY c.contactId ASC"),
69                         @NamedQuery (name = "AllContactEmailAddresses", query = "SELECT c.contactEmailAddress FROM contacts AS c ORDER BY c.contactId ASC"),
70                         @NamedQuery (name = "AllContactsByCellphone", query = "SELECT c FROM contacts AS c WHERE c.contactMobileNumber = :mobileNumber ORDER BY c.contactId ASC"),
71                         @NamedQuery (name = "SearchContact", query = "SELECT c FROM contacts AS c WHERE c = :contact"),
72                         @NamedQuery (name = "SearchContactById", query = "SELECT c FROM contacts AS c WHERE c.contactId = :contactId"),
73                         @NamedQuery (name = "SearchContactByEmailAddress", query = "SELECT c FROM contacts AS c WHERE LOWER(c.contactEmailAddress) LIKE LOWER(:emailAddress)")
74                 }
75 )
76 @SuppressWarnings ("PersistenceUnitPresent")
77 public class UserContact implements Contact {
78
79         /**
80          * Serial number
81          */
82         @Transient
83         private static final long serialVersionUID = 58_744_284_981_863L;
84
85         /**
86          * Birth day
87          */
88         @Column (name = "contact_birthday")
89         @Temporal (TemporalType.DATE)
90         private Date contactBirthday;
91
92         /**
93          * City
94          */
95         @Column (name = "contact_city", length = 100)
96         private String contactCity;
97
98         /**
99          * Optional comments
100          */
101         @Lob
102         @Column (name = "contact_comment")
103         private String contactComment;
104
105         /**
106          * Country code
107          */
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;
111
112         /**
113          * When the contact has been created
114          */
115         @Basic (optional = false)
116         @Temporal (TemporalType.TIMESTAMP)
117         @Column (name = "contact_created", nullable = false)
118         private Date contactCreated;
119
120         /**
121          * Email address
122          */
123         @Column (name = "contact_email_address", length = 100, unique = true)
124         private String contactEmailAddress;
125
126         /**
127          * Family name
128          */
129         @Basic (optional = false)
130         @Column (name = "contact_family_name", length = 100, nullable = false)
131         private String contactFamilyName;
132
133         /**
134          * Fax number
135          */
136         @JoinColumn (name = "contact_fax_number_id", referencedColumnName = "fax_id", unique = true)
137         @OneToOne (targetEntity = FaxNumber.class, cascade = CascadeType.ALL)
138         private DialableFaxNumber contactFaxNumber;
139
140         /**
141          * First name
142          */
143         @Basic (optional = false)
144         @Column (name = "contact_first_name", length = 100, nullable = false)
145         private String contactFirstName;
146
147         /**
148          * House number
149          */
150         @Column (name = "contact_house_number")
151         private Short contactHouseNumber;
152
153         /**
154          * House number extension
155          */
156         @Column (name = "contact_house_number_extension", length = 5)
157         private String contactHouseNumberExtension;
158
159         /**
160          * Id number
161          */
162         @Id
163         @GeneratedValue (strategy = GenerationType.IDENTITY)
164         @Column (name = "contact_id", nullable = false, updatable = false)
165         private Long contactId;
166
167         /**
168          * Cellphone number
169          */
170         @JoinColumn (name = "contact_mobile_number_id", referencedColumnName = "mobile_id", unique = true)
171         @OneToOne (targetEntity = MobileNumber.class, cascade = CascadeType.ALL)
172         private DialableMobileNumber contactMobileNumber;
173
174         /**
175          * Flag whether this contact is user's own data
176          */
177         @Basic (optional = false)
178         @Column (name = "contact_own_contact", nullable = false)
179         private Boolean contactOwnContact;
180
181         /**
182          * Contact's personal title (Mr./Mrs.)
183          */
184         @Basic (optional = false)
185         @Column (name = "contact_personal_title", nullable = false)
186         @Enumerated (EnumType.STRING)
187         private PersonalTitle contactPersonalTitle;
188
189         /**
190          * Phone number
191          */
192         @JoinColumn (name = "contact_landline_number_id", referencedColumnName = "landline_id", unique = true)
193         @OneToOne (targetEntity = LandLineNumber.class, cascade = CascadeType.ALL)
194         private DialableLandLineNumber contactPhoneNumber;
195
196         /**
197          * Street
198          */
199         @Column (name = "contact_street")
200         private String contactStreet;
201
202         /**
203          * Title (Doctor, etc)
204          */
205         @Column (name = "contact_title")
206         private String contactTitle;
207
208         /**
209          * When the contact has been updated
210          */
211         @Temporal (TemporalType.TIMESTAMP)
212         @Column (name = "contact_updated")
213         private Date contactUpdated;
214
215         /**
216          * ZIP code
217          */
218         @Column (name = "contact_zip_code")
219         private Integer contactZipCode;
220
221         /**
222          * Default constructor
223          */
224         public UserContact () {
225                 // Default is not user's own contact
226                 this.contactOwnContact = Boolean.FALSE;
227         }
228
229         /**
230          * Constructor for title and names
231          * <p>
232          * @param contactTitle      Personal title
233          * @param contactFirstName  First name
234          * @param contactFamilyName Family name
235          */
236         public UserContact (final PersonalTitle contactTitle, final String contactFirstName, final String contactFamilyName) {
237                 // Call default constructor
238                 this();
239
240                 // Set all
241                 this.contactPersonalTitle = contactTitle;
242                 this.contactFirstName = contactFirstName;
243                 this.contactFamilyName = contactFamilyName;
244         }
245
246         @Override
247         public boolean equals (final Object object) {
248                 if (this == object) {
249                         return true;
250                 } else if (null == object) {
251                         return false;
252                 } else if (this.getClass() != object.getClass()) {
253                         return false;
254                 } else if (!(object instanceof Contact)) {
255                         // Not correct interface
256                         return false;
257                 }
258
259                 final Contact other = (Contact) object;
260
261                 if (!Objects.equals(this.getContactId(), other.getContactId())) {
262                         return false;
263                 } else if (!Objects.equals(this.getContactCity(), other.getContactCity())) {
264                         return false;
265                 } else if (!Objects.equals(this.getContactEmailAddress(), other.getContactEmailAddress())) {
266                         return false;
267                 } else if (!Objects.equals(this.getContactFamilyName(), other.getContactFamilyName())) {
268                         return false;
269                 } else if (!Objects.equals(this.getContactFirstName(), other.getContactFirstName())) {
270                         return false;
271                 } else if (!Objects.equals(this.getContactStreet(), other.getContactStreet())) {
272                         return false;
273                 } else if (!Objects.equals(this.getContactTitle(), other.getContactTitle())) {
274                         return false;
275                 } else if (!Objects.equals(this.getContactBirthday(), other.getContactBirthday())) {
276                         return false;
277                 } else if (!Objects.equals(this.getContactCountry(), other.getContactCountry())) {
278                         return false;
279                 } else if (this.getContactPersonalTitle() != other.getContactPersonalTitle()) {
280                         return false;
281                 } else if (!Objects.equals(this.getContactHouseNumber(), other.getContactHouseNumber())) {
282                         return false;
283                 } else if (!Objects.equals(this.getContactHouseNumberExtension(), other.getContactHouseNumberExtension())) {
284                         return false;
285                 }
286
287                 return true;
288         }
289
290         @Override
291         @SuppressWarnings ("ReturnOfDateField")
292         public Date getContactBirthday () {
293                 return this.contactBirthday;
294         }
295
296         @Override
297         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
298         public void setContactBirthday (final Date contactBirthday) {
299                 this.contactBirthday = contactBirthday;
300         }
301
302         @Override
303         public String getContactCity () {
304                 return this.contactCity;
305         }
306
307         @Override
308         public void setContactCity (final String contactCity) {
309                 this.contactCity = contactCity;
310         }
311
312         @Override
313         public String getContactComment () {
314                 return this.contactComment;
315         }
316
317         @Override
318         public void setContactComment (final String contactComment) {
319                 this.contactComment = contactComment;
320         }
321
322         @Override
323         public Country getContactCountry () {
324                 return this.contactCountry;
325         }
326
327         @Override
328         public void setContactCountry (final Country contactCountry) {
329                 this.contactCountry = contactCountry;
330         }
331
332         @Override
333         @SuppressWarnings ("ReturnOfDateField")
334         public Date getContactCreated () {
335                 return this.contactCreated;
336         }
337
338         @Override
339         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
340         public void setContactCreated (final Date contactCreated) {
341                 this.contactCreated = contactCreated;
342         }
343
344         @Override
345         public String getContactEmailAddress () {
346                 return this.contactEmailAddress;
347         }
348
349         @Override
350         public void setContactEmailAddress (final String contactEmailAddress) {
351                 this.contactEmailAddress = contactEmailAddress;
352         }
353
354         @Override
355         public String getContactFamilyName () {
356                 //* NOISY-DEBUG: */ this.getLogger().logTrace("CALLED!");
357                 return this.contactFamilyName;
358         }
359
360         @Override
361         public void setContactFamilyName (final String contactFamilyName) {
362                 this.contactFamilyName = contactFamilyName;
363         }
364
365         @Override
366         public DialableFaxNumber getContactFaxNumber () {
367                 return this.contactFaxNumber;
368         }
369
370         @Override
371         public void setContactFaxNumber (final DialableFaxNumber contactFaxNumber) {
372                 this.contactFaxNumber = contactFaxNumber;
373         }
374
375         @Override
376         public String getContactFirstName () {
377                 return this.contactFirstName;
378         }
379
380         @Override
381         public void setContactFirstName (final String contactFirstName) {
382                 this.contactFirstName = contactFirstName;
383         }
384
385         @Override
386         public Short getContactHouseNumber () {
387                 return this.contactHouseNumber;
388         }
389
390         @Override
391         public void setContactHouseNumber (final Short contactHouseNumber) {
392                 this.contactHouseNumber = contactHouseNumber;
393         }
394
395         @Override
396         public String getContactHouseNumberExtension () {
397                 return this.contactHouseNumberExtension;
398         }
399
400         @Override
401         public void setContactHouseNumberExtension (final String contactHouseNumberExtension) {
402                 this.contactHouseNumberExtension = contactHouseNumberExtension;
403         }
404
405         @Override
406         public Long getContactId () {
407                 return this.contactId;
408         }
409
410         @Override
411         public void setContactId (final Long contactId) {
412                 this.contactId = contactId;
413         }
414
415         @Override
416         public DialableLandLineNumber getContactLandLineNumber () {
417                 return this.contactPhoneNumber;
418         }
419
420         @Override
421         public void setContactLandLineNumber (final DialableLandLineNumber contactPhoneNumber) {
422                 this.contactPhoneNumber = contactPhoneNumber;
423         }
424
425         @Override
426         public DialableMobileNumber getContactMobileNumber () {
427                 return this.contactMobileNumber;
428         }
429
430         @Override
431         public void setContactMobileNumber (final DialableMobileNumber contactMobileNumber) {
432                 this.contactMobileNumber = contactMobileNumber;
433         }
434
435         @Override
436         public void setContactOwnContact (final Boolean contactOwnContact) {
437                 this.contactOwnContact = contactOwnContact;
438         }
439
440         @Override
441         public PersonalTitle getContactPersonalTitle () {
442                 return this.contactPersonalTitle;
443         }
444
445         @Override
446         public void setContactPersonalTitle (final PersonalTitle contactPersonalTitle) {
447                 this.contactPersonalTitle = contactPersonalTitle;
448         }
449
450         @Override
451         public String getContactStreet () {
452                 return this.contactStreet;
453         }
454
455         @Override
456         public void setContactStreet (final String contactStreet) {
457                 this.contactStreet = contactStreet;
458         }
459
460         @Override
461         public String getContactTitle () {
462                 return this.contactTitle;
463         }
464
465         @Override
466         public void setContactTitle (final String contactTitle) {
467                 this.contactTitle = contactTitle;
468         }
469
470         @Override
471         @SuppressWarnings ("ReturnOfDateField")
472         public Date getContactUpdated () {
473                 return this.contactUpdated;
474         }
475
476         @Override
477         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
478         public void setContactUpdated (final Date contactUpdated) {
479                 this.contactUpdated = contactUpdated;
480         }
481
482         @Override
483         public Integer getContactZipCode () {
484                 return this.contactZipCode;
485         }
486
487         @Override
488         public void setContactZipCode (final Integer contactZipCode) {
489                 this.contactZipCode = contactZipCode;
490         }
491
492         @Override
493         public int hashCode () {
494                 int hash = 5;
495
496                 hash = 29 * hash + Objects.hashCode(this.getContactBirthday());
497                 hash = 29 * hash + Objects.hashCode(this.getContactCity());
498                 hash = 29 * hash + Objects.hashCode(this.getContactCountry());
499                 hash = 29 * hash + Objects.hashCode(this.getContactEmailAddress());
500                 hash = 29 * hash + Objects.hashCode(this.getContactFamilyName());
501                 hash = 29 * hash + Objects.hashCode(this.getContactFirstName());
502                 hash = 29 * hash + Objects.hashCode(this.getContactPersonalTitle());
503                 hash = 29 * hash + Objects.hashCode(this.getContactHouseNumber());
504                 hash = 29 * hash + Objects.hashCode(this.getContactHouseNumberExtension());
505                 hash = 29 * hash + Objects.hashCode(this.getContactId());
506                 hash = 29 * hash + Objects.hashCode(this.getContactStreet());
507                 hash = 29 * hash + Objects.hashCode(this.getContactTitle());
508
509                 return hash;
510         }
511
512         @Override
513         public Boolean isOwnContact () {
514                 return this.contactOwnContact;
515         }
516
517 }