]> git.mxchange.org Git - addressbook-core.git/blob - src/org/mxchange/addressbook/database/BaseAddressbookDatabaseBean.java
Please cherry-pick:
[addressbook-core.git] / src / org / mxchange / addressbook / database / BaseAddressbookDatabaseBean.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.addressbook.database;
18
19 import java.text.MessageFormat;
20 import java.util.GregorianCalendar;
21 import java.util.Objects;
22 import java.util.Properties;
23 import javax.ejb.EJBException;
24 import javax.jms.JMSException;
25 import javax.jms.ObjectMessage;
26 import javax.mail.Address;
27 import org.mxchange.jcontacts.contact.Contact;
28 import org.mxchange.jcoreee.database.BaseDatabaseBean;
29 import org.mxchange.jmailee.model.delivery.wrapper.EmailDeliveryWrapper;
30 import org.mxchange.jmailee.model.delivery.wrapper.WrapableEmailDelivery;
31 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
32 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
33 import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
34 import org.mxchange.jphone.utils.PhoneUtils;
35 import org.mxchange.jusercore.model.user.User;
36 import org.mxchange.jusercore.model.user.UserUtils;
37
38 /**
39  * A helper class for beans that access the database.
40  * <p>
41  * @author Roland Häder<roland@mxchange.org>
42  */
43 public abstract class BaseAddressbookDatabaseBean extends BaseDatabaseBean {
44
45         /**
46          * Serial number
47          */
48         private static final long serialVersionUID = 12_895_410_275_811_963L;
49
50         /**
51          * Protected constructor
52          */
53         protected BaseAddressbookDatabaseBean () {
54                 // Call super constructor
55                 super("jms/addressbook-queue-factory", "jms/addressbook-email-queue"); //NOI18N
56         }
57
58         /**
59          * Updates all contacts's phone entry's created timestamps
60          * <p>
61          * @param contact Contact instance to update
62          */
63         protected void setAllContactPhoneEntriesCreated (final Contact contact) {
64                 // Trace message
65                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N
66
67                 // The contact instance must be valid
68                 if (null == contact) {
69                         // Throw NPE again
70                         throw new NullPointerException("contact is null"); //NOI18N
71                 }
72
73                 // Get all phone instances
74                 DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber();
75                 DialableFaxNumber faxNumber = contact.getContactFaxNumber();
76                 DialableMobileNumber mobileNumber = contact.getContactMobileNumber();
77
78                 // Debug message
79                 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: landLineNumber={1},faxNumber={2},mobileNumber={3}", this.getClass().getSimpleName(), landLineNumber, faxNumber, mobileNumber)); //NOI18N
80
81                 // Is a phone number instance set?
82                 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() == null)) {
83                         // Debug message
84                         this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for land-line number ...", this.getClass().getSimpleName())); //NOI18N
85
86                         // Set updated timestamp
87                         landLineNumber.setPhoneEntryCreated(new GregorianCalendar());
88                 }
89
90                 // Is a fax number instance set?
91                 if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() == null)) {
92                         // Debug message
93                         this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for fax number ...", this.getClass().getSimpleName())); //NOI18N
94
95                         // Set updated timestamp
96                         faxNumber.setPhoneEntryCreated(new GregorianCalendar());
97                 }
98
99                 // Is a mobile number instance set?
100                 if ((mobileNumber instanceof DialableMobileNumber) && (mobileNumber.getPhoneId() == null)) {
101                         // Debug message
102                         this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for cellphone number ...", this.getClass().getSimpleName())); //NOI18N
103
104                         // Set updated timestamp
105                         mobileNumber.setPhoneEntryCreated(new GregorianCalendar());
106                 }
107
108                 // Trace message
109                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: EXIT!", this.getClass().getSimpleName())); //NOI18N
110         }
111
112         /**
113          * Returns a managed instance from given mobile number
114          * <p>
115          * @param mobileNumber Mobile number
116          * @param fetchedNumber Found mobile number in database
117          * <p>
118          * @return Managed instance
119          */
120         protected DialableMobileNumber getManaged (final DialableMobileNumber mobileNumber, final DialableMobileNumber fetchedNumber) {
121                 // Trace message
122                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: mobileNumber={1},fetchedNumber={2} - CALLED!", this.getClass().getSimpleName(), mobileNumber, fetchedNumber)); //NOI18N
123
124                 // Should be valid
125                 if (null == mobileNumber) {
126                         // Throw NPE
127                         throw new NullPointerException("mobileNumber is null"); //NOI18N
128                 } else if (null == fetchedNumber) {
129                         // Throw NPE again
130                         throw new NullPointerException("fetchedNumber is null"); //NOI18N
131                 } else if (fetchedNumber.getPhoneId() == null) {
132                         // ..and again
133                         throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
134                 }
135
136                 // Debug message
137                 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.getDetached: fetchedNumber.phoneId={1}", this.getClass().getSimpleName(), fetchedNumber.getPhoneId())); //NOI18N
138
139                 // Default is null
140                 DialableMobileNumber managedNumber = null;
141
142                 // Is there a difference?
143                 if (!PhoneUtils.isSameMobileNumber(mobileNumber, fetchedNumber)) {
144                         // Merge this entry
145                         managedNumber = this.getEntityManager().merge(fetchedNumber);
146                 }
147
148                 // Trace message
149                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N
150
151                 // Return it
152                 return managedNumber;
153         }
154
155         /**
156          * Returns a managed instance from given land-line number
157          * <p>
158          * @param landLineNumber Land-line number
159          * @param fetchedNumber Found land-line number in database
160          * <p>
161          * @return Managed instance
162          */
163         protected DialableLandLineNumber getManaged (final DialableLandLineNumber landLineNumber, final DialableLandLineNumber fetchedNumber) {
164                 // Trace message
165                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: landLineNumber={1},fetchedNumber={2} - CALLED!", this.getClass().getSimpleName(), landLineNumber, fetchedNumber)); //NOI18N
166
167                 // Should be valid
168                 if (null == landLineNumber) {
169                         // Throw NPE
170                         throw new NullPointerException("landLineNumber is null"); //NOI18N
171                 } else if (null == fetchedNumber) {
172                         // Throw NPE again
173                         throw new NullPointerException("fetchedNumber is null"); //NOI18N
174                 } else if (fetchedNumber.getPhoneId() == null) {
175                         // ..and again
176                         throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N
177                 }
178
179                 // Debug message
180                 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.getDetached: fetchedNumber.phoneId={1}", this.getClass().getSimpleName(), fetchedNumber.getPhoneId())); //NOI18N
181
182                 // Default is null
183                 DialableLandLineNumber managedNumber = null;
184
185                 // Is there a difference?
186                 if (!PhoneUtils.isSameLandLineNumber(landLineNumber, fetchedNumber)) {
187                         // Merge this entry
188                         managedNumber = this.getEntityManager().merge(fetchedNumber);
189                 }
190
191                 // Trace message
192                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N
193
194                 // Return it
195                 return managedNumber;
196         }
197
198         /**
199          * Returns a managed instance from given fax number
200          * <p>
201          * @param faxNumber Fax number
202          * @param fetchedNumber Found fax number in database
203          * <p>
204          * @return Managed instance
205          */
206         protected DialableFaxNumber getManaged (final DialableFaxNumber faxNumber, final DialableFaxNumber fetchedNumber) {
207                 // Trace message
208                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: faxNumber={1},fetchedNumber={2} - CALLED!", this.getClass().getSimpleName(), faxNumber, fetchedNumber)); //NOI18N
209
210                 // Should be valid
211                 if (null == faxNumber) {
212                         // Throw NPE
213                         throw new NullPointerException("faxNumber is null"); //NOI18N
214                 } else if (null == fetchedNumber) {
215                         // Throw NPE again
216                         throw new NullPointerException("fetchedNumber is null"); //NOI18N
217                 } else if (fetchedNumber.getPhoneId() == null) {
218                         // ..and again
219                         throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
220                 }
221
222                 // Debug message
223                 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.getDetached: fetchedNumber.phoneId={1}", this.getClass().getSimpleName(), fetchedNumber.getPhoneId())); //NOI18N
224
225                 // Default is null
226                 DialableFaxNumber managedNumber = null;
227
228                 // Is there a difference?
229                 if (!PhoneUtils.isSameFaxNumber(faxNumber, fetchedNumber)) {
230                         // Merge this entry
231                         managedNumber = this.getEntityManager().merge(fetchedNumber);
232                 }
233
234                 // Trace message
235                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N
236
237                 // Return it
238                 return managedNumber;
239         }
240
241         /**
242          * Merges given (detached) contact's data
243          * <p>
244          * @param detachedContact Contact instance to merge
245          * <p>
246          * @return Detached contact instance
247          */
248         protected Contact mergeContactData (final Contact detachedContact) {
249                 // Trace message
250                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactData: contact={1} - CALLED!", this.getClass().getSimpleName(), detachedContact)); //NOI18N
251
252                 // The contact instance must be valid
253                 if (null == detachedContact) {
254                         // Throw NPE again
255                         throw new NullPointerException("detachedContact is null"); //NOI18N
256                 } else if (detachedContact.getContactId() == null) {
257                         // Throw NPE again
258                         throw new NullPointerException("detachedContact.contactId is null"); //NOI18N //NOI18N
259                 } else if (detachedContact.getContactId() < 1) {
260                         // Not valid
261                         throw new IllegalStateException(MessageFormat.format("{0}.detachedContact.contactId={1} is not valid.", this.getClass().getSimpleName(), detachedContact.getContactId())); //NOI18N
262                 }
263
264                 // Get contact from it and find it
265                 Contact foundContact = this.getEntityManager().getReference(detachedContact.getClass(), detachedContact.getContactId());
266
267                 // Should be found
268                 assert (foundContact instanceof Contact) : MessageFormat.format("Contact with id {0} not found, but should be.", detachedContact.getContactId()); //NOI18N
269
270                 // Debug message
271                 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.updateUserPersonalData: foundContact.contactId={1}", this.getClass().getSimpleName(), foundContact.getContactId())); //NOI18N
272
273                 // Merge contact instance
274                 Contact managedContact = this.getEntityManager().merge(foundContact);
275
276                 // Set updated timestamp
277                 managedContact.setContactUpdated(new GregorianCalendar());
278
279                 // Copy all
280                 managedContact.copyAll(detachedContact);
281
282                 // Trace message
283                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactData: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N
284
285                 // Return detached contact
286                 return managedContact;
287         }
288
289         /**
290          * Merges given (detached) contact's cellphone, land-line and fax numbers
291          * <p>
292          * @param detachedContact Detached contact instance
293          */
294         protected void mergeContactsMobileLandLineFaxNumbers (final Contact detachedContact) {
295                 // Trace message
296                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactsMobileLandLineFaxNumbers: detachedContact={1} - CALLED!", this.getClass().getSimpleName(), detachedContact)); //NOI18N
297
298                 // The contact instance must be valid
299                 if (null == detachedContact) {
300                         // Throw NPE again
301                         throw new NullPointerException("detachedContact is null"); //NOI18N
302                 } else if (detachedContact.getContactId() == null) {
303                         // Throw NPE again
304                         throw new NullPointerException("detachedContact.contactId is null"); //NOI18N //NOI18N
305                 } else if (detachedContact.getContactId() < 1) {
306                         // Not valid
307                         throw new IllegalStateException(MessageFormat.format("{0}.detachedContact.contactId={1} is not valid.", this.getClass().getSimpleName(), detachedContact.getContactId())); //NOI18N
308                 }
309
310                 // Get all instances
311                 DialableMobileNumber cellphone = detachedContact.getContactMobileNumber();
312                 DialableLandLineNumber landLine = detachedContact.getContactLandLineNumber();
313                 DialableFaxNumber fax = detachedContact.getContactFaxNumber();
314
315                 // Is there a  cellphone instance set?
316                 if (cellphone instanceof DialableMobileNumber) {
317                         // Debug message
318                         this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: cellphone.phoneId={0} is being updated ...", cellphone.getPhoneId())); //NOI18N
319
320                         // Then find it, too
321                         DialableMobileNumber foundMobile = this.getEntityManager().find(cellphone.getClass(), cellphone.getPhoneId());
322
323                         // Should be there
324                         assert (foundMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", foundMobile.getPhoneId()); //NOI18N
325
326                         // Copy all
327                         foundMobile.copyAll(detachedContact.getContactMobileNumber());
328
329                         // Set it back
330                         detachedContact.setContactMobileNumber(foundMobile);
331                 }
332
333                 // Is there a  fax instance set?
334                 if (fax instanceof DialableFaxNumber) {
335                         // Debug message
336                         this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: fax.phoneId={0} is being updated ...", fax.getPhoneId())); //NOI18N
337
338                         // Then find it, too
339                         DialableFaxNumber foundFax = this.getEntityManager().find(fax.getClass(), fax.getPhoneId());
340
341                         // Copy all
342                         foundFax.copyAll(detachedContact.getContactFaxNumber());
343
344                         // Set it back
345                         detachedContact.setContactFaxNumber(foundFax);
346                 }
347
348                 // Is there a  fax instance set?
349                 if (landLine instanceof DialableLandLineNumber) {
350                         // Debug message
351                         this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: landLine.phoneId={0} is being updated ...", landLine.getPhoneId())); //NOI18N
352
353                         // Then find it, too
354                         DialableLandLineNumber foundLandLine = this.getEntityManager().find(landLine.getClass(), landLine.getPhoneId());
355
356                         // Should be there
357                         assert (foundLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", foundLandLine.getPhoneId()); //NOI18N
358
359                         // Copy all
360                         foundLandLine.copyAll(detachedContact.getContactLandLineNumber());
361
362                         // Set it back
363                         detachedContact.setContactLandLineNumber(foundLandLine);
364                 }
365
366                 // Trace message
367                 this.getLoggerBeanLocal().logTrace("mergeContactsMobileLandLineFaxNumbers: EXIT!"); //NOI18N
368         }
369
370         /**
371          * Sends an email with given subject line, template name to given recipient
372          * and user data
373          * <p>
374          * @param subjectLine Subject line
375          * @param templateName Template name
376          * @param emailAddress Recipient's email address
377          * @param user User instance
378          * @param baseUrl Base URL
379          */
380         protected void sendEmail (final String subjectLine, final String templateName, final Address emailAddress, final User user, final String baseUrl) {
381                 // Trace message
382                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("sendEmail: subjectLine={0},templateName={1},emailAddress={2},user={3},baseUrl={4} - CALLED!", subjectLine, templateName, emailAddress, user, baseUrl)); //NOI18N
383
384                 // All should be set
385                 if (null == subjectLine) {
386                         // Throw NPE
387                         throw new NullPointerException("subjectLine is null"); //NOI18N
388                 } else if (subjectLine.isEmpty()) {
389                         // No subject line
390                         throw new IllegalArgumentException("subjectLine is empty"); //NOI18N
391                 } else if (null == templateName) {
392                         // Throw NPE
393                         throw new NullPointerException("templateName is null"); //NOI18N
394                 } else if (templateName.isEmpty()) {
395                         // No template name
396                         throw new IllegalArgumentException("templateName is empty"); //NOI18N
397                 } else if (null == emailAddress) {
398                         // Throw NPE
399                         throw new NullPointerException("emailAddress is null"); //NOI18N
400                 }
401
402                 // Prepare mail wrapper
403                 WrapableEmailDelivery emailWrapper = new EmailDeliveryWrapper();
404
405                 // Set all values
406                 Properties variables = UserUtils.getAllUserFields(user);
407
408                 // Set base URL
409                 variables.put("baseUrl", baseUrl); //NOI18N
410
411                 // Set all
412                 // @TODO Language from message bundle
413                 emailWrapper.setRecipient(emailAddress);
414                 emailWrapper.setLocale(user.getUserLocale());
415                 emailWrapper.setSubjectLine(subjectLine);
416                 emailWrapper.setTemplateName(templateName);
417                 emailWrapper.setTemplateVariables(variables);
418
419                 try {
420                         // Send out email change
421                         ObjectMessage message = this.getSession().createObjectMessage();
422                         message.setObject(emailWrapper);
423
424                         // Send message
425                         this.sendMessage(message);
426                 } catch (final JMSException ex) {
427                         // Throw again
428                         throw new EJBException(ex);
429                 }
430
431                 // Trace message
432                 this.getLoggerBeanLocal().logTrace("sendEmail: EXIT!"); //NOI18N
433         }
434
435         /**
436          * Updates all contact's phone instances from other contact, both contacts
437          * should be the same.
438          * <p>
439          * @param contact Contact to set instances
440          * @param other Other contact to get instances from
441          */
442         protected void setAllContactPhoneEntries (final Contact contact, final Contact other) {
443                 // Trace message
444                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntries: contact={1},other={2} - CALLED!", this.getClass().getSimpleName(), contact, other)); //NOI18N
445
446                 // Both must be the same and not null
447                 if (null == contact) {
448                         // Throw NPE
449                         throw new NullPointerException("contact is null"); //NOI18N
450                 } else if (null == other) {
451                         // Throw NPE
452                         throw new NullPointerException("other is null"); //NOI18N
453                 } else if (!Objects.equals(contact, other)) {
454                         // Not same instances
455                         throw new IllegalArgumentException(MessageFormat.format("contact={0} and other={1} are not equal!", contact, other)); //NOI18N
456                 }
457
458                 // Debug message
459                 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: other.contactMobileNumber={0}", other.getContactMobileNumber())); //NOI18N
460
461                 // Is other cellphone not set?
462                 if ((other.getContactMobileNumber() == null) || (PhoneUtils.isSameMobileNumber(contact.getContactMobileNumber(), other.getContactMobileNumber()))) {
463                         // Debug message
464                         this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: Copying cellphone entry ...", this.getClass().getSimpleName())); //NOI18N
465
466                         // Is the fax number set?
467                         if (other.getContactMobileNumber() instanceof DialableMobileNumber) {
468                                 // Copy cellphone number
469                                 contact.setContactMobileNumber(this.getManaged(other.getContactMobileNumber(), contact.getContactMobileNumber()));
470                         } else {
471                                 // Null it
472                                 contact.setContactMobileNumber(null);
473                         }
474                 }
475
476                 // Debug message
477                 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: other.contactLandLineNumber={0}", other.getContactLandLineNumber())); //NOI18N
478
479                 // Is other cellphone not set?
480                 if ((other.getContactLandLineNumber() == null) || (PhoneUtils.isSameLandLineNumber(contact.getContactLandLineNumber(), other.getContactLandLineNumber()))) {
481                         // Debug message
482                         this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: Copying land-line entry ...", this.getClass().getSimpleName())); //NOI18N
483
484                         // Is the land-line number set?
485                         if (other.getContactLandLineNumber() instanceof DialableLandLineNumber) {
486                                 // Copy land-line number
487                                 contact.setContactLandLineNumber(this.getManaged(other.getContactLandLineNumber(), contact.getContactLandLineNumber()));
488                         } else {
489                                 // Null it
490                                 contact.setContactLandLineNumber(null);
491                         }
492                 }
493
494                 // Debug message
495                 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: other.contactFaxNumber={1}", this.getClass().getSimpleName(), other.getContactFaxNumber())); //NOI18N
496
497                 // Is other cellphone not set?
498                 if ((other.getContactFaxNumber() == null) || (PhoneUtils.isSameFaxNumber(contact.getContactFaxNumber(), other.getContactFaxNumber()))) {
499                         // Debug message
500                         this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: Copying fax entry ...", this.getClass().getSimpleName())); //NOI18N
501
502                         // Is the fax number set?
503                         if (other.getContactFaxNumber() instanceof DialableFaxNumber) {
504                                 // Copy fax number
505                                 contact.setContactFaxNumber(this.getManaged(other.getContactFaxNumber(), contact.getContactFaxNumber()));
506                         } else {
507                                 // Null it
508                                 contact.setContactFaxNumber(null);
509                         }
510                 }
511
512                 // Trace message
513                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntries: EXIT!", this.getClass().getSimpleName())); //NOI18N
514         }
515
516         /**
517          * Updates all contact's phone entry's updated timestamps
518          * <p>
519          * @param contact Contact instance to update
520          * @param isMobileUnlinked Whether a cellphone entry has been unlinked in
521          * contact instance
522          * @param isLandlineUnlinked Whether a land-line entry has been unlinked in
523          * contact instance
524          * @param isFaxUnlinked Whether a fax entry has been unlinked in contact
525          * instance
526          */
527         protected void setAllContactPhoneEntriesUpdated (final Contact contact, final boolean isMobileUnlinked, final boolean isLandlineUnlinked, final boolean isFaxUnlinked) {
528                 // Trace message
529                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: contact={1},isMobileUnlinked={2},isLandlineUnlinked={3},isFaxUnlinked={4} - CALLED", this.getClass().getSimpleName(), contact, isMobileUnlinked, isLandlineUnlinked, isFaxUnlinked)); //NOI18N
530
531                 // The contact instance must be valid
532                 if (null == contact) {
533                         // Throw NPE again
534                         throw new NullPointerException("contact is null"); //NOI18N
535                 } else if (contact.getContactId() == null) {
536                         // Throw NPE again
537                         throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
538                 } else if (contact.getContactId() < 1) {
539                         // Not valid
540                         throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
541                 }
542
543                 // Get all phone instances
544                 DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber();
545                 DialableFaxNumber faxNumber = contact.getContactFaxNumber();
546                 DialableMobileNumber mobileNumber = contact.getContactMobileNumber();
547
548                 // Flags and instances must be constistent
549                 if (isMobileUnlinked && mobileNumber instanceof DialableMobileNumber) {
550                         // Bad state
551                         throw new IllegalStateException("isCellPhoneUnlinked is TRUE, but mobileNumber is set."); //NOI18N
552                 } else if (isLandlineUnlinked && landLineNumber instanceof DialableLandLineNumber) {
553                         // Bad state
554                         throw new IllegalStateException("isLandlineUnlinked is TRUE, but landLineNumber is set."); //NOI18N
555                 } else if (isFaxUnlinked && faxNumber instanceof DialableFaxNumber) {
556                         // Bad state
557                         throw new IllegalStateException("isFaxUnlinked is TRUE, but faxNumber is set."); //NOI18N
558                 }
559
560                 // Is a phone number instance set?
561                 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() instanceof Long) && (landLineNumber.getPhoneId() > 0)) {
562                         // Debug message
563                         this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: Setting updated timestamp for land-line number ...", this.getClass().getSimpleName())); //NOI18N
564
565                         // Set updated timestamp
566                         landLineNumber.setPhoneEntryUpdated(new GregorianCalendar());
567                 }
568
569                 // Is a fax number instance set?
570                 if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() instanceof Long) && (faxNumber.getPhoneId() > 0)) {
571                         // Debug message
572                         this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: Setting updated timestamp for fax number ...", this.getClass().getSimpleName())); //NOI18N
573
574                         // Set updated timestamp
575                         faxNumber.setPhoneEntryUpdated(new GregorianCalendar());
576                 }
577
578                 // Is a mobile number instance set?
579                 if ((mobileNumber instanceof DialableMobileNumber) && (mobileNumber.getPhoneId() instanceof Long) && (mobileNumber.getPhoneId() > 0)) {
580                         // Debug message
581                         this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: Setting updated timestamp for cellphone number ...", this.getClass().getSimpleName())); //NOI18N
582
583                         // Set updated timestamp
584                         mobileNumber.setPhoneEntryUpdated(new GregorianCalendar());
585                 }
586
587                 // Trace message
588                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: EXIT!", this.getClass().getSimpleName())); //NOI18N
589         }
590
591 }