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.pizzaaplication.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 BasePizzaDatabaseBean extends BaseDatabaseBean {
53 private static final long serialVersionUID = 12_895_410_275_811_963L;
56 * Protected constructor
58 protected BasePizzaDatabaseBean () {
59 // Call super constructor
60 super("jms/pizzaservice-queue-factory", "jms/pizzaservice-email-queue"); //NOI18N
64 * Updates all contact's phone entry's created timestamps
66 * @param contact Contact instance to update
68 protected void setAllContactPhoneEntriesCreated (final Contact contact) {
70 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N
72 // The contact instance must be valid
73 if (null == contact) {
75 throw new NullPointerException("contact is null"); //NOI18N
78 // Get all phone instances
79 DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber();
80 DialableFaxNumber faxNumber = contact.getContactFaxNumber();
81 DialableMobileNumber mobileNumber = contact.getContactMobileNumber();
84 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: landLineNumber={1},faxNumber={2},mobileNumber={3}", this.getClass().getSimpleName(), landLineNumber, faxNumber, mobileNumber)); //NOI18N
86 // Is a phone number instance set?
87 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() == null)) {
89 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for land-line number ...", this.getClass().getSimpleName())); //NOI18N
91 // Set updated timestamp
92 landLineNumber.setPhoneEntryCreated(new GregorianCalendar());
95 // Is a fax number instance set?
96 if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() == null)) {
98 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for fax number ...", this.getClass().getSimpleName())); //NOI18N
100 // Set updated timestamp
101 faxNumber.setPhoneEntryCreated(new GregorianCalendar());
104 // Is a mobile number instance set?
105 if ((mobileNumber instanceof DialableMobileNumber) && (mobileNumber.getPhoneId() == null)) {
107 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for cellphone number ...", this.getClass().getSimpleName())); //NOI18N
109 // Set updated timestamp
110 mobileNumber.setPhoneEntryCreated(new GregorianCalendar());
114 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: EXIT!", this.getClass().getSimpleName())); //NOI18N
118 * Returns a managed instance from given mobile number
120 * @param mobileNumber Mobile instance
121 * @param fetchedNumber Found mobile number in database
123 * @return Managed instance
125 protected DialableMobileNumber getManaged (final DialableMobileNumber mobileNumber, final DialableMobileNumber fetchedNumber) {
127 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: mobileNumber={1},fetchedNumber={2} - CALLED!", this.getClass().getSimpleName(), mobileNumber, fetchedNumber)); //NOI18N
130 if (null == mobileNumber) {
132 throw new NullPointerException("mobileNumber is null"); //NOI18N
133 } else if (null == fetchedNumber) {
135 throw new NullPointerException("fetchedNumber is null"); //NOI18N
136 } else if (fetchedNumber.getPhoneId() == null) {
138 throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
142 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.getDetached: fetchedNumber.phoneId={1}", this.getClass().getSimpleName(), fetchedNumber.getPhoneId())); //NOI18N
145 DialableMobileNumber managedNumber = null;
147 // Is there a difference?
148 if (!PhoneUtils.isSameMobileNumber(mobileNumber, fetchedNumber)) {
150 managedNumber = this.getEntityManager().merge(fetchedNumber);
154 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N
157 return managedNumber;
161 * Returns a managed instance from given land-line number
163 * @param landLineNumber Land-line instance
164 * @param fetchedNumber Found land-line number in database
166 * @return Managed instance
168 protected DialableLandLineNumber getManaged (final DialableLandLineNumber landLineNumber, final DialableLandLineNumber fetchedNumber) {
170 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: landLineNumber={1},fetchedNumber={2} - CALLED!", this.getClass().getSimpleName(), landLineNumber, fetchedNumber)); //NOI18N
173 if (null == landLineNumber) {
175 throw new NullPointerException("landLineNumber is null"); //NOI18N
176 } else if (null == fetchedNumber) {
178 throw new NullPointerException("fetchedNumber is null"); //NOI18N
179 } else if (fetchedNumber.getPhoneId() == null) {
181 throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N
185 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.getDetached: fetchedNumber.phoneId={1}", this.getClass().getSimpleName(), fetchedNumber.getPhoneId())); //NOI18N
188 DialableLandLineNumber managedNumber = null;
190 // Is there a difference?
191 if (!PhoneUtils.isSameLandLineNumber(landLineNumber, fetchedNumber)) {
193 managedNumber = this.getEntityManager().merge(fetchedNumber);
197 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N
200 return managedNumber;
204 * Returns a managed instance from given fax number
206 * @param faxNumber Fax instance
207 * @param fetchedNumber Found fax number in database
209 * @return Managed instance
211 protected DialableFaxNumber getManaged (final DialableFaxNumber faxNumber, final DialableFaxNumber fetchedNumber) {
213 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: faxNumber={1},fetchedNumber={2} - CALLED!", this.getClass().getSimpleName(), faxNumber, fetchedNumber)); //NOI18N
216 if (null == faxNumber) {
218 throw new NullPointerException("faxNumber is null"); //NOI18N
219 } else if (null == fetchedNumber) {
221 throw new NullPointerException("fetchedNumber is null"); //NOI18N
222 } else if (fetchedNumber.getPhoneId() == null) {
224 throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
228 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.getDetached: fetchedNumber.phoneId={1}", this.getClass().getSimpleName(), fetchedNumber.getPhoneId())); //NOI18N
231 DialableFaxNumber managedNumber = null;
233 // Is there a difference?
234 if (!PhoneUtils.isSameFaxNumber(faxNumber, fetchedNumber)) {
236 managedNumber = this.getEntityManager().merge(fetchedNumber);
240 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N
243 return managedNumber;
247 * Get back a managed instance from given user
249 * @param user Unmanaged/detached user instance
251 * @return Managed user instance
253 protected User getManagedUser (final User user) {
255 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getManaged: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
257 // user should not be null
260 throw new NullPointerException("user is null"); //NOI18N
261 } else if (user.getUserId() == null) {
263 throw new NullPointerException("user.userId is null"); //NOI18N
264 } else if (user.getUserId() < 1) {
266 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is null", user.getUserId())); //NOI18N
267 } else if (user.getUserContact() == null) {
269 throw new NullPointerException("user.userContact is null"); //NOI18N
270 } else if (user.getUserContact().getContactId() == null) {
272 throw new NullPointerException("user.userContact.contactId is null"); //NOI18N
273 } else if (user.getUserContact().getContactId() < 1) {
274 // Not valid id number
275 throw new IllegalArgumentException(MessageFormat.format("user.userContact.contactId={0} is not valid", user.getUserContact().getContactId())); //NOI18N#
278 // Try to find it (should be there)
279 User managedUser = this.getEntityManager().find(LoginUser.class, user.getUserId());
282 assert (managedUser instanceof User) : "managedUser is null"; //NOI18N
285 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getManaged: managedUser={1} - EXIT!", this.getClass().getSimpleName(), managedUser)); //NOI18N
292 * Merges given (detached) contact's data
294 * @param detachedContact Contact instance to merge
296 * @return Detached contact instance
298 protected Contact mergeContactData (final Contact detachedContact) {
300 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactData: contact={1} - CALLED!", this.getClass().getSimpleName(), detachedContact)); //NOI18N
302 // The contact instance must be valid
303 if (null == detachedContact) {
305 throw new NullPointerException("detachedContact is null"); //NOI18N
306 } else if (detachedContact.getContactId() == null) {
308 throw new NullPointerException("detachedContact.contactId is null"); //NOI18N //NOI18N
309 } else if (detachedContact.getContactId() < 1) {
311 throw new IllegalStateException(MessageFormat.format("{0}.detachedContact.contactId={1} is not valid.", this.getClass().getSimpleName(), detachedContact.getContactId())); //NOI18N
314 // Get contact from it and find it
315 Contact managedContact = this.getEntityManager().find(detachedContact.getClass(), detachedContact.getContactId());
318 assert (managedContact instanceof Contact) : MessageFormat.format("Contact with id {0} not found, but should be.", detachedContact.getContactId()); //NOI18N
321 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.updateUserPersonalData: managedContact.contactId={1}", this.getClass().getSimpleName(), managedContact.getContactId())); //NOI18N
323 // Is a fax number set?
324 if (detachedContact.getContactFaxNumber() instanceof DialableFaxNumber) {
325 // Make fax numbers managed
326 managedContact.setContactFaxNumber(this.getManaged(detachedContact.getContactFaxNumber(), detachedContact.getContactFaxNumber()));
329 // Is a land-line number set?
330 if (detachedContact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
331 // Make land-line numbers managed
332 managedContact.setContactLandLineNumber(this.getManaged(detachedContact.getContactLandLineNumber(), detachedContact.getContactLandLineNumber()));
335 // Is a mobile number set?
336 if (detachedContact.getContactMobileNumber() instanceof DialableMobileNumber) {
337 // Make mobile numbers managed
338 managedContact.setContactMobileNumber(this.getManaged(detachedContact.getContactMobileNumber(), detachedContact.getContactMobileNumber()));
341 // Set updated timestamp
342 managedContact.setContactUpdated(new GregorianCalendar());
345 ContactUtils.copyAll(detachedContact, managedContact);
348 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactData: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N
350 // Return detached contact
351 return managedContact;
355 * Merges given (detached) contact's cellphone, land-line and fax numbers
357 * @param detachedContact Detached contact instance
359 protected void mergeContactsMobileLandLineFaxNumbers (final Contact detachedContact) {
361 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactsMobileLandLineFaxNumbers: detachedContact={1} - CALLED!", this.getClass().getSimpleName(), detachedContact)); //NOI18N
363 // The contact instance must be valid
364 if (null == detachedContact) {
366 throw new NullPointerException("detachedContact is null"); //NOI18N
367 } else if (detachedContact.getContactId() == null) {
369 throw new NullPointerException("detachedContact.contactId is null"); //NOI18N //NOI18N
370 } else if (detachedContact.getContactId() < 1) {
372 throw new IllegalStateException(MessageFormat.format("{0}.detachedContact.contactId={1} is not valid.", this.getClass().getSimpleName(), detachedContact.getContactId())); //NOI18N
376 DialableMobileNumber cellphone = detachedContact.getContactMobileNumber();
377 DialableLandLineNumber landLine = detachedContact.getContactLandLineNumber();
378 DialableFaxNumber fax = detachedContact.getContactFaxNumber();
380 // Is there a cellphone instance set?
381 if (cellphone instanceof DialableMobileNumber) {
383 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: cellphone.phoneId={0} is being updated ...", cellphone.getPhoneId())); //NOI18N
386 DialableMobileNumber foundMobile = this.getEntityManager().find(cellphone.getClass(), cellphone.getPhoneId());
389 assert (foundMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", foundMobile.getPhoneId()); //NOI18N
391 // Then merge it, too
392 DialableMobileNumber managedMobile = this.getEntityManager().merge(foundMobile);
395 assert (managedMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", managedMobile.getPhoneId()); //NOI18N
398 MobileNumbers.copyAll(detachedContact.getContactMobileNumber(), managedMobile);
401 detachedContact.setContactMobileNumber(managedMobile);
404 // Is there a fax instance set?
405 if (fax instanceof DialableFaxNumber) {
407 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: fax.phoneId={0} is being updated ...", fax.getPhoneId())); //NOI18N
410 DialableFaxNumber foundFax = this.getEntityManager().find(fax.getClass(), fax.getPhoneId());
413 assert (foundFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", foundFax.getPhoneId()); //NOI18N
415 // Then merge it, too
416 DialableFaxNumber managedFax = this.getEntityManager().merge(foundFax);
419 assert (managedFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", managedFax.getPhoneId()); //NOI18N
422 FaxNumbers.copyAll(detachedContact.getContactFaxNumber(), managedFax);
425 detachedContact.setContactFaxNumber(managedFax);
428 // Is there a fax instance set?
429 if (landLine instanceof DialableLandLineNumber) {
431 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: landLine.phoneId={0} is being updated ...", landLine.getPhoneId())); //NOI18N
434 DialableLandLineNumber foundLandLine = this.getEntityManager().find(landLine.getClass(), landLine.getPhoneId());
437 assert (foundLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", foundLandLine.getPhoneId()); //NOI18N
439 // Then merge it, too
440 DialableLandLineNumber managedLandLine = this.getEntityManager().merge(foundLandLine);
443 assert (managedLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", managedLandLine.getPhoneId()); //NOI18N
446 LandLineNumbers.copyAll(detachedContact.getContactLandLineNumber(), managedLandLine);
449 detachedContact.setContactLandLineNumber(managedLandLine);
453 this.getLoggerBeanLocal().logTrace("mergeContactsMobileLandLineFaxNumbers: EXIT!"); //NOI18N
457 * Sends an email with given subject line, template name to given recipient
460 * @param subjectLine Subject line
461 * @param templateName Template name
462 * @param emailAddress Recipient's email address
463 * @param user User instance
464 * @param baseUrl Base URL
465 * @param randomPassword A randomly-generated password or NULL if user had
468 protected void sendEmail (final String subjectLine, final String templateName, final Address emailAddress, final User user, final String baseUrl, final String randomPassword) {
470 this.getLoggerBeanLocal().logTrace(MessageFormat.format("sendEmail: subjectLine={0},templateName={1},emailAddress={2},user={3},baseUrl={4} - CALLED!", subjectLine, templateName, emailAddress, user, baseUrl)); //NOI18N
473 if (null == subjectLine) {
475 throw new NullPointerException("subjectLine is null"); //NOI18N
476 } else if (subjectLine.isEmpty()) {
478 throw new IllegalArgumentException("subjectLine is empty"); //NOI18N
479 } else if (null == templateName) {
481 throw new NullPointerException("templateName is null"); //NOI18N
482 } else if (templateName.isEmpty()) {
484 throw new IllegalArgumentException("templateName is empty"); //NOI18N
485 } else if (null == emailAddress) {
487 throw new NullPointerException("emailAddress is null"); //NOI18N
488 } else if (null == user) {
490 throw new NullPointerException("user is null"); //NOI18N
491 } else if (user.getUserId() == null) {
493 throw new NullPointerException("user.userId is null"); //NOI18N
494 } else if (user.getUserId() < 1) {
496 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid.", user.getUserId())); //NOI18N
497 } else if (user.getUserName() == null) {
499 throw new NullPointerException("user.userName is null"); //NOI18N
500 } else if (user.getUserName().isEmpty()) {
502 throw new IllegalArgumentException("user.userName is empty"); //NOI18N
503 } else if (user.getUserAccountStatus() == null) {
505 throw new NullPointerException("user.userAccountStatus is null"); //NOI18N
506 } else if (user.getUserContact() == null) {
508 throw new NullPointerException("user.userContact is null"); //NOI18N
509 } else if (user.getUserContact().getContactId() == null) {
511 throw new NullPointerException("user.userContact.contactId is null"); //NOI18N
512 } else if (user.getUserContact().getContactId() < 1) {
514 throw new IllegalArgumentException(MessageFormat.format("user.userContact.contactId={0} is invalid", user.getUserContact().getContactId())); //NOI18N
515 } else if (user.getUserContact().getContactPersonalTitle() == null) {
517 throw new NullPointerException("user.userContact.contactPersonalTitle is null"); //NOI18N
518 } else if (user.getUserLocale() == null) {
520 throw new NullPointerException("user.userLocale is null"); //NOI18N
523 // Prepare mail wrapper
524 WrapableEmailDelivery emailWrapper = new EmailDeliveryWrapper();
527 Properties variables = UserUtils.getAllUserFields(user);
529 // Set base URL and random password
530 variables.put("baseUrl", baseUrl); //NOI18N
531 variables.put("randomPassword", ""); //NOI18N
533 // Is the random password set?
534 if ((randomPassword instanceof String) && (!randomPassword.isEmpty())) {
535 variables.put("randomPassword", randomPassword); //NOI18N
539 // @TODO Language from message bundle
540 emailWrapper.setRecipient(emailAddress);
541 emailWrapper.setLocale(user.getUserLocale());
542 emailWrapper.setSubjectLine(subjectLine);
543 emailWrapper.setTemplateName(templateName);
544 emailWrapper.setTemplateVariables(variables);
547 // Send out email change
548 ObjectMessage message = this.getSession().createObjectMessage();
549 message.setObject(emailWrapper);
552 this.sendMessage(message);
553 } catch (final JMSException ex) {
555 throw new EJBException(ex);
559 this.getLoggerBeanLocal().logTrace("sendEmail: EXIT!"); //NOI18N
563 * Updates all contact's phone instances from other contact, both contacts
564 * should be the same.
566 * @param contact Contact to set instances
567 * @param other Other contact to get instances from
569 protected void setAllContactPhoneEntries (final Contact contact, final Contact other) {
571 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntries: contact={1},other={2} - CALLED!", this.getClass().getSimpleName(), contact, other)); //NOI18N
573 // Both must be the same and not null
574 if (null == contact) {
576 throw new NullPointerException("contact is null"); //NOI18N
577 } else if (null == other) {
579 throw new NullPointerException("other is null"); //NOI18N
580 } else if (!Objects.equals(contact, other)) {
581 // Not same instances
582 throw new IllegalArgumentException(MessageFormat.format("contact={0} and other={1} are not equal!", contact, other)); //NOI18N
586 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: other.contactMobileNumber={0}", other.getContactMobileNumber())); //NOI18N
588 // Is other cellphone not set?
589 if ((other.getContactMobileNumber() == null) || (PhoneUtils.isSameMobileNumber(contact.getContactMobileNumber(), other.getContactMobileNumber()))) {
591 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: Copying cellphone entry ...", this.getClass().getSimpleName())); //NOI18N
593 // Is the fax number set?
594 if (other.getContactMobileNumber() instanceof DialableMobileNumber) {
595 // Copy cellphone number
596 contact.setContactMobileNumber(this.getManaged(other.getContactMobileNumber(), contact.getContactMobileNumber()));
599 contact.setContactMobileNumber(null);
604 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: other.contactLandLineNumber={0}", other.getContactLandLineNumber())); //NOI18N
606 // Is other cellphone not set?
607 if ((other.getContactLandLineNumber() == null) || (PhoneUtils.isSameLandLineNumber(contact.getContactLandLineNumber(), other.getContactLandLineNumber()))) {
609 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: Copying land-line entry ...", this.getClass().getSimpleName())); //NOI18N
611 // Is the land-line number set?
612 if (other.getContactLandLineNumber() instanceof DialableLandLineNumber) {
613 // Copy land-line number
614 contact.setContactLandLineNumber(this.getManaged(other.getContactLandLineNumber(), contact.getContactLandLineNumber()));
617 contact.setContactLandLineNumber(null);
622 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: other.contactFaxNumber={1}", this.getClass().getSimpleName(), other.getContactFaxNumber())); //NOI18N
624 // Is other cellphone not set?
625 if ((other.getContactFaxNumber() == null) || (PhoneUtils.isSameFaxNumber(contact.getContactFaxNumber(), other.getContactFaxNumber()))) {
627 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: Copying fax entry ...", this.getClass().getSimpleName())); //NOI18N
629 // Is the fax number set?
630 if (other.getContactFaxNumber() instanceof DialableFaxNumber) {
632 contact.setContactFaxNumber(this.getManaged(other.getContactFaxNumber(), contact.getContactFaxNumber()));
635 contact.setContactFaxNumber(null);
640 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntries: EXIT!", this.getClass().getSimpleName())); //NOI18N
644 * Updates all contact's phone entry's updated timestamps
646 * @param contact Contact instance to update
647 * @param isMobileUnlinked Whether a mobile entry has been unlinked in
649 * @param isLandlineUnlinked Whether a land-line entry has been unlinked in
651 * @param isFaxUnlinked Whether a fax entry has been unlinked in
654 protected void setAllContactPhoneEntriesUpdated (final Contact contact, final boolean isMobileUnlinked, final boolean isLandlineUnlinked, final boolean isFaxUnlinked) {
656 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: contact={1},isMobileUnlinked={2},isLandlineUnlinked={3},isFaxUnlinked={4} - CALLED", this.getClass().getSimpleName(), contact, isMobileUnlinked, isLandlineUnlinked, isFaxUnlinked)); //NOI18N
658 // The contact instance must be valid
659 if (null == contact) {
661 throw new NullPointerException("contact is null"); //NOI18N
662 } else if (contact.getContactId() == null) {
664 throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
665 } else if (contact.getContactId() < 1) {
667 throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
670 // Get all phone instances
671 DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber();
672 DialableFaxNumber faxNumber = contact.getContactFaxNumber();
673 DialableMobileNumber mobileNumber = contact.getContactMobileNumber();
675 // Flags and instances must be constistent
676 if (isMobileUnlinked && mobileNumber instanceof DialableMobileNumber) {
678 throw new IllegalStateException("isCellPhoneUnlinked is TRUE, but mobileNumber is set."); //NOI18N
679 } else if (isLandlineUnlinked && landLineNumber instanceof DialableLandLineNumber) {
681 throw new IllegalStateException("isLandlineUnlinked is TRUE, but landLineNumber is set."); //NOI18N
682 } else if (isFaxUnlinked && faxNumber instanceof DialableFaxNumber) {
684 throw new IllegalStateException("isFaxUnlinked is TRUE, but faxNumber is set."); //NOI18N
687 // Is a phone number instance set?
688 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() instanceof Long) && (landLineNumber.getPhoneId() > 0)) {
690 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: Setting updated timestamp for land-line number ...", this.getClass().getSimpleName())); //NOI18N
692 // Set updated timestamp
693 landLineNumber.setPhoneEntryUpdated(new GregorianCalendar());
696 // Is a fax number instance set?
697 if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() instanceof Long) && (faxNumber.getPhoneId() > 0)) {
699 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: Setting updated timestamp for fax number ...", this.getClass().getSimpleName())); //NOI18N
701 // Set updated timestamp
702 faxNumber.setPhoneEntryUpdated(new GregorianCalendar());
705 // Is a mobile number instance set?
706 if ((mobileNumber instanceof DialableMobileNumber) && (mobileNumber.getPhoneId() instanceof Long) && (mobileNumber.getPhoneId() > 0)) {
708 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: Setting updated timestamp for cellphone number ...", this.getClass().getSimpleName())); //NOI18N
710 // Set updated timestamp
711 mobileNumber.setPhoneEntryUpdated(new GregorianCalendar());
715 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: EXIT!", this.getClass().getSimpleName())); //NOI18N