2 * Copyright (C) 2016 Roland Haeder
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.faces.FacesException;
25 import javax.jms.Connection;
26 import javax.jms.JMSException;
27 import javax.jms.MessageProducer;
28 import javax.jms.ObjectMessage;
29 import javax.jms.Queue;
30 import javax.jms.QueueConnectionFactory;
31 import javax.jms.Session;
32 import javax.mail.Address;
33 import javax.naming.Context;
34 import javax.naming.InitialContext;
35 import javax.naming.NamingException;
36 import org.mxchange.jcontacts.contact.Contact;
37 import org.mxchange.jcoreee.database.BaseDatabaseBean;
38 import org.mxchange.jmailee.model.delivery.wrapper.EmailDeliveryWrapper;
39 import org.mxchange.jmailee.model.delivery.wrapper.WrapableEmailDelivery;
40 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
41 import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
42 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
43 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
44 import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
45 import org.mxchange.jphone.phonenumbers.mobile.MobileNumber;
46 import org.mxchange.jphone.utils.PhoneUtils;
47 import org.mxchange.jusercore.model.user.User;
48 import org.mxchange.jusercore.model.user.UserUtils;
51 * A helper class for beans that access the database.
53 * @author Roland Haeder<roland@mxchange.org>
55 public abstract class BasePizzaDatabaseBean extends BaseDatabaseBean {
60 private static final long serialVersionUID = 12_895_410_275_811_963L;
65 private Connection connection;
70 private MessageProducer messageProducer;
73 * Mailer message queue
80 private Session session;
83 * Protected constructor
85 protected BasePizzaDatabaseBean () {
86 // Call super constructor
90 // Get initial context
91 Context context = new InitialContext();
93 // Get factory from JMS resource
94 QueueConnectionFactory connectionFactory = (QueueConnectionFactory) context.lookup("jms/jlandingpage-queue-factory"); //NOI18N
97 this.queue = (Queue) context.lookup("jms/jlandingpage-email-queue"); //NOI18N
100 this.connection = connectionFactory.createConnection();
102 // Init session instance
103 this.session = this.connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
105 // And message producer
106 this.messageProducer = this.session.createProducer(this.queue);
107 } catch (final NamingException | JMSException e) {
108 // Continued to throw
109 throw new FacesException(e);
114 * Detaches all contact's phone instances.
116 * @param contact Contact to set instances
118 protected void detachAllContactPhoneEntries (final Contact contact) {
120 this.getLoggerBeanLocal().logTrace(MessageFormat.format("detachAllContactPhoneEntries: contact={0} - CALLED!", contact)); //NOI18N
122 // Both must be the same and not null
123 if (null == contact) {
125 throw new NullPointerException("contact is null"); //NOI18N
129 this.getLoggerBeanLocal().logDebug(MessageFormat.format("detachAllContactPhoneEntries: contact.contactMobileNumber={0}", contact.getContactMobileNumber())); //NOI18N
131 // Is contact cellphone set?
132 if (contact.getContactMobileNumber() instanceof DialableMobileNumber) {
133 // Fetch it from entity manager
134 DialableMobileNumber fetchedNumber = this.getEntityManager().getReference(MobileNumber.class, contact.getContactMobileNumber().getPhoneId());
136 // Copy mobile number
137 contact.setContactMobileNumber(this.getDetached(contact.getContactMobileNumber(), fetchedNumber));
141 this.getLoggerBeanLocal().logDebug(MessageFormat.format("detachAllContactPhoneEntries: contact.contactLandLineNumber={0}", contact.getContactLandLineNumber())); //NOI18N
143 // Is the land-line number set?
144 if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
145 // Fetch it from entity manager
146 DialableLandLineNumber fetchedNumber = this.getEntityManager().getReference(LandLineNumber.class, contact.getContactLandLineNumber().getPhoneId());
148 // Copy land-line number
149 contact.setContactLandLineNumber(this.getDetached(contact.getContactLandLineNumber(), fetchedNumber));
153 this.getLoggerBeanLocal().logDebug(MessageFormat.format("detachAllContactPhoneEntries: contact.contactFaxNumber={0}", contact.getContactFaxNumber())); //NOI18N
155 // Is the fax number set?
156 if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
157 // Fetch it from entity manager
158 DialableFaxNumber fetchedNumber = this.getEntityManager().getReference(FaxNumber.class, contact.getContactFaxNumber().getPhoneId());
161 contact.setContactFaxNumber(this.getDetached(contact.getContactFaxNumber(), fetchedNumber));
165 this.getLoggerBeanLocal().logTrace("detachAllContactPhoneEntries: EXIT!"); //NOI18N
169 * Updates all contacts's phone entry's created timestamps
171 * @param contact Contact instance to update
173 protected void setAllContactPhoneEntriesCreated (final Contact contact) {
175 this.getLoggerBeanLocal().logTrace(MessageFormat.format("setAllContactPhoneEntriesCreated: contact={0} - CALLED!", contact)); //NOI18N
177 // The contact instance must be valid
178 if (null == contact) {
180 throw new NullPointerException("contact is null"); //NOI18N
183 // Get all phone instances
184 DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber();
185 DialableFaxNumber faxNumber = contact.getContactFaxNumber();
186 DialableMobileNumber mobileNumber = contact.getContactMobileNumber();
189 this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllContactPhoneEntriesCreated: landLineNumber={0},faxNumber={1},mobileNumber={2}", landLineNumber, faxNumber, mobileNumber)); //NOI18N
191 // Is a phone number instance set?
192 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() == null)) {
194 this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntriesCreated: Setting created timestamp for land-line number ..."); //NOI18N
196 // Set updated timestamp
197 landLineNumber.setPhoneEntryCreated(new GregorianCalendar());
200 // Is a fax number instance set?
201 if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() == null)) {
203 this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntriesCreated: Setting created timestamp for fax number ..."); //NOI18N
205 // Set updated timestamp
206 faxNumber.setPhoneEntryCreated(new GregorianCalendar());
209 // Is a mobile number instance set?
210 if ((mobileNumber instanceof DialableMobileNumber) && (mobileNumber.getPhoneId() == null)) {
212 this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntriesCreated: Setting created timestamp for cellphone number ..."); //NOI18N
214 // Set updated timestamp
215 mobileNumber.setPhoneEntryCreated(new GregorianCalendar());
219 this.getLoggerBeanLocal().logTrace("setAllContactPhoneEntriesCreated: EXIT!"); //NOI18N
223 * Returnes a detached instance from given cellphone instance
225 * @param mobileNumber Mobile instance
226 * @param fetchedNumber Found cellphone number in database
228 * @return Detached instance
230 protected DialableMobileNumber getDetached (final DialableMobileNumber mobileNumber, final DialableMobileNumber fetchedNumber) {
232 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: mobileNumber={0},fetchedNumber={1} - CALLED!", mobileNumber, fetchedNumber)); //NOI18N
235 if (null == mobileNumber) {
237 throw new NullPointerException("mobileNumber is null"); //NOI18N
238 } else if (null == fetchedNumber) {
240 throw new NullPointerException("fetchedNumber is null"); //NOI18N
241 } else if (fetchedNumber.getPhoneId() == null) {
243 throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
247 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N
249 // Init query instance
250 DialableMobileNumber foundNumber = this.getEntityManager().getReference(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
253 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N
255 // Default is fetched number
256 DialableMobileNumber detachedNumber = fetchedNumber;
258 // Is there a difference?
259 if (!PhoneUtils.isSameMobileNumber(mobileNumber, fetchedNumber)) {
261 detachedNumber = this.getEntityManager().merge(foundNumber);
265 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: detachedNumber={0} - EXIT!", detachedNumber)); //NOI18N
268 return detachedNumber;
272 * Returnes a detached instance from given land-line instance
274 * @param landLineNumber Land-line instance
275 * @param fetchedNumber Found land-line number in database
277 * @return Detached instance
279 protected DialableLandLineNumber getDetached (final DialableLandLineNumber landLineNumber, final DialableLandLineNumber fetchedNumber) {
281 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: landLineNumber={0},fetchedNumber={1} - CALLED!", landLineNumber, fetchedNumber)); //NOI18N
284 if (null == landLineNumber) {
286 throw new NullPointerException("landLineNumber is null"); //NOI18N
287 } else if (fetchedNumber.getPhoneId() == null) {
289 throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N
293 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N
295 // Init query instance
296 DialableLandLineNumber foundNumber = this.getEntityManager().getReference(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
299 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N
302 DialableLandLineNumber detachedNumber = null;
304 // Is there a difference?
305 if (!PhoneUtils.isSameLandLineNumber(landLineNumber, fetchedNumber)) {
307 detachedNumber = this.getEntityManager().merge(foundNumber);
311 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: detachedNumber={0} - EXIT!", detachedNumber)); //NOI18N
314 return detachedNumber;
318 * Returnes a detached instance from given fax instance
320 * @param faxNumber Fax instance
321 * @param fetchedNumber Found fax number in database
323 * @return Detached instance
325 protected DialableFaxNumber getDetached (final DialableFaxNumber faxNumber, final DialableFaxNumber fetchedNumber) {
327 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: faxNumber={0},fetchedNumber={1} - CALLED!", faxNumber, fetchedNumber)); //NOI18N
330 if (null == faxNumber) {
332 throw new NullPointerException("faxNumber is null"); //NOI18N
333 } else if (fetchedNumber.getPhoneId() == null) {
335 throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
339 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N
341 // Init query instance
342 DialableFaxNumber foundNumber = this.getEntityManager().getReference(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
345 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N
348 DialableFaxNumber detachedNumber = null;
350 // Is there a difference?
351 if (!PhoneUtils.isSameFaxNumber(faxNumber, fetchedNumber)) {
353 detachedNumber = this.getEntityManager().merge(foundNumber);
357 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: detachedNumber={0} - EXIT!", detachedNumber)); //NOI18N
360 return detachedNumber;
364 * Merges given contact's data
366 * @param contact Contact instance to merge
368 * @return Detached contact instance
370 protected Contact mergeContactData (final Contact contact) {
372 this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeContactData: contact={0} - CALLED!", contact)); //NOI18N
374 // The contact instance must be valid
375 if (null == contact) {
377 throw new NullPointerException("contact is null"); //NOI18N
378 } else if (contact.getContactId() == null) {
380 throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
381 } else if (contact.getContactId() < 1) {
383 throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
386 // Set updated timestamp
387 contact.setContactUpdated(new GregorianCalendar());
389 // Get contact from it and find it
390 Contact foundContact = this.getEntityManager().getReference(contact.getClass(), contact.getContactId());
393 assert (foundContact instanceof Contact) : MessageFormat.format("Contact with id {0} not found, but should be.", contact.getContactId()); //NOI18N
396 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: foundContact.contactId={0}", foundContact.getContactId())); //NOI18N
398 // Merge contact instance
399 Contact detachedContact = this.getEntityManager().merge(foundContact);
402 detachedContact.copyAll(contact);
405 this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeContactData: detachedContact={0} - EXIT!", detachedContact)); //NOI18N
407 // Return detached contact
408 return detachedContact;
412 * Merges given (detached) contact's cellphone, land-line and fax numbers
414 * @param detachedContact Detached contact instance
416 protected void mergeContactsMobileLandLineFaxNumbers (final Contact detachedContact) {
418 this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeContactsMobileLandLineFaxNumbers: detachedContact={0} - CALLED!", detachedContact)); //NOI18N
420 // The contact instance must be valid
421 if (null == detachedContact) {
423 throw new NullPointerException("detachedContact is null"); //NOI18N
424 } else if (detachedContact.getContactId() == null) {
426 throw new NullPointerException("detachedContact.contactId is null"); //NOI18N //NOI18N
427 } else if (detachedContact.getContactId() < 1) {
429 throw new IllegalStateException(MessageFormat.format("detachedContact.contactId={0} is not valid.", detachedContact.getContactId())); //NOI18N
433 DialableMobileNumber cellphone = detachedContact.getContactMobileNumber();
434 DialableLandLineNumber landLine = detachedContact.getContactLandLineNumber();
435 DialableFaxNumber fax = detachedContact.getContactFaxNumber();
437 // Is there a cellphone instance set?
438 if (cellphone instanceof DialableMobileNumber) {
440 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: cellphone.phoneId={0} is being updated ...", cellphone.getPhoneId())); //NOI18N
443 DialableMobileNumber foundMobile = this.getEntityManager().getReference(cellphone.getClass(), cellphone.getPhoneId());
446 assert (foundMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", foundMobile.getPhoneId()); //NOI18N
448 // Then merge it, too
449 DialableMobileNumber detachedMobile = this.getEntityManager().merge(foundMobile);
452 assert (detachedMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", detachedMobile.getPhoneId()); //NOI18N
455 detachedMobile.copyAll(detachedContact.getContactMobileNumber());
458 detachedContact.setContactMobileNumber(detachedMobile);
461 // Is there a fax instance set?
462 if (fax instanceof DialableFaxNumber) {
464 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: fax.phoneId={0} is being updated ...", fax.getPhoneId())); //NOI18N
467 DialableFaxNumber foundFax = this.getEntityManager().getReference(fax.getClass(), fax.getPhoneId());
470 assert (foundFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", foundFax.getPhoneId()); //NOI18N
472 // Then merge it, too
473 DialableFaxNumber detachedFax = this.getEntityManager().merge(foundFax);
476 assert (detachedFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", detachedFax.getPhoneId()); //NOI18N
479 detachedFax.copyAll(detachedContact.getContactFaxNumber());
482 detachedContact.setContactFaxNumber(detachedFax);
485 // Is there a fax instance set?
486 if (landLine instanceof DialableLandLineNumber) {
488 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: landLine.phoneId={0} is being updated ...", landLine.getPhoneId())); //NOI18N
491 DialableLandLineNumber foundLandLine = this.getEntityManager().getReference(landLine.getClass(), landLine.getPhoneId());
494 assert (foundLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", foundLandLine.getPhoneId()); //NOI18N
496 // Then merge it, too
497 DialableLandLineNumber detachedLandLine = this.getEntityManager().merge(foundLandLine);
500 assert (detachedLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", detachedLandLine.getPhoneId()); //NOI18N
503 detachedLandLine.copyAll(detachedContact.getContactLandLineNumber());
506 detachedContact.setContactLandLineNumber(detachedLandLine);
510 this.getLoggerBeanLocal().logTrace("mergeContactsMobileLandLineFaxNumbers: EXIT!"); //NOI18N
514 * Sends an email with given subject line, template name to given recipient
517 * @param subjectLine Subject line
518 * @param templateName Template name
519 * @param emailAddress Recipient's email address
520 * @param user User instance
521 * @param baseUrl Base URL
523 protected void sendEmail (final String subjectLine, final String templateName, final Address emailAddress, final User user, final String baseUrl) {
525 this.getLoggerBeanLocal().logTrace(MessageFormat.format("sendEmail: subjectLine={0},templateName={1},emailAddress={2},user={3},baseUrl={4} - CALLED!", subjectLine, templateName, emailAddress, user, baseUrl)); //NOI18N
528 if (null == subjectLine) {
530 throw new NullPointerException("subjectLine is null"); //NOI18N
531 } else if (subjectLine.isEmpty()) {
533 throw new IllegalArgumentException("subjectLine is empty"); //NOI18N
534 } else if (null == templateName) {
536 throw new NullPointerException("templateName is null"); //NOI18N
537 } else if (templateName.isEmpty()) {
539 throw new IllegalArgumentException("templateName is empty"); //NOI18N
540 } else if (null == emailAddress) {
542 throw new NullPointerException("emailAddress is null"); //NOI18N
545 // Prepare mail wrapper
546 WrapableEmailDelivery emailWrapper = new EmailDeliveryWrapper();
549 Properties variables = UserUtils.getAllUserFields(user);
552 variables.put("baseUrl", baseUrl); //NOI18N
555 // @TODO Language from message bundle
556 emailWrapper.setRecipient(emailAddress);
557 emailWrapper.setLocale(user.getUserLocale());
558 emailWrapper.setSubjectLine(subjectLine);
559 emailWrapper.setTemplateName(templateName);
560 emailWrapper.setTemplateVariables(variables);
563 // Send out email change
564 ObjectMessage message = this.session.createObjectMessage();
565 message.setObject(emailWrapper);
568 this.sendMessage(message, this.messageProducer);
569 } catch (final JMSException ex) {
571 throw new EJBException(ex);
575 this.getLoggerBeanLocal().logTrace("sendEmail: EXIT!"); //NOI18N
579 * Updates all contact's phone instances from other contact, both contacts
580 * should be the same.
582 * @param contact Contact to set instances
583 * @param other Other contact to get instances from
585 protected void setAllContactPhoneEntries (final Contact contact, final Contact other) {
587 this.getLoggerBeanLocal().logTrace(MessageFormat.format("setAllContactPhoneEntries: contact={0},other={1} - CALLED!", contact, other)); //NOI18N
589 // Both must be the same and not null
590 if (null == contact) {
592 throw new NullPointerException("contact is null"); //NOI18N
593 } else if (null == other) {
595 throw new NullPointerException("other is null"); //NOI18N
596 } else if (!Objects.equals(contact, other)) {
597 // Not same instances
598 throw new IllegalArgumentException(MessageFormat.format("contact={0} and other={1} are not equal!", contact, other)); //NOI18N
602 this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllContactPhoneEntries: other.contactMobileNumber={0}", other.getContactMobileNumber())); //NOI18N
604 // Is other cellphone not set?
605 if ((other.getContactMobileNumber() == null) || (PhoneUtils.isSameMobileNumber(contact.getContactMobileNumber(), other.getContactMobileNumber()))) {
607 this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntries: Copying cellphone entry ..."); //NOI18N
609 // Is the fax number set?
610 if (other.getContactMobileNumber() instanceof DialableMobileNumber) {
611 // Copy cellphone number
612 contact.setContactMobileNumber(this.getDetached(other.getContactMobileNumber(), contact.getContactMobileNumber()));
615 contact.setContactMobileNumber(null);
620 this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllContactPhoneEntries: other.contactLandLineNumber={0}", other.getContactLandLineNumber())); //NOI18N
622 // Is other cellphone not set?
623 if ((other.getContactLandLineNumber() == null) || (PhoneUtils.isSameLandLineNumber(contact.getContactLandLineNumber(), other.getContactLandLineNumber()))) {
625 this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntries: Copying land-line entry ..."); //NOI18N
627 // Is the land-line number set?
628 if (other.getContactLandLineNumber() instanceof DialableLandLineNumber) {
629 // Copy land-line number
630 contact.setContactLandLineNumber(this.getDetached(other.getContactLandLineNumber(), contact.getContactLandLineNumber()));
633 contact.setContactLandLineNumber(null);
638 this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllContactPhoneEntries: other.contactFaxNumber={0}", other.getContactFaxNumber())); //NOI18N
640 // Is other cellphone not set?
641 if ((other.getContactFaxNumber() == null) || (PhoneUtils.isSameFaxNumber(contact.getContactFaxNumber(), other.getContactFaxNumber()))) {
643 this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntries: Copying fax entry ..."); //NOI18N
645 // Is the fax number set?
646 if (other.getContactFaxNumber() instanceof DialableFaxNumber) {
648 contact.setContactFaxNumber(this.getDetached(other.getContactFaxNumber(), contact.getContactFaxNumber()));
651 contact.setContactFaxNumber(null);
656 this.getLoggerBeanLocal().logTrace("setAllContactPhoneEntries: EXIT!"); //NOI18N
660 * Updates all contacts's phone entry's updated timestamps
662 * @param contact Contact instance to update
663 * @param isMobileUnlinked Whether a cellphone entry has been unlinked in
665 * @param isLandlineUnlinked Whether a land-line entry has been unlinked in
667 * @param isFaxUnlinked Whether a fax entry has been unlinked in contact
670 protected void setAllContactPhoneEntriesUpdated (final Contact contact, final boolean isMobileUnlinked, final boolean isLandlineUnlinked, final boolean isFaxUnlinked) {
672 this.getLoggerBeanLocal().logTrace(MessageFormat.format("setAllContactPhoneEntriesUpdated: contact={0},isMobileUnlinked={1},isLandlineUnlinked={2},isFaxUnlinked={3} - CALLED", contact, isMobileUnlinked, isLandlineUnlinked, isFaxUnlinked)); //NOI18N
674 // The contact instance must be valid
675 if (null == contact) {
677 throw new NullPointerException("contact is null"); //NOI18N
678 } else if (contact.getContactId() == null) {
680 throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
681 } else if (contact.getContactId() < 1) {
683 throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
686 // Get all phone instances
687 DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber();
688 DialableFaxNumber faxNumber = contact.getContactFaxNumber();
689 DialableMobileNumber mobileNumber = contact.getContactMobileNumber();
691 // Flags and instances must be constistent
692 if (isMobileUnlinked && mobileNumber instanceof DialableMobileNumber) {
694 throw new IllegalStateException("isCellPhoneUnlinked is TRUE, but mobileNumber is set."); //NOI18N
695 } else if (isLandlineUnlinked && landLineNumber instanceof DialableLandLineNumber) {
697 throw new IllegalStateException("isLandlineUnlinked is TRUE, but landLineNumber is set."); //NOI18N
698 } else if (isFaxUnlinked && faxNumber instanceof DialableFaxNumber) {
700 throw new IllegalStateException("isFaxUnlinked is TRUE, but faxNumber is set."); //NOI18N
703 // Is a phone number instance set?
704 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() instanceof Long) && (landLineNumber.getPhoneId() > 0)) {
706 this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntriesUpdated: Setting updated timestamp for land-line number ..."); //NOI18N
708 // Set updated timestamp
709 landLineNumber.setPhoneEntryUpdated(new GregorianCalendar());
712 // Is a fax number instance set?
713 if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() instanceof Long) && (faxNumber.getPhoneId() > 0)) {
715 this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntriesUpdated: Setting updated timestamp for fax number ..."); //NOI18N
717 // Set updated timestamp
718 faxNumber.setPhoneEntryUpdated(new GregorianCalendar());
721 // Is a mobile number instance set?
722 if ((mobileNumber instanceof DialableMobileNumber) && (mobileNumber.getPhoneId() instanceof Long) && (mobileNumber.getPhoneId() > 0)) {
724 this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntriesUpdated: Setting updated timestamp for cellphone number ..."); //NOI18N
726 // Set updated timestamp
727 mobileNumber.setPhoneEntryUpdated(new GregorianCalendar());
731 this.getLoggerBeanLocal().logTrace("setAllContactPhoneEntriesUpdated: EXIT!"); //NOI18N