]> git.mxchange.org Git - pizzaservice-core.git/blob - src/org/mxchange/pizzaaplication/database/BasePizzaDatabaseBean.java
minor: improved message, foundContact is the right variable name
[pizzaservice-core.git] / src / org / mxchange / pizzaaplication / database / BasePizzaDatabaseBean.java
1 /*
2  * Copyright (C) 2016 Roland Haeder
3  *
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.
8  *
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.
13  *
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/>.
16  */
17 package org.mxchange.pizzaaplication.database;
18
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;
46
47 /**
48  * A helper class for beans that access the database.
49  * <p>
50  * @author Roland Haeder<roland@mxchange.org>
51  */
52 public abstract class BasePizzaDatabaseBean extends BaseDatabaseBean {
53
54         /**
55          * Serial number
56          */
57         private static final long serialVersionUID = 12_895_410_275_811_963L;
58
59         /**
60          * Connection
61          */
62         private Connection connection;
63
64         /**
65          * Message producer
66          */
67         private MessageProducer messageProducer;
68
69         /**
70          * Mailer message queue
71          */
72         private Queue queue;
73
74         /**
75          * Session instance
76          */
77         private Session session;
78
79         /**
80          * Protected constructor
81          */
82         protected BasePizzaDatabaseBean () {
83                 // Call super constructor
84                 super();
85
86                 try {
87                         // Get initial context
88                         Context context = new InitialContext();
89
90                         // Get factory from JMS resource
91                         QueueConnectionFactory connectionFactory = (QueueConnectionFactory) context.lookup("jms/jlandingpage-queue-factory"); //NOI18N
92
93                         // Lookup queue
94                         this.queue = (Queue) context.lookup("jms/jlandingpage-email-queue"); //NOI18N
95
96                         // Create connection
97                         this.connection = connectionFactory.createConnection();
98
99                         // Init session instance
100                         this.session = this.connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
101
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);
107                 }
108         }
109
110         /**
111          * Updates all contacts's phone entry's created timestamps
112          * <p>
113          * @param contact Contact instance to update
114          */
115         protected void setAllContactPhoneEntriesCreated (final Contact contact) {
116                 // Trace message
117                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("setAllContactPhoneEntriesCreated: contact={0} - CALLED!", contact)); //NOI18N
118
119                 // The contact instance must be valid
120                 if (null == contact) {
121                         // Throw NPE again
122                         throw new NullPointerException("contact is null"); //NOI18N
123                 }
124
125                 // Get all phone instances
126                 DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber();
127                 DialableFaxNumber faxNumber = contact.getContactFaxNumber();
128                 DialableMobileNumber mobileNumber = contact.getContactMobileNumber();
129
130                 // Debug message
131                 this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllContactPhoneEntriesCreated: landLineNumber={0},faxNumber={1},cellphoneNumber={2}", landLineNumber, faxNumber, mobileNumber)); //NOI18N
132
133                 // Is a phone number instance set?
134                 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() == null)) {
135                         // Debug message
136                         this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntriesCreated: Setting created timestamp for land-line number ..."); //NOI18N
137
138                         // Set updated timestamp
139                         landLineNumber.setPhoneEntryCreated(new GregorianCalendar());
140                 }
141
142                 // Is a fax number instance set?
143                 if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() == null)) {
144                         // Debug message
145                         this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntriesCreated: Setting created timestamp for fax number ..."); //NOI18N
146
147                         // Set updated timestamp
148                         faxNumber.setPhoneEntryCreated(new GregorianCalendar());
149                 }
150
151                 // Is a mobile number instance set?
152                 if ((mobileNumber instanceof DialableMobileNumber) && (mobileNumber.getPhoneId() == null)) {
153                         // Debug message
154                         this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntriesCreated: Setting created timestamp for cellphone number ..."); //NOI18N
155
156                         // Set updated timestamp
157                         mobileNumber.setPhoneEntryCreated(new GregorianCalendar());
158                 }
159
160                 // Trace message
161                 this.getLoggerBeanLocal().logTrace("setAllContactPhoneEntriesCreated: EXIT!"); //NOI18N
162         }
163
164         /**
165          * Returnes a detached instance from given cellphone instance
166          * <p>
167          * @param mobileNumber Mobile instance
168          * @param fetchedNumber Found cellphone number in database
169          * <p>
170          * @return Detached instance
171          */
172         protected DialableMobileNumber getDetached (final DialableMobileNumber mobileNumber, final DialableMobileNumber fetchedNumber) {
173                 // Trace message
174                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: cellphoneNumber={0},fetchedNumber={1} - CALLED!", mobileNumber, fetchedNumber)); //NOI18N
175
176                 // Should be valid
177                 if (null == mobileNumber) {
178                         // Throw NPE
179                         throw new NullPointerException("cellphoneNumber is null"); //NOI18N
180                 } else if (fetchedNumber.getPhoneId() == null) {
181                         // ..and again
182                         throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
183                 }
184
185                 // Debug message
186                 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N
187
188                 // Init query instance
189                 DialableMobileNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
190
191                 // Debug message
192                 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N
193
194                 // Default is null
195                 DialableMobileNumber detachedNumber = null;
196
197                 // Is there a difference?
198                 if (!PhoneUtils.isSameMobileNumber(mobileNumber, fetchedNumber)) {
199                         // Merge this entry
200                         detachedNumber = this.getEntityManager().merge(foundNumber);
201
202                         // Copy all
203                 }
204
205                 // Trace message
206                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: detachedNumber={0} - EXIT!", detachedNumber)); //NOI18N
207
208                 // Return it
209                 return detachedNumber;
210         }
211
212         /**
213          * Returnes a detached instance from given land-line instance
214          * <p>
215          * @param landLineNumber Land-line instance
216          * @param fetchedNumber Found land-line number in database
217          * <p>
218          * @return Detached instance
219          */
220         protected DialableLandLineNumber getDetached (final DialableLandLineNumber landLineNumber, final DialableLandLineNumber fetchedNumber) {
221                 // Trace message
222                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: landLineNumber={0},fetchedNumber={1} - CALLED!", landLineNumber, fetchedNumber)); //NOI18N
223
224                 // Should be valid
225                 if (null == landLineNumber) {
226                         // Throw NPE
227                         throw new NullPointerException("landLineNumber is null"); //NOI18N
228                 } else if (fetchedNumber.getPhoneId() == null) {
229                         // ..and again
230                         throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N
231                 }
232
233                 // Debug message
234                 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N
235
236                 // Init query instance
237                 DialableLandLineNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
238
239                 // Debug message
240                 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N
241
242                 // Default is null
243                 DialableLandLineNumber detachedNumber = null;
244
245                 // Is there a difference?
246                 if (!PhoneUtils.isSameLandLineNumber(landLineNumber, fetchedNumber)) {
247                         // Merge this entry
248                         detachedNumber = this.getEntityManager().merge(foundNumber);
249                 }
250
251                 // Trace message
252                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: detachedNumber={0} - EXIT!", detachedNumber)); //NOI18N
253
254                 // Return it
255                 return detachedNumber;
256         }
257
258         /**
259          * Returnes a detached instance from given fax instance
260          * <p>
261          * @param faxNumber Fax instance
262          * @param fetchedNumber Found fax number in database
263          * <p>
264          * @return Detached instance
265          */
266         protected DialableFaxNumber getDetached (final DialableFaxNumber faxNumber, final DialableFaxNumber fetchedNumber) {
267                 // Trace message
268                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: faxNumber={0},fetchedNumber={1} - CALLED!", faxNumber, fetchedNumber)); //NOI18N
269
270                 // Should be valid
271                 if (null == faxNumber) {
272                         // Throw NPE
273                         throw new NullPointerException("faxNumber is null"); //NOI18N
274                 } else if (fetchedNumber.getPhoneId() == null) {
275                         // ..and again
276                         throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
277                 }
278
279                 // Debug message
280                 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N
281
282                 // Init query instance
283                 DialableFaxNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
284
285                 // Debug message
286                 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N
287
288                 // Default is null
289                 DialableFaxNumber detachedNumber = null;
290
291                 // Is there a difference?
292                 if (!PhoneUtils.isSameFaxNumber(faxNumber, fetchedNumber)) {
293                         // Merge this entry
294                         detachedNumber = this.getEntityManager().merge(foundNumber);
295                 }
296
297                 // Trace message
298                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: detachedNumber={0} - EXIT!", detachedNumber)); //NOI18N
299
300                 // Return it
301                 return detachedNumber;
302         }
303
304         /**
305          * Merges given contact's data
306          * <p>
307          * @param contact Contact instance to merge
308          * <p>
309          * @return Detached contact instance
310          */
311         protected Contact mergeContactData (final Contact contact) {
312                 // Trace message
313                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeContactData: contact={0} - CALLED!", contact)); //NOI18N
314
315                 // The contact instance must be valid
316                 if (null == contact) {
317                         // Throw NPE again
318                         throw new NullPointerException("contact is null"); //NOI18N
319                 } else if (contact.getContactId() == null) {
320                         // Throw NPE again
321                         throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
322                 } else if (contact.getContactId() < 1) {
323                         // Not valid
324                         throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
325                 }
326
327                 // Set updated timestamp
328                 contact.setContactUpdated(new GregorianCalendar());
329
330                 // Get contact from it and find it
331                 Contact foundContact = this.getEntityManager().find(contact.getClass(), contact.getContactId());
332
333                 // Should be found
334                 assert (foundContact instanceof Contact) : MessageFormat.format("Contact with id {0} not found, but should be.", contact.getContactId()); //NOI18N
335
336                 // Debug message
337                 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: foundContact.contactId={0}", foundContact.getContactId())); //NOI18N
338
339                 // Merge contact instance
340                 Contact detachedContact = this.getEntityManager().merge(foundContact);
341
342                 // Copy all
343                 detachedContact.copyAll(contact);
344
345                 // Trace message
346                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeContactData: detachedContact={0} - EXIT!", detachedContact)); //NOI18N
347
348                 // Return detached contact
349                 return detachedContact;
350         }
351
352         /**
353          * Merges given (detached) contact's cellphone, land-line and fax numbers
354          * <p>
355          * @param detachedContact Detached contact instance
356          */
357         protected void mergeContactsMobileLandLineFaxNumbers (final Contact detachedContact) {
358                 // Trace message
359                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeContactsMobileLandLineFaxNumbers: detachedContact={0} - CALLED!", detachedContact)); //NOI18N
360
361                 // The contact instance must be valid
362                 if (null == detachedContact) {
363                         // Throw NPE again
364                         throw new NullPointerException("detachedContact is null"); //NOI18N
365                 } else if (detachedContact.getContactId() == null) {
366                         // Throw NPE again
367                         throw new NullPointerException("detachedContact.contactId is null"); //NOI18N //NOI18N
368                 } else if (detachedContact.getContactId() < 1) {
369                         // Not valid
370                         throw new IllegalStateException(MessageFormat.format("detachedContact.contactId={0} is not valid.", detachedContact.getContactId())); //NOI18N
371                 }
372
373                 // Get all instances
374                 DialableMobileNumber cellphone = detachedContact.getContactMobileNumber();
375                 DialableLandLineNumber landLine = detachedContact.getContactLandLineNumber();
376                 DialableFaxNumber fax = detachedContact.getContactFaxNumber();
377
378                 // Is there a  cellphone instance set?
379                 if (cellphone instanceof DialableMobileNumber) {
380                         // Debug message
381                         this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: cellphone.phoneId={0} is being updated ...", cellphone.getPhoneId())); //NOI18N
382
383                         // Then find it, too
384                         DialableMobileNumber foundMobile = this.getEntityManager().find(cellphone.getClass(), cellphone.getPhoneId());
385
386                         // Should be there
387                         assert (foundMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", foundMobile.getPhoneId()); //NOI18N
388
389                         // Then merge it, too
390                         DialableMobileNumber detachedMobile = this.getEntityManager().merge(foundMobile);
391
392                         // Should be there
393                         assert (detachedMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", detachedMobile.getPhoneId()); //NOI18N
394
395                         // Copy all
396                         detachedMobile.copyAll(detachedContact.getContactMobileNumber());
397
398                         // Set it back
399                         detachedContact.setContactMobileNumber(detachedMobile);
400                 }
401
402                 // Is there a  fax instance set?
403                 if (fax instanceof DialableFaxNumber) {
404                         // Debug message
405                         this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: fax.phoneId={0} is being updated ...", fax.getPhoneId())); //NOI18N
406
407                         // Then find it, too
408                         DialableFaxNumber foundFax = this.getEntityManager().find(fax.getClass(), fax.getPhoneId());
409
410                         // Should be there
411                         assert (foundFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", foundFax.getPhoneId()); //NOI18N
412
413                         // Then merge it, too
414                         DialableFaxNumber detachedFax = this.getEntityManager().merge(foundFax);
415
416                         // Should be there
417                         assert (detachedFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", detachedFax.getPhoneId()); //NOI18N
418
419                         // Copy all
420                         detachedFax.copyAll(detachedContact.getContactFaxNumber());
421
422                         // Set it back
423                         detachedContact.setContactFaxNumber(detachedFax);
424                 }
425
426                 // Is there a  fax instance set?
427                 if (landLine instanceof DialableLandLineNumber) {
428                         // Debug message
429                         this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: landLine.phoneId={0} is being updated ...", landLine.getPhoneId())); //NOI18N
430
431                         // Then find it, too
432                         DialableLandLineNumber foundLandLine = this.getEntityManager().find(landLine.getClass(), landLine.getPhoneId());
433
434                         // Should be there
435                         assert (foundLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", foundLandLine.getPhoneId()); //NOI18N
436
437                         // Then merge it, too
438                         DialableLandLineNumber detachedLandLine = this.getEntityManager().merge(foundLandLine);
439
440                         // Should be there
441                         assert (detachedLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", detachedLandLine.getPhoneId()); //NOI18N
442
443                         // Copy all
444                         detachedLandLine.copyAll(detachedContact.getContactLandLineNumber());
445
446                         // Set it back
447                         detachedContact.setContactLandLineNumber(detachedLandLine);
448                 }
449
450                 // Trace message
451                 this.getLoggerBeanLocal().logTrace("mergeContactsMobileLandLineFaxNumbers: EXIT!"); //NOI18N
452         }
453
454         /**
455          * Sends an email with given subject line, template name to given recipient
456          * and user data
457          * <p>
458          * @param subjectLine Subject line
459          * @param templateName Template name
460          * @param emailAddress Recipient's email address
461          * @param user User instance
462          * @param baseUrl Base URL
463          */
464         protected void sendEmail (final String subjectLine, final String templateName, final Address emailAddress, final User user, final String baseUrl) {
465                 // Trace message
466                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("sendEmail: subjectLine={0},templateName={1},emailAddress={2},user={3},baseUrl={4} - CALLED!", subjectLine, templateName, emailAddress, user, baseUrl)); //NOI18N
467
468                 // All should be set
469                 if (null == subjectLine) {
470                         // Throw NPE
471                         throw new NullPointerException("subjectLine is null"); //NOI18N
472                 } else if (subjectLine.isEmpty()) {
473                         // No subject line
474                         throw new IllegalArgumentException("subjectLine is empty"); //NOI18N
475                 } else if (null == templateName) {
476                         // Throw NPE
477                         throw new NullPointerException("templateName is null"); //NOI18N
478                 } else if (templateName.isEmpty()) {
479                         // No template name
480                         throw new IllegalArgumentException("templateName is empty"); //NOI18N
481                 } else if (null == emailAddress) {
482                         // Throw NPE
483                         throw new NullPointerException("emailAddress is null"); //NOI18N
484                 }
485
486                 // Prepare mail wrapper
487                 WrapableEmailDelivery emailWrapper = new EmailDeliveryWrapper();
488
489                 // Set all values
490                 Properties variables = UserUtils.getAllUserFields(user);
491
492                 // Set base URL
493                 variables.put("baseUrl", baseUrl); //NOI18N
494
495                 // Set all
496                 // @TODO Language from message bundle
497                 emailWrapper.setRecipient(emailAddress);
498                 emailWrapper.setLocale(user.getUserLocale());
499                 emailWrapper.setSubjectLine(subjectLine);
500                 emailWrapper.setTemplateName(templateName);
501                 emailWrapper.setTemplateVariables(variables);
502
503                 try {
504                         // Send out email change
505                         ObjectMessage message = this.session.createObjectMessage();
506                         message.setObject(emailWrapper);
507
508                         // Send message
509                         this.sendMessage(message, this.messageProducer);
510                 } catch (final JMSException ex) {
511                         // Throw again
512                         throw new EJBException(ex);
513                 }
514
515                 // Trace message
516                 this.getLoggerBeanLocal().logTrace("sendEmail: EXIT!"); //NOI18N
517         }
518
519         /**
520          * Updates all contact's phone instances from other contact, both contacts
521          * should be the same.
522          * <p>
523          * @param contact Contact to set instances
524          * @param other Other contact to get instances from
525          */
526         protected void setAllContactPhoneEntries (final Contact contact, final Contact other) {
527                 // Trace message
528                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("setAllContactPhoneEntries: contact={0},other={1} - CALLED!", contact, other)); //NOI18N
529
530                 // Both must be the same and not null
531                 if (null == contact) {
532                         // Throw NPE
533                         throw new NullPointerException("contact is null"); //NOI18N
534                 } else if (null == other) {
535                         // Throw NPE
536                         throw new NullPointerException("other is null"); //NOI18N
537                 } else if (!Objects.equals(contact, other)) {
538                         // Not same instances
539                         throw new IllegalArgumentException(MessageFormat.format("contact={0} and other={1} are not equal!", contact, other)); //NOI18N
540                 }
541
542                 // Debug message
543                 this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllContactPhoneEntries: other.contactMobileNumber={0}", other.getContactMobileNumber())); //NOI18N
544
545                 // Is other cellphone not set?
546                 if ((other.getContactMobileNumber() == null) || (PhoneUtils.isSameMobileNumber(contact.getContactMobileNumber(), other.getContactMobileNumber()))) {
547                         // Debug message
548                         this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntries: Copying cellphone entry ..."); //NOI18N
549
550                         // Is the fax number set?
551                         if (other.getContactMobileNumber() instanceof DialableMobileNumber) {
552                                 // Copy cellphone number
553                                 contact.setContactMobileNumber(this.getDetached(other.getContactMobileNumber(), contact.getContactMobileNumber()));
554                         } else {
555                                 // Null it
556                                 contact.setContactMobileNumber(null);
557                         }
558                 }
559
560                 // Debug message
561                 this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllContactPhoneEntries: other.contactLandLineNumber={0}", other.getContactLandLineNumber())); //NOI18N
562
563                 // Is other cellphone not set?
564                 if ((other.getContactLandLineNumber() == null) || (PhoneUtils.isSameLandLineNumber(contact.getContactLandLineNumber(), other.getContactLandLineNumber()))) {
565                         // Debug message
566                         this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntries: Copying land-line entry ..."); //NOI18N
567
568                         // Is the land-line number set?
569                         if (other.getContactLandLineNumber() instanceof DialableLandLineNumber) {
570                                 // Copy land-line number
571                                 contact.setContactLandLineNumber(this.getDetached(other.getContactLandLineNumber(), contact.getContactLandLineNumber()));
572                         } else {
573                                 // Null it
574                                 contact.setContactLandLineNumber(null);
575                         }
576                 }
577
578                 // Debug message
579                 this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllContactPhoneEntries: other.contactFaxNumber={0}", other.getContactFaxNumber())); //NOI18N
580
581                 // Is other cellphone not set?
582                 if ((other.getContactFaxNumber() == null) || (PhoneUtils.isSameFaxNumber(contact.getContactFaxNumber(), other.getContactFaxNumber()))) {
583                         // Debug message
584                         this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntries: Copying fax entry ..."); //NOI18N
585
586                         // Is the fax number set?
587                         if (other.getContactFaxNumber() instanceof DialableFaxNumber) {
588                                 // Copy fax number
589                                 contact.setContactFaxNumber(this.getDetached(other.getContactFaxNumber(), contact.getContactFaxNumber()));
590                         } else {
591                                 // Null it
592                                 contact.setContactFaxNumber(null);
593                         }
594                 }
595
596                 // Trace message
597                 this.getLoggerBeanLocal().logTrace("setAllContactPhoneEntries: EXIT!"); //NOI18N
598         }
599
600         /**
601          * Updates all contacts's phone entry's updated timestamps
602          * <p>
603          * @param contact Contact instance to update
604          * @param isMobileUnlinked Whether a cellphone entry has been unlinked in
605          * contact instance
606          * @param isLandlineUnlinked Whether a land-line entry has been unlinked in
607          * contact instance
608          * @param isFaxUnlinked Whether a fax entry has been unlinked in contact
609          * instance
610          */
611         protected void setAllContactPhoneEntriesUpdated (final Contact contact, final boolean isMobileUnlinked, final boolean isLandlineUnlinked, final boolean isFaxUnlinked) {
612                 // Trace message
613                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("setAllContactPhoneEntriesUpdated: contact={0},isMobileUnlinked={1},isLandlineUnlinked={2},isFaxUnlinked={3} - CALLED", contact, isMobileUnlinked, isLandlineUnlinked, isFaxUnlinked)); //NOI18N
614
615                 // The contact instance must be valid
616                 if (null == contact) {
617                         // Throw NPE again
618                         throw new NullPointerException("contact is null"); //NOI18N
619                 } else if (contact.getContactId() == null) {
620                         // Throw NPE again
621                         throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
622                 } else if (contact.getContactId() < 1) {
623                         // Not valid
624                         throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
625                 }
626
627                 // Get all phone instances
628                 DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber();
629                 DialableFaxNumber faxNumber = contact.getContactFaxNumber();
630                 DialableMobileNumber cellphoneNumber = contact.getContactMobileNumber();
631
632                 // Flags and instances must be constistent
633                 if (isMobileUnlinked && cellphoneNumber instanceof DialableMobileNumber) {
634                         // Bad state
635                         throw new IllegalStateException("isCellPhoneUnlinked is TRUE, but cellphoneNumber is set."); //NOI18N
636                 } else if (isLandlineUnlinked && landLineNumber instanceof DialableLandLineNumber) {
637                         // Bad state
638                         throw new IllegalStateException("isLandlineUnlinked is TRUE, but landLineNumber is set."); //NOI18N
639                 } else if (isFaxUnlinked && faxNumber instanceof DialableFaxNumber) {
640                         // Bad state
641                         throw new IllegalStateException("isFaxUnlinked is TRUE, but faxNumber is set."); //NOI18N
642                 }
643
644                 // Is a phone number instance set?
645                 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() instanceof Long) && (landLineNumber.getPhoneId() > 0)) {
646                         // Debug message
647                         this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntriesUpdated: Setting updated timestamp for land-line number ..."); //NOI18N
648
649                         // Set updated timestamp
650                         landLineNumber.setPhoneEntryUpdated(new GregorianCalendar());
651                 }
652
653                 // Is a fax number instance set?
654                 if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() instanceof Long) && (faxNumber.getPhoneId() > 0)) {
655                         // Debug message
656                         this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntriesUpdated: Setting updated timestamp for fax number ..."); //NOI18N
657
658                         // Set updated timestamp
659                         faxNumber.setPhoneEntryUpdated(new GregorianCalendar());
660                 }
661
662                 // Is a mobile number instance set?
663                 if ((cellphoneNumber instanceof DialableMobileNumber) && (cellphoneNumber.getPhoneId() instanceof Long) && (cellphoneNumber.getPhoneId() > 0)) {
664                         // Debug message
665                         this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntriesUpdated: Setting updated timestamp for cellphone number ..."); //NOI18N
666
667                         // Set updated timestamp
668                         cellphoneNumber.setPhoneEntryUpdated(new GregorianCalendar());
669                 }
670
671                 // Trace message
672                 this.getLoggerBeanLocal().logTrace("setAllContactPhoneEntriesUpdated: EXIT!"); //NOI18N
673         }
674
675 }