2 * Copyright (C) 2016, 2017 Roland Häder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.jjobs.database;
19 import java.text.MessageFormat;
20 import java.util.Date;
21 import java.util.List;
22 import java.util.Objects;
23 import java.util.Properties;
24 import javax.ejb.EJBException;
25 import javax.jms.JMSException;
26 import javax.jms.ObjectMessage;
27 import javax.mail.Address;
28 import javax.mail.internet.AddressException;
29 import javax.mail.internet.InternetAddress;
30 import org.mxchange.jcontacts.model.contact.Contact;
31 import org.mxchange.jcontacts.model.contact.ContactUtils;
32 import org.mxchange.jcontacts.model.contact.UserContact;
33 import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData;
34 import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
35 import org.mxchange.jcontactsbusiness.model.branchoffice.BusinessBranchOffice;
36 import org.mxchange.jcontactsbusiness.model.employee.BusinessEmployee;
37 import org.mxchange.jcontactsbusiness.model.headquarters.CompanyHeadquartersData;
38 import org.mxchange.jcontactsbusiness.model.headquarters.HeadquartersData;
39 import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime;
40 import org.mxchange.jcoreee.database.BaseDatabaseBean;
41 import org.mxchange.jcountry.model.data.Country;
42 import org.mxchange.jcountry.model.data.CountryData;
43 import org.mxchange.jmailee.model.delivery.wrapper.EmailDeliveryWrapper;
44 import org.mxchange.jmailee.model.delivery.wrapper.WrapableEmailDelivery;
45 import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
46 import org.mxchange.jphone.model.phonenumbers.fax.FaxNumbers;
47 import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
48 import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumbers;
49 import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
50 import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumbers;
51 import org.mxchange.jphone.utils.PhoneUtils;
52 import org.mxchange.jusercore.model.user.LoginUser;
53 import org.mxchange.jusercore.model.user.User;
54 import org.mxchange.jusercore.model.user.UserUtils;
55 import org.mxchange.jcontactsbusiness.model.employee.Employable;
56 import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
59 * A helper class for beans that access the database.
61 * @author Roland Häder<roland@mxchange.org>
63 public abstract class BaseJobsDatabaseBean extends BaseDatabaseBean {
68 private static final long serialVersionUID = 12_895_410_275_811_963L;
71 * Protected constructor
73 protected BaseJobsDatabaseBean () {
74 // Call super constructor
79 * Constructor with queue factory JNDI and queue JNDI names
81 * @param factoryJndi JNDI name for queue factory
82 * @param queueJndi JNDI name for email queue
84 protected BaseJobsDatabaseBean (final String factoryJndi, final String queueJndi) {
85 // Call super constructor
86 super(factoryJndi, queueJndi);
90 * Updates all contact's phone entry's created timestamps
92 * @param contact Contact instance to update
94 protected void setAllContactPhoneEntriesCreated (final Contact contact) {
96 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N
98 // The contact instance must be valid
99 if (null == contact) {
101 throw new NullPointerException("contact is null"); //NOI18N
104 // Get all phone instances
105 final DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber();
106 final DialableFaxNumber faxNumber = contact.getContactFaxNumber();
107 final DialableMobileNumber mobileNumber = contact.getContactMobileNumber();
110 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: landLineNumber={1},faxNumber={2},mobileNumber={3}", this.getClass().getSimpleName(), landLineNumber, faxNumber, mobileNumber)); //NOI18N
112 // Is a phone number instance set?
113 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() == null)) {
115 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for land-line number ...", this.getClass().getSimpleName())); //NOI18N
117 // Set updated timestamp
118 landLineNumber.setPhoneEntryCreated(new Date());
121 // Is a fax number instance set?
122 if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() == null)) {
124 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for fax number ...", this.getClass().getSimpleName())); //NOI18N
126 // Set updated timestamp
127 faxNumber.setPhoneEntryCreated(new Date());
130 // Is a mobile number instance set?
131 if ((mobileNumber instanceof DialableMobileNumber) && (mobileNumber.getPhoneId() == null)) {
133 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for mobile number ...", this.getClass().getSimpleName())); //NOI18N
135 // Set updated timestamp
136 mobileNumber.setPhoneEntryCreated(new Date());
140 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: EXIT!", this.getClass().getSimpleName())); //NOI18N
144 * Returns a managed instance from given mobile number
146 * @param mobileNumber Mobile instance
147 * @param fetchedNumber Found mobile number in database
149 * @return Managed instance
151 protected DialableMobileNumber getManaged (final DialableMobileNumber mobileNumber, final DialableMobileNumber fetchedNumber) {
153 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: mobileNumber={1},fetchedNumber={2} - CALLED!", this.getClass().getSimpleName(), mobileNumber, fetchedNumber)); //NOI18N
156 if (null == mobileNumber) {
158 throw new NullPointerException("mobileNumber is null"); //NOI18N
159 } else if (null == fetchedNumber) {
161 throw new NullPointerException("fetchedNumber is null"); //NOI18N
162 } else if (fetchedNumber.getPhoneId() == null) {
164 throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
168 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N
170 // Init query instance
171 final DialableMobileNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
174 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N
177 DialableMobileNumber detachedNumber = null;
179 // Is there a difference?
180 if (!PhoneUtils.isSameMobileNumber(mobileNumber, fetchedNumber)) {
182 detachedNumber = this.getEntityManager().merge(foundNumber);
188 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: detachedNumber={1} - EXIT!", this.getClass().getSimpleName(), detachedNumber)); //NOI18N
191 return detachedNumber;
195 * Returns a managed instance from given land-line number
197 * @param landLineNumber Land-line instance
198 * @param fetchedNumber Found land-line number in database
200 * @return Managed instance
202 protected DialableLandLineNumber getManaged (final DialableLandLineNumber landLineNumber, final DialableLandLineNumber fetchedNumber) {
204 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: landLineNumber={1},fetchedNumber={2} - CALLED!", this.getClass().getSimpleName(), landLineNumber, fetchedNumber)); //NOI18N
207 if (null == landLineNumber) {
209 throw new NullPointerException("landLineNumber is null"); //NOI18N
210 } else if (null == fetchedNumber) {
212 throw new NullPointerException("fetchedNumber is null"); //NOI18N
213 } else if (fetchedNumber.getPhoneId() == null) {
215 throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N
219 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N
221 // Init query instance
222 final DialableLandLineNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
225 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N
228 DialableLandLineNumber detachedNumber = null;
230 // Is there a difference?
231 if (!PhoneUtils.isSameLandLineNumber(landLineNumber, fetchedNumber)) {
233 detachedNumber = this.getEntityManager().merge(foundNumber);
239 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), detachedNumber)); //NOI18N
242 return detachedNumber;
246 * Returns a managed instance from given fax number
248 * @param faxNumber Fax instance
249 * @param fetchedNumber Found fax number in database
251 * @return Managed instance
253 protected DialableFaxNumber getManaged (final DialableFaxNumber faxNumber, final DialableFaxNumber fetchedNumber) {
255 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: faxNumber={1},fetchedNumber={2} - CALLED!", this.getClass().getSimpleName(), faxNumber, fetchedNumber)); //NOI18N
258 if (null == faxNumber) {
260 throw new NullPointerException("faxNumber is null"); //NOI18N
261 } else if (null == fetchedNumber) {
263 throw new NullPointerException("fetchedNumber is null"); //NOI18N
264 } else if (fetchedNumber.getPhoneId() == null) {
266 throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
270 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N
272 // Init query instance
273 final DialableFaxNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
276 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N
279 DialableFaxNumber detachedNumber = null;
281 // Is there a difference?
282 if (!PhoneUtils.isSameFaxNumber(faxNumber, fetchedNumber)) {
284 detachedNumber = this.getEntityManager().merge(foundNumber);
290 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), detachedNumber)); //NOI18N
293 return detachedNumber;
297 * Get back a managed instance from given contact
299 * @param contact Unmanaged/detached contact instance
301 * @return Managed contact instance
303 protected Contact createManaged (final Contact contact) {
305 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N
307 // user should not be null
308 if (null == contact) {
310 throw new NullPointerException("contact is null"); //NOI18N
311 } else if (contact.getContactId() == null) {
313 throw new NullPointerException("contact.contactId is null"); //NOI18N
314 } else if (contact.getContactId() < 1) {
316 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
319 // Try to find it (should be there)
320 final Contact managedContact = this.getEntityManager().find(UserContact.class, contact.getContactId());
323 assert (managedContact instanceof Contact) : "managedContact is null"; //NOI18N
326 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N
329 return managedContact;
333 * Get back a managed instance from given country
335 * @param country Unmanaged/detached country instance
337 * @return Managed country instance
339 protected Country createManaged (final Country country) {
341 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: country={1} - CALLED!", this.getClass().getSimpleName(), country)); //NOI18N
343 // user should not be null
344 if (null == country) {
346 throw new NullPointerException("country is null"); //NOI18N
347 } else if (country.getCountryId() == null) {
349 throw new NullPointerException("country.countryId is null"); //NOI18N
350 } else if (country.getCountryId() < 1) {
352 throw new IllegalArgumentException(MessageFormat.format("country.countryId={0} is invalid", country.getCountryId())); //NOI18N
355 // Try to find it (should be there)
356 final Country managedCountry = this.getEntityManager().find(CountryData.class, country.getCountryId());
359 assert (managedCountry instanceof Country) : "managedCountry is null"; //NOI18N
362 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedCountry={1} - EXIT!", this.getClass().getSimpleName(), managedCountry)); //NOI18N
365 return managedCountry;
369 * Get back a managed instance from given basic data
371 * @param basicData Unmanaged/detached basic data instance
373 * @return Managed basic data instance
375 protected BasicData createManaged (final BasicData basicData) {
377 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: basicData={1} - CALLED!", this.getClass().getSimpleName(), basicData)); //NOI18N
379 // user should not be null
380 if (null == basicData) {
382 throw new NullPointerException("basicData is null"); //NOI18N
383 } else if (basicData.getBasicDataId() == null) {
385 throw new NullPointerException("basicData.basicDataId is null"); //NOI18N
386 } else if (basicData.getBasicDataId() < 1) {
388 throw new IllegalArgumentException(MessageFormat.format("basicData.basicDataId={0} is invalid", basicData.getBasicDataId())); //NOI18N
391 // Try to find it (should be there)
392 final BasicData managedBasicData = this.getEntityManager().find(BusinessBasicData.class, basicData.getBasicDataId());
395 assert (managedBasicData instanceof BasicData) : "managedBasicData is null"; //NOI18N
398 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedBasicData={1} - EXIT!", this.getClass().getSimpleName(), managedBasicData)); //NOI18N
401 return managedBasicData;
405 * Get back a managed instance from given branch office
407 * @param branchOffice Unmanaged/detached branch office instance
409 * @return Managed basic data instance
411 protected BranchOffice createManaged (final BranchOffice branchOffice) {
413 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: branchOffice={1} - CALLED!", this.getClass().getSimpleName(), branchOffice)); //NOI18N
415 // user should not be null
416 if (null == branchOffice) {
418 throw new NullPointerException("branchOffice is null"); //NOI18N
419 } else if (branchOffice.getBranchId() == null) {
421 throw new NullPointerException("branchOffice.branchOfficeId is null"); //NOI18N
422 } else if (branchOffice.getBranchId() < 1) {
424 throw new IllegalArgumentException(MessageFormat.format("branchOffice.branchOfficeId={0} is invalid", branchOffice.getBranchId())); //NOI18N
427 // Try to find it (should be there)
428 final BranchOffice managedBranchOffice = this.getEntityManager().find(BusinessBranchOffice.class, branchOffice.getBranchId());
431 assert (managedBranchOffice instanceof BasicData) : "managedBranchOffice is null"; //NOI18N
434 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedBranchOffice={1} - EXIT!", this.getClass().getSimpleName(), managedBranchOffice)); //NOI18N
437 return managedBranchOffice;
441 * Get back a managed instance from given employee
443 * @param employee Unmanaged/detached employee instance
445 * @return Managed employee instance
447 protected Employable createManaged (final Employable employee) {
449 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: employee={1} - CALLED!", this.getClass().getSimpleName(), employee)); //NOI18N
451 // user should not be null
452 if (null == employee) {
454 throw new NullPointerException("employee is null"); //NOI18N
455 } else if (employee.getEmployeeId() == null) {
457 throw new NullPointerException("employee.employeeId is null"); //NOI18N
458 } else if (employee.getEmployeeId() < 1) {
460 throw new IllegalArgumentException(MessageFormat.format("employee.employeeId={0} is invalid", employee.getEmployeeId())); //NOI18N
463 // Try to find it (should be there)
464 final Employable managedEmployee = this.getEntityManager().find(BusinessEmployee.class, employee.getEmployeeId());
467 assert (managedEmployee instanceof Employable) : "managedEmployee is null"; //NOI18N
470 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedEmployee={1} - EXIT!", this.getClass().getSimpleName(), managedEmployee)); //NOI18N
473 return managedEmployee;
477 * Get back a managed instance from given headquarters
479 * @param headquarters Unmanaged/detached headquarters instance
481 * @return Managed basic data instance
483 protected HeadquartersData createManaged (final HeadquartersData headquarters) {
485 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: branchOffice={1} - CALLED!", this.getClass().getSimpleName(), headquarters)); //NOI18N
487 // user should not be null
488 if (null == headquarters) {
490 throw new NullPointerException("branchOffice is null"); //NOI18N
491 } else if (headquarters.getHeadquartersId() == null) {
493 throw new NullPointerException("branchOffice.headquartersId is null"); //NOI18N
494 } else if (headquarters.getHeadquartersId() < 1) {
496 throw new IllegalArgumentException(MessageFormat.format("branchOffice.headquartersId={0} is invalid", headquarters.getHeadquartersId())); //NOI18N
499 // Try to find it (should be there)
500 final HeadquartersData managedHeadquarters = this.getEntityManager().find(CompanyHeadquartersData.class, headquarters.getHeadquartersId());
503 assert (managedHeadquarters instanceof BasicData) : "managedHeadquarters is null"; //NOI18N
506 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedHeadquarters={1} - EXIT!", this.getClass().getSimpleName(), managedHeadquarters)); //NOI18N
509 return managedHeadquarters;
513 * Get back a managed instance from given user
515 * @param user Unmanaged/detached user instance
517 * @return Managed user instance
519 protected User createManaged (final User user) {
521 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
523 // user should not be null
526 throw new NullPointerException("user is null"); //NOI18N
527 } else if (user.getUserId() == null) {
529 throw new NullPointerException("user.userId is null"); //NOI18N
530 } else if (user.getUserId() < 1) {
532 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); //NOI18N
533 } else if (user.getUserContact() == null) {
535 throw new NullPointerException("user.userContact is null"); //NOI18N
536 } else if (user.getUserContact().getContactId() == null) {
538 throw new NullPointerException("user.userContact.contactId is null"); //NOI18N
539 } else if (user.getUserContact().getContactId() < 1) {
540 // Not valid id number
541 throw new IllegalArgumentException(MessageFormat.format("user.userContact.contactId={0} is not valid", user.getUserContact().getContactId())); //NOI18N#
544 // Try to find it (should be there)
545 final User managedUser = this.getEntityManager().find(LoginUser.class, user.getUserId());
548 assert (managedUser instanceof User) : "managedUser is null"; //NOI18N
551 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedUser={1} - EXIT!", this.getClass().getSimpleName(), managedUser)); //NOI18N
558 * Sets created timestamp on all opening times.
560 * @param openingTimes Opening times list
562 * @throws NullPointerException If given list is null
563 * @throws IllegalArgumentException If given list is empty
564 * @throws IllegalStateException If openingId is not null
566 protected void setAllOpeningTimesCreated (final List<OpeningTime> openingTimes) {
567 // Validate parameter
568 if (null == openingTimes) {
570 throw new NullPointerException("openingTimes is null");
571 } else if (openingTimes.isEmpty()) {
573 throw new IllegalArgumentException("openingTimes is empty");
576 // Walk through whole list
577 for (final OpeningTime openingTime : openingTimes) {
578 // Id should not be set
579 if (openingTime.getOpeningId() != null) {
581 throw new IllegalStateException("openingTime.openingId is not null");
584 // Set created timestamp
585 openingTime.setOpeningCreated(new Date());
590 * Updates all contact's phone entry's created timestamps
592 * @param contact Contact instance to update
594 protected void setAllPhoneEntriesCreated (final Contact contact) {
596 this.getLoggerBeanLocal().logTrace(MessageFormat.format("setAllPhoneEntriesCreated: contact={0} - CALLED!", contact)); //NOI18N
598 // The contact instance must be valid
599 if (null == contact) {
601 throw new NullPointerException("contact is null"); //NOI18N
602 } else if (contact.getContactId() != null) {
604 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is unexpected.", contact.getContactId()));
607 // Get all phone instances
608 final DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber();
609 final DialableFaxNumber faxNumber = contact.getContactFaxNumber();
610 final DialableMobileNumber mobileNumber = contact.getContactMobileNumber();
613 this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllPhoneEntriesCreated: landLineNumber={0},faxNumber={1},mobileNumber={2}", landLineNumber, faxNumber, mobileNumber)); //NOI18N
615 // Is a phone number instance set?
616 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() == null)) {
618 this.getLoggerBeanLocal().logDebug("setAllPhoneEntriesCreated: Setting created timestamp for land-line number ..."); //NOI18N
620 // Set updated timestamp
621 landLineNumber.setPhoneEntryCreated(new Date());
624 // Is a fax number instance set?
625 if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() == null)) {
627 this.getLoggerBeanLocal().logDebug("setAllPhoneEntriesCreated: Setting created timestamp for fax number ..."); //NOI18N
629 // Set updated timestamp
630 faxNumber.setPhoneEntryCreated(new Date());
633 // Is a mobile number instance set?
634 if ((mobileNumber instanceof DialableMobileNumber) && (mobileNumber.getPhoneId() == null)) {
636 this.getLoggerBeanLocal().logDebug("setAllPhoneEntriesCreated: Setting created timestamp for mobile number ..."); //NOI18N
638 // Set updated timestamp
639 mobileNumber.setPhoneEntryCreated(new Date());
643 this.getLoggerBeanLocal().logTrace("setAllPhoneEntriesCreated: EXIT!"); //NOI18N
647 * Updates all branch office's phone entry's created timestamps
649 * @param branchOffice Branch office instance to update
651 protected void setAllPhoneEntriesCreated (final BranchOffice branchOffice) {
653 this.getLoggerBeanLocal().logTrace(MessageFormat.format("setAllPhoneEntriesCreated: branchOffice={0} - CALLED!", branchOffice)); //NOI18N
655 // The contact instance must be valid
656 if (null == branchOffice) {
658 throw new NullPointerException("branchOffice is null"); //NOI18N
659 } else if (branchOffice.getBranchId() != null) {
661 throw new IllegalArgumentException(MessageFormat.format("branchOffice.branchId={0} is unexpected.", branchOffice.getBranchId()));
664 // Get all phone instances
665 final DialableLandLineNumber landLineNumber = branchOffice.getBranchLandLineNumber();
666 final DialableFaxNumber faxNumber = branchOffice.getBranchFaxNumber();
669 this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllPhoneEntriesCreated: landLineNumber={0},faxNumber={1}", landLineNumber, faxNumber)); //NOI18N
671 // Is a phone number instance set?
672 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() == null)) {
674 this.getLoggerBeanLocal().logDebug("setAllPhoneEntriesCreated: Setting created timestamp for land-line number ..."); //NOI18N
676 // Set updated timestamp
677 landLineNumber.setPhoneEntryCreated(new Date());
680 // Is a fax number instance set?
681 if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() == null)) {
683 this.getLoggerBeanLocal().logDebug("setAllPhoneEntriesCreated: Setting created timestamp for fax number ..."); //NOI18N
685 // Set updated timestamp
686 faxNumber.setPhoneEntryCreated(new Date());
690 this.getLoggerBeanLocal().logTrace("setAllPhoneEntriesCreated: EXIT!"); //NOI18N
694 * Updates all company's phone entry's created timestamps
696 * @param basicData Company basic data instance to update
698 protected void setAllPhoneEntriesCreated (final BasicData basicData) {
700 this.getLoggerBeanLocal().logTrace(MessageFormat.format("setAllPhoneEntriesCreated: basicData={0} - CALLED!", basicData)); //NOI18N
702 // The contact instance must be valid
703 if (null == basicData) {
705 throw new NullPointerException("basicData is null"); //NOI18N
706 } else if (basicData.getBasicDataId() != null) {
708 throw new IllegalArgumentException(MessageFormat.format("basicData.basicDataId={0} is unexpected.", basicData.getBasicDataId()));
711 // Get all phone instances
712 final DialableLandLineNumber landLineNumber = basicData.getCompanyLandLineNumber();
713 final DialableFaxNumber faxNumber = basicData.getCompanyFaxNumber();
716 this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllPhoneEntriesCreated: landLineNumber={0},faxNumber={1}", landLineNumber, faxNumber)); //NOI18N
718 // Is a phone number instance set?
719 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() == null)) {
721 this.getLoggerBeanLocal().logDebug("setAllPhoneEntriesCreated: Setting created timestamp for land-line number ..."); //NOI18N
723 // Set updated timestamp
724 landLineNumber.setPhoneEntryCreated(new Date());
726 // Set it back in basic data
727 basicData.setCompanyLandLineNumber(landLineNumber);
730 // Is a fax number instance set?
731 if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() == null)) {
733 this.getLoggerBeanLocal().logDebug("setAllPhoneEntriesCreated: Setting created timestamp for fax number ..."); //NOI18N
735 // Set updated timestamp
736 faxNumber.setPhoneEntryCreated(new Date());
738 // Set it back in basic data
739 basicData.setCompanyFaxNumber(faxNumber);
743 this.getLoggerBeanLocal().logTrace("setAllPhoneEntriesCreated: EXIT!"); //NOI18N
747 * Returns a detached instance from given mobile instance
749 * @param mobileNumber Mobile instance
750 * @param fetchedNumber Found mobile number in database
752 * @return Detached instance
754 protected DialableMobileNumber getDetached (final DialableMobileNumber mobileNumber, final DialableMobileNumber fetchedNumber) {
756 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: mobileNumber={0},fetchedNumber={1} - CALLED!", mobileNumber, fetchedNumber)); //NOI18N
759 if (null == mobileNumber) {
761 throw new NullPointerException("mobileNumber is null"); //NOI18N
762 } else if (fetchedNumber.getPhoneId() == null) {
764 throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
768 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N
770 // Init query instance
771 final DialableMobileNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
774 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N
777 DialableMobileNumber detachedNumber = null;
779 // Is there a difference?
780 if (!PhoneUtils.isSameMobileNumber(mobileNumber, fetchedNumber)) {
782 detachedNumber = this.getEntityManager().merge(foundNumber);
788 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: detachedNumber={0} - EXIT!", detachedNumber)); //NOI18N
791 return detachedNumber;
795 * Returns a detached instance from given land-line instance
797 * @param landLineNumber Land-line instance
798 * @param fetchedNumber Found land-line number in database
800 * @return Detached instance
802 protected DialableLandLineNumber getDetached (final DialableLandLineNumber landLineNumber, final DialableLandLineNumber fetchedNumber) {
804 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: landLineNumber={0},fetchedNumber={1} - CALLED!", landLineNumber, fetchedNumber)); //NOI18N
807 if (null == landLineNumber) {
809 throw new NullPointerException("landLineNumber is null"); //NOI18N
810 } else if (fetchedNumber.getPhoneId() == null) {
812 throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N
816 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N
818 // Init query instance
819 final DialableLandLineNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
822 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N
825 DialableLandLineNumber detachedNumber = null;
827 // Is there a difference?
828 if (!PhoneUtils.isSameLandLineNumber(landLineNumber, fetchedNumber)) {
830 detachedNumber = this.getEntityManager().merge(foundNumber);
836 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: detachedNumber={0} - EXIT!", detachedNumber)); //NOI18N
839 return detachedNumber;
843 * Returns a detached instance from given fax instance
845 * @param faxNumber Fax instance
846 * @param fetchedNumber Found fax number in database
848 * @return Detached instance
850 protected DialableFaxNumber getDetached (final DialableFaxNumber faxNumber, final DialableFaxNumber fetchedNumber) {
852 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: faxNumber={0},fetchedNumber={1} - CALLED!", faxNumber, fetchedNumber)); //NOI18N
855 if (null == faxNumber) {
857 throw new NullPointerException("faxNumber is null"); //NOI18N
858 } else if (fetchedNumber.getPhoneId() == null) {
860 throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
864 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N
866 // Init query instance
867 final DialableFaxNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
870 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N
873 DialableFaxNumber detachedNumber = null;
875 // Is there a difference?
876 if (!PhoneUtils.isSameFaxNumber(faxNumber, fetchedNumber)) {
878 detachedNumber = this.getEntityManager().merge(foundNumber);
884 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: detachedNumber={0} - EXIT!", detachedNumber)); //NOI18N
887 return detachedNumber;
891 * Merges given contact's data
893 * @param detachedContact Contact instance to merge
895 * @return Detached contact instance
897 protected Contact mergeContactData (final Contact detachedContact) {
899 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactData: contact={1} - CALLED!", this.getClass().getSimpleName(), detachedContact)); //NOI18N
901 // The contact instance must be valid
902 if (null == detachedContact) {
904 throw new NullPointerException("detachedContact is null"); //NOI18N
905 } else if (detachedContact.getContactId() == null) {
907 throw new NullPointerException("detachedContact.contactId is null"); //NOI18N //NOI18N
908 } else if (detachedContact.getContactId() < 1) {
910 throw new IllegalStateException(MessageFormat.format("{0}.detachedContact.contactId={1} is not valid.", this.getClass().getSimpleName(), detachedContact.getContactId())); //NOI18N
913 // Set updated timestamp
914 detachedContact.setContactUpdated(new Date());
916 // Get contact from it and find it
917 final Contact foundContact = this.getEntityManager().find(detachedContact.getClass(), detachedContact.getContactId());
920 assert (foundContact instanceof Contact) : MessageFormat.format("Contact with id {0} not found, but should be.", detachedContact.getContactId()); //NOI18N
923 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.updateUserPersonalData: foundContact.contactId={1}", this.getClass().getSimpleName(), foundContact.getContactId())); //NOI18N
925 // Is a fax number set?
926 if (detachedContact.getContactFaxNumber() instanceof DialableFaxNumber) {
927 // Make fax numbers managed
928 foundContact.setContactFaxNumber(this.getManaged(detachedContact.getContactFaxNumber(), detachedContact.getContactFaxNumber()));
931 // Is a land-line number set?
932 if (detachedContact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
933 // Make land-line numbers managed
934 foundContact.setContactLandLineNumber(this.getManaged(detachedContact.getContactLandLineNumber(), detachedContact.getContactLandLineNumber()));
937 // Is a mobile number set?
938 if (detachedContact.getContactMobileNumber() instanceof DialableMobileNumber) {
939 // Make mobile numbers managed
940 foundContact.setContactMobileNumber(this.getManaged(detachedContact.getContactMobileNumber(), detachedContact.getContactMobileNumber()));
943 // Merge contact instance
944 final Contact managedContact = this.getEntityManager().merge(foundContact);
947 ContactUtils.copyAll(detachedContact, managedContact);
950 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactData: foundContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N
952 // Return detached contact
953 return managedContact;
957 * Merges given (detached) contact's mobile, land-line and fax numbers
959 * @param detachedContact Detached contact instance
961 protected void mergeContactsMobileLandLineFaxNumbers (final Contact detachedContact) {
963 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactsMobileLandLineFaxNumbers: detachedContact={1} - CALLED!", this.getClass().getSimpleName(), detachedContact)); //NOI18N
965 // The contact instance must be valid
966 if (null == detachedContact) {
968 throw new NullPointerException("detachedContact is null"); //NOI18N
969 } else if (detachedContact.getContactId() == null) {
971 throw new NullPointerException("detachedContact.contactId is null"); //NOI18N //NOI18N
972 } else if (detachedContact.getContactId() < 1) {
974 throw new IllegalStateException(MessageFormat.format("{0}.detachedContact.contactId={1} is not valid.", this.getClass().getSimpleName(), detachedContact.getContactId())); //NOI18N
978 final DialableMobileNumber mobile = detachedContact.getContactMobileNumber();
979 final DialableLandLineNumber landLine = detachedContact.getContactLandLineNumber();
980 final DialableFaxNumber fax = detachedContact.getContactFaxNumber();
982 // Is there a mobile instance set?
983 if (mobile instanceof DialableMobileNumber) {
985 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: mobile.phoneId={0} is being updated ...", mobile.getPhoneId())); //NOI18N
988 final DialableMobileNumber foundMobile = this.getEntityManager().find(mobile.getClass(), mobile.getPhoneId());
991 assert (foundMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", foundMobile.getPhoneId()); //NOI18N
993 // Then merge it, too
994 final DialableMobileNumber managedMobile = this.getEntityManager().merge(foundMobile);
997 assert (managedMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", managedMobile.getPhoneId()); //NOI18N
1000 MobileNumbers.copyAll(detachedContact.getContactMobileNumber(), managedMobile);
1003 detachedContact.setContactMobileNumber(managedMobile);
1006 // Is there a fax instance set?
1007 if (fax instanceof DialableFaxNumber) {
1009 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: fax.phoneId={0} is being updated ...", fax.getPhoneId())); //NOI18N
1011 // Then find it, too
1012 final DialableFaxNumber foundFax = this.getEntityManager().find(fax.getClass(), fax.getPhoneId());
1015 assert (foundFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", foundFax.getPhoneId()); //NOI18N
1017 // Then merge it, too
1018 final DialableFaxNumber managedFax = this.getEntityManager().merge(foundFax);
1021 assert (managedFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", managedFax.getPhoneId()); //NOI18N
1024 FaxNumbers.copyAll(detachedContact.getContactFaxNumber(), managedFax);
1027 detachedContact.setContactFaxNumber(managedFax);
1030 // Is there a fax instance set?
1031 if (landLine instanceof DialableLandLineNumber) {
1033 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: landLine.phoneId={0} is being updated ...", landLine.getPhoneId())); //NOI18N
1035 // Then find it, too
1036 final DialableLandLineNumber foundLandLine = this.getEntityManager().find(landLine.getClass(), landLine.getPhoneId());
1039 assert (foundLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", foundLandLine.getPhoneId()); //NOI18N
1041 // Then merge it, too
1042 final DialableLandLineNumber managedLandLine = this.getEntityManager().merge(foundLandLine);
1045 assert (managedLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", managedLandLine.getPhoneId()); //NOI18N
1048 LandLineNumbers.copyAll(detachedContact.getContactLandLineNumber(), managedLandLine);
1051 detachedContact.setContactLandLineNumber(managedLandLine);
1055 this.getLoggerBeanLocal().logTrace("mergeContactsMobileLandLineFaxNumbers: EXIT!"); //NOI18N
1059 * Sends an email with given subject line, template name to given recipient
1062 * @param subjectLine Subject line
1063 * @param templateName Template name
1064 * @param user User instance
1065 * @param baseUrl Base URL
1066 * @param randomPassword A randomly-generated password or NULL if user had
1069 protected void sendEmail (final String subjectLine, final String templateName, final User user, final String baseUrl, final String randomPassword) {
1071 this.getLoggerBeanLocal().logTrace(MessageFormat.format("sendEmail: subjectLine={0},templateName={1},user={2},baseUrl={3} - CALLED!", subjectLine, templateName, user, baseUrl)); //NOI18N
1073 // All should be set
1074 if (null == subjectLine) {
1076 throw new NullPointerException("subjectLine is null"); //NOI18N
1077 } else if (subjectLine.isEmpty()) {
1079 throw new IllegalArgumentException("subjectLine is empty"); //NOI18N
1080 } else if (null == templateName) {
1082 throw new NullPointerException("templateName is null"); //NOI18N
1083 } else if (templateName.isEmpty()) {
1085 throw new IllegalArgumentException("templateName is empty"); //NOI18N
1086 } else if (null == user) {
1088 throw new NullPointerException("user is null"); //NOI18N
1089 } else if (user.getUserId() == null) {
1091 throw new NullPointerException("user.userId is null"); //NOI18N
1092 } else if (user.getUserId() < 1) {
1094 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid.", user.getUserId())); //NOI18N
1095 } else if (user.getUserName() == null) {
1097 throw new NullPointerException("user.userName is null"); //NOI18N
1098 } else if (user.getUserName().isEmpty()) {
1100 throw new IllegalArgumentException("user.userName is empty"); //NOI18N
1101 } else if (user.getUserAccountStatus() == null) {
1103 throw new NullPointerException("user.userAccountStatus is null"); //NOI18N
1104 } else if (user.getUserContact() == null) {
1106 throw new NullPointerException("user.userContact is null"); //NOI18N
1107 } else if (user.getUserContact().getContactId() == null) {
1109 throw new NullPointerException("user.userContact.contactId is null"); //NOI18N
1110 } else if (user.getUserContact().getContactId() < 1) {
1112 throw new IllegalArgumentException(MessageFormat.format("user.userContact.contactId={0} is invalid", user.getUserContact().getContactId())); //NOI18N
1113 } else if (user.getUserContact().getContactPersonalTitle() == null) {
1115 throw new NullPointerException("user.userContact.contactPersonalTitle is null"); //NOI18N
1116 } else if (user.getUserLocale() == null) {
1118 throw new NullPointerException("user.userLocale is null"); //NOI18N
1119 } else if (this.getSession() == null) {
1121 throw new NullPointerException("this.session is not set. Have you forgotten to call super(String, String) and called only super() ?"); //NOI18N
1125 final Properties variables = UserUtils.getAllUserFields(user);
1127 // Set base URL and random password
1128 variables.put("baseUrl", baseUrl); //NOI18N
1129 variables.put("randomPassword", ""); //NOI18N
1131 // Is the random password set?
1132 if ((randomPassword instanceof String) && (!randomPassword.isEmpty())) {
1133 variables.put("randomPassword", randomPassword); //NOI18N
1137 final Address recipientAddress;
1140 // Create email address and set
1141 recipientAddress = new InternetAddress(user.getUserContact().getContactEmailAddress());
1142 } catch (final AddressException ex) {
1144 throw new EJBException(ex);
1147 // Prepare mail wrapper
1148 // @TODO Language from message bundle
1149 final WrapableEmailDelivery emailWrapper = new EmailDeliveryWrapper(recipientAddress, subjectLine, templateName, variables, user.getUserLocale());
1152 // Send out email change
1153 final ObjectMessage message = this.getSession().createObjectMessage();
1154 message.setObject(emailWrapper);
1157 this.sendMessage(message);
1158 } catch (final JMSException ex) {
1160 throw new EJBException(ex);
1164 this.getLoggerBeanLocal().logTrace("sendEmail: EXIT!"); //NOI18N
1168 * Updates all contact's phone instances from other contact, both contacts
1169 * should be the same.
1171 * @param contact Contact to set instances
1172 * @param other Other contact to get instances from
1174 protected void setAllContactPhoneEntries (final Contact contact, final Contact other) {
1176 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntries: contact={1},other={2} - CALLED!", this.getClass().getSimpleName(), contact, other)); //NOI18N
1178 // Both must be the same and not null
1179 if (null == contact) {
1181 throw new NullPointerException("contact is null"); //NOI18N
1182 } else if (null == other) {
1184 throw new NullPointerException("other is null"); //NOI18N
1185 } else if (!Objects.equals(contact, other)) {
1186 // Not same instances
1187 throw new IllegalArgumentException(MessageFormat.format("contact={0} and other={1} are not equal!", contact, other)); //NOI18N
1191 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: other.contactMobileNumber={0}", other.getContactMobileNumber())); //NOI18N
1193 // Is other mobile not set?
1194 if ((other.getContactMobileNumber() == null) || (PhoneUtils.isSameMobileNumber(contact.getContactMobileNumber(), other.getContactMobileNumber()))) {
1196 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: Copying mobile entry ...", this.getClass().getSimpleName())); //NOI18N
1198 // Is the fax number set?
1199 if (other.getContactMobileNumber() instanceof DialableMobileNumber) {
1200 // Copy mobile number
1201 contact.setContactMobileNumber(this.getManaged(other.getContactMobileNumber(), contact.getContactMobileNumber()));
1204 contact.setContactMobileNumber(null);
1209 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: other.contactLandLineNumber={0}", other.getContactLandLineNumber())); //NOI18N
1211 // Is other mobile not set?
1212 if ((other.getContactLandLineNumber() == null) || (PhoneUtils.isSameLandLineNumber(contact.getContactLandLineNumber(), other.getContactLandLineNumber()))) {
1214 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: Copying land-line entry ...", this.getClass().getSimpleName())); //NOI18N
1216 // Is the land-line number set?
1217 if (other.getContactLandLineNumber() instanceof DialableLandLineNumber) {
1218 // Copy land-line number
1219 contact.setContactLandLineNumber(this.getManaged(other.getContactLandLineNumber(), contact.getContactLandLineNumber()));
1222 contact.setContactLandLineNumber(null);
1227 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: other.contactFaxNumber={1}", this.getClass().getSimpleName(), other.getContactFaxNumber())); //NOI18N
1229 // Is other mobile not set?
1230 if ((other.getContactFaxNumber() == null) || (PhoneUtils.isSameFaxNumber(contact.getContactFaxNumber(), other.getContactFaxNumber()))) {
1232 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: Copying fax entry ...", this.getClass().getSimpleName())); //NOI18N
1234 // Is the fax number set?
1235 if (other.getContactFaxNumber() instanceof DialableFaxNumber) {
1237 contact.setContactFaxNumber(this.getManaged(other.getContactFaxNumber(), contact.getContactFaxNumber()));
1240 contact.setContactFaxNumber(null);
1245 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntries: EXIT!", this.getClass().getSimpleName())); //NOI18N
1249 * Updates all contact's phone entry's updated timestamps
1251 * @param contact Contact instance to update
1252 * @param isMobileUnlinked Whether a mobile entry has been unlinked in
1254 * @param isLandlineUnlinked Whether a land-line entry has been unlinked in
1256 * @param isFaxUnlinked Whether a fax entry has been unlinked in
1259 protected void setAllContactPhoneEntriesUpdated (final Contact contact, final boolean isMobileUnlinked, final boolean isLandlineUnlinked, final boolean isFaxUnlinked) {
1261 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: contact={1},isMobileUnlinked={2},isLandlineUnlinked={3},isFaxUnlinked={4} - CALLED", this.getClass().getSimpleName(), contact, isMobileUnlinked, isLandlineUnlinked, isFaxUnlinked)); //NOI18N
1263 // The contact instance must be valid
1264 if (null == contact) {
1266 throw new NullPointerException("contact is null"); //NOI18N
1267 } else if (contact.getContactId() == null) {
1269 throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
1270 } else if (contact.getContactId() < 1) {
1272 throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1275 // Get all phone instances
1276 final DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber();
1277 final DialableFaxNumber faxNumber = contact.getContactFaxNumber();
1278 final DialableMobileNumber mobileNumber = contact.getContactMobileNumber();
1280 // Flags and instances must be constistent
1281 if (isMobileUnlinked && mobileNumber instanceof DialableMobileNumber) {
1283 throw new IllegalStateException("isCellPhoneUnlinked is TRUE, but mobileNumber is set."); //NOI18N
1284 } else if (isLandlineUnlinked && landLineNumber instanceof DialableLandLineNumber) {
1286 throw new IllegalStateException("isLandlineUnlinked is TRUE, but landLineNumber is set."); //NOI18N
1287 } else if (isFaxUnlinked && faxNumber instanceof DialableFaxNumber) {
1289 throw new IllegalStateException("isFaxUnlinked is TRUE, but faxNumber is set."); //NOI18N
1292 // Is a phone number instance set?
1293 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() instanceof Long) && (landLineNumber.getPhoneId() > 0)) {
1295 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: Setting updated timestamp for land-line number ...", this.getClass().getSimpleName())); //NOI18N
1297 // Set updated timestamp
1298 landLineNumber.setPhoneEntryUpdated(new Date());
1301 // Is a fax number instance set?
1302 if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() instanceof Long) && (faxNumber.getPhoneId() > 0)) {
1304 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: Setting updated timestamp for fax number ...", this.getClass().getSimpleName())); //NOI18N
1306 // Set updated timestamp
1307 faxNumber.setPhoneEntryUpdated(new Date());
1310 // Is a mobile number instance set?
1311 if ((mobileNumber instanceof DialableMobileNumber) && (mobileNumber.getPhoneId() instanceof Long) && (mobileNumber.getPhoneId() > 0)) {
1313 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: Setting updated timestamp for mobile number ...", this.getClass().getSimpleName())); //NOI18N
1315 // Set updated timestamp
1316 mobileNumber.setPhoneEntryUpdated(new Date());
1320 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: EXIT!", this.getClass().getSimpleName())); //NOI18N