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.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.fax.FaxNumber;
33 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
34 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
35 import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
36 import org.mxchange.jphone.phonenumbers.mobile.MobileNumber;
37 import org.mxchange.jphone.utils.PhoneUtils;
38 import org.mxchange.jusercore.model.user.LoginUser;
39 import org.mxchange.jusercore.model.user.User;
40 import org.mxchange.jusercore.model.user.UserUtils;
43 * A helper class for beans that access the database.
45 * @author Roland Häder<roland@mxchange.org>
47 public abstract class BaseAddressbookDatabaseBean extends BaseDatabaseBean {
52 private static final long serialVersionUID = 12_895_410_275_811_963L;
55 * Protected constructor
57 protected BaseAddressbookDatabaseBean () {
58 // Call super constructor
59 super("jms/addressbook-queue-factory", "jms/addressbook-email-queue"); //NOI18N
63 * Detaches all contact's phone instances.
65 * @param contact Contact to set instances
67 protected void detachAllContactPhoneEntries (final Contact contact) {
69 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.detachAllContactPhoneEntries: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N
71 // Both must be the same and not null
72 if (null == contact) {
74 throw new NullPointerException("contact is null"); //NOI18N
78 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.detachAllContactPhoneEntries: contact.contactMobileNumber={1}", this.getClass().getSimpleName(), contact.getContactMobileNumber())); //NOI18N
80 // Is contact cellphone set?
81 if (contact.getContactMobileNumber() instanceof DialableMobileNumber) {
82 // Fetch it from entity manager
83 DialableMobileNumber fetchedNumber = this.getEntityManager().getReference(MobileNumber.class, contact.getContactMobileNumber().getPhoneId());
86 contact.setContactMobileNumber(this.getDetached(contact.getContactMobileNumber(), fetchedNumber));
90 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.detachAllContactPhoneEntries: contact.contactLandLineNumber={1}", this.getClass().getSimpleName(), contact.getContactLandLineNumber())); //NOI18N
92 // Is the land-line number set?
93 if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
94 // Fetch it from entity manager
95 DialableLandLineNumber fetchedNumber = this.getEntityManager().getReference(LandLineNumber.class, contact.getContactLandLineNumber().getPhoneId());
97 // Copy land-line number
98 contact.setContactLandLineNumber(this.getDetached(contact.getContactLandLineNumber(), fetchedNumber));
102 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.detachAllContactPhoneEntries: contact.contactFaxNumber={1}", this.getClass().getSimpleName(), contact.getContactFaxNumber())); //NOI18N
104 // Is the fax number set?
105 if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
106 // Fetch it from entity manager
107 DialableFaxNumber fetchedNumber = this.getEntityManager().getReference(FaxNumber.class, contact.getContactFaxNumber().getPhoneId());
110 contact.setContactFaxNumber(this.getDetached(contact.getContactFaxNumber(), fetchedNumber));
114 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.detachAllContactPhoneEntries: EXIT!", this.getClass().getSimpleName())); //NOI18N
118 * Updates all contacts's phone entry's created timestamps
120 * @param contact Contact instance to update
122 protected void setAllContactPhoneEntriesCreated (final Contact contact) {
124 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N
126 // The contact instance must be valid
127 if (null == contact) {
129 throw new NullPointerException("contact is null"); //NOI18N
132 // Get all phone instances
133 DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber();
134 DialableFaxNumber faxNumber = contact.getContactFaxNumber();
135 DialableMobileNumber mobileNumber = contact.getContactMobileNumber();
138 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: landLineNumber={1},faxNumber={2},mobileNumber={3}", this.getClass().getSimpleName(), landLineNumber, faxNumber, mobileNumber)); //NOI18N
140 // Is a phone number instance set?
141 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() == null)) {
143 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for land-line number ...", this.getClass().getSimpleName())); //NOI18N
145 // Set updated timestamp
146 landLineNumber.setPhoneEntryCreated(new GregorianCalendar());
149 // Is a fax number instance set?
150 if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() == null)) {
152 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for fax number ...", this.getClass().getSimpleName())); //NOI18N
154 // Set updated timestamp
155 faxNumber.setPhoneEntryCreated(new GregorianCalendar());
158 // Is a mobile number instance set?
159 if ((mobileNumber instanceof DialableMobileNumber) && (mobileNumber.getPhoneId() == null)) {
161 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for cellphone number ...", this.getClass().getSimpleName())); //NOI18N
163 // Set updated timestamp
164 mobileNumber.setPhoneEntryCreated(new GregorianCalendar());
168 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: EXIT!", this.getClass().getSimpleName())); //NOI18N
172 * Returns a detached instance from given cellphone instance
174 * @param mobileNumber Mobile instance
175 * @param fetchedNumber Found cellphone number in database
177 * @return Detached instance
179 protected DialableMobileNumber getDetached (final DialableMobileNumber mobileNumber, final DialableMobileNumber fetchedNumber) {
181 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: mobileNumber={1},fetchedNumber={2} - CALLED!", this.getClass().getSimpleName(), mobileNumber, fetchedNumber)); //NOI18N
184 if (null == mobileNumber) {
186 throw new NullPointerException("mobileNumber is null"); //NOI18N
187 } else if (null == fetchedNumber) {
189 throw new NullPointerException("fetchedNumber is null"); //NOI18N
190 } else if (fetchedNumber.getPhoneId() == null) {
192 throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
196 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.getDetached: fetchedNumber.phoneId={1}", this.getClass().getSimpleName(), fetchedNumber.getPhoneId())); //NOI18N
198 // Init query instance
199 DialableMobileNumber foundNumber = this.getEntityManager().getReference(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
202 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.getDetached: foundNumber={1}", this.getClass().getSimpleName(), foundNumber)); //NOI18N
204 // Default is fetched number
205 DialableMobileNumber detachedNumber = fetchedNumber;
207 // Is there a difference?
208 if (!PhoneUtils.isSameMobileNumber(mobileNumber, fetchedNumber)) {
210 detachedNumber = this.getEntityManager().merge(foundNumber);
214 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: detachedNumber={1} - EXIT!", this.getClass().getSimpleName(), detachedNumber)); //NOI18N
217 return detachedNumber;
221 * Returns a detached instance from given land-line instance
223 * @param landLineNumber Land-line instance
224 * @param fetchedNumber Found land-line number in database
226 * @return Detached instance
228 protected DialableLandLineNumber getDetached (final DialableLandLineNumber landLineNumber, final DialableLandLineNumber fetchedNumber) {
230 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: landLineNumber={1},fetchedNumber={2} - CALLED!", this.getClass().getSimpleName(), landLineNumber, fetchedNumber)); //NOI18N
233 if (null == landLineNumber) {
235 throw new NullPointerException("landLineNumber is null"); //NOI18N
236 } else if (fetchedNumber.getPhoneId() == null) {
238 throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N
242 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.getDetached: fetchedNumber.phoneId={1}", this.getClass().getSimpleName(), fetchedNumber.getPhoneId())); //NOI18N
244 // Init query instance
245 DialableLandLineNumber foundNumber = this.getEntityManager().getReference(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
248 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.getDetached: foundNumber={1}", this.getClass().getSimpleName(), foundNumber)); //NOI18N
251 DialableLandLineNumber detachedNumber = null;
253 // Is there a difference?
254 if (!PhoneUtils.isSameLandLineNumber(landLineNumber, fetchedNumber)) {
256 detachedNumber = this.getEntityManager().merge(foundNumber);
260 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: detachedNumber={1} - EXIT!", this.getClass().getSimpleName(), detachedNumber)); //NOI18N
263 return detachedNumber;
267 * Returns a detached instance from given fax instance
269 * @param faxNumber Fax instance
270 * @param fetchedNumber Found fax number in database
272 * @return Detached instance
274 protected DialableFaxNumber getDetached (final DialableFaxNumber faxNumber, final DialableFaxNumber fetchedNumber) {
276 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: faxNumber={1},fetchedNumber={2} - CALLED!", this.getClass().getSimpleName(), faxNumber, fetchedNumber)); //NOI18N
279 if (null == faxNumber) {
281 throw new NullPointerException("faxNumber is null"); //NOI18N
282 } else if (fetchedNumber.getPhoneId() == null) {
284 throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
288 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.getDetached: fetchedNumber.phoneId={1}", this.getClass().getSimpleName(), fetchedNumber.getPhoneId())); //NOI18N
290 // Init query instance
291 DialableFaxNumber foundNumber = this.getEntityManager().getReference(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
294 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.getDetached: foundNumber={1}", this.getClass().getSimpleName(), foundNumber)); //NOI18N
297 DialableFaxNumber detachedNumber = null;
299 // Is there a difference?
300 if (!PhoneUtils.isSameFaxNumber(faxNumber, fetchedNumber)) {
302 detachedNumber = this.getEntityManager().merge(foundNumber);
306 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: detachedNumber={1} - EXIT!", this.getClass().getSimpleName(), detachedNumber)); //NOI18N
309 return detachedNumber;
313 * Get back a managed instance from given user
315 * @param user Unmanaged/detached user instance
317 * @return Managed user instance
319 protected User getManagedUser (final User user) {
321 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getManaged: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
323 // user should not be null
326 throw new NullPointerException("user is null"); //NOI18N
327 } else if (user.getUserId() == null) {
329 throw new NullPointerException("user.userId is null"); //NOI18N
330 } else if (user.getUserId() < 1) {
332 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is null", user.getUserId())); //NOI18N
333 } else if (user.getUserContact() == null) {
335 throw new NullPointerException("user.userContact is null"); //NOI18N
336 } else if (user.getUserContact().getContactId() == null) {
338 throw new NullPointerException("user.userContact.contactId is null"); //NOI18N
339 } else if (user.getUserContact().getContactId() < 1) {
340 // Not valid id number
341 throw new IllegalArgumentException(MessageFormat.format("user.userContact.contactId={0} is not valid", user.getUserContact().getContactId())); //NOI18N#
344 // Try to find it (should be there)
345 User managedUser = this.getEntityManager().find(LoginUser.class, user.getUserId());
348 assert (managedUser instanceof User) : "managedUser is null"; //NOI18N
351 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getManaged: managedUser={1} - EXIT!", this.getClass().getSimpleName(), managedUser)); //NOI18N
358 * Merges given contact's data
360 * @param contact Contact instance to merge
362 * @return Detached contact instance
364 protected Contact mergeContactData (final Contact contact) {
366 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactData: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N
368 // The contact instance must be valid
369 if (null == contact) {
371 throw new NullPointerException("contact is null"); //NOI18N
372 } else if (contact.getContactId() == null) {
374 throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
375 } else if (contact.getContactId() < 1) {
377 throw new IllegalStateException(MessageFormat.format("{0}.contact.contactId={1} is not valid.", this.getClass().getSimpleName(), contact.getContactId())); //NOI18N
380 // Set updated timestamp
381 contact.setContactUpdated(new GregorianCalendar());
383 // Get contact from it and find it
384 Contact foundContact = this.getEntityManager().getReference(contact.getClass(), contact.getContactId());
387 assert (foundContact instanceof Contact) : MessageFormat.format("Contact with id {0} not found, but should be.", contact.getContactId()); //NOI18N
390 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.updateUserPersonalData: foundContact.contactId={1}", this.getClass().getSimpleName(), foundContact.getContactId())); //NOI18N
392 // Merge contact instance
393 Contact detachedContact = this.getEntityManager().merge(foundContact);
396 detachedContact.copyAll(contact);
399 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactData: detachedContact={1} - EXIT!", this.getClass().getSimpleName(), detachedContact)); //NOI18N
401 // Return detached contact
402 return detachedContact;
406 * Merges given (detached) contact's cellphone, land-line and fax numbers
408 * @param detachedContact Detached contact instance
410 protected void mergeContactsMobileLandLineFaxNumbers (final Contact detachedContact) {
412 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactsMobileLandLineFaxNumbers: detachedContact={1} - CALLED!", this.getClass().getSimpleName(), detachedContact)); //NOI18N
414 // The contact instance must be valid
415 if (null == detachedContact) {
417 throw new NullPointerException("detachedContact is null"); //NOI18N
418 } else if (detachedContact.getContactId() == null) {
420 throw new NullPointerException("detachedContact.contactId is null"); //NOI18N //NOI18N
421 } else if (detachedContact.getContactId() < 1) {
423 throw new IllegalStateException(MessageFormat.format("{0}.detachedContact.contactId={1} is not valid.", this.getClass().getSimpleName(), detachedContact.getContactId())); //NOI18N
427 DialableMobileNumber cellphone = detachedContact.getContactMobileNumber();
428 DialableLandLineNumber landLine = detachedContact.getContactLandLineNumber();
429 DialableFaxNumber fax = detachedContact.getContactFaxNumber();
431 // Is there a cellphone instance set?
432 if (cellphone instanceof DialableMobileNumber) {
434 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: cellphone.phoneId={0} is being updated ...", cellphone.getPhoneId())); //NOI18N
437 DialableMobileNumber foundMobile = this.getEntityManager().getReference(cellphone.getClass(), cellphone.getPhoneId());
440 assert (foundMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", foundMobile.getPhoneId()); //NOI18N
442 // Then merge it, too
443 DialableMobileNumber detachedMobile = this.getEntityManager().merge(foundMobile);
446 assert (detachedMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", detachedMobile.getPhoneId()); //NOI18N
449 detachedMobile.copyAll(detachedContact.getContactMobileNumber());
452 detachedContact.setContactMobileNumber(detachedMobile);
455 // Is there a fax instance set?
456 if (fax instanceof DialableFaxNumber) {
458 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: fax.phoneId={0} is being updated ...", fax.getPhoneId())); //NOI18N
461 DialableFaxNumber foundFax = this.getEntityManager().getReference(fax.getClass(), fax.getPhoneId());
464 assert (foundFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", foundFax.getPhoneId()); //NOI18N
466 // Then merge it, too
467 DialableFaxNumber detachedFax = this.getEntityManager().merge(foundFax);
470 assert (detachedFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", detachedFax.getPhoneId()); //NOI18N
473 detachedFax.copyAll(detachedContact.getContactFaxNumber());
476 detachedContact.setContactFaxNumber(detachedFax);
479 // Is there a fax instance set?
480 if (landLine instanceof DialableLandLineNumber) {
482 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: landLine.phoneId={0} is being updated ...", landLine.getPhoneId())); //NOI18N
485 DialableLandLineNumber foundLandLine = this.getEntityManager().getReference(landLine.getClass(), landLine.getPhoneId());
488 assert (foundLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", foundLandLine.getPhoneId()); //NOI18N
490 // Then merge it, too
491 DialableLandLineNumber detachedLandLine = this.getEntityManager().merge(foundLandLine);
494 assert (detachedLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", detachedLandLine.getPhoneId()); //NOI18N
497 detachedLandLine.copyAll(detachedContact.getContactLandLineNumber());
500 detachedContact.setContactLandLineNumber(detachedLandLine);
504 this.getLoggerBeanLocal().logTrace("mergeContactsMobileLandLineFaxNumbers: EXIT!"); //NOI18N
508 * Sends an email with given subject line, template name to given recipient
511 * @param subjectLine Subject line
512 * @param templateName Template name
513 * @param emailAddress Recipient's email address
514 * @param user User instance
515 * @param baseUrl Base URL
517 protected void sendEmail (final String subjectLine, final String templateName, final Address emailAddress, final User user, final String baseUrl) {
519 this.getLoggerBeanLocal().logTrace(MessageFormat.format("sendEmail: subjectLine={0},templateName={1},emailAddress={2},user={3},baseUrl={4} - CALLED!", subjectLine, templateName, emailAddress, user, baseUrl)); //NOI18N
522 if (null == subjectLine) {
524 throw new NullPointerException("subjectLine is null"); //NOI18N
525 } else if (subjectLine.isEmpty()) {
527 throw new IllegalArgumentException("subjectLine is empty"); //NOI18N
528 } else if (null == templateName) {
530 throw new NullPointerException("templateName is null"); //NOI18N
531 } else if (templateName.isEmpty()) {
533 throw new IllegalArgumentException("templateName is empty"); //NOI18N
534 } else if (null == emailAddress) {
536 throw new NullPointerException("emailAddress is null"); //NOI18N
539 // Prepare mail wrapper
540 WrapableEmailDelivery emailWrapper = new EmailDeliveryWrapper();
543 Properties variables = UserUtils.getAllUserFields(user);
546 variables.put("baseUrl", baseUrl); //NOI18N
549 // @TODO Language from message bundle
550 emailWrapper.setRecipient(emailAddress);
551 emailWrapper.setLocale(user.getUserLocale());
552 emailWrapper.setSubjectLine(subjectLine);
553 emailWrapper.setTemplateName(templateName);
554 emailWrapper.setTemplateVariables(variables);
557 // Send out email change
558 ObjectMessage message = this.getSession().createObjectMessage();
559 message.setObject(emailWrapper);
562 this.sendMessage(message);
563 } catch (final JMSException ex) {
565 throw new EJBException(ex);
569 this.getLoggerBeanLocal().logTrace("sendEmail: EXIT!"); //NOI18N
573 * Updates all contact's phone instances from other contact, both contacts
574 * should be the same.
576 * @param contact Contact to set instances
577 * @param other Other contact to get instances from
579 protected void setAllContactPhoneEntries (final Contact contact, final Contact other) {
581 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntries: contact={1},other={2} - CALLED!", this.getClass().getSimpleName(), contact, other)); //NOI18N
583 // Both must be the same and not null
584 if (null == contact) {
586 throw new NullPointerException("contact is null"); //NOI18N
587 } else if (null == other) {
589 throw new NullPointerException("other is null"); //NOI18N
590 } else if (!Objects.equals(contact, other)) {
591 // Not same instances
592 throw new IllegalArgumentException(MessageFormat.format("contact={0} and other={1} are not equal!", contact, other)); //NOI18N
596 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: other.contactMobileNumber={0}", other.getContactMobileNumber())); //NOI18N
598 // Is other cellphone not set?
599 if ((other.getContactMobileNumber() == null) || (PhoneUtils.isSameMobileNumber(contact.getContactMobileNumber(), other.getContactMobileNumber()))) {
601 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: Copying cellphone entry ...", this.getClass().getSimpleName())); //NOI18N
603 // Is the fax number set?
604 if (other.getContactMobileNumber() instanceof DialableMobileNumber) {
605 // Copy cellphone number
606 contact.setContactMobileNumber(this.getDetached(other.getContactMobileNumber(), contact.getContactMobileNumber()));
609 contact.setContactMobileNumber(null);
614 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: other.contactLandLineNumber={0}", other.getContactLandLineNumber())); //NOI18N
616 // Is other cellphone not set?
617 if ((other.getContactLandLineNumber() == null) || (PhoneUtils.isSameLandLineNumber(contact.getContactLandLineNumber(), other.getContactLandLineNumber()))) {
619 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: Copying land-line entry ...", this.getClass().getSimpleName())); //NOI18N
621 // Is the land-line number set?
622 if (other.getContactLandLineNumber() instanceof DialableLandLineNumber) {
623 // Copy land-line number
624 contact.setContactLandLineNumber(this.getDetached(other.getContactLandLineNumber(), contact.getContactLandLineNumber()));
627 contact.setContactLandLineNumber(null);
632 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: other.contactFaxNumber={1}", this.getClass().getSimpleName(), other.getContactFaxNumber())); //NOI18N
634 // Is other cellphone not set?
635 if ((other.getContactFaxNumber() == null) || (PhoneUtils.isSameFaxNumber(contact.getContactFaxNumber(), other.getContactFaxNumber()))) {
637 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: Copying fax entry ...", this.getClass().getSimpleName())); //NOI18N
639 // Is the fax number set?
640 if (other.getContactFaxNumber() instanceof DialableFaxNumber) {
642 contact.setContactFaxNumber(this.getDetached(other.getContactFaxNumber(), contact.getContactFaxNumber()));
645 contact.setContactFaxNumber(null);
650 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntries: EXIT!", this.getClass().getSimpleName())); //NOI18N
654 * Updates all contact's phone entry's updated timestamps
656 * @param contact Contact instance to update
657 * @param isMobileUnlinked Whether a cellphone entry has been unlinked in
659 * @param isLandlineUnlinked Whether a land-line entry has been unlinked in
661 * @param isFaxUnlinked Whether a fax entry has been unlinked in contact
664 protected void setAllContactPhoneEntriesUpdated (final Contact contact, final boolean isMobileUnlinked, final boolean isLandlineUnlinked, final boolean isFaxUnlinked) {
666 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: contact={1},isMobileUnlinked={2},isLandlineUnlinked={3},isFaxUnlinked={4} - CALLED", this.getClass().getSimpleName(), contact, isMobileUnlinked, isLandlineUnlinked, isFaxUnlinked)); //NOI18N
668 // The contact instance must be valid
669 if (null == contact) {
671 throw new NullPointerException("contact is null"); //NOI18N
672 } else if (contact.getContactId() == null) {
674 throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
675 } else if (contact.getContactId() < 1) {
677 throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
680 // Get all phone instances
681 DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber();
682 DialableFaxNumber faxNumber = contact.getContactFaxNumber();
683 DialableMobileNumber mobileNumber = contact.getContactMobileNumber();
685 // Flags and instances must be constistent
686 if (isMobileUnlinked && mobileNumber instanceof DialableMobileNumber) {
688 throw new IllegalStateException("isCellPhoneUnlinked is TRUE, but mobileNumber is set."); //NOI18N
689 } else if (isLandlineUnlinked && landLineNumber instanceof DialableLandLineNumber) {
691 throw new IllegalStateException("isLandlineUnlinked is TRUE, but landLineNumber is set."); //NOI18N
692 } else if (isFaxUnlinked && faxNumber instanceof DialableFaxNumber) {
694 throw new IllegalStateException("isFaxUnlinked is TRUE, but faxNumber is set."); //NOI18N
697 // Is a phone number instance set?
698 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() instanceof Long) && (landLineNumber.getPhoneId() > 0)) {
700 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: Setting updated timestamp for land-line number ...", this.getClass().getSimpleName())); //NOI18N
702 // Set updated timestamp
703 landLineNumber.setPhoneEntryUpdated(new GregorianCalendar());
706 // Is a fax number instance set?
707 if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() instanceof Long) && (faxNumber.getPhoneId() > 0)) {
709 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: Setting updated timestamp for fax number ...", this.getClass().getSimpleName())); //NOI18N
711 // Set updated timestamp
712 faxNumber.setPhoneEntryUpdated(new GregorianCalendar());
715 // Is a mobile number instance set?
716 if ((mobileNumber instanceof DialableMobileNumber) && (mobileNumber.getPhoneId() instanceof Long) && (mobileNumber.getPhoneId() > 0)) {
718 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: Setting updated timestamp for cellphone number ...", this.getClass().getSimpleName())); //NOI18N
720 // Set updated timestamp
721 mobileNumber.setPhoneEntryUpdated(new GregorianCalendar());
725 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: EXIT!", this.getClass().getSimpleName())); //NOI18N