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