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.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.landline.DialableLandLineNumber;
33 import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
34 import org.mxchange.jphone.utils.PhoneUtils;
35 import org.mxchange.jusercore.model.user.LoginUser;
36 import org.mxchange.jusercore.model.user.User;
37 import org.mxchange.jusercore.model.user.UserUtils;
40 * A helper class for beans that access the database.
42 * @author Roland Häder<roland@mxchange.org>
44 public abstract class BasePizzaDatabaseBean extends BaseDatabaseBean {
49 private static final long serialVersionUID = 12_895_410_275_811_963L;
52 * Protected constructor
54 protected BasePizzaDatabaseBean () {
55 // Call super constructor
56 super("jms/pizzaservice-queue-factory", "jms/pizzaservice-email-queue"); //NOI18N
60 * Updates all contact's phone entry's created timestamps
62 * @param contact Contact instance to update
64 protected void setAllContactPhoneEntriesCreated (final Contact contact) {
66 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N
68 // The contact instance must be valid
69 if (null == contact) {
71 throw new NullPointerException("contact is null"); //NOI18N
74 // Get all phone instances
75 DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber();
76 DialableFaxNumber faxNumber = contact.getContactFaxNumber();
77 DialableMobileNumber mobileNumber = contact.getContactMobileNumber();
80 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: landLineNumber={1},faxNumber={2},mobileNumber={3}", this.getClass().getSimpleName(), landLineNumber, faxNumber, mobileNumber)); //NOI18N
82 // Is a phone number instance set?
83 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() == null)) {
85 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for land-line number ...", this.getClass().getSimpleName())); //NOI18N
87 // Set updated timestamp
88 landLineNumber.setPhoneEntryCreated(new GregorianCalendar());
91 // Is a fax number instance set?
92 if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() == null)) {
94 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for fax number ...", this.getClass().getSimpleName())); //NOI18N
96 // Set updated timestamp
97 faxNumber.setPhoneEntryCreated(new GregorianCalendar());
100 // Is a mobile number instance set?
101 if ((mobileNumber instanceof DialableMobileNumber) && (mobileNumber.getPhoneId() == null)) {
103 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for cellphone number ...", this.getClass().getSimpleName())); //NOI18N
105 // Set updated timestamp
106 mobileNumber.setPhoneEntryCreated(new GregorianCalendar());
110 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: EXIT!", this.getClass().getSimpleName())); //NOI18N
114 * Returns a managed instance from given mobile number
116 * @param mobileNumber Mobile number
117 * @param fetchedNumber Found mobile number in database
119 * @return Managed instance
121 protected DialableMobileNumber getManaged (final DialableMobileNumber mobileNumber, final DialableMobileNumber fetchedNumber) {
123 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: mobileNumber={1},fetchedNumber={2} - CALLED!", this.getClass().getSimpleName(), mobileNumber, fetchedNumber)); //NOI18N
126 if (null == mobileNumber) {
128 throw new NullPointerException("mobileNumber is null"); //NOI18N
129 } else if (null == fetchedNumber) {
131 throw new NullPointerException("fetchedNumber is null"); //NOI18N
132 } else if (fetchedNumber.getPhoneId() == null) {
134 throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
138 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.getDetached: fetchedNumber.phoneId={1}", this.getClass().getSimpleName(), fetchedNumber.getPhoneId())); //NOI18N
141 DialableMobileNumber managedNumber = null;
143 // Is there a difference?
144 if (!PhoneUtils.isSameMobileNumber(mobileNumber, fetchedNumber)) {
146 managedNumber = this.getEntityManager().merge(fetchedNumber);
150 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N
153 return managedNumber;
157 * Returns a managed instance from given land-line number
159 * @param landLineNumber Land-line number
160 * @param fetchedNumber Found land-line number in database
162 * @return Managed instance
164 protected DialableLandLineNumber getManaged (final DialableLandLineNumber landLineNumber, final DialableLandLineNumber fetchedNumber) {
166 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: landLineNumber={1},fetchedNumber={2} - CALLED!", this.getClass().getSimpleName(), landLineNumber, fetchedNumber)); //NOI18N
169 if (null == landLineNumber) {
171 throw new NullPointerException("landLineNumber is null"); //NOI18N
172 } else if (null == fetchedNumber) {
174 throw new NullPointerException("fetchedNumber is null"); //NOI18N
175 } else if (fetchedNumber.getPhoneId() == null) {
177 throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N
181 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.getDetached: fetchedNumber.phoneId={1}", this.getClass().getSimpleName(), fetchedNumber.getPhoneId())); //NOI18N
184 DialableLandLineNumber managedNumber = null;
186 // Is there a difference?
187 if (!PhoneUtils.isSameLandLineNumber(landLineNumber, fetchedNumber)) {
189 managedNumber = this.getEntityManager().merge(fetchedNumber);
193 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N
196 return managedNumber;
200 * Returns a managed instance from given fax number
202 * @param faxNumber Fax number
203 * @param fetchedNumber Found fax number in database
205 * @return Managed instance
207 protected DialableFaxNumber getManaged (final DialableFaxNumber faxNumber, final DialableFaxNumber fetchedNumber) {
209 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: faxNumber={1},fetchedNumber={2} - CALLED!", this.getClass().getSimpleName(), faxNumber, fetchedNumber)); //NOI18N
212 if (null == faxNumber) {
214 throw new NullPointerException("faxNumber is null"); //NOI18N
215 } else if (null == fetchedNumber) {
217 throw new NullPointerException("fetchedNumber is null"); //NOI18N
218 } else if (fetchedNumber.getPhoneId() == null) {
220 throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
224 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.getDetached: fetchedNumber.phoneId={1}", this.getClass().getSimpleName(), fetchedNumber.getPhoneId())); //NOI18N
227 DialableFaxNumber managedNumber = null;
229 // Is there a difference?
230 if (!PhoneUtils.isSameFaxNumber(faxNumber, fetchedNumber)) {
232 managedNumber = this.getEntityManager().merge(fetchedNumber);
236 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N
239 return managedNumber;
243 * Get back a managed instance from given user
245 * @param user Unmanaged/detached user instance
247 * @return Managed user instance
249 protected User getManagedUser (final User user) {
251 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getManaged: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
253 // user should not be null
256 throw new NullPointerException("user is null"); //NOI18N
257 } else if (user.getUserId() == null) {
259 throw new NullPointerException("user.userId is null"); //NOI18N
260 } else if (user.getUserId() < 1) {
262 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is null", user.getUserId())); //NOI18N
263 } else if (user.getUserContact() == null) {
265 throw new NullPointerException("user.userContact is null"); //NOI18N
266 } else if (user.getUserContact().getContactId() == null) {
268 throw new NullPointerException("user.userContact.contactId is null"); //NOI18N
269 } else if (user.getUserContact().getContactId() < 1) {
270 // Not valid id number
271 throw new IllegalArgumentException(MessageFormat.format("user.userContact.contactId={0} is not valid", user.getUserContact().getContactId())); //NOI18N#
274 // Try to find it (should be there)
275 User managedUser = this.getEntityManager().find(LoginUser.class, user.getUserId());
278 assert (managedUser instanceof User) : "managedUser is null"; //NOI18N
281 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getManaged: managedUser={1} - EXIT!", this.getClass().getSimpleName(), managedUser)); //NOI18N
288 * Merges given (detached) contact's data
290 * @param detachedContact Contact instance to merge
292 * @return Detached contact instance
294 protected Contact mergeContactData (final Contact detachedContact) {
296 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactData: contact={1} - CALLED!", this.getClass().getSimpleName(), detachedContact)); //NOI18N
298 // The contact instance must be valid
299 if (null == detachedContact) {
301 throw new NullPointerException("detachedContact is null"); //NOI18N
302 } else if (detachedContact.getContactId() == null) {
304 throw new NullPointerException("detachedContact.contactId is null"); //NOI18N //NOI18N
305 } else if (detachedContact.getContactId() < 1) {
307 throw new IllegalStateException(MessageFormat.format("{0}.detachedContact.contactId={1} is not valid.", this.getClass().getSimpleName(), detachedContact.getContactId())); //NOI18N
310 // Get contact from it and find it
311 Contact managedContact = this.getEntityManager().find(detachedContact.getClass(), detachedContact.getContactId());
314 assert (managedContact instanceof Contact) : MessageFormat.format("Contact with id {0} not found, but should be.", detachedContact.getContactId()); //NOI18N
317 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.updateUserPersonalData: managedContact.contactId={1}", this.getClass().getSimpleName(), managedContact.getContactId())); //NOI18N
319 // Is a fax number set?
320 if (detachedContact.getContactFaxNumber() instanceof DialableFaxNumber) {
321 // Make fax numbers managed
322 managedContact.setContactFaxNumber(this.getManaged(detachedContact.getContactFaxNumber(), detachedContact.getContactFaxNumber()));
325 // Is a land-line number set?
326 if (detachedContact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
327 // Make land-line numbers managed
328 managedContact.setContactLandLineNumber(this.getManaged(detachedContact.getContactLandLineNumber(), detachedContact.getContactLandLineNumber()));
331 // Is a mobile number set?
332 if (detachedContact.getContactMobileNumber() instanceof DialableMobileNumber) {
333 // Make mobile numbers managed
334 managedContact.setContactMobileNumber(this.getManaged(detachedContact.getContactMobileNumber(), detachedContact.getContactMobileNumber()));
337 // Set updated timestamp
338 managedContact.setContactUpdated(new GregorianCalendar());
341 managedContact.copyAll(detachedContact);
344 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactData: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N
346 // Return detached contact
347 return managedContact;
351 * Merges given (detached) contact's cellphone, land-line and fax numbers
353 * @param detachedContact Detached contact instance
355 protected void mergeContactsMobileLandLineFaxNumbers (final Contact detachedContact) {
357 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactsMobileLandLineFaxNumbers: detachedContact={1} - CALLED!", this.getClass().getSimpleName(), detachedContact)); //NOI18N
359 // The contact instance must be valid
360 if (null == detachedContact) {
362 throw new NullPointerException("detachedContact is null"); //NOI18N
363 } else if (detachedContact.getContactId() == null) {
365 throw new NullPointerException("detachedContact.contactId is null"); //NOI18N //NOI18N
366 } else if (detachedContact.getContactId() < 1) {
368 throw new IllegalStateException(MessageFormat.format("{0}.detachedContact.contactId={1} is not valid.", this.getClass().getSimpleName(), detachedContact.getContactId())); //NOI18N
372 DialableMobileNumber cellphone = detachedContact.getContactMobileNumber();
373 DialableLandLineNumber landLine = detachedContact.getContactLandLineNumber();
374 DialableFaxNumber fax = detachedContact.getContactFaxNumber();
376 // Is there a cellphone instance set?
377 if (cellphone instanceof DialableMobileNumber) {
379 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: cellphone.phoneId={0} is being updated ...", cellphone.getPhoneId())); //NOI18N
382 DialableMobileNumber foundMobile = this.getEntityManager().find(cellphone.getClass(), cellphone.getPhoneId());
385 assert (foundMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", foundMobile.getPhoneId()); //NOI18N
388 foundMobile.copyAll(detachedContact.getContactMobileNumber());
391 detachedContact.setContactMobileNumber(foundMobile);
394 // Is there a fax instance set?
395 if (fax instanceof DialableFaxNumber) {
397 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: fax.phoneId={0} is being updated ...", fax.getPhoneId())); //NOI18N
400 DialableFaxNumber foundFax = this.getEntityManager().find(fax.getClass(), fax.getPhoneId());
403 foundFax.copyAll(detachedContact.getContactFaxNumber());
406 detachedContact.setContactFaxNumber(foundFax);
409 // Is there a fax instance set?
410 if (landLine instanceof DialableLandLineNumber) {
412 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: landLine.phoneId={0} is being updated ...", landLine.getPhoneId())); //NOI18N
415 DialableLandLineNumber foundLandLine = this.getEntityManager().find(landLine.getClass(), landLine.getPhoneId());
418 assert (foundLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", foundLandLine.getPhoneId()); //NOI18N
421 foundLandLine.copyAll(detachedContact.getContactLandLineNumber());
424 detachedContact.setContactLandLineNumber(foundLandLine);
428 this.getLoggerBeanLocal().logTrace("mergeContactsMobileLandLineFaxNumbers: EXIT!"); //NOI18N
432 * Sends an email with given subject line, template name to given recipient
435 * @param subjectLine Subject line
436 * @param templateName Template name
437 * @param emailAddress Recipient's email address
438 * @param user User instance
439 * @param baseUrl Base URL
441 protected void sendEmail (final String subjectLine, final String templateName, final Address emailAddress, final User user, final String baseUrl) {
443 this.getLoggerBeanLocal().logTrace(MessageFormat.format("sendEmail: subjectLine={0},templateName={1},emailAddress={2},user={3},baseUrl={4} - CALLED!", subjectLine, templateName, emailAddress, user, baseUrl)); //NOI18N
446 if (null == subjectLine) {
448 throw new NullPointerException("subjectLine is null"); //NOI18N
449 } else if (subjectLine.isEmpty()) {
451 throw new IllegalArgumentException("subjectLine is empty"); //NOI18N
452 } else if (null == templateName) {
454 throw new NullPointerException("templateName is null"); //NOI18N
455 } else if (templateName.isEmpty()) {
457 throw new IllegalArgumentException("templateName is empty"); //NOI18N
458 } else if (null == emailAddress) {
460 throw new NullPointerException("emailAddress is null"); //NOI18N
461 }else if (null == user) {
463 throw new NullPointerException("user is null"); //NOI18N
464 } else if (user.getUserId() == null) {
466 throw new NullPointerException("user.userId is null"); //NOI18N
467 } else if (user.getUserId() < 1) {
469 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid.", user.getUserId())); //NOI18N
470 } else if (user.getUserName() == null) {
472 throw new NullPointerException("user.userName is null"); //NOI18N
473 } else if (user.getUserName().isEmpty()) {
475 throw new IllegalArgumentException("user.userName is empty"); //NOI18N
476 } else if (user.getUserAccountStatus() == null) {
478 throw new NullPointerException("user.userAccountStatus is null"); //NOI18N
479 } else if (user.getUserContact() == null) {
481 throw new NullPointerException("user.userContact is null"); //NOI18N
482 } else if (user.getUserContact().getContactId() == null) {
484 throw new NullPointerException("user.userContact.contactId is null"); //NOI18N
485 } else if (user.getUserContact().getContactId() < 1) {
487 throw new IllegalArgumentException(MessageFormat.format("user.userContact.contactId={0} is invalid", user.getUserContact().getContactId())); //NOI18N
488 } else if (user.getUserContact().getContactGender() == null) {
490 throw new NullPointerException("user.userContact.contactGender is null"); //NOI18N
493 // Prepare mail wrapper
494 WrapableEmailDelivery emailWrapper = new EmailDeliveryWrapper();
497 Properties variables = UserUtils.getAllUserFields(user);
500 variables.put("baseUrl", baseUrl); //NOI18N
503 // @TODO Language from message bundle
504 emailWrapper.setRecipient(emailAddress);
505 emailWrapper.setLocale(user.getUserLocale());
506 emailWrapper.setSubjectLine(subjectLine);
507 emailWrapper.setTemplateName(templateName);
508 emailWrapper.setTemplateVariables(variables);
511 // Send out email change
512 ObjectMessage message = this.getSession().createObjectMessage();
513 message.setObject(emailWrapper);
516 this.sendMessage(message);
517 } catch (final JMSException ex) {
519 throw new EJBException(ex);
523 this.getLoggerBeanLocal().logTrace("sendEmail: EXIT!"); //NOI18N
527 * Updates all contact's phone instances from other contact, both contacts
528 * should be the same.
530 * @param contact Contact to set instances
531 * @param other Other contact to get instances from
533 protected void setAllContactPhoneEntries (final Contact contact, final Contact other) {
535 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntries: contact={1},other={2} - CALLED!", this.getClass().getSimpleName(), contact, other)); //NOI18N
537 // Both must be the same and not null
538 if (null == contact) {
540 throw new NullPointerException("contact is null"); //NOI18N
541 } else if (null == other) {
543 throw new NullPointerException("other is null"); //NOI18N
544 } else if (!Objects.equals(contact, other)) {
545 // Not same instances
546 throw new IllegalArgumentException(MessageFormat.format("contact={0} and other={1} are not equal!", contact, other)); //NOI18N
550 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: other.contactMobileNumber={0}", other.getContactMobileNumber())); //NOI18N
552 // Is other cellphone not set?
553 if ((other.getContactMobileNumber() == null) || (PhoneUtils.isSameMobileNumber(contact.getContactMobileNumber(), other.getContactMobileNumber()))) {
555 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: Copying cellphone entry ...", this.getClass().getSimpleName())); //NOI18N
557 // Is the fax number set?
558 if (other.getContactMobileNumber() instanceof DialableMobileNumber) {
559 // Copy cellphone number
560 contact.setContactMobileNumber(this.getManaged(other.getContactMobileNumber(), contact.getContactMobileNumber()));
563 contact.setContactMobileNumber(null);
568 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: other.contactLandLineNumber={0}", other.getContactLandLineNumber())); //NOI18N
570 // Is other cellphone not set?
571 if ((other.getContactLandLineNumber() == null) || (PhoneUtils.isSameLandLineNumber(contact.getContactLandLineNumber(), other.getContactLandLineNumber()))) {
573 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: Copying land-line entry ...", this.getClass().getSimpleName())); //NOI18N
575 // Is the land-line number set?
576 if (other.getContactLandLineNumber() instanceof DialableLandLineNumber) {
577 // Copy land-line number
578 contact.setContactLandLineNumber(this.getManaged(other.getContactLandLineNumber(), contact.getContactLandLineNumber()));
581 contact.setContactLandLineNumber(null);
586 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: other.contactFaxNumber={1}", this.getClass().getSimpleName(), other.getContactFaxNumber())); //NOI18N
588 // Is other cellphone not set?
589 if ((other.getContactFaxNumber() == null) || (PhoneUtils.isSameFaxNumber(contact.getContactFaxNumber(), other.getContactFaxNumber()))) {
591 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: Copying fax entry ...", this.getClass().getSimpleName())); //NOI18N
593 // Is the fax number set?
594 if (other.getContactFaxNumber() instanceof DialableFaxNumber) {
596 contact.setContactFaxNumber(this.getManaged(other.getContactFaxNumber(), contact.getContactFaxNumber()));
599 contact.setContactFaxNumber(null);
604 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntries: EXIT!", this.getClass().getSimpleName())); //NOI18N
608 * Updates all contact's phone entry's updated timestamps
610 * @param contact Contact instance to update
611 * @param isMobileUnlinked Whether a cellphone entry has been unlinked in
613 * @param isLandlineUnlinked Whether a land-line entry has been unlinked in
615 * @param isFaxUnlinked Whether a fax entry has been unlinked in contact
618 protected void setAllContactPhoneEntriesUpdated (final Contact contact, final boolean isMobileUnlinked, final boolean isLandlineUnlinked, final boolean isFaxUnlinked) {
620 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: contact={1},isMobileUnlinked={2},isLandlineUnlinked={3},isFaxUnlinked={4} - CALLED", this.getClass().getSimpleName(), contact, isMobileUnlinked, isLandlineUnlinked, isFaxUnlinked)); //NOI18N
622 // The contact instance must be valid
623 if (null == contact) {
625 throw new NullPointerException("contact is null"); //NOI18N
626 } else if (contact.getContactId() == null) {
628 throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
629 } else if (contact.getContactId() < 1) {
631 throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
634 // Get all phone instances
635 DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber();
636 DialableFaxNumber faxNumber = contact.getContactFaxNumber();
637 DialableMobileNumber mobileNumber = contact.getContactMobileNumber();
639 // Flags and instances must be constistent
640 if (isMobileUnlinked && mobileNumber instanceof DialableMobileNumber) {
642 throw new IllegalStateException("isCellPhoneUnlinked is TRUE, but mobileNumber is set."); //NOI18N
643 } else if (isLandlineUnlinked && landLineNumber instanceof DialableLandLineNumber) {
645 throw new IllegalStateException("isLandlineUnlinked is TRUE, but landLineNumber is set."); //NOI18N
646 } else if (isFaxUnlinked && faxNumber instanceof DialableFaxNumber) {
648 throw new IllegalStateException("isFaxUnlinked is TRUE, but faxNumber is set."); //NOI18N
651 // Is a phone number instance set?
652 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() instanceof Long) && (landLineNumber.getPhoneId() > 0)) {
654 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: Setting updated timestamp for land-line number ...", this.getClass().getSimpleName())); //NOI18N
656 // Set updated timestamp
657 landLineNumber.setPhoneEntryUpdated(new GregorianCalendar());
660 // Is a fax number instance set?
661 if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() instanceof Long) && (faxNumber.getPhoneId() > 0)) {
663 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: Setting updated timestamp for fax number ...", this.getClass().getSimpleName())); //NOI18N
665 // Set updated timestamp
666 faxNumber.setPhoneEntryUpdated(new GregorianCalendar());
669 // Is a mobile number instance set?
670 if ((mobileNumber instanceof DialableMobileNumber) && (mobileNumber.getPhoneId() instanceof Long) && (mobileNumber.getPhoneId() > 0)) {
672 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: Setting updated timestamp for cellphone number ...", this.getClass().getSimpleName())); //NOI18N
674 // Set updated timestamp
675 mobileNumber.setPhoneEntryUpdated(new GregorianCalendar());
679 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: EXIT!", this.getClass().getSimpleName())); //NOI18N