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 javax.mail.internet.AddressException;
28 import javax.mail.internet.InternetAddress;
29 import org.mxchange.jcontacts.contact.Contact;
30 import org.mxchange.jcontacts.contact.ContactUtils;
31 import org.mxchange.jcoreee.database.BaseDatabaseBean;
32 import org.mxchange.jmailee.model.delivery.wrapper.EmailDeliveryWrapper;
33 import org.mxchange.jmailee.model.delivery.wrapper.WrapableEmailDelivery;
34 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
35 import org.mxchange.jphone.phonenumbers.fax.FaxNumbers;
36 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
37 import org.mxchange.jphone.phonenumbers.landline.LandLineNumbers;
38 import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
39 import org.mxchange.jphone.phonenumbers.mobile.MobileNumbers;
40 import org.mxchange.jphone.utils.PhoneUtils;
41 import org.mxchange.jusercore.model.user.LoginUser;
42 import org.mxchange.jusercore.model.user.User;
43 import org.mxchange.jusercore.model.user.UserUtils;
46 * A helper class for beans that access the database.
48 * @author Roland Häder<roland@mxchange.org>
50 public abstract class BaseAddressbookDatabaseBean extends BaseDatabaseBean {
55 private static final long serialVersionUID = 12_895_410_275_811_963L;
58 * Protected constructor
60 protected BaseAddressbookDatabaseBean () {
61 // Call super constructor
66 * Constructor with queue factory JNDI and queue JNDI names
68 * @param factoryJndi JNDI name for queue factory
69 * @param queueJndi JNDI name for email queue
71 protected BaseAddressbookDatabaseBean (final String factoryJndi, final String queueJndi) {
72 // Call super constructor
73 super(factoryJndi, queueJndi);
77 * Updates all contact's phone entry's created timestamps
79 * @param contact Contact instance to update
81 protected void setAllContactPhoneEntriesCreated (final Contact contact) {
83 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N
85 // The contact instance must be valid
86 if (null == contact) {
88 throw new NullPointerException("contact is null"); //NOI18N
91 // Get all phone instances
92 DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber();
93 DialableFaxNumber faxNumber = contact.getContactFaxNumber();
94 DialableMobileNumber mobileNumber = contact.getContactMobileNumber();
97 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: landLineNumber={1},faxNumber={2},mobileNumber={3}", this.getClass().getSimpleName(), landLineNumber, faxNumber, mobileNumber)); //NOI18N
99 // Is a phone number instance set?
100 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() == null)) {
102 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for land-line number ...", this.getClass().getSimpleName())); //NOI18N
104 // Set updated timestamp
105 landLineNumber.setPhoneEntryCreated(new GregorianCalendar());
108 // Is a fax number instance set?
109 if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() == null)) {
111 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for fax number ...", this.getClass().getSimpleName())); //NOI18N
113 // Set updated timestamp
114 faxNumber.setPhoneEntryCreated(new GregorianCalendar());
117 // Is a mobile number instance set?
118 if ((mobileNumber instanceof DialableMobileNumber) && (mobileNumber.getPhoneId() == null)) {
120 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for cellphone number ...", this.getClass().getSimpleName())); //NOI18N
122 // Set updated timestamp
123 mobileNumber.setPhoneEntryCreated(new GregorianCalendar());
127 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: EXIT!", this.getClass().getSimpleName())); //NOI18N
131 * Returns a managed instance from given mobile number
133 * @param mobileNumber Mobile instance
134 * @param fetchedNumber Found mobile number in database
136 * @return Managed instance
138 protected DialableMobileNumber getManaged (final DialableMobileNumber mobileNumber, final DialableMobileNumber fetchedNumber) {
140 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: mobileNumber={1},fetchedNumber={2} - CALLED!", this.getClass().getSimpleName(), mobileNumber, fetchedNumber)); //NOI18N
143 if (null == mobileNumber) {
145 throw new NullPointerException("mobileNumber is null"); //NOI18N
146 } else if (null == fetchedNumber) {
148 throw new NullPointerException("fetchedNumber is null"); //NOI18N
149 } else if (fetchedNumber.getPhoneId() == null) {
151 throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
155 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.getDetached: fetchedNumber.phoneId={1}", this.getClass().getSimpleName(), fetchedNumber.getPhoneId())); //NOI18N
158 DialableMobileNumber managedNumber = null;
160 // Is there a difference?
161 if (!PhoneUtils.isSameMobileNumber(mobileNumber, fetchedNumber)) {
163 managedNumber = this.getEntityManager().merge(fetchedNumber);
167 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N
170 return managedNumber;
174 * Returns a managed instance from given land-line number
176 * @param landLineNumber Land-line instance
177 * @param fetchedNumber Found land-line number in database
179 * @return Managed instance
181 protected DialableLandLineNumber getManaged (final DialableLandLineNumber landLineNumber, final DialableLandLineNumber fetchedNumber) {
183 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: landLineNumber={1},fetchedNumber={2} - CALLED!", this.getClass().getSimpleName(), landLineNumber, fetchedNumber)); //NOI18N
186 if (null == landLineNumber) {
188 throw new NullPointerException("landLineNumber is null"); //NOI18N
189 } else if (null == fetchedNumber) {
191 throw new NullPointerException("fetchedNumber is null"); //NOI18N
192 } else if (fetchedNumber.getPhoneId() == null) {
194 throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N
198 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.getDetached: fetchedNumber.phoneId={1}", this.getClass().getSimpleName(), fetchedNumber.getPhoneId())); //NOI18N
201 DialableLandLineNumber managedNumber = null;
203 // Is there a difference?
204 if (!PhoneUtils.isSameLandLineNumber(landLineNumber, fetchedNumber)) {
206 managedNumber = this.getEntityManager().merge(fetchedNumber);
210 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N
213 return managedNumber;
217 * Returns a managed instance from given fax number
219 * @param faxNumber Fax instance
220 * @param fetchedNumber Found fax number in database
222 * @return Managed instance
224 protected DialableFaxNumber getManaged (final DialableFaxNumber faxNumber, final DialableFaxNumber fetchedNumber) {
226 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: faxNumber={1},fetchedNumber={2} - CALLED!", this.getClass().getSimpleName(), faxNumber, fetchedNumber)); //NOI18N
229 if (null == faxNumber) {
231 throw new NullPointerException("faxNumber is null"); //NOI18N
232 } else if (null == fetchedNumber) {
234 throw new NullPointerException("fetchedNumber is null"); //NOI18N
235 } else if (fetchedNumber.getPhoneId() == null) {
237 throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
241 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.getDetached: fetchedNumber.phoneId={1}", this.getClass().getSimpleName(), fetchedNumber.getPhoneId())); //NOI18N
244 DialableFaxNumber managedNumber = null;
246 // Is there a difference?
247 if (!PhoneUtils.isSameFaxNumber(faxNumber, fetchedNumber)) {
249 managedNumber = this.getEntityManager().merge(fetchedNumber);
253 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N
256 return managedNumber;
260 * Get back a managed instance from given user
262 * @param user Unmanaged/detached user instance
264 * @return Managed user instance
266 protected User getManagedUser (final User user) {
268 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getManaged: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
270 // user should not be null
273 throw new NullPointerException("user is null"); //NOI18N
274 } else if (user.getUserId() == null) {
276 throw new NullPointerException("user.userId is null"); //NOI18N
277 } else if (user.getUserId() < 1) {
279 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is null", user.getUserId())); //NOI18N
280 } else if (user.getUserContact() == null) {
282 throw new NullPointerException("user.userContact is null"); //NOI18N
283 } else if (user.getUserContact().getContactId() == null) {
285 throw new NullPointerException("user.userContact.contactId is null"); //NOI18N
286 } else if (user.getUserContact().getContactId() < 1) {
287 // Not valid id number
288 throw new IllegalArgumentException(MessageFormat.format("user.userContact.contactId={0} is not valid", user.getUserContact().getContactId())); //NOI18N#
291 // Try to find it (should be there)
292 User managedUser = this.getEntityManager().find(LoginUser.class, user.getUserId());
295 assert (managedUser instanceof User) : "managedUser is null"; //NOI18N
298 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getManaged: managedUser={1} - EXIT!", this.getClass().getSimpleName(), managedUser)); //NOI18N
305 * Merges given (detached) contact's data
307 * @param detachedContact Contact instance to merge
309 * @return Detached contact instance
311 protected Contact mergeContactData (final Contact detachedContact) {
313 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactData: detachedContact={1} - CALLED!", this.getClass().getSimpleName(), detachedContact)); //NOI18N
315 // The contact instance must be valid
316 if (null == detachedContact) {
318 throw new NullPointerException("detachedContact is null"); //NOI18N
319 } else if (detachedContact.getContactId() == null) {
321 throw new NullPointerException("detachedContact.contactId is null"); //NOI18N //NOI18N
322 } else if (detachedContact.getContactId() < 1) {
324 throw new IllegalStateException(MessageFormat.format("{0}.detachedContact.contactId={1} is not valid.", this.getClass().getSimpleName(), detachedContact.getContactId())); //NOI18N
327 // Get contact from it and find it
328 Contact managedContact = this.getEntityManager().find(detachedContact.getClass(), detachedContact.getContactId());
331 assert (managedContact instanceof Contact) : MessageFormat.format("Contact with id {0} not found, but should be.", detachedContact.getContactId()); //NOI18N
334 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.updateUserPersonalData: managedContact.contactId={1}", this.getClass().getSimpleName(), managedContact.getContactId())); //NOI18N
336 // Is a fax number set?
337 if (detachedContact.getContactFaxNumber() instanceof DialableFaxNumber) {
338 // Make fax numbers managed
339 managedContact.setContactFaxNumber(this.getManaged(detachedContact.getContactFaxNumber(), detachedContact.getContactFaxNumber()));
342 // Is a land-line number set?
343 if (detachedContact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
344 // Make land-line numbers managed
345 managedContact.setContactLandLineNumber(this.getManaged(detachedContact.getContactLandLineNumber(), detachedContact.getContactLandLineNumber()));
348 // Is a mobile number set?
349 if (detachedContact.getContactMobileNumber() instanceof DialableMobileNumber) {
350 // Make mobile numbers managed
351 managedContact.setContactMobileNumber(this.getManaged(detachedContact.getContactMobileNumber(), detachedContact.getContactMobileNumber()));
354 // Set updated timestamp
355 managedContact.setContactUpdated(new GregorianCalendar());
358 ContactUtils.copyAll(detachedContact, managedContact);
361 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactData: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N
363 // Return detached contact
364 return managedContact;
368 * Merges given (detached) contact's cellphone, land-line and fax numbers
370 * @param detachedContact Detached contact instance
372 protected void mergeContactsMobileLandLineFaxNumbers (final Contact detachedContact) {
374 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactsMobileLandLineFaxNumbers: detachedContact={1} - CALLED!", this.getClass().getSimpleName(), detachedContact)); //NOI18N
376 // The contact instance must be valid
377 if (null == detachedContact) {
379 throw new NullPointerException("detachedContact is null"); //NOI18N
380 } else if (detachedContact.getContactId() == null) {
382 throw new NullPointerException("detachedContact.contactId is null"); //NOI18N //NOI18N
383 } else if (detachedContact.getContactId() < 1) {
385 throw new IllegalStateException(MessageFormat.format("{0}.detachedContact.contactId={1} is not valid.", this.getClass().getSimpleName(), detachedContact.getContactId())); //NOI18N
389 DialableMobileNumber cellphone = detachedContact.getContactMobileNumber();
390 DialableLandLineNumber landLine = detachedContact.getContactLandLineNumber();
391 DialableFaxNumber fax = detachedContact.getContactFaxNumber();
393 // Is there a cellphone instance set?
394 if (cellphone instanceof DialableMobileNumber) {
396 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: cellphone.phoneId={0} is being updated ...", cellphone.getPhoneId())); //NOI18N
399 DialableMobileNumber foundMobile = this.getEntityManager().find(cellphone.getClass(), cellphone.getPhoneId());
402 assert (foundMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", foundMobile.getPhoneId()); //NOI18N
404 // Then merge it, too
405 DialableMobileNumber managedMobile = this.getEntityManager().merge(foundMobile);
408 assert (managedMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", managedMobile.getPhoneId()); //NOI18N
411 MobileNumbers.copyAll(detachedContact.getContactMobileNumber(), managedMobile);
414 detachedContact.setContactMobileNumber(managedMobile);
417 // Is there a fax instance set?
418 if (fax instanceof DialableFaxNumber) {
420 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: fax.phoneId={0} is being updated ...", fax.getPhoneId())); //NOI18N
423 DialableFaxNumber foundFax = this.getEntityManager().find(fax.getClass(), fax.getPhoneId());
426 assert (foundFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", foundFax.getPhoneId()); //NOI18N
428 // Then merge it, too
429 DialableFaxNumber managedFax = this.getEntityManager().merge(foundFax);
432 assert (managedFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", managedFax.getPhoneId()); //NOI18N
435 FaxNumbers.copyAll(detachedContact.getContactFaxNumber(), managedFax);
438 detachedContact.setContactFaxNumber(managedFax);
441 // Is there a fax instance set?
442 if (landLine instanceof DialableLandLineNumber) {
444 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: landLine.phoneId={0} is being updated ...", landLine.getPhoneId())); //NOI18N
447 DialableLandLineNumber foundLandLine = this.getEntityManager().find(landLine.getClass(), landLine.getPhoneId());
450 assert (foundLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", foundLandLine.getPhoneId()); //NOI18N
452 // Then merge it, too
453 DialableLandLineNumber managedLandLine = this.getEntityManager().merge(foundLandLine);
456 assert (managedLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", managedLandLine.getPhoneId()); //NOI18N
459 LandLineNumbers.copyAll(detachedContact.getContactLandLineNumber(), managedLandLine);
462 detachedContact.setContactLandLineNumber(managedLandLine);
466 this.getLoggerBeanLocal().logTrace("mergeContactsMobileLandLineFaxNumbers: EXIT!"); //NOI18N
470 * Sends an email with given subject line, template name to given recipient
473 * @param subjectLine Subject line
474 * @param templateName Template name
475 * @param user User instance
476 * @param baseUrl Base URL
477 * @param randomPassword A randomly-generated password or NULL if user had
480 protected void sendEmail (final String subjectLine, final String templateName, final User user, final String baseUrl, final String randomPassword) {
482 this.getLoggerBeanLocal().logTrace(MessageFormat.format("sendEmail: subjectLine={0},templateName={1},user={2},baseUrl={3} - CALLED!", subjectLine, templateName, user, baseUrl)); //NOI18N
485 if (null == subjectLine) {
487 throw new NullPointerException("subjectLine is null"); //NOI18N
488 } else if (subjectLine.isEmpty()) {
490 throw new IllegalArgumentException("subjectLine is empty"); //NOI18N
491 } else if (null == templateName) {
493 throw new NullPointerException("templateName is null"); //NOI18N
494 } else if (templateName.isEmpty()) {
496 throw new IllegalArgumentException("templateName is empty"); //NOI18N
497 } else if (null == user) {
499 throw new NullPointerException("user is null"); //NOI18N
500 } else if (user.getUserId() == null) {
502 throw new NullPointerException("user.userId is null"); //NOI18N
503 } else if (user.getUserId() < 1) {
505 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid.", user.getUserId())); //NOI18N
506 } else if (user.getUserName() == null) {
508 throw new NullPointerException("user.userName is null"); //NOI18N
509 } else if (user.getUserName().isEmpty()) {
511 throw new IllegalArgumentException("user.userName is empty"); //NOI18N
512 } else if (user.getUserAccountStatus() == null) {
514 throw new NullPointerException("user.userAccountStatus is null"); //NOI18N
515 } else if (user.getUserContact() == null) {
517 throw new NullPointerException("user.userContact is null"); //NOI18N
518 } else if (user.getUserContact().getContactId() == null) {
520 throw new NullPointerException("user.userContact.contactId is null"); //NOI18N
521 } else if (user.getUserContact().getContactId() < 1) {
523 throw new IllegalArgumentException(MessageFormat.format("user.userContact.contactId={0} is invalid", user.getUserContact().getContactId())); //NOI18N
524 } else if (user.getUserContact().getContactPersonalTitle() == null) {
526 throw new NullPointerException("user.userContact.contactPersonalTitle is null"); //NOI18N
527 } else if (user.getUserLocale() == null) {
529 throw new NullPointerException("user.userLocale is null"); //NOI18N
530 } else if (this.getSession() == null) {
532 throw new NullPointerException("this.session is not set. Have you forgotten to call super(String, String) and called only super() ?"); //NOI18N
536 Properties variables = UserUtils.getAllUserFields(user);
538 // Set base URL and random password
539 variables.put("baseUrl", baseUrl); //NOI18N
540 variables.put("randomPassword", ""); //NOI18N
542 // Is the random password set?
543 if ((randomPassword instanceof String) && (!randomPassword.isEmpty())) {
544 variables.put("randomPassword", randomPassword); //NOI18N
548 Address recipientAddress;
551 // Create email address and set
552 recipientAddress = new InternetAddress(user.getUserContact().getContactEmailAddress());
553 } catch (final AddressException ex) {
555 throw new EJBException(ex);
558 // Prepare mail wrapper
559 // @TODO Language from message bundle
560 WrapableEmailDelivery emailWrapper = new EmailDeliveryWrapper(recipientAddress, subjectLine, templateName, variables, user.getUserLocale());
563 // Send out email change
564 ObjectMessage message = this.getSession().createObjectMessage();
565 message.setObject(emailWrapper);
568 this.sendMessage(message);
569 } catch (final JMSException ex) {
571 throw new EJBException(ex);
575 this.getLoggerBeanLocal().logTrace("sendEmail: EXIT!"); //NOI18N
579 * Updates all contact's phone instances from other contact, both contacts
580 * should be the same.
582 * @param contact Contact to set instances
583 * @param other Other contact to get instances from
585 protected void setAllContactPhoneEntries (final Contact contact, final Contact other) {
587 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntries: contact={1},other={2} - CALLED!", this.getClass().getSimpleName(), contact, other)); //NOI18N
589 // Both must be the same and not null
590 if (null == contact) {
592 throw new NullPointerException("contact is null"); //NOI18N
593 } else if (null == other) {
595 throw new NullPointerException("other is null"); //NOI18N
596 } else if (!Objects.equals(contact, other)) {
597 // Not same instances
598 throw new IllegalArgumentException(MessageFormat.format("contact={0} and other={1} are not equal!", contact, other)); //NOI18N
602 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: other.contactMobileNumber={0}", other.getContactMobileNumber())); //NOI18N
604 // Is other cellphone not set?
605 if ((other.getContactMobileNumber() == null) || (PhoneUtils.isSameMobileNumber(contact.getContactMobileNumber(), other.getContactMobileNumber()))) {
607 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: Copying cellphone entry ...", this.getClass().getSimpleName())); //NOI18N
609 // Is the fax number set?
610 if (other.getContactMobileNumber() instanceof DialableMobileNumber) {
611 // Copy cellphone number
612 contact.setContactMobileNumber(this.getManaged(other.getContactMobileNumber(), contact.getContactMobileNumber()));
615 contact.setContactMobileNumber(null);
620 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: other.contactLandLineNumber={0}", other.getContactLandLineNumber())); //NOI18N
622 // Is other cellphone not set?
623 if ((other.getContactLandLineNumber() == null) || (PhoneUtils.isSameLandLineNumber(contact.getContactLandLineNumber(), other.getContactLandLineNumber()))) {
625 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: Copying land-line entry ...", this.getClass().getSimpleName())); //NOI18N
627 // Is the land-line number set?
628 if (other.getContactLandLineNumber() instanceof DialableLandLineNumber) {
629 // Copy land-line number
630 contact.setContactLandLineNumber(this.getManaged(other.getContactLandLineNumber(), contact.getContactLandLineNumber()));
633 contact.setContactLandLineNumber(null);
638 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: other.contactFaxNumber={1}", this.getClass().getSimpleName(), other.getContactFaxNumber())); //NOI18N
640 // Is other cellphone not set?
641 if ((other.getContactFaxNumber() == null) || (PhoneUtils.isSameFaxNumber(contact.getContactFaxNumber(), other.getContactFaxNumber()))) {
643 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: Copying fax entry ...", this.getClass().getSimpleName())); //NOI18N
645 // Is the fax number set?
646 if (other.getContactFaxNumber() instanceof DialableFaxNumber) {
648 contact.setContactFaxNumber(this.getManaged(other.getContactFaxNumber(), contact.getContactFaxNumber()));
651 contact.setContactFaxNumber(null);
656 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntries: EXIT!", this.getClass().getSimpleName())); //NOI18N
660 * Updates all contact's phone entry's updated timestamps
662 * @param contact Contact instance to update
663 * @param isMobileUnlinked Whether a mobile entry has been unlinked in
665 * @param isLandlineUnlinked Whether a land-line entry has been unlinked in
667 * @param isFaxUnlinked Whether a fax entry has been unlinked in
670 protected void setAllContactPhoneEntriesUpdated (final Contact contact, final boolean isMobileUnlinked, final boolean isLandlineUnlinked, final boolean isFaxUnlinked) {
672 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: contact={1},isMobileUnlinked={2},isLandlineUnlinked={3},isFaxUnlinked={4} - CALLED", this.getClass().getSimpleName(), contact, isMobileUnlinked, isLandlineUnlinked, isFaxUnlinked)); //NOI18N
674 // The contact instance must be valid
675 if (null == contact) {
677 throw new NullPointerException("contact is null"); //NOI18N
678 } else if (contact.getContactId() == null) {
680 throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
681 } else if (contact.getContactId() < 1) {
683 throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
686 // Get all phone instances
687 DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber();
688 DialableFaxNumber faxNumber = contact.getContactFaxNumber();
689 DialableMobileNumber mobileNumber = contact.getContactMobileNumber();
691 // Flags and instances must be constistent
692 if (isMobileUnlinked && mobileNumber instanceof DialableMobileNumber) {
694 throw new IllegalStateException("isCellPhoneUnlinked is TRUE, but mobileNumber is set."); //NOI18N
695 } else if (isLandlineUnlinked && landLineNumber instanceof DialableLandLineNumber) {
697 throw new IllegalStateException("isLandlineUnlinked is TRUE, but landLineNumber is set."); //NOI18N
698 } else if (isFaxUnlinked && faxNumber instanceof DialableFaxNumber) {
700 throw new IllegalStateException("isFaxUnlinked is TRUE, but faxNumber is set."); //NOI18N
703 // Is a phone number instance set?
704 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() instanceof Long) && (landLineNumber.getPhoneId() > 0)) {
706 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: Setting updated timestamp for land-line number ...", this.getClass().getSimpleName())); //NOI18N
708 // Set updated timestamp
709 landLineNumber.setPhoneEntryUpdated(new GregorianCalendar());
712 // Is a fax number instance set?
713 if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() instanceof Long) && (faxNumber.getPhoneId() > 0)) {
715 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: Setting updated timestamp for fax number ...", this.getClass().getSimpleName())); //NOI18N
717 // Set updated timestamp
718 faxNumber.setPhoneEntryUpdated(new GregorianCalendar());
721 // Is a mobile number instance set?
722 if ((mobileNumber instanceof DialableMobileNumber) && (mobileNumber.getPhoneId() instanceof Long) && (mobileNumber.getPhoneId() > 0)) {
724 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: Setting updated timestamp for cellphone number ...", this.getClass().getSimpleName())); //NOI18N
726 // Set updated timestamp
727 mobileNumber.setPhoneEntryUpdated(new GregorianCalendar());
731 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: EXIT!", this.getClass().getSimpleName())); //NOI18N