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