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.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.landline.DialableLandLineNumber;
42 import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
43 import org.mxchange.jphone.utils.PhoneUtils;
44 import org.mxchange.jusercore.model.user.LoginUser;
45 import org.mxchange.jusercore.model.user.User;
46 import org.mxchange.jusercore.model.user.UserUtils;
49 * A helper class for beans that access the database.
51 * @author Roland Häder<roland@mxchange.org>
53 public abstract class BasePizzaDatabaseBean extends BaseDatabaseBean {
58 private static final long serialVersionUID = 12_895_410_275_811_963L;
63 private Connection connection;
68 private MessageProducer messageProducer;
71 * Mailer message queue
78 private Session session;
81 * Protected constructor
83 protected BasePizzaDatabaseBean () {
84 // Call super constructor
88 // Get initial context
89 Context context = new InitialContext();
91 // Get factory from JMS resource
92 QueueConnectionFactory connectionFactory = (QueueConnectionFactory) context.lookup("jms/pizzaservice-queue-factory"); //NOI18N
95 this.queue = (Queue) context.lookup("jms/pizzaservice-email-queue"); //NOI18N
98 this.connection = connectionFactory.createConnection();
100 // Init session instance
101 this.session = this.connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
103 // And message producer
104 this.messageProducer = this.session.createProducer(this.queue);
105 } catch (final NamingException | JMSException e) {
106 // Continued to throw
107 throw new FacesException(e);
112 * Updates all contact's phone entry's created timestamps
114 * @param contact Contact instance to update
116 protected void setAllContactPhoneEntriesCreated (final Contact contact) {
118 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N
120 // The contact instance must be valid
121 if (null == contact) {
123 throw new NullPointerException("contact is null"); //NOI18N
126 // Get all phone instances
127 DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber();
128 DialableFaxNumber faxNumber = contact.getContactFaxNumber();
129 DialableMobileNumber mobileNumber = contact.getContactMobileNumber();
132 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: landLineNumber={1},faxNumber={2},mobileNumber={3}", this.getClass().getSimpleName(), landLineNumber, faxNumber, mobileNumber)); //NOI18N
134 // Is a phone number instance set?
135 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() == null)) {
137 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for land-line number ...", this.getClass().getSimpleName())); //NOI18N
139 // Set updated timestamp
140 landLineNumber.setPhoneEntryCreated(new GregorianCalendar());
143 // Is a fax number instance set?
144 if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() == null)) {
146 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for fax number ...", this.getClass().getSimpleName())); //NOI18N
148 // Set updated timestamp
149 faxNumber.setPhoneEntryCreated(new GregorianCalendar());
152 // Is a mobile number instance set?
153 if ((mobileNumber instanceof DialableMobileNumber) && (mobileNumber.getPhoneId() == null)) {
155 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for cellphone number ...", this.getClass().getSimpleName())); //NOI18N
157 // Set updated timestamp
158 mobileNumber.setPhoneEntryCreated(new GregorianCalendar());
162 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: EXIT!", this.getClass().getSimpleName())); //NOI18N
166 * Returns a managed instance from given mobile number
168 * @param mobileNumber Mobile number
169 * @param fetchedNumber Found mobile number in database
171 * @return Managed instance
173 protected DialableMobileNumber getManaged (final DialableMobileNumber mobileNumber, final DialableMobileNumber fetchedNumber) {
175 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: mobileNumber={1},fetchedNumber={2} - CALLED!", this.getClass().getSimpleName(), mobileNumber, fetchedNumber)); //NOI18N
178 if (null == mobileNumber) {
180 throw new NullPointerException("mobileNumber is null"); //NOI18N
181 } else if (null == fetchedNumber) {
183 throw new NullPointerException("fetchedNumber is null"); //NOI18N
184 } else if (fetchedNumber.getPhoneId() == null) {
186 throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
190 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.getDetached: fetchedNumber.phoneId={1}", this.getClass().getSimpleName(), fetchedNumber.getPhoneId())); //NOI18N
193 DialableMobileNumber managedNumber = null;
195 // Is there a difference?
196 if (!PhoneUtils.isSameMobileNumber(mobileNumber, fetchedNumber)) {
198 managedNumber = this.getEntityManager().merge(fetchedNumber);
202 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N
205 return managedNumber;
209 * Returns a managed instance from given land-line number
211 * @param landLineNumber Land-line number
212 * @param fetchedNumber Found land-line number in database
214 * @return Managed instance
216 protected DialableLandLineNumber getManaged (final DialableLandLineNumber landLineNumber, final DialableLandLineNumber fetchedNumber) {
218 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: landLineNumber={1},fetchedNumber={2} - CALLED!", this.getClass().getSimpleName(), landLineNumber, fetchedNumber)); //NOI18N
221 if (null == landLineNumber) {
223 throw new NullPointerException("landLineNumber is null"); //NOI18N
224 } else if (null == fetchedNumber) {
226 throw new NullPointerException("fetchedNumber is null"); //NOI18N
227 } else if (fetchedNumber.getPhoneId() == null) {
229 throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N
233 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.getDetached: fetchedNumber.phoneId={1}", this.getClass().getSimpleName(), fetchedNumber.getPhoneId())); //NOI18N
236 DialableLandLineNumber managedNumber = null;
238 // Is there a difference?
239 if (!PhoneUtils.isSameLandLineNumber(landLineNumber, fetchedNumber)) {
241 managedNumber = this.getEntityManager().merge(fetchedNumber);
245 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N
248 return managedNumber;
252 * Returns a managed instance from given fax number
254 * @param faxNumber Fax number
255 * @param fetchedNumber Found fax number in database
257 * @return Managed instance
259 protected DialableFaxNumber getManaged (final DialableFaxNumber faxNumber, final DialableFaxNumber fetchedNumber) {
261 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: faxNumber={1},fetchedNumber={2} - CALLED!", this.getClass().getSimpleName(), faxNumber, fetchedNumber)); //NOI18N
264 if (null == faxNumber) {
266 throw new NullPointerException("faxNumber is null"); //NOI18N
267 } else if (null == fetchedNumber) {
269 throw new NullPointerException("fetchedNumber is null"); //NOI18N
270 } else if (fetchedNumber.getPhoneId() == null) {
272 throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
276 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.getDetached: fetchedNumber.phoneId={1}", this.getClass().getSimpleName(), fetchedNumber.getPhoneId())); //NOI18N
279 DialableFaxNumber managedNumber = null;
281 // Is there a difference?
282 if (!PhoneUtils.isSameFaxNumber(faxNumber, fetchedNumber)) {
284 managedNumber = this.getEntityManager().merge(fetchedNumber);
288 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N
291 return managedNumber;
295 * Get back a managed instance from given user
297 * @param user Unmanaged/detached user instance
299 * @return Managed user instance
301 protected User getManagedUser (final User user) {
303 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getManaged: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
305 // user should not be null
308 throw new NullPointerException("user is null"); //NOI18N
309 } else if (user.getUserId() == null) {
311 throw new NullPointerException("user.userId is null"); //NOI18N
312 } else if (user.getUserId() < 1) {
314 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is null", user.getUserId())); //NOI18N
315 } else if (user.getUserContact() == null) {
317 throw new NullPointerException("user.userContact is null"); //NOI18N
318 } else if (user.getUserContact().getContactId() == null) {
320 throw new NullPointerException("user.userContact.contactId is null"); //NOI18N
321 } else if (user.getUserContact().getContactId() < 1) {
322 // Not valid id number
323 throw new IllegalArgumentException(MessageFormat.format("user.userContact.contactId={0} is not valid", user.getUserContact().getContactId())); //NOI18N#
326 // Try to find it (should be there)
327 User managedUser = this.getEntityManager().find(LoginUser.class, user.getUserId());
330 assert (managedUser instanceof User) : "managedUser is null"; //NOI18N
333 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getManaged: managedUser={1} - EXIT!", this.getClass().getSimpleName(), managedUser)); //NOI18N
340 * Merges given (detached) contact's data
342 * @param detachedContact Contact instance to merge
344 * @return Detached contact instance
346 protected Contact mergeContactData (final Contact detachedContact) {
348 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactData: contact={1} - CALLED!", this.getClass().getSimpleName(), detachedContact)); //NOI18N
350 // The contact instance must be valid
351 if (null == detachedContact) {
353 throw new NullPointerException("detachedContact is null"); //NOI18N
354 } else if (detachedContact.getContactId() == null) {
356 throw new NullPointerException("detachedContact.contactId is null"); //NOI18N //NOI18N
357 } else if (detachedContact.getContactId() < 1) {
359 throw new IllegalStateException(MessageFormat.format("{0}.detachedContact.contactId={1} is not valid.", this.getClass().getSimpleName(), detachedContact.getContactId())); //NOI18N
362 // Get contact from it and find it
363 Contact managedContact = this.getEntityManager().find(detachedContact.getClass(), detachedContact.getContactId());
366 assert (managedContact instanceof Contact) : MessageFormat.format("Contact with id {0} not found, but should be.", detachedContact.getContactId()); //NOI18N
369 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.updateUserPersonalData: managedContact.contactId={1}", this.getClass().getSimpleName(), managedContact.getContactId())); //NOI18N
371 // Is a fax number set?
372 if (detachedContact.getContactFaxNumber() instanceof DialableFaxNumber) {
373 // Make fax numbers managed
374 managedContact.setContactFaxNumber(this.getManaged(detachedContact.getContactFaxNumber(), detachedContact.getContactFaxNumber()));
377 // Is a land-line number set?
378 if (detachedContact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
379 // Make land-line numbers managed
380 managedContact.setContactLandLineNumber(this.getManaged(detachedContact.getContactLandLineNumber(), detachedContact.getContactLandLineNumber()));
383 // Is a mobile number set?
384 if (detachedContact.getContactMobileNumber() instanceof DialableMobileNumber) {
385 // Make mobile numbers managed
386 managedContact.setContactMobileNumber(this.getManaged(detachedContact.getContactMobileNumber(), detachedContact.getContactMobileNumber()));
389 // Set updated timestamp
390 managedContact.setContactUpdated(new GregorianCalendar());
393 managedContact.copyAll(detachedContact);
396 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactData: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N
398 // Return detached contact
399 return managedContact;
403 * Merges given (detached) contact's cellphone, land-line and fax numbers
405 * @param detachedContact Detached contact instance
407 protected void mergeContactsMobileLandLineFaxNumbers (final Contact detachedContact) {
409 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactsMobileLandLineFaxNumbers: detachedContact={1} - CALLED!", this.getClass().getSimpleName(), detachedContact)); //NOI18N
411 // The contact instance must be valid
412 if (null == detachedContact) {
414 throw new NullPointerException("detachedContact is null"); //NOI18N
415 } else if (detachedContact.getContactId() == null) {
417 throw new NullPointerException("detachedContact.contactId is null"); //NOI18N //NOI18N
418 } else if (detachedContact.getContactId() < 1) {
420 throw new IllegalStateException(MessageFormat.format("{0}.detachedContact.contactId={1} is not valid.", this.getClass().getSimpleName(), detachedContact.getContactId())); //NOI18N
424 DialableMobileNumber cellphone = detachedContact.getContactMobileNumber();
425 DialableLandLineNumber landLine = detachedContact.getContactLandLineNumber();
426 DialableFaxNumber fax = detachedContact.getContactFaxNumber();
428 // Is there a cellphone instance set?
429 if (cellphone instanceof DialableMobileNumber) {
431 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: cellphone.phoneId={0} is being updated ...", cellphone.getPhoneId())); //NOI18N
434 DialableMobileNumber foundMobile = this.getEntityManager().find(cellphone.getClass(), cellphone.getPhoneId());
437 assert (foundMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", foundMobile.getPhoneId()); //NOI18N
440 foundMobile.copyAll(detachedContact.getContactMobileNumber());
443 detachedContact.setContactMobileNumber(foundMobile);
446 // Is there a fax instance set?
447 if (fax instanceof DialableFaxNumber) {
449 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: fax.phoneId={0} is being updated ...", fax.getPhoneId())); //NOI18N
452 DialableFaxNumber foundFax = this.getEntityManager().find(fax.getClass(), fax.getPhoneId());
455 foundFax.copyAll(detachedContact.getContactFaxNumber());
458 detachedContact.setContactFaxNumber(foundFax);
461 // Is there a fax instance set?
462 if (landLine instanceof DialableLandLineNumber) {
464 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: landLine.phoneId={0} is being updated ...", landLine.getPhoneId())); //NOI18N
467 DialableLandLineNumber foundLandLine = this.getEntityManager().find(landLine.getClass(), landLine.getPhoneId());
470 assert (foundLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", foundLandLine.getPhoneId()); //NOI18N
473 foundLandLine.copyAll(detachedContact.getContactLandLineNumber());
476 detachedContact.setContactLandLineNumber(foundLandLine);
480 this.getLoggerBeanLocal().logTrace("mergeContactsMobileLandLineFaxNumbers: EXIT!"); //NOI18N
484 * Sends an email with given subject line, template name to given recipient
487 * @param subjectLine Subject line
488 * @param templateName Template name
489 * @param emailAddress Recipient's email address
490 * @param user User instance
491 * @param baseUrl Base URL
493 protected void sendEmail (final String subjectLine, final String templateName, final Address emailAddress, final User user, final String baseUrl) {
495 this.getLoggerBeanLocal().logTrace(MessageFormat.format("sendEmail: subjectLine={0},templateName={1},emailAddress={2},user={3},baseUrl={4} - CALLED!", subjectLine, templateName, emailAddress, user, baseUrl)); //NOI18N
498 if (null == subjectLine) {
500 throw new NullPointerException("subjectLine is null"); //NOI18N
501 } else if (subjectLine.isEmpty()) {
503 throw new IllegalArgumentException("subjectLine is empty"); //NOI18N
504 } else if (null == templateName) {
506 throw new NullPointerException("templateName is null"); //NOI18N
507 } else if (templateName.isEmpty()) {
509 throw new IllegalArgumentException("templateName is empty"); //NOI18N
510 } else if (null == emailAddress) {
512 throw new NullPointerException("emailAddress is null"); //NOI18N
513 }else if (null == user) {
515 throw new NullPointerException("user is null"); //NOI18N
516 } else if (user.getUserId() == null) {
518 throw new NullPointerException("user.userId is null"); //NOI18N
519 } else if (user.getUserId() < 1) {
521 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid.", user.getUserId())); //NOI18N
522 } else if (user.getUserName() == null) {
524 throw new NullPointerException("user.userName is null"); //NOI18N
525 } else if (user.getUserName().isEmpty()) {
527 throw new IllegalArgumentException("user.userName is empty"); //NOI18N
528 } else if (user.getUserAccountStatus() == null) {
530 throw new NullPointerException("user.userAccountStatus is null"); //NOI18N
531 } else if (user.getUserContact() == null) {
533 throw new NullPointerException("user.userContact is null"); //NOI18N
534 } else if (user.getUserContact().getContactId() == null) {
536 throw new NullPointerException("user.userContact.contactId is null"); //NOI18N
537 } else if (user.getUserContact().getContactId() < 1) {
539 throw new IllegalArgumentException(MessageFormat.format("user.userContact.contactId={0} is invalid", user.getUserContact().getContactId())); //NOI18N
540 } else if (user.getUserContact().getContactGender() == null) {
542 throw new NullPointerException("user.userContact.contactGender 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("{0}.setAllContactPhoneEntries: contact={1},other={2} - CALLED!", this.getClass().getSimpleName(), 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("{0}.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(MessageFormat.format("{0}.setAllContactPhoneEntries: Copying cellphone entry ...", this.getClass().getSimpleName())); //NOI18N
609 // Is the fax number set?
610 if (other.getContactMobileNumber() instanceof DialableMobileNumber) {
611 // Copy cellphone number
612 contact.setContactMobileNumber(this.getManaged(other.getContactMobileNumber(), contact.getContactMobileNumber()));
615 contact.setContactMobileNumber(null);
620 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.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(MessageFormat.format("{0}.setAllContactPhoneEntries: Copying land-line entry ...", this.getClass().getSimpleName())); //NOI18N
627 // Is the land-line number set?
628 if (other.getContactLandLineNumber() instanceof DialableLandLineNumber) {
629 // Copy land-line number
630 contact.setContactLandLineNumber(this.getManaged(other.getContactLandLineNumber(), contact.getContactLandLineNumber()));
633 contact.setContactLandLineNumber(null);
638 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: other.contactFaxNumber={1}", this.getClass().getSimpleName(), other.getContactFaxNumber())); //NOI18N
640 // Is other cellphone not set?
641 if ((other.getContactFaxNumber() == null) || (PhoneUtils.isSameFaxNumber(contact.getContactFaxNumber(), other.getContactFaxNumber()))) {
643 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: Copying fax entry ...", this.getClass().getSimpleName())); //NOI18N
645 // Is the fax number set?
646 if (other.getContactFaxNumber() instanceof DialableFaxNumber) {
648 contact.setContactFaxNumber(this.getManaged(other.getContactFaxNumber(), contact.getContactFaxNumber()));
651 contact.setContactFaxNumber(null);
656 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntries: EXIT!", this.getClass().getSimpleName())); //NOI18N
660 * Updates all contact'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("{0}.setAllContactPhoneEntriesUpdated: contact={1},isMobileUnlinked={2},isLandlineUnlinked={3},isFaxUnlinked={4} - CALLED", this.getClass().getSimpleName(), 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(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: Setting updated timestamp for land-line number ...", this.getClass().getSimpleName())); //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(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: Setting updated timestamp for fax number ...", this.getClass().getSimpleName())); //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(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: Setting updated timestamp for cellphone number ...", this.getClass().getSimpleName())); //NOI18N
726 // Set updated timestamp
727 mobileNumber.setPhoneEntryUpdated(new GregorianCalendar());
731 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: EXIT!", this.getClass().getSimpleName())); //NOI18N