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.jjobs.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.fax.FaxNumbers;
34 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
35 import org.mxchange.jphone.phonenumbers.landline.LandLineNumbers;
36 import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
37 import org.mxchange.jphone.phonenumbers.mobile.MobileNumbers;
38 import org.mxchange.jphone.utils.PhoneUtils;
39 import org.mxchange.jusercore.model.user.LoginUser;
40 import org.mxchange.jusercore.model.user.User;
41 import org.mxchange.jusercore.model.user.UserUtils;
44 * A helper class for beans that access the database.
46 * @author Roland Häder<roland@mxchange.org>
48 public abstract class BaseJobsDatabaseBean extends BaseDatabaseBean {
53 private static final long serialVersionUID = 12_895_410_275_811_963L;
56 * Protected constructor
58 protected BaseJobsDatabaseBean () {
59 // Call super constructor
64 * Constructor with queue factory JNDI and queue JNDI names
66 * @param factoryJndi JNDI name for queue factory
67 * @param queueJndi JNDI name for email queue
69 protected BaseJobsDatabaseBean (final String factoryJndi, final String queueJndi) {
70 // Call super constructor
71 super(factoryJndi, queueJndi);
75 * Updates all contact's phone entry's created timestamps
77 * @param contact Contact instance to update
79 protected void setAllContactPhoneEntriesCreated (final Contact contact) {
81 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N
83 // The contact instance must be valid
84 if (null == contact) {
86 throw new NullPointerException("contact is null"); //NOI18N
89 // Get all phone instances
90 DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber();
91 DialableFaxNumber faxNumber = contact.getContactFaxNumber();
92 DialableMobileNumber mobileNumber = contact.getContactMobileNumber();
95 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: landLineNumber={1},faxNumber={2},mobileNumber={3}", this.getClass().getSimpleName(), landLineNumber, faxNumber, mobileNumber)); //NOI18N
97 // Is a phone number instance set?
98 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() == null)) {
100 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for land-line number ...", this.getClass().getSimpleName())); //NOI18N
102 // Set updated timestamp
103 landLineNumber.setPhoneEntryCreated(new GregorianCalendar());
106 // Is a fax number instance set?
107 if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() == null)) {
109 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for fax number ...", this.getClass().getSimpleName())); //NOI18N
111 // Set updated timestamp
112 faxNumber.setPhoneEntryCreated(new GregorianCalendar());
115 // Is a mobile number instance set?
116 if ((mobileNumber instanceof DialableMobileNumber) && (mobileNumber.getPhoneId() == null)) {
118 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for cellphone number ...", this.getClass().getSimpleName())); //NOI18N
120 // Set updated timestamp
121 mobileNumber.setPhoneEntryCreated(new GregorianCalendar());
125 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: EXIT!", this.getClass().getSimpleName())); //NOI18N
129 * Returns a managed instance from given mobile number
131 * @param mobileNumber Mobile instance
132 * @param fetchedNumber Found mobile number in database
134 * @return Managed instance
136 protected DialableMobileNumber getManaged (final DialableMobileNumber mobileNumber, final DialableMobileNumber fetchedNumber) {
138 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: mobileNumber={1},fetchedNumber={2} - CALLED!", this.getClass().getSimpleName(), mobileNumber, fetchedNumber)); //NOI18N
141 if (null == mobileNumber) {
143 throw new NullPointerException("mobileNumber is null"); //NOI18N
144 } else if (null == fetchedNumber) {
146 throw new NullPointerException("fetchedNumber is null"); //NOI18N
147 } else if (fetchedNumber.getPhoneId() == null) {
149 throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
153 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.getDetached: fetchedNumber.phoneId={1}", this.getClass().getSimpleName(), fetchedNumber.getPhoneId())); //NOI18N
156 DialableMobileNumber managedNumber = null;
158 // Is there a difference?
159 if (!PhoneUtils.isSameMobileNumber(mobileNumber, fetchedNumber)) {
161 managedNumber = this.getEntityManager().merge(fetchedNumber);
165 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N
168 return managedNumber;
172 * Returns a managed instance from given land-line number
174 * @param landLineNumber Land-line instance
175 * @param fetchedNumber Found land-line number in database
177 * @return Managed instance
179 protected DialableLandLineNumber getManaged (final DialableLandLineNumber landLineNumber, final DialableLandLineNumber fetchedNumber) {
181 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: landLineNumber={1},fetchedNumber={2} - CALLED!", this.getClass().getSimpleName(), landLineNumber, fetchedNumber)); //NOI18N
184 if (null == landLineNumber) {
186 throw new NullPointerException("landLineNumber 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("landLineNumber.phoneId is null"); //NOI18N
196 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.getDetached: fetchedNumber.phoneId={1}", this.getClass().getSimpleName(), fetchedNumber.getPhoneId())); //NOI18N
199 DialableLandLineNumber managedNumber = null;
201 // Is there a difference?
202 if (!PhoneUtils.isSameLandLineNumber(landLineNumber, fetchedNumber)) {
204 managedNumber = this.getEntityManager().merge(fetchedNumber);
208 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N
211 return managedNumber;
215 * Returns a managed instance from given fax number
217 * @param faxNumber Fax instance
218 * @param fetchedNumber Found fax number in database
220 * @return Managed instance
222 protected DialableFaxNumber getManaged (final DialableFaxNumber faxNumber, final DialableFaxNumber fetchedNumber) {
224 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: faxNumber={1},fetchedNumber={2} - CALLED!", this.getClass().getSimpleName(), faxNumber, fetchedNumber)); //NOI18N
227 if (null == faxNumber) {
229 throw new NullPointerException("faxNumber is null"); //NOI18N
230 } else if (null == fetchedNumber) {
232 throw new NullPointerException("fetchedNumber is null"); //NOI18N
233 } else if (fetchedNumber.getPhoneId() == null) {
235 throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
239 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.getDetached: fetchedNumber.phoneId={1}", this.getClass().getSimpleName(), fetchedNumber.getPhoneId())); //NOI18N
242 DialableFaxNumber managedNumber = null;
244 // Is there a difference?
245 if (!PhoneUtils.isSameFaxNumber(faxNumber, fetchedNumber)) {
247 managedNumber = this.getEntityManager().merge(fetchedNumber);
251 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N
254 return managedNumber;
258 * Get back a managed instance from given user
260 * @param user Unmanaged/detached user instance
262 * @return Managed user instance
264 protected User getManagedUser (final User user) {
266 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getManaged: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
268 // user should not be null
271 throw new NullPointerException("user is null"); //NOI18N
272 } else if (user.getUserId() == null) {
274 throw new NullPointerException("user.userId is null"); //NOI18N
275 } else if (user.getUserId() < 1) {
277 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is null", user.getUserId())); //NOI18N
278 } else if (user.getUserContact() == null) {
280 throw new NullPointerException("user.userContact is null"); //NOI18N
281 } else if (user.getUserContact().getContactId() == null) {
283 throw new NullPointerException("user.userContact.contactId is null"); //NOI18N
284 } else if (user.getUserContact().getContactId() < 1) {
285 // Not valid id number
286 throw new IllegalArgumentException(MessageFormat.format("user.userContact.contactId={0} is not valid", user.getUserContact().getContactId())); //NOI18N#
289 // Try to find it (should be there)
290 User managedUser = this.getEntityManager().find(LoginUser.class, user.getUserId());
293 assert (managedUser instanceof User) : "managedUser is null"; //NOI18N
296 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getManaged: managedUser={1} - EXIT!", this.getClass().getSimpleName(), managedUser)); //NOI18N
303 * Merges given (detached) contact's data
305 * @param detachedContact Contact instance to merge
307 * @return Detached contact instance
309 protected Contact mergeContactData (final Contact detachedContact) {
311 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactData: contact={1} - CALLED!", this.getClass().getSimpleName(), detachedContact)); //NOI18N
313 // The contact instance must be valid
314 if (null == detachedContact) {
316 throw new NullPointerException("detachedContact is null"); //NOI18N
317 } else if (detachedContact.getContactId() == null) {
319 throw new NullPointerException("detachedContact.contactId is null"); //NOI18N //NOI18N
320 } else if (detachedContact.getContactId() < 1) {
322 throw new IllegalStateException(MessageFormat.format("{0}.detachedContact.contactId={1} is not valid.", this.getClass().getSimpleName(), detachedContact.getContactId())); //NOI18N
325 // Get contact from it and find it
326 Contact managedContact = this.getEntityManager().find(detachedContact.getClass(), detachedContact.getContactId());
329 assert (managedContact instanceof Contact) : MessageFormat.format("Contact with id {0} not found, but should be.", detachedContact.getContactId()); //NOI18N
332 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.updateUserPersonalData: managedContact.contactId={1}", this.getClass().getSimpleName(), managedContact.getContactId())); //NOI18N
334 // Is a fax number set?
335 if (detachedContact.getContactFaxNumber() instanceof DialableFaxNumber) {
336 // Make fax numbers managed
337 managedContact.setContactFaxNumber(this.getManaged(detachedContact.getContactFaxNumber(), detachedContact.getContactFaxNumber()));
340 // Is a land-line number set?
341 if (detachedContact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
342 // Make land-line numbers managed
343 managedContact.setContactLandLineNumber(this.getManaged(detachedContact.getContactLandLineNumber(), detachedContact.getContactLandLineNumber()));
346 // Is a mobile number set?
347 if (detachedContact.getContactMobileNumber() instanceof DialableMobileNumber) {
348 // Make mobile numbers managed
349 managedContact.setContactMobileNumber(this.getManaged(detachedContact.getContactMobileNumber(), detachedContact.getContactMobileNumber()));
352 // Set updated timestamp
353 managedContact.setContactUpdated(new GregorianCalendar());
356 ContactUtils.copyAll(detachedContact, managedContact);
359 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactData: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N
361 // Return detached contact
362 return managedContact;
366 * Merges given (detached) contact's cellphone, land-line and fax numbers
368 * @param detachedContact Detached contact instance
370 protected void mergeContactsMobileLandLineFaxNumbers (final Contact detachedContact) {
372 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactsMobileLandLineFaxNumbers: detachedContact={1} - CALLED!", this.getClass().getSimpleName(), detachedContact)); //NOI18N
374 // The contact instance must be valid
375 if (null == detachedContact) {
377 throw new NullPointerException("detachedContact is null"); //NOI18N
378 } else if (detachedContact.getContactId() == null) {
380 throw new NullPointerException("detachedContact.contactId is null"); //NOI18N //NOI18N
381 } else if (detachedContact.getContactId() < 1) {
383 throw new IllegalStateException(MessageFormat.format("{0}.detachedContact.contactId={1} is not valid.", this.getClass().getSimpleName(), detachedContact.getContactId())); //NOI18N
387 DialableMobileNumber cellphone = detachedContact.getContactMobileNumber();
388 DialableLandLineNumber landLine = detachedContact.getContactLandLineNumber();
389 DialableFaxNumber fax = detachedContact.getContactFaxNumber();
391 // Is there a cellphone instance set?
392 if (cellphone instanceof DialableMobileNumber) {
394 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: cellphone.phoneId={0} is being updated ...", cellphone.getPhoneId())); //NOI18N
397 DialableMobileNumber foundMobile = this.getEntityManager().find(cellphone.getClass(), cellphone.getPhoneId());
400 assert (foundMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", foundMobile.getPhoneId()); //NOI18N
402 // Then merge it, too
403 DialableMobileNumber managedMobile = this.getEntityManager().merge(foundMobile);
406 assert (managedMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", managedMobile.getPhoneId()); //NOI18N
409 MobileNumbers.copyAll(detachedContact.getContactMobileNumber(), managedMobile);
412 detachedContact.setContactMobileNumber(managedMobile);
415 // Is there a fax instance set?
416 if (fax instanceof DialableFaxNumber) {
418 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: fax.phoneId={0} is being updated ...", fax.getPhoneId())); //NOI18N
421 DialableFaxNumber foundFax = this.getEntityManager().find(fax.getClass(), fax.getPhoneId());
424 assert (foundFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", foundFax.getPhoneId()); //NOI18N
426 // Then merge it, too
427 DialableFaxNumber managedFax = this.getEntityManager().merge(foundFax);
430 assert (managedFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", managedFax.getPhoneId()); //NOI18N
433 FaxNumbers.copyAll(detachedContact.getContactFaxNumber(), managedFax);
436 detachedContact.setContactFaxNumber(managedFax);
439 // Is there a fax instance set?
440 if (landLine instanceof DialableLandLineNumber) {
442 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: landLine.phoneId={0} is being updated ...", landLine.getPhoneId())); //NOI18N
445 DialableLandLineNumber foundLandLine = this.getEntityManager().find(landLine.getClass(), landLine.getPhoneId());
448 assert (foundLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", foundLandLine.getPhoneId()); //NOI18N
450 // Then merge it, too
451 DialableLandLineNumber managedLandLine = this.getEntityManager().merge(foundLandLine);
454 assert (managedLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", managedLandLine.getPhoneId()); //NOI18N
457 LandLineNumbers.copyAll(detachedContact.getContactLandLineNumber(), managedLandLine);
460 detachedContact.setContactLandLineNumber(managedLandLine);
464 this.getLoggerBeanLocal().logTrace("mergeContactsMobileLandLineFaxNumbers: EXIT!"); //NOI18N
468 * Sends an email with given subject line, template name to given recipient
471 * @param subjectLine Subject line
472 * @param templateName Template name
473 * @param emailAddress Recipient's email address
474 * @param user User instance
475 * @param baseUrl Base URL
476 * @param randomPassword A randomly-generated password or NULL if user had
479 protected void sendEmail (final String subjectLine, final String templateName, final Address emailAddress, final User user, final String baseUrl, final String randomPassword) {
481 this.getLoggerBeanLocal().logTrace(MessageFormat.format("sendEmail: subjectLine={0},templateName={1},emailAddress={2},user={3},baseUrl={4} - CALLED!", subjectLine, templateName, emailAddress, user, baseUrl)); //NOI18N
484 if (null == subjectLine) {
486 throw new NullPointerException("subjectLine is null"); //NOI18N
487 } else if (subjectLine.isEmpty()) {
489 throw new IllegalArgumentException("subjectLine is empty"); //NOI18N
490 } else if (null == templateName) {
492 throw new NullPointerException("templateName is null"); //NOI18N
493 } else if (templateName.isEmpty()) {
495 throw new IllegalArgumentException("templateName is empty"); //NOI18N
496 } else if (null == emailAddress) {
498 throw new NullPointerException("emailAddress is null"); //NOI18N
499 } else if (null == user) {
501 throw new NullPointerException("user is null"); //NOI18N
502 } else if (user.getUserId() == null) {
504 throw new NullPointerException("user.userId is null"); //NOI18N
505 } else if (user.getUserId() < 1) {
507 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid.", user.getUserId())); //NOI18N
508 } else if (user.getUserName() == null) {
510 throw new NullPointerException("user.userName is null"); //NOI18N
511 } else if (user.getUserName().isEmpty()) {
513 throw new IllegalArgumentException("user.userName is empty"); //NOI18N
514 } else if (user.getUserAccountStatus() == null) {
516 throw new NullPointerException("user.userAccountStatus is null"); //NOI18N
517 } else if (user.getUserContact() == null) {
519 throw new NullPointerException("user.userContact is null"); //NOI18N
520 } else if (user.getUserContact().getContactId() == null) {
522 throw new NullPointerException("user.userContact.contactId is null"); //NOI18N
523 } else if (user.getUserContact().getContactId() < 1) {
525 throw new IllegalArgumentException(MessageFormat.format("user.userContact.contactId={0} is invalid", user.getUserContact().getContactId())); //NOI18N
526 } else if (user.getUserContact().getContactPersonalTitle() == null) {
528 throw new NullPointerException("user.userContact.contactPersonalTitle is null"); //NOI18N
529 } else if (user.getUserLocale() == null) {
531 throw new NullPointerException("user.userLocale is null"); //NOI18N
534 // Prepare mail wrapper
535 WrapableEmailDelivery emailWrapper = new EmailDeliveryWrapper();
538 Properties variables = UserUtils.getAllUserFields(user);
540 // Set base URL and random password
541 variables.put("baseUrl", baseUrl); //NOI18N
542 variables.put("randomPassword", ""); //NOI18N
544 // Is the random password set?
545 if ((randomPassword instanceof String) && (!randomPassword.isEmpty())) {
546 variables.put("randomPassword", randomPassword); //NOI18N
550 // @TODO Language from message bundle
551 emailWrapper.setRecipient(emailAddress);
552 emailWrapper.setLocale(user.getUserLocale());
553 emailWrapper.setSubjectLine(subjectLine);
554 emailWrapper.setTemplateName(templateName);
555 emailWrapper.setTemplateVariables(variables);
558 // Send out email change
559 ObjectMessage message = this.getSession().createObjectMessage();
560 message.setObject(emailWrapper);
563 this.sendMessage(message);
564 } catch (final JMSException ex) {
566 throw new EJBException(ex);
570 this.getLoggerBeanLocal().logTrace("sendEmail: EXIT!"); //NOI18N
574 * Updates all contact's phone instances from other contact, both contacts
575 * should be the same.
577 * @param contact Contact to set instances
578 * @param other Other contact to get instances from
580 protected void setAllContactPhoneEntries (final Contact contact, final Contact other) {
582 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntries: contact={1},other={2} - CALLED!", this.getClass().getSimpleName(), contact, other)); //NOI18N
584 // Both must be the same and not null
585 if (null == contact) {
587 throw new NullPointerException("contact is null"); //NOI18N
588 } else if (null == other) {
590 throw new NullPointerException("other is null"); //NOI18N
591 } else if (!Objects.equals(contact, other)) {
592 // Not same instances
593 throw new IllegalArgumentException(MessageFormat.format("contact={0} and other={1} are not equal!", contact, other)); //NOI18N
597 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: other.contactMobileNumber={0}", other.getContactMobileNumber())); //NOI18N
599 // Is other cellphone not set?
600 if ((other.getContactMobileNumber() == null) || (PhoneUtils.isSameMobileNumber(contact.getContactMobileNumber(), other.getContactMobileNumber()))) {
602 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: Copying cellphone entry ...", this.getClass().getSimpleName())); //NOI18N
604 // Is the fax number set?
605 if (other.getContactMobileNumber() instanceof DialableMobileNumber) {
606 // Copy cellphone number
607 contact.setContactMobileNumber(this.getManaged(other.getContactMobileNumber(), contact.getContactMobileNumber()));
610 contact.setContactMobileNumber(null);
615 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: other.contactLandLineNumber={0}", other.getContactLandLineNumber())); //NOI18N
617 // Is other cellphone not set?
618 if ((other.getContactLandLineNumber() == null) || (PhoneUtils.isSameLandLineNumber(contact.getContactLandLineNumber(), other.getContactLandLineNumber()))) {
620 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: Copying land-line entry ...", this.getClass().getSimpleName())); //NOI18N
622 // Is the land-line number set?
623 if (other.getContactLandLineNumber() instanceof DialableLandLineNumber) {
624 // Copy land-line number
625 contact.setContactLandLineNumber(this.getManaged(other.getContactLandLineNumber(), contact.getContactLandLineNumber()));
628 contact.setContactLandLineNumber(null);
633 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: other.contactFaxNumber={1}", this.getClass().getSimpleName(), other.getContactFaxNumber())); //NOI18N
635 // Is other cellphone not set?
636 if ((other.getContactFaxNumber() == null) || (PhoneUtils.isSameFaxNumber(contact.getContactFaxNumber(), other.getContactFaxNumber()))) {
638 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: Copying fax entry ...", this.getClass().getSimpleName())); //NOI18N
640 // Is the fax number set?
641 if (other.getContactFaxNumber() instanceof DialableFaxNumber) {
643 contact.setContactFaxNumber(this.getManaged(other.getContactFaxNumber(), contact.getContactFaxNumber()));
646 contact.setContactFaxNumber(null);
651 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntries: EXIT!", this.getClass().getSimpleName())); //NOI18N
655 * Updates all contact's phone entry's updated timestamps
657 * @param contact Contact instance to update
658 * @param isMobileUnlinked Whether a mobile entry has been unlinked in
660 * @param isLandlineUnlinked Whether a land-line entry has been unlinked in
662 * @param isFaxUnlinked Whether a fax entry has been unlinked in
665 protected void setAllContactPhoneEntriesUpdated (final Contact contact, final boolean isMobileUnlinked, final boolean isLandlineUnlinked, final boolean isFaxUnlinked) {
667 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: contact={1},isMobileUnlinked={2},isLandlineUnlinked={3},isFaxUnlinked={4} - CALLED", this.getClass().getSimpleName(), contact, isMobileUnlinked, isLandlineUnlinked, isFaxUnlinked)); //NOI18N
669 // The contact instance must be valid
670 if (null == contact) {
672 throw new NullPointerException("contact is null"); //NOI18N
673 } else if (contact.getContactId() == null) {
675 throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
676 } else if (contact.getContactId() < 1) {
678 throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
681 // Get all phone instances
682 DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber();
683 DialableFaxNumber faxNumber = contact.getContactFaxNumber();
684 DialableMobileNumber mobileNumber = contact.getContactMobileNumber();
686 // Flags and instances must be constistent
687 if (isMobileUnlinked && mobileNumber instanceof DialableMobileNumber) {
689 throw new IllegalStateException("isCellPhoneUnlinked is TRUE, but mobileNumber is set."); //NOI18N
690 } else if (isLandlineUnlinked && landLineNumber instanceof DialableLandLineNumber) {
692 throw new IllegalStateException("isLandlineUnlinked is TRUE, but landLineNumber is set."); //NOI18N
693 } else if (isFaxUnlinked && faxNumber instanceof DialableFaxNumber) {
695 throw new IllegalStateException("isFaxUnlinked is TRUE, but faxNumber is set."); //NOI18N
698 // Is a phone number instance set?
699 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() instanceof Long) && (landLineNumber.getPhoneId() > 0)) {
701 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: Setting updated timestamp for land-line number ...", this.getClass().getSimpleName())); //NOI18N
703 // Set updated timestamp
704 landLineNumber.setPhoneEntryUpdated(new GregorianCalendar());
707 // Is a fax number instance set?
708 if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() instanceof Long) && (faxNumber.getPhoneId() > 0)) {
710 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: Setting updated timestamp for fax number ...", this.getClass().getSimpleName())); //NOI18N
712 // Set updated timestamp
713 faxNumber.setPhoneEntryUpdated(new GregorianCalendar());
716 // Is a mobile number instance set?
717 if ((mobileNumber instanceof DialableMobileNumber) && (mobileNumber.getPhoneId() instanceof Long) && (mobileNumber.getPhoneId() > 0)) {
719 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: Setting updated timestamp for cellphone number ...", this.getClass().getSimpleName())); //NOI18N
721 // Set updated timestamp
722 mobileNumber.setPhoneEntryUpdated(new GregorianCalendar());
726 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: EXIT!", this.getClass().getSimpleName())); //NOI18N