2 * Copyright (C) 2016, 2017 Roland Häder
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.addressbook.database;
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.jcontacts.contact.ContactUtils;
29 import org.mxchange.jcoreee.database.BaseDatabaseBean;
30 import org.mxchange.jmailee.model.delivery.wrapper.EmailDeliveryWrapper;
31 import org.mxchange.jmailee.model.delivery.wrapper.WrapableEmailDelivery;
32 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
33 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
34 import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
35 import org.mxchange.jphone.utils.PhoneUtils;
36 import org.mxchange.jusercore.model.user.LoginUser;
37 import org.mxchange.jusercore.model.user.User;
38 import org.mxchange.jusercore.model.user.UserUtils;
41 * A helper class for beans that access the database.
43 * @author Roland Häder<roland@mxchange.org>
45 public abstract class BaseAddressbookDatabaseBean extends BaseDatabaseBean {
50 private static final long serialVersionUID = 12_895_410_275_811_963L;
53 * Protected constructor
55 protected BaseAddressbookDatabaseBean () {
56 // Call super constructor
57 super("jms/addressbook-queue-factory", "jms/addressbook-email-queue"); //NOI18N
61 * Updates all contact's phone entry's created timestamps
63 * @param contact Contact instance to update
65 protected void setAllContactPhoneEntriesCreated (final Contact contact) {
67 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N
69 // The contact instance must be valid
70 if (null == contact) {
72 throw new NullPointerException("contact is null"); //NOI18N
75 // Get all phone instances
76 DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber();
77 DialableFaxNumber faxNumber = contact.getContactFaxNumber();
78 DialableMobileNumber mobileNumber = contact.getContactMobileNumber();
81 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: landLineNumber={1},faxNumber={2},mobileNumber={3}", this.getClass().getSimpleName(), landLineNumber, faxNumber, mobileNumber)); //NOI18N
83 // Is a phone number instance set?
84 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() == null)) {
86 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for land-line number ...", this.getClass().getSimpleName())); //NOI18N
88 // Set updated timestamp
89 landLineNumber.setPhoneEntryCreated(new GregorianCalendar());
92 // Is a fax number instance set?
93 if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() == null)) {
95 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for fax number ...", this.getClass().getSimpleName())); //NOI18N
97 // Set updated timestamp
98 faxNumber.setPhoneEntryCreated(new GregorianCalendar());
101 // Is a mobile number instance set?
102 if ((mobileNumber instanceof DialableMobileNumber) && (mobileNumber.getPhoneId() == null)) {
104 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for cellphone number ...", this.getClass().getSimpleName())); //NOI18N
106 // Set updated timestamp
107 mobileNumber.setPhoneEntryCreated(new GregorianCalendar());
111 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: EXIT!", this.getClass().getSimpleName())); //NOI18N
115 * Returns a managed instance from given mobile number
117 * @param mobileNumber Mobile instance
118 * @param fetchedNumber Found mobile number in database
120 * @return Managed instance
122 protected DialableMobileNumber getManaged (final DialableMobileNumber mobileNumber, final DialableMobileNumber fetchedNumber) {
124 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: mobileNumber={1},fetchedNumber={2} - CALLED!", this.getClass().getSimpleName(), mobileNumber, fetchedNumber)); //NOI18N
127 if (null == mobileNumber) {
129 throw new NullPointerException("mobileNumber is null"); //NOI18N
130 } else if (null == fetchedNumber) {
132 throw new NullPointerException("fetchedNumber is null"); //NOI18N
133 } else if (fetchedNumber.getPhoneId() == null) {
135 throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
139 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.getDetached: fetchedNumber.phoneId={1}", this.getClass().getSimpleName(), fetchedNumber.getPhoneId())); //NOI18N
142 DialableMobileNumber managedNumber = null;
144 // Is there a difference?
145 if (!PhoneUtils.isSameMobileNumber(mobileNumber, fetchedNumber)) {
147 managedNumber = this.getEntityManager().merge(fetchedNumber);
151 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N
154 return managedNumber;
158 * Returns a managed instance from given land-line number
160 * @param landLineNumber Land-line instance
161 * @param fetchedNumber Found land-line number in database
163 * @return Managed instance
165 protected DialableLandLineNumber getManaged (final DialableLandLineNumber landLineNumber, final DialableLandLineNumber fetchedNumber) {
167 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: landLineNumber={1},fetchedNumber={2} - CALLED!", this.getClass().getSimpleName(), landLineNumber, fetchedNumber)); //NOI18N
170 if (null == landLineNumber) {
172 throw new NullPointerException("landLineNumber is null"); //NOI18N
173 } else if (null == fetchedNumber) {
175 throw new NullPointerException("fetchedNumber is null"); //NOI18N
176 } else if (fetchedNumber.getPhoneId() == null) {
178 throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N
182 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.getDetached: fetchedNumber.phoneId={1}", this.getClass().getSimpleName(), fetchedNumber.getPhoneId())); //NOI18N
185 DialableLandLineNumber managedNumber = null;
187 // Is there a difference?
188 if (!PhoneUtils.isSameLandLineNumber(landLineNumber, fetchedNumber)) {
190 managedNumber = this.getEntityManager().merge(fetchedNumber);
194 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N
197 return managedNumber;
201 * Returns a managed instance from given fax number
203 * @param faxNumber Fax instance
204 * @param fetchedNumber Found fax number in database
206 * @return Managed instance
208 protected DialableFaxNumber getManaged (final DialableFaxNumber faxNumber, final DialableFaxNumber fetchedNumber) {
210 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: faxNumber={1},fetchedNumber={2} - CALLED!", this.getClass().getSimpleName(), faxNumber, fetchedNumber)); //NOI18N
213 if (null == faxNumber) {
215 throw new NullPointerException("faxNumber is null"); //NOI18N
216 } else if (null == fetchedNumber) {
218 throw new NullPointerException("fetchedNumber is null"); //NOI18N
219 } else if (fetchedNumber.getPhoneId() == null) {
221 throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
225 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.getDetached: fetchedNumber.phoneId={1}", this.getClass().getSimpleName(), fetchedNumber.getPhoneId())); //NOI18N
228 DialableFaxNumber managedNumber = null;
230 // Is there a difference?
231 if (!PhoneUtils.isSameFaxNumber(faxNumber, fetchedNumber)) {
233 managedNumber = this.getEntityManager().merge(fetchedNumber);
237 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N
240 return managedNumber;
244 * Get back a managed instance from given user
246 * @param user Unmanaged/detached user instance
248 * @return Managed user instance
250 protected User getManagedUser (final User user) {
252 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getManaged: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
254 // user should not be null
257 throw new NullPointerException("user is null"); //NOI18N
258 } else if (user.getUserId() == null) {
260 throw new NullPointerException("user.userId is null"); //NOI18N
261 } else if (user.getUserId() < 1) {
263 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is null", user.getUserId())); //NOI18N
264 } else if (user.getUserContact() == null) {
266 throw new NullPointerException("user.userContact is null"); //NOI18N
267 } else if (user.getUserContact().getContactId() == null) {
269 throw new NullPointerException("user.userContact.contactId is null"); //NOI18N
270 } else if (user.getUserContact().getContactId() < 1) {
271 // Not valid id number
272 throw new IllegalArgumentException(MessageFormat.format("user.userContact.contactId={0} is not valid", user.getUserContact().getContactId())); //NOI18N#
275 // Try to find it (should be there)
276 User managedUser = this.getEntityManager().find(LoginUser.class, user.getUserId());
279 assert (managedUser instanceof User) : "managedUser is null"; //NOI18N
282 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getManaged: managedUser={1} - EXIT!", this.getClass().getSimpleName(), managedUser)); //NOI18N
289 * Merges given (detached) contact's data
291 * @param detachedContact Contact instance to merge
293 * @return Detached contact instance
295 protected Contact mergeContactData (final Contact detachedContact) {
297 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactData: detachedContact={1} - CALLED!", this.getClass().getSimpleName(), detachedContact)); //NOI18N
299 // The contact instance must be valid
300 if (null == detachedContact) {
302 throw new NullPointerException("detachedContact is null"); //NOI18N
303 } else if (detachedContact.getContactId() == null) {
305 throw new NullPointerException("detachedContact.contactId is null"); //NOI18N //NOI18N
306 } else if (detachedContact.getContactId() < 1) {
308 throw new IllegalStateException(MessageFormat.format("{0}.detachedContact.contactId={1} is not valid.", this.getClass().getSimpleName(), detachedContact.getContactId())); //NOI18N
311 // Get contact from it and find it
312 Contact managedContact = this.getEntityManager().find(detachedContact.getClass(), detachedContact.getContactId());
315 assert (managedContact instanceof Contact) : MessageFormat.format("Contact with id {0} not found, but should be.", detachedContact.getContactId()); //NOI18N
318 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.updateUserPersonalData: managedContact.contactId={1}", this.getClass().getSimpleName(), managedContact.getContactId())); //NOI18N
320 // Is a fax number set?
321 if (detachedContact.getContactFaxNumber() instanceof DialableFaxNumber) {
322 // Make fax numbers managed
323 managedContact.setContactFaxNumber(this.getManaged(detachedContact.getContactFaxNumber(), detachedContact.getContactFaxNumber()));
326 // Is a land-line number set?
327 if (detachedContact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
328 // Make land-line numbers managed
329 managedContact.setContactLandLineNumber(this.getManaged(detachedContact.getContactLandLineNumber(), detachedContact.getContactLandLineNumber()));
332 // Is a mobile number set?
333 if (detachedContact.getContactMobileNumber() instanceof DialableMobileNumber) {
334 // Make mobile numbers managed
335 managedContact.setContactMobileNumber(this.getManaged(detachedContact.getContactMobileNumber(), detachedContact.getContactMobileNumber()));
338 // Set updated timestamp
339 managedContact.setContactUpdated(new GregorianCalendar());
342 ContactUtils.copyAll(detachedContact, managedContact);
345 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactData: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N
347 // Return detached contact
348 return managedContact;
352 * Merges given (detached) contact's cellphone, land-line and fax numbers
354 * @param detachedContact Detached contact instance
356 protected void mergeContactsMobileLandLineFaxNumbers (final Contact detachedContact) {
358 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactsMobileLandLineFaxNumbers: detachedContact={1} - CALLED!", this.getClass().getSimpleName(), detachedContact)); //NOI18N
360 // The contact instance must be valid
361 if (null == detachedContact) {
363 throw new NullPointerException("detachedContact is null"); //NOI18N
364 } else if (detachedContact.getContactId() == null) {
366 throw new NullPointerException("detachedContact.contactId is null"); //NOI18N //NOI18N
367 } else if (detachedContact.getContactId() < 1) {
369 throw new IllegalStateException(MessageFormat.format("{0}.detachedContact.contactId={1} is not valid.", this.getClass().getSimpleName(), detachedContact.getContactId())); //NOI18N
373 DialableMobileNumber cellphone = detachedContact.getContactMobileNumber();
374 DialableLandLineNumber landLine = detachedContact.getContactLandLineNumber();
375 DialableFaxNumber fax = detachedContact.getContactFaxNumber();
377 // Is there a cellphone instance set?
378 if (cellphone instanceof DialableMobileNumber) {
380 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: cellphone.phoneId={0} is being updated ...", cellphone.getPhoneId())); //NOI18N
383 DialableMobileNumber foundMobile = this.getEntityManager().find(cellphone.getClass(), cellphone.getPhoneId());
386 assert (foundMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", foundMobile.getPhoneId()); //NOI18N
389 foundMobile.copyAll(detachedContact.getContactMobileNumber());
392 detachedContact.setContactMobileNumber(foundMobile);
395 // Is there a fax instance set?
396 if (fax instanceof DialableFaxNumber) {
398 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: fax.phoneId={0} is being updated ...", fax.getPhoneId())); //NOI18N
401 DialableFaxNumber foundFax = this.getEntityManager().find(fax.getClass(), fax.getPhoneId());
404 foundFax.copyAll(detachedContact.getContactFaxNumber());
407 detachedContact.setContactFaxNumber(foundFax);
410 // Is there a fax instance set?
411 if (landLine instanceof DialableLandLineNumber) {
413 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: landLine.phoneId={0} is being updated ...", landLine.getPhoneId())); //NOI18N
416 DialableLandLineNumber foundLandLine = this.getEntityManager().find(landLine.getClass(), landLine.getPhoneId());
419 assert (foundLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", foundLandLine.getPhoneId()); //NOI18N
422 foundLandLine.copyAll(detachedContact.getContactLandLineNumber());
425 detachedContact.setContactLandLineNumber(foundLandLine);
429 this.getLoggerBeanLocal().logTrace("mergeContactsMobileLandLineFaxNumbers: EXIT!"); //NOI18N
433 * Sends an email with given subject line, template name to given recipient
436 * @param subjectLine Subject line
437 * @param templateName Template name
438 * @param emailAddress Recipient's email address
439 * @param user User instance
440 * @param baseUrl Base URL
441 * @param randomPassword A randomly-generated password or NULL if user had
444 protected void sendEmail (final String subjectLine, final String templateName, final Address emailAddress, final User user, final String baseUrl, final String randomPassword) {
446 this.getLoggerBeanLocal().logTrace(MessageFormat.format("sendEmail: subjectLine={0},templateName={1},emailAddress={2},user={3},baseUrl={4} - CALLED!", subjectLine, templateName, emailAddress, user, baseUrl)); //NOI18N
449 if (null == subjectLine) {
451 throw new NullPointerException("subjectLine is null"); //NOI18N
452 } else if (subjectLine.isEmpty()) {
454 throw new IllegalArgumentException("subjectLine is empty"); //NOI18N
455 } else if (null == templateName) {
457 throw new NullPointerException("templateName is null"); //NOI18N
458 } else if (templateName.isEmpty()) {
460 throw new IllegalArgumentException("templateName is empty"); //NOI18N
461 } else if (null == emailAddress) {
463 throw new NullPointerException("emailAddress is null"); //NOI18N
464 } else if (null == user) {
466 throw new NullPointerException("user is null"); //NOI18N
467 } else if (user.getUserId() == null) {
469 throw new NullPointerException("user.userId is null"); //NOI18N
470 } else if (user.getUserId() < 1) {
472 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid.", user.getUserId())); //NOI18N
473 } else if (user.getUserName() == null) {
475 throw new NullPointerException("user.userName is null"); //NOI18N
476 } else if (user.getUserName().isEmpty()) {
478 throw new IllegalArgumentException("user.userName is empty"); //NOI18N
479 } else if (user.getUserAccountStatus() == null) {
481 throw new NullPointerException("user.userAccountStatus is null"); //NOI18N
482 } else if (user.getUserContact() == null) {
484 throw new NullPointerException("user.userContact is null"); //NOI18N
485 } else if (user.getUserContact().getContactId() == null) {
487 throw new NullPointerException("user.userContact.contactId is null"); //NOI18N
488 } else if (user.getUserContact().getContactId() < 1) {
490 throw new IllegalArgumentException(MessageFormat.format("user.userContact.contactId={0} is invalid", user.getUserContact().getContactId())); //NOI18N
491 } else if (user.getUserContact().getContactPersonalTitle() == null) {
493 throw new NullPointerException("user.userContact.contactPersonalTitle is null"); //NOI18N
496 // Prepare mail wrapper
497 WrapableEmailDelivery emailWrapper = new EmailDeliveryWrapper();
500 Properties variables = UserUtils.getAllUserFields(user);
502 // Set base URL and random password
503 variables.put("baseUrl", baseUrl); //NOI18N
504 variables.put("randomPassword", ""); //NOI18N
506 // Is the random password set?
507 if ((randomPassword instanceof String) && (!randomPassword.isEmpty())) {
508 variables.put("randomPassword", randomPassword); //NOI18N
512 // @TODO Language from message bundle
513 emailWrapper.setRecipient(emailAddress);
514 emailWrapper.setLocale(user.getUserLocale());
515 emailWrapper.setSubjectLine(subjectLine);
516 emailWrapper.setTemplateName(templateName);
517 emailWrapper.setTemplateVariables(variables);
520 // Send out email change
521 ObjectMessage message = this.getSession().createObjectMessage();
522 message.setObject(emailWrapper);
525 this.sendMessage(message);
526 } catch (final JMSException ex) {
528 throw new EJBException(ex);
532 this.getLoggerBeanLocal().logTrace("sendEmail: EXIT!"); //NOI18N
536 * Updates all contact's phone instances from other contact, both contacts
537 * should be the same.
539 * @param contact Contact to set instances
540 * @param other Other contact to get instances from
542 protected void setAllContactPhoneEntries (final Contact contact, final Contact other) {
544 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntries: contact={1},other={2} - CALLED!", this.getClass().getSimpleName(), contact, other)); //NOI18N
546 // Both must be the same and not null
547 if (null == contact) {
549 throw new NullPointerException("contact is null"); //NOI18N
550 } else if (null == other) {
552 throw new NullPointerException("other is null"); //NOI18N
553 } else if (!Objects.equals(contact, other)) {
554 // Not same instances
555 throw new IllegalArgumentException(MessageFormat.format("contact={0} and other={1} are not equal!", contact, other)); //NOI18N
559 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: other.contactMobileNumber={0}", other.getContactMobileNumber())); //NOI18N
561 // Is other cellphone not set?
562 if ((other.getContactMobileNumber() == null) || (PhoneUtils.isSameMobileNumber(contact.getContactMobileNumber(), other.getContactMobileNumber()))) {
564 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: Copying cellphone entry ...", this.getClass().getSimpleName())); //NOI18N
566 // Is the fax number set?
567 if (other.getContactMobileNumber() instanceof DialableMobileNumber) {
568 // Copy cellphone number
569 contact.setContactMobileNumber(this.getManaged(other.getContactMobileNumber(), contact.getContactMobileNumber()));
572 contact.setContactMobileNumber(null);
577 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: other.contactLandLineNumber={0}", other.getContactLandLineNumber())); //NOI18N
579 // Is other cellphone not set?
580 if ((other.getContactLandLineNumber() == null) || (PhoneUtils.isSameLandLineNumber(contact.getContactLandLineNumber(), other.getContactLandLineNumber()))) {
582 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: Copying land-line entry ...", this.getClass().getSimpleName())); //NOI18N
584 // Is the land-line number set?
585 if (other.getContactLandLineNumber() instanceof DialableLandLineNumber) {
586 // Copy land-line number
587 contact.setContactLandLineNumber(this.getManaged(other.getContactLandLineNumber(), contact.getContactLandLineNumber()));
590 contact.setContactLandLineNumber(null);
595 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: other.contactFaxNumber={1}", this.getClass().getSimpleName(), other.getContactFaxNumber())); //NOI18N
597 // Is other cellphone not set?
598 if ((other.getContactFaxNumber() == null) || (PhoneUtils.isSameFaxNumber(contact.getContactFaxNumber(), other.getContactFaxNumber()))) {
600 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: Copying fax entry ...", this.getClass().getSimpleName())); //NOI18N
602 // Is the fax number set?
603 if (other.getContactFaxNumber() instanceof DialableFaxNumber) {
605 contact.setContactFaxNumber(this.getManaged(other.getContactFaxNumber(), contact.getContactFaxNumber()));
608 contact.setContactFaxNumber(null);
613 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntries: EXIT!", this.getClass().getSimpleName())); //NOI18N
617 * Updates all contact's phone entry's updated timestamps
619 * @param contact Contact instance to update
620 * @param isMobileUnlinked Whether a mobile entry has been unlinked in
622 * @param isLandlineUnlinked Whether a land-line entry has been unlinked in
624 * @param isFaxUnlinked Whether a fax entry has been unlinked in
627 protected void setAllContactPhoneEntriesUpdated (final Contact contact, final boolean isMobileUnlinked, final boolean isLandlineUnlinked, final boolean isFaxUnlinked) {
629 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: contact={1},isMobileUnlinked={2},isLandlineUnlinked={3},isFaxUnlinked={4} - CALLED", this.getClass().getSimpleName(), contact, isMobileUnlinked, isLandlineUnlinked, isFaxUnlinked)); //NOI18N
631 // The contact instance must be valid
632 if (null == contact) {
634 throw new NullPointerException("contact is null"); //NOI18N
635 } else if (contact.getContactId() == null) {
637 throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
638 } else if (contact.getContactId() < 1) {
640 throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
643 // Get all phone instances
644 DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber();
645 DialableFaxNumber faxNumber = contact.getContactFaxNumber();
646 DialableMobileNumber mobileNumber = contact.getContactMobileNumber();
648 // Flags and instances must be constistent
649 if (isMobileUnlinked && mobileNumber instanceof DialableMobileNumber) {
651 throw new IllegalStateException("isCellPhoneUnlinked is TRUE, but mobileNumber is set."); //NOI18N
652 } else if (isLandlineUnlinked && landLineNumber instanceof DialableLandLineNumber) {
654 throw new IllegalStateException("isLandlineUnlinked is TRUE, but landLineNumber is set."); //NOI18N
655 } else if (isFaxUnlinked && faxNumber instanceof DialableFaxNumber) {
657 throw new IllegalStateException("isFaxUnlinked is TRUE, but faxNumber is set."); //NOI18N
660 // Is a phone number instance set?
661 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() instanceof Long) && (landLineNumber.getPhoneId() > 0)) {
663 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: Setting updated timestamp for land-line number ...", this.getClass().getSimpleName())); //NOI18N
665 // Set updated timestamp
666 landLineNumber.setPhoneEntryUpdated(new GregorianCalendar());
669 // Is a fax number instance set?
670 if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() instanceof Long) && (faxNumber.getPhoneId() > 0)) {
672 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: Setting updated timestamp for fax number ...", this.getClass().getSimpleName())); //NOI18N
674 // Set updated timestamp
675 faxNumber.setPhoneEntryUpdated(new GregorianCalendar());
678 // Is a mobile number instance set?
679 if ((mobileNumber instanceof DialableMobileNumber) && (mobileNumber.getPhoneId() instanceof Long) && (mobileNumber.getPhoneId() > 0)) {
681 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: Setting updated timestamp for cellphone number ...", this.getClass().getSimpleName())); //NOI18N
683 // Set updated timestamp
684 mobileNumber.setPhoneEntryUpdated(new GregorianCalendar());
688 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: EXIT!", this.getClass().getSimpleName())); //NOI18N