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.jjobs.database;
19 import java.text.MessageFormat;
20 import java.util.GregorianCalendar;
21 import java.util.Objects;
22 import java.util.Properties;
23 import javax.ejb.EJBException;
24 import javax.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.User;
45 import org.mxchange.jusercore.model.user.UserUtils;
48 * A helper class for beans that access the database.
50 * @author Roland Haeder<roland@mxchange.org>
52 public abstract class BaseJobsDatabaseBean extends BaseDatabaseBean {
57 private static final long serialVersionUID = 12_895_410_275_811_963L;
62 private Connection connection;
67 private MessageProducer messageProducer;
70 * Mailer message queue
77 private Session session;
80 * Protected constructor
82 protected BaseJobsDatabaseBean () {
83 // Call super constructor
87 // Get initial context
88 Context context = new InitialContext();
90 // Get factory from JMS resource
91 QueueConnectionFactory connectionFactory = (QueueConnectionFactory) context.lookup("jms/jlandingpage-queue-factory"); //NOI18N
94 this.queue = (Queue) context.lookup("jms/jlandingpage-email-queue"); //NOI18N
97 this.connection = connectionFactory.createConnection();
99 // Init session instance
100 this.session = this.connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
102 // And message producer
103 this.messageProducer = this.session.createProducer(this.queue);
104 } catch (final NamingException | JMSException e) {
105 // Continued to throw
106 throw new FacesException(e);
111 * Detaches all contact's phone instances.
113 * @param contact Contact to set instances
115 protected void detachAllContactPhoneEntries (final Contact contact) {
117 this.getLoggerBeanLocal().logTrace(MessageFormat.format("detachAllContactPhoneEntries: contact={0} - CALLED!", contact)); //NOI18N
119 // Both must be the same and not null
120 if (null == contact) {
122 throw new NullPointerException("contact is null"); //NOI18N
126 this.getLoggerBeanLocal().logDebug(MessageFormat.format("detachAllContactPhoneEntries: contact.contactMobileNumber={0}", contact.getContactMobileNumber())); //NOI18N
128 // Is contact cellphone set?
129 if (contact.getContactMobileNumber() instanceof DialableMobileNumber) {
130 // Copy cellphone number
131 contact.setContactMobileNumber(this.getDetached(contact.getContactMobileNumber(), contact.getContactMobileNumber()));
135 this.getLoggerBeanLocal().logDebug(MessageFormat.format("detachAllContactPhoneEntries: contact.contactLandLineNumber={0}", contact.getContactLandLineNumber())); //NOI18N
137 // Is the land-line number set?
138 if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
139 // Copy land-line number
140 contact.setContactLandLineNumber(this.getDetached(contact.getContactLandLineNumber(), contact.getContactLandLineNumber()));
144 this.getLoggerBeanLocal().logDebug(MessageFormat.format("detachAllContactPhoneEntries: contact.contactFaxNumber={0}", contact.getContactFaxNumber())); //NOI18N
146 // Is the fax number set?
147 if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
149 contact.setContactFaxNumber(this.getDetached(contact.getContactFaxNumber(), contact.getContactFaxNumber()));
153 this.getLoggerBeanLocal().logTrace("detachAllContactPhoneEntries: EXIT!"); //NOI18N
157 * Updates all contacts's phone entry's created timestamps
159 * @param contact Contact instance to update
161 protected void setAllContactPhoneEntriesCreated (final Contact contact) {
163 this.getLoggerBeanLocal().logTrace(MessageFormat.format("setAllContactPhoneEntriesCreated: contact={0} - CALLED!", contact)); //NOI18N
165 // The contact instance must be valid
166 if (null == contact) {
168 throw new NullPointerException("contact is null"); //NOI18N
171 // Get all phone instances
172 DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber();
173 DialableFaxNumber faxNumber = contact.getContactFaxNumber();
174 DialableMobileNumber mobileNumber = contact.getContactMobileNumber();
177 this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllContactPhoneEntriesCreated: landLineNumber={0},faxNumber={1},cellphoneNumber={2}", landLineNumber, faxNumber, mobileNumber)); //NOI18N
179 // Is a phone number instance set?
180 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() == null)) {
182 this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntriesCreated: Setting created timestamp for land-line number ..."); //NOI18N
184 // Set updated timestamp
185 landLineNumber.setPhoneEntryCreated(new GregorianCalendar());
188 // Is a fax number instance set?
189 if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() == null)) {
191 this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntriesCreated: Setting created timestamp for fax number ..."); //NOI18N
193 // Set updated timestamp
194 faxNumber.setPhoneEntryCreated(new GregorianCalendar());
197 // Is a mobile number instance set?
198 if ((mobileNumber instanceof DialableMobileNumber) && (mobileNumber.getPhoneId() == null)) {
200 this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntriesCreated: Setting created timestamp for cellphone number ..."); //NOI18N
202 // Set updated timestamp
203 mobileNumber.setPhoneEntryCreated(new GregorianCalendar());
207 this.getLoggerBeanLocal().logTrace("setAllContactPhoneEntriesCreated: EXIT!"); //NOI18N
211 * Returnes a detached instance from given cellphone instance
213 * @param mobileNumber Mobile instance
214 * @param fetchedNumber Found cellphone number in database
216 * @return Detached instance
218 protected DialableMobileNumber getDetached (final DialableMobileNumber mobileNumber, final DialableMobileNumber fetchedNumber) {
220 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: cellphoneNumber={0},fetchedNumber={1} - CALLED!", mobileNumber, fetchedNumber)); //NOI18N
223 if (null == mobileNumber) {
225 throw new NullPointerException("cellphoneNumber is null"); //NOI18N
226 } else if (fetchedNumber.getPhoneId() == null) {
228 throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
232 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N
234 // Init query instance
235 DialableMobileNumber foundNumber = this.getEntityManager().getReference(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
238 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N
241 DialableMobileNumber detachedNumber = null;
243 // Is there a difference?
244 if (!PhoneUtils.isSameMobileNumber(mobileNumber, fetchedNumber)) {
246 detachedNumber = this.getEntityManager().merge(foundNumber);
252 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: detachedNumber={0} - EXIT!", detachedNumber)); //NOI18N
255 return detachedNumber;
259 * Returnes a detached instance from given land-line instance
261 * @param landLineNumber Land-line instance
262 * @param fetchedNumber Found land-line number in database
264 * @return Detached instance
266 protected DialableLandLineNumber getDetached (final DialableLandLineNumber landLineNumber, final DialableLandLineNumber fetchedNumber) {
268 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: landLineNumber={0},fetchedNumber={1} - CALLED!", landLineNumber, fetchedNumber)); //NOI18N
271 if (null == landLineNumber) {
273 throw new NullPointerException("landLineNumber is null"); //NOI18N
274 } else if (fetchedNumber.getPhoneId() == null) {
276 throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N
280 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N
282 // Init query instance
283 DialableLandLineNumber foundNumber = this.getEntityManager().getReference(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
286 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N
289 DialableLandLineNumber detachedNumber = null;
291 // Is there a difference?
292 if (!PhoneUtils.isSameLandLineNumber(landLineNumber, fetchedNumber)) {
294 detachedNumber = this.getEntityManager().merge(foundNumber);
298 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: detachedNumber={0} - EXIT!", detachedNumber)); //NOI18N
301 return detachedNumber;
305 * Returnes a detached instance from given fax instance
307 * @param faxNumber Fax instance
308 * @param fetchedNumber Found fax number in database
310 * @return Detached instance
312 protected DialableFaxNumber getDetached (final DialableFaxNumber faxNumber, final DialableFaxNumber fetchedNumber) {
314 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: faxNumber={0},fetchedNumber={1} - CALLED!", faxNumber, fetchedNumber)); //NOI18N
317 if (null == faxNumber) {
319 throw new NullPointerException("faxNumber is null"); //NOI18N
320 } else if (fetchedNumber.getPhoneId() == null) {
322 throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
326 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N
328 // Init query instance
329 DialableFaxNumber foundNumber = this.getEntityManager().getReference(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
332 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N
335 DialableFaxNumber detachedNumber = null;
337 // Is there a difference?
338 if (!PhoneUtils.isSameFaxNumber(faxNumber, fetchedNumber)) {
340 detachedNumber = this.getEntityManager().merge(foundNumber);
344 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: detachedNumber={0} - EXIT!", detachedNumber)); //NOI18N
347 return detachedNumber;
351 * Merges given contact's data
353 * @param contact Contact instance to merge
355 * @return Detached contact instance
357 protected Contact mergeContactData (final Contact contact) {
359 this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeContactData: contact={0} - CALLED!", contact)); //NOI18N
361 // The contact instance must be valid
362 if (null == contact) {
364 throw new NullPointerException("contact is null"); //NOI18N
365 } else if (contact.getContactId() == null) {
367 throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
368 } else if (contact.getContactId() < 1) {
370 throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
373 // Set updated timestamp
374 contact.setContactUpdated(new GregorianCalendar());
376 // Get contact from it and find it
377 Contact foundContact = this.getEntityManager().getReference(contact.getClass(), contact.getContactId());
380 assert (foundContact instanceof Contact) : MessageFormat.format("Contact with id {0} not found, but should be.", contact.getContactId()); //NOI18N
383 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: foundContact.contactId={0}", foundContact.getContactId())); //NOI18N
385 // Merge contact instance
386 Contact detachedContact = this.getEntityManager().merge(foundContact);
389 detachedContact.copyAll(contact);
392 this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeContactData: detachedContact={0} - EXIT!", detachedContact)); //NOI18N
394 // Return detached contact
395 return detachedContact;
399 * Merges given (detached) contact's cellphone, land-line and fax numbers
401 * @param detachedContact Detached contact instance
403 protected void mergeContactsMobileLandLineFaxNumbers (final Contact detachedContact) {
405 this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeContactsMobileLandLineFaxNumbers: detachedContact={0} - CALLED!", detachedContact)); //NOI18N
407 // The contact instance must be valid
408 if (null == detachedContact) {
410 throw new NullPointerException("detachedContact is null"); //NOI18N
411 } else if (detachedContact.getContactId() == null) {
413 throw new NullPointerException("detachedContact.contactId is null"); //NOI18N //NOI18N
414 } else if (detachedContact.getContactId() < 1) {
416 throw new IllegalStateException(MessageFormat.format("detachedContact.contactId={0} is not valid.", detachedContact.getContactId())); //NOI18N
420 DialableMobileNumber cellphone = detachedContact.getContactMobileNumber();
421 DialableLandLineNumber landLine = detachedContact.getContactLandLineNumber();
422 DialableFaxNumber fax = detachedContact.getContactFaxNumber();
424 // Is there a cellphone instance set?
425 if (cellphone instanceof DialableMobileNumber) {
427 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: cellphone.phoneId={0} is being updated ...", cellphone.getPhoneId())); //NOI18N
430 DialableMobileNumber foundMobile = this.getEntityManager().getReference(cellphone.getClass(), cellphone.getPhoneId());
433 assert (foundMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", foundMobile.getPhoneId()); //NOI18N
435 // Then merge it, too
436 DialableMobileNumber detachedMobile = this.getEntityManager().merge(foundMobile);
439 assert (detachedMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", detachedMobile.getPhoneId()); //NOI18N
442 detachedMobile.copyAll(detachedContact.getContactMobileNumber());
445 detachedContact.setContactMobileNumber(detachedMobile);
448 // Is there a fax instance set?
449 if (fax instanceof DialableFaxNumber) {
451 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: fax.phoneId={0} is being updated ...", fax.getPhoneId())); //NOI18N
454 DialableFaxNumber foundFax = this.getEntityManager().getReference(fax.getClass(), fax.getPhoneId());
457 assert (foundFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", foundFax.getPhoneId()); //NOI18N
459 // Then merge it, too
460 DialableFaxNumber detachedFax = this.getEntityManager().merge(foundFax);
463 assert (detachedFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", detachedFax.getPhoneId()); //NOI18N
466 detachedFax.copyAll(detachedContact.getContactFaxNumber());
469 detachedContact.setContactFaxNumber(detachedFax);
472 // Is there a fax instance set?
473 if (landLine instanceof DialableLandLineNumber) {
475 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: landLine.phoneId={0} is being updated ...", landLine.getPhoneId())); //NOI18N
478 DialableLandLineNumber foundLandLine = this.getEntityManager().getReference(landLine.getClass(), landLine.getPhoneId());
481 assert (foundLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", foundLandLine.getPhoneId()); //NOI18N
483 // Then merge it, too
484 DialableLandLineNumber detachedLandLine = this.getEntityManager().merge(foundLandLine);
487 assert (detachedLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", detachedLandLine.getPhoneId()); //NOI18N
490 detachedLandLine.copyAll(detachedContact.getContactLandLineNumber());
493 detachedContact.setContactLandLineNumber(detachedLandLine);
497 this.getLoggerBeanLocal().logTrace("mergeContactsMobileLandLineFaxNumbers: EXIT!"); //NOI18N
501 * Sends an email with given subject line, template name to given recipient
504 * @param subjectLine Subject line
505 * @param templateName Template name
506 * @param emailAddress Recipient's email address
507 * @param user User instance
508 * @param baseUrl Base URL
510 protected void sendEmail (final String subjectLine, final String templateName, final Address emailAddress, final User user, final String baseUrl) {
512 this.getLoggerBeanLocal().logTrace(MessageFormat.format("sendEmail: subjectLine={0},templateName={1},emailAddress={2},user={3},baseUrl={4} - CALLED!", subjectLine, templateName, emailAddress, user, baseUrl)); //NOI18N
515 if (null == subjectLine) {
517 throw new NullPointerException("subjectLine is null"); //NOI18N
518 } else if (subjectLine.isEmpty()) {
520 throw new IllegalArgumentException("subjectLine is empty"); //NOI18N
521 } else if (null == templateName) {
523 throw new NullPointerException("templateName is null"); //NOI18N
524 } else if (templateName.isEmpty()) {
526 throw new IllegalArgumentException("templateName is empty"); //NOI18N
527 } else if (null == emailAddress) {
529 throw new NullPointerException("emailAddress is null"); //NOI18N
532 // Prepare mail wrapper
533 WrapableEmailDelivery emailWrapper = new EmailDeliveryWrapper();
536 Properties variables = UserUtils.getAllUserFields(user);
539 variables.put("baseUrl", baseUrl); //NOI18N
542 // @TODO Language from message bundle
543 emailWrapper.setRecipient(emailAddress);
544 emailWrapper.setLocale(user.getUserLocale());
545 emailWrapper.setSubjectLine(subjectLine);
546 emailWrapper.setTemplateName(templateName);
547 emailWrapper.setTemplateVariables(variables);
550 // Send out email change
551 ObjectMessage message = this.session.createObjectMessage();
552 message.setObject(emailWrapper);
555 this.sendMessage(message, this.messageProducer);
556 } catch (final JMSException ex) {
558 throw new EJBException(ex);
562 this.getLoggerBeanLocal().logTrace("sendEmail: EXIT!"); //NOI18N
566 * Updates all contact's phone instances from other contact, both contacts
567 * should be the same.
569 * @param contact Contact to set instances
570 * @param other Other contact to get instances from
572 protected void setAllContactPhoneEntries (final Contact contact, final Contact other) {
574 this.getLoggerBeanLocal().logTrace(MessageFormat.format("setAllContactPhoneEntries: contact={0},other={1} - CALLED!", contact, other)); //NOI18N
576 // Both must be the same and not null
577 if (null == contact) {
579 throw new NullPointerException("contact is null"); //NOI18N
580 } else if (null == other) {
582 throw new NullPointerException("other is null"); //NOI18N
583 } else if (!Objects.equals(contact, other)) {
584 // Not same instances
585 throw new IllegalArgumentException(MessageFormat.format("contact={0} and other={1} are not equal!", contact, other)); //NOI18N
589 this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllContactPhoneEntries: other.contactMobileNumber={0}", other.getContactMobileNumber())); //NOI18N
591 // Is other cellphone not set?
592 if ((other.getContactMobileNumber() == null) || (PhoneUtils.isSameMobileNumber(contact.getContactMobileNumber(), other.getContactMobileNumber()))) {
594 this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntries: Copying cellphone entry ..."); //NOI18N
596 // Is the fax number set?
597 if (other.getContactMobileNumber() instanceof DialableMobileNumber) {
598 // Copy cellphone number
599 contact.setContactMobileNumber(this.getDetached(other.getContactMobileNumber(), contact.getContactMobileNumber()));
602 contact.setContactMobileNumber(null);
607 this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllContactPhoneEntries: other.contactLandLineNumber={0}", other.getContactLandLineNumber())); //NOI18N
609 // Is other cellphone not set?
610 if ((other.getContactLandLineNumber() == null) || (PhoneUtils.isSameLandLineNumber(contact.getContactLandLineNumber(), other.getContactLandLineNumber()))) {
612 this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntries: Copying land-line entry ..."); //NOI18N
614 // Is the land-line number set?
615 if (other.getContactLandLineNumber() instanceof DialableLandLineNumber) {
616 // Copy land-line number
617 contact.setContactLandLineNumber(this.getDetached(other.getContactLandLineNumber(), contact.getContactLandLineNumber()));
620 contact.setContactLandLineNumber(null);
625 this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllContactPhoneEntries: other.contactFaxNumber={0}", other.getContactFaxNumber())); //NOI18N
627 // Is other cellphone not set?
628 if ((other.getContactFaxNumber() == null) || (PhoneUtils.isSameFaxNumber(contact.getContactFaxNumber(), other.getContactFaxNumber()))) {
630 this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntries: Copying fax entry ..."); //NOI18N
632 // Is the fax number set?
633 if (other.getContactFaxNumber() instanceof DialableFaxNumber) {
635 contact.setContactFaxNumber(this.getDetached(other.getContactFaxNumber(), contact.getContactFaxNumber()));
638 contact.setContactFaxNumber(null);
643 this.getLoggerBeanLocal().logTrace("setAllContactPhoneEntries: EXIT!"); //NOI18N
647 * Updates all contacts's phone entry's updated timestamps
649 * @param contact Contact instance to update
650 * @param isMobileUnlinked Whether a cellphone entry has been unlinked in
652 * @param isLandlineUnlinked Whether a land-line entry has been unlinked in
654 * @param isFaxUnlinked Whether a fax entry has been unlinked in contact
657 protected void setAllContactPhoneEntriesUpdated (final Contact contact, final boolean isMobileUnlinked, final boolean isLandlineUnlinked, final boolean isFaxUnlinked) {
659 this.getLoggerBeanLocal().logTrace(MessageFormat.format("setAllContactPhoneEntriesUpdated: contact={0},isMobileUnlinked={1},isLandlineUnlinked={2},isFaxUnlinked={3} - CALLED", contact, isMobileUnlinked, isLandlineUnlinked, isFaxUnlinked)); //NOI18N
661 // The contact instance must be valid
662 if (null == contact) {
664 throw new NullPointerException("contact is null"); //NOI18N
665 } else if (contact.getContactId() == null) {
667 throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
668 } else if (contact.getContactId() < 1) {
670 throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
673 // Get all phone instances
674 DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber();
675 DialableFaxNumber faxNumber = contact.getContactFaxNumber();
676 DialableMobileNumber cellphoneNumber = contact.getContactMobileNumber();
678 // Flags and instances must be constistent
679 if (isMobileUnlinked && cellphoneNumber instanceof DialableMobileNumber) {
681 throw new IllegalStateException("isCellPhoneUnlinked is TRUE, but cellphoneNumber is set."); //NOI18N
682 } else if (isLandlineUnlinked && landLineNumber instanceof DialableLandLineNumber) {
684 throw new IllegalStateException("isLandlineUnlinked is TRUE, but landLineNumber is set."); //NOI18N
685 } else if (isFaxUnlinked && faxNumber instanceof DialableFaxNumber) {
687 throw new IllegalStateException("isFaxUnlinked is TRUE, but faxNumber is set."); //NOI18N
690 // Is a phone number instance set?
691 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() instanceof Long) && (landLineNumber.getPhoneId() > 0)) {
693 this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntriesUpdated: Setting updated timestamp for land-line number ..."); //NOI18N
695 // Set updated timestamp
696 landLineNumber.setPhoneEntryUpdated(new GregorianCalendar());
699 // Is a fax number instance set?
700 if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() instanceof Long) && (faxNumber.getPhoneId() > 0)) {
702 this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntriesUpdated: Setting updated timestamp for fax number ..."); //NOI18N
704 // Set updated timestamp
705 faxNumber.setPhoneEntryUpdated(new GregorianCalendar());
708 // Is a mobile number instance set?
709 if ((cellphoneNumber instanceof DialableMobileNumber) && (cellphoneNumber.getPhoneId() instanceof Long) && (cellphoneNumber.getPhoneId() > 0)) {
711 this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntriesUpdated: Setting updated timestamp for cellphone number ..."); //NOI18N
713 // Set updated timestamp
714 cellphoneNumber.setPhoneEntryUpdated(new GregorianCalendar());
718 this.getLoggerBeanLocal().logTrace("setAllContactPhoneEntriesUpdated: EXIT!"); //NOI18N