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.beans.ejb;
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.Contacts;
32 import org.mxchange.jcontacts.model.contact.UserContact;
33 import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
34 import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData;
35 import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
36 import org.mxchange.jcontactsbusiness.model.branchoffice.BusinessBranchOffice;
37 import org.mxchange.jcontactsbusiness.model.employee.BusinessEmployee;
38 import org.mxchange.jcontactsbusiness.model.employee.Employable;
39 import org.mxchange.jcontactsbusiness.model.headquarter.BusinessHeadquarter;
40 import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter;
41 import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime;
42 import org.mxchange.jcoreee.bean.ejb.BaseEnterpriseBean;
43 import org.mxchange.jcountry.model.data.Country;
44 import org.mxchange.jcountry.model.data.CountryData;
45 import org.mxchange.jmailee.model.delivery.wrapper.EmailDeliveryWrapper;
46 import org.mxchange.jmailee.model.delivery.wrapper.WrapableEmailDelivery;
47 import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
48 import org.mxchange.jphone.model.phonenumbers.fax.FaxNumbers;
49 import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
50 import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumbers;
51 import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
52 import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumbers;
53 import org.mxchange.jphone.utils.PhoneUtils;
54 import org.mxchange.jusercore.model.user.LoginUser;
55 import org.mxchange.jusercore.model.user.User;
56 import org.mxchange.jusercore.model.user.Users;
59 * A helper class for beans that access the database.
61 * @author Roland Häder<roland@mxchange.org>
63 public abstract class BaseJobsEnterpriseBean extends BaseEnterpriseBean {
68 private static final long serialVersionUID = 12_895_410_275_811_963L;
71 * Protected constructor
73 protected BaseJobsEnterpriseBean () {
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 BaseJobsEnterpriseBean (final String factoryJndi, final String queueJndi) {
85 // Call super constructor
86 super(factoryJndi, queueJndi);
90 * Get back a managed instance from given contact
92 * @param contact Unmanaged/detached contact instance
94 * @return Managed contact instance
96 protected Contact createManaged (final Contact contact) {
98 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N
100 // user should not be null
101 if (null == contact) {
103 throw new NullPointerException("contact is null"); //NOI18N
104 } else if (contact.getContactId() == null) {
106 throw new NullPointerException("contact.contactId is null"); //NOI18N
107 } else if (contact.getContactId() < 1) {
109 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
112 // Try to find it (should be there)
113 final Contact managedContact = this.getEntityManager().find(UserContact.class, contact.getContactId());
116 assert (managedContact instanceof Contact) : "managedContact is null"; //NOI18N
119 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N
122 return managedContact;
126 * Get back a managed instance from given country
128 * @param country Unmanaged/detached country instance
130 * @return Managed country instance
132 protected Country createManaged (final Country country) {
134 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: country={1} - CALLED!", this.getClass().getSimpleName(), country)); //NOI18N
136 // user should not be null
137 if (null == country) {
139 throw new NullPointerException("country is null"); //NOI18N
140 } else if (country.getCountryId() == null) {
142 throw new NullPointerException("country.countryId is null"); //NOI18N
143 } else if (country.getCountryId() < 1) {
145 throw new IllegalArgumentException(MessageFormat.format("country.countryId={0} is invalid", country.getCountryId())); //NOI18N
148 // Try to find it (should be there)
149 final Country managedCountry = this.getEntityManager().find(CountryData.class, country.getCountryId());
152 assert (managedCountry instanceof Country) : "managedCountry is null"; //NOI18N
155 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedCountry={1} - EXIT!", this.getClass().getSimpleName(), managedCountry)); //NOI18N
158 return managedCountry;
162 * Get back a managed instance from given basic data
164 * @param basicData Unmanaged/detached basic data instance
166 * @return Managed basic data instance
168 protected BasicData createManaged (final BasicData basicData) {
170 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: basicData={1} - CALLED!", this.getClass().getSimpleName(), basicData)); //NOI18N
172 // user should not be null
173 if (null == basicData) {
175 throw new NullPointerException("basicData is null"); //NOI18N
176 } else if (basicData.getBasicDataId() == null) {
178 throw new NullPointerException("basicData.basicDataId is null"); //NOI18N
179 } else if (basicData.getBasicDataId() < 1) {
181 throw new IllegalArgumentException(MessageFormat.format("basicData.basicDataId={0} is invalid", basicData.getBasicDataId())); //NOI18N
184 // Try to find it (should be there)
185 final BasicData managedBasicData = this.getEntityManager().find(BusinessBasicData.class, basicData.getBasicDataId());
188 assert (managedBasicData instanceof BasicData) : "managedBasicData is null"; //NOI18N
191 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedBasicData={1} - EXIT!", this.getClass().getSimpleName(), managedBasicData)); //NOI18N
194 return managedBasicData;
198 * Get back a managed instance from given branch office
200 * @param headquarter Unmanaged/detached branch office instance
202 * @return Managed basic data instance
204 protected BranchOffice createManaged (final BranchOffice headquarter) {
206 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: headquarter={1} - CALLED!", this.getClass().getSimpleName(), headquarter)); //NOI18N
208 // user should not be null
209 if (null == headquarter) {
211 throw new NullPointerException("headquarter is null"); //NOI18N
212 } else if (headquarter.getBranchId() == null) {
214 throw new NullPointerException("headquarter.headquarterId is null"); //NOI18N
215 } else if (headquarter.getBranchId() < 1) {
217 throw new IllegalArgumentException(MessageFormat.format("headquarter.headquarterId={0} is invalid", headquarter.getBranchId())); //NOI18N
220 // Try to find it (should be there)
221 final BranchOffice managedBranchOffice = this.getEntityManager().find(BusinessBranchOffice.class, headquarter.getBranchId());
224 assert (managedBranchOffice instanceof BranchOffice) : "managedBranchOffice is null"; //NOI18N
227 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedBranchOffice={1} - EXIT!", this.getClass().getSimpleName(), managedBranchOffice)); //NOI18N
230 return managedBranchOffice;
234 * Get back a managed instance from given employee
236 * @param employee Unmanaged/detached employee instance
238 * @return Managed employee instance
240 protected Employable createManaged (final Employable employee) {
242 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: employee={1} - CALLED!", this.getClass().getSimpleName(), employee)); //NOI18N
244 // user should not be null
245 if (null == employee) {
247 throw new NullPointerException("employee is null"); //NOI18N
248 } else if (employee.getEmployeeId() == null) {
250 throw new NullPointerException("employee.employeeId is null"); //NOI18N
251 } else if (employee.getEmployeeId() < 1) {
253 throw new IllegalArgumentException(MessageFormat.format("employee.employeeId={0} is invalid", employee.getEmployeeId())); //NOI18N
256 // Try to find it (should be there)
257 final Employable managedEmployee = this.getEntityManager().find(BusinessEmployee.class, employee.getEmployeeId());
260 assert (managedEmployee instanceof Employable) : "managedEmployee is null"; //NOI18N
263 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedEmployee={1} - EXIT!", this.getClass().getSimpleName(), managedEmployee)); //NOI18N
266 return managedEmployee;
270 * Get back a managed instance from given headquarter
272 * @param headquarter Unmanaged/detached headquarter instance
274 * @return Managed basic data instance
276 protected Headquarter createManaged (final Headquarter headquarter) {
278 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: headquarter={1} - CALLED!", this.getClass().getSimpleName(), headquarter)); //NOI18N
280 // user should not be null
281 if (null == headquarter) {
283 throw new NullPointerException("headquarter is null"); //NOI18N
284 } else if (headquarter.getHeadquarterId() == null) {
286 throw new NullPointerException("headquarter.headquarterId is null"); //NOI18N
287 } else if (headquarter.getHeadquarterId() < 1) {
289 throw new IllegalArgumentException(MessageFormat.format("headquarter.headquarterId={0} is invalid", headquarter.getHeadquarterId())); //NOI18N
292 // Try to find it (should be there)
293 final Headquarter managedHeadquarter = this.getEntityManager().find(BusinessHeadquarter.class, headquarter.getHeadquarterId());
296 assert (managedHeadquarter instanceof Headquarter) : "managedHeadquarter is null"; //NOI18N
299 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedHeadquarter={1} - EXIT!", this.getClass().getSimpleName(), managedHeadquarter)); //NOI18N
302 return managedHeadquarter;
306 * Get back a managed instance from given user
308 * @param user Unmanaged/detached user instance
310 * @return Managed user instance
312 protected User createManaged (final User user) {
314 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
316 // user should not be null
319 throw new NullPointerException("user is null"); //NOI18N
320 } else if (user.getUserId() == null) {
322 throw new NullPointerException("user.userId is null"); //NOI18N
323 } else if (user.getUserId() < 1) {
325 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); //NOI18N
326 } else if (user.getUserContact() == null) {
328 throw new NullPointerException("user.userContact is null"); //NOI18N
329 } else if (user.getUserContact().getContactId() == null) {
331 throw new NullPointerException("user.userContact.contactId is null"); //NOI18N
332 } else if (user.getUserContact().getContactId() < 1) {
333 // Not valid id number
334 throw new IllegalArgumentException(MessageFormat.format("user.userContact.contactId={0} is not valid", user.getUserContact().getContactId())); //NOI18N#
337 // Try to find it (should be there)
338 final User managedUser = this.getEntityManager().find(LoginUser.class, user.getUserId());
341 assert (managedUser instanceof User) : "managedUser is null"; //NOI18N
344 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedUser={1} - EXIT!", this.getClass().getSimpleName(), managedUser)); //NOI18N
351 * Updates all contact's phone entry's created timestamps
353 * @param contact Contact instance to update
355 protected void setAllContactPhoneEntriesCreated (final Contact contact) {
357 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N
359 // The contact instance must be valid
360 if (null == contact) {
362 throw new NullPointerException("contact is null"); //NOI18N
365 // Get all phone instances
366 final DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber();
367 final DialableFaxNumber faxNumber = contact.getContactFaxNumber();
368 final DialableMobileNumber mobileNumber = contact.getContactMobileNumber();
371 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: landLineNumber={1},faxNumber={2},mobileNumber={3}", this.getClass().getSimpleName(), landLineNumber, faxNumber, mobileNumber)); //NOI18N
373 // Is a phone number instance set?
374 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() == null)) {
376 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for land-line number ...", this.getClass().getSimpleName())); //NOI18N
378 // Set updated timestamp
379 landLineNumber.setPhoneEntryCreated(new Date());
382 // Is a fax number instance set?
383 if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() == null)) {
385 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for fax number ...", this.getClass().getSimpleName())); //NOI18N
387 // Set updated timestamp
388 faxNumber.setPhoneEntryCreated(new Date());
391 // Is a mobile number instance set?
392 if ((mobileNumber instanceof DialableMobileNumber) && (mobileNumber.getPhoneId() == null)) {
394 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for mobile number ...", this.getClass().getSimpleName())); //NOI18N
396 // Set updated timestamp
397 mobileNumber.setPhoneEntryCreated(new Date());
401 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: EXIT!", this.getClass().getSimpleName())); //NOI18N
405 * Sets created timestamp on all opening times.
407 * @param openingTimes Opening times list
409 * @throws NullPointerException If given list is null
410 * @throws IllegalArgumentException If given list is empty
411 * @throws IllegalStateException If openingId is not null
413 protected void setAllOpeningTimesCreated (final List<OpeningTime> openingTimes) {
414 // Validate parameter
415 if (null == openingTimes) {
417 throw new NullPointerException("openingTimes is null");
418 } else if (openingTimes.isEmpty()) {
420 throw new IllegalArgumentException("openingTimes is empty");
423 // Walk through whole list
424 for (final OpeningTime openingTime : openingTimes) {
425 // Id should not be set
426 if (openingTime.getOpeningId() != null) {
428 throw new IllegalStateException("openingTime.openingId is not null");
431 // Set created timestamp
432 openingTime.setOpeningCreated(new Date());
437 * Updates all contact's phone entry's created timestamps
439 * @param contact Contact instance to update
441 protected void setAllPhoneEntriesCreated (final Contact contact) {
443 this.getLoggerBeanLocal().logTrace(MessageFormat.format("setAllPhoneEntriesCreated: contact={0} - CALLED!", contact)); //NOI18N
445 // The contact instance must be valid
446 if (null == contact) {
448 throw new NullPointerException("contact is null"); //NOI18N
449 } else if (contact.getContactId() != null) {
451 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is unexpected.", contact.getContactId()));
454 // Get all phone instances
455 final DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber();
456 final DialableFaxNumber faxNumber = contact.getContactFaxNumber();
457 final DialableMobileNumber mobileNumber = contact.getContactMobileNumber();
460 this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllPhoneEntriesCreated: landLineNumber={0},faxNumber={1},mobileNumber={2}", landLineNumber, faxNumber, mobileNumber)); //NOI18N
462 // Is a phone number instance set?
463 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() == null)) {
465 this.getLoggerBeanLocal().logDebug("setAllPhoneEntriesCreated: Setting created timestamp for land-line number ..."); //NOI18N
467 // Set updated timestamp
468 landLineNumber.setPhoneEntryCreated(new Date());
471 // Is a fax number instance set?
472 if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() == null)) {
474 this.getLoggerBeanLocal().logDebug("setAllPhoneEntriesCreated: Setting created timestamp for fax number ..."); //NOI18N
476 // Set updated timestamp
477 faxNumber.setPhoneEntryCreated(new Date());
480 // Is a mobile number instance set?
481 if ((mobileNumber instanceof DialableMobileNumber) && (mobileNumber.getPhoneId() == null)) {
483 this.getLoggerBeanLocal().logDebug("setAllPhoneEntriesCreated: Setting created timestamp for mobile number ..."); //NOI18N
485 // Set updated timestamp
486 mobileNumber.setPhoneEntryCreated(new Date());
490 this.getLoggerBeanLocal().logTrace("setAllPhoneEntriesCreated: EXIT!"); //NOI18N
494 * Updates all branch office's phone entry's created timestamps
496 * @param branchOffice Branch office instance to update
498 protected void setAllPhoneEntriesCreated (final BranchOffice branchOffice) {
500 this.getLoggerBeanLocal().logTrace(MessageFormat.format("setAllPhoneEntriesCreated: branchOffice={0} - CALLED!", branchOffice)); //NOI18N
502 // The contact instance must be valid
503 if (null == branchOffice) {
505 throw new NullPointerException("branchOffice is null"); //NOI18N
506 } else if (branchOffice.getBranchId() != null) {
508 throw new IllegalArgumentException(MessageFormat.format("branchOffice.branchId={0} is unexpected.", branchOffice.getBranchId()));
511 // Get all phone instances
512 final DialableLandLineNumber landLineNumber = branchOffice.getBranchLandLineNumber();
513 final DialableFaxNumber faxNumber = branchOffice.getBranchFaxNumber();
516 this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllPhoneEntriesCreated: landLineNumber={0},faxNumber={1}", landLineNumber, faxNumber)); //NOI18N
518 // Is a phone number instance set?
519 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() == null)) {
521 this.getLoggerBeanLocal().logDebug("setAllPhoneEntriesCreated: Setting created timestamp for land-line number ..."); //NOI18N
523 // Set updated timestamp
524 landLineNumber.setPhoneEntryCreated(new Date());
527 // Is a fax number instance set?
528 if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() == null)) {
530 this.getLoggerBeanLocal().logDebug("setAllPhoneEntriesCreated: Setting created timestamp for fax number ..."); //NOI18N
532 // Set updated timestamp
533 faxNumber.setPhoneEntryCreated(new Date());
537 this.getLoggerBeanLocal().logTrace("setAllPhoneEntriesCreated: EXIT!"); //NOI18N
541 * Updates all branch office's phone entry's created timestamps
543 * @param headquarter Headquarters instance to update
545 protected void setAllPhoneEntriesCreated (final Headquarter headquarter) {
547 this.getLoggerBeanLocal().logTrace(MessageFormat.format("setAllPhoneEntriesCreated: headquarter={0} - CALLED!", headquarter)); //NOI18N
549 // The contact instance must be valid
550 if (null == headquarter) {
552 throw new NullPointerException("headquarter is null"); //NOI18N
553 } else if (headquarter.getHeadquarterId() != null) {
555 throw new IllegalArgumentException(MessageFormat.format("headquarter.headquarterId={0} is unexpected.", headquarter.getHeadquarterId()));
558 // Get all phone instances
559 final DialableLandLineNumber landLineNumber = headquarter.getHeadquarterLandLineNumber();
560 final DialableFaxNumber faxNumber = headquarter.getHeadquarterFaxNumber();
563 this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllPhoneEntriesCreated: landLineNumber={0},faxNumber={1}", landLineNumber, faxNumber)); //NOI18N
565 // Is a phone number instance set?
566 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() == null)) {
568 this.getLoggerBeanLocal().logDebug("setAllPhoneEntriesCreated: Setting created timestamp for land-line number ..."); //NOI18N
570 // Set updated timestamp
571 landLineNumber.setPhoneEntryCreated(new Date());
574 // Is a fax number instance set?
575 if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() == null)) {
577 this.getLoggerBeanLocal().logDebug("setAllPhoneEntriesCreated: Setting created timestamp for fax number ..."); //NOI18N
579 // Set updated timestamp
580 faxNumber.setPhoneEntryCreated(new Date());
584 this.getLoggerBeanLocal().logTrace("setAllPhoneEntriesCreated: EXIT!"); //NOI18N
588 * Updates all company's phone entry's created timestamps
590 * @param basicData Company basic data instance to update
592 protected void setAllPhoneEntriesCreated (final BasicData basicData) {
594 this.getLoggerBeanLocal().logTrace(MessageFormat.format("setAllPhoneEntriesCreated: basicData={0} - CALLED!", basicData)); //NOI18N
596 // The contact instance must be valid
597 if (null == basicData) {
599 throw new NullPointerException("basicData is null"); //NOI18N
600 } else if (basicData.getBasicDataId() != null) {
602 throw new IllegalArgumentException(MessageFormat.format("basicData.basicDataId={0} is unexpected.", basicData.getBasicDataId()));
605 // Get all phone instances
606 final DialableLandLineNumber landLineNumber = basicData.getCompanyLandLineNumber();
607 final DialableFaxNumber faxNumber = basicData.getCompanyFaxNumber();
610 this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllPhoneEntriesCreated: landLineNumber={0},faxNumber={1}", landLineNumber, faxNumber)); //NOI18N
612 // Is a phone number instance set?
613 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() == null)) {
615 this.getLoggerBeanLocal().logDebug("setAllPhoneEntriesCreated: Setting created timestamp for land-line number ..."); //NOI18N
617 // Set updated timestamp
618 landLineNumber.setPhoneEntryCreated(new Date());
620 // Set it back in basic data
621 basicData.setCompanyLandLineNumber(landLineNumber);
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());
632 // Set it back in basic data
633 basicData.setCompanyFaxNumber(faxNumber);
637 this.getLoggerBeanLocal().logTrace("setAllPhoneEntriesCreated: EXIT!"); //NOI18N
641 * Returns a detached instance from given mobile instance
643 * @param mobileNumber Mobile instance
644 * @param fetchedNumber Found mobile number in database
646 * @return Detached instance
648 protected DialableMobileNumber getDetached (final DialableMobileNumber mobileNumber, final DialableMobileNumber fetchedNumber) {
650 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: mobileNumber={0},fetchedNumber={1} - CALLED!", mobileNumber, fetchedNumber)); //NOI18N
653 if (null == mobileNumber) {
655 throw new NullPointerException("mobileNumber is null"); //NOI18N
656 } else if (fetchedNumber.getPhoneId() == null) {
658 throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
662 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N
664 // Init query instance
665 final DialableMobileNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
668 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N
671 DialableMobileNumber detachedNumber = null;
673 // Is there a difference?
674 if (!PhoneUtils.isSameMobileNumber(mobileNumber, fetchedNumber)) {
676 detachedNumber = this.getEntityManager().merge(foundNumber);
682 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: detachedNumber={0} - EXIT!", detachedNumber)); //NOI18N
685 return detachedNumber;
689 * Returns a detached instance from given land-line instance
691 * @param landLineNumber Land-line instance
692 * @param fetchedNumber Found land-line number in database
694 * @return Detached instance
696 protected DialableLandLineNumber getDetached (final DialableLandLineNumber landLineNumber, final DialableLandLineNumber fetchedNumber) {
698 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: landLineNumber={0},fetchedNumber={1} - CALLED!", landLineNumber, fetchedNumber)); //NOI18N
701 if (null == landLineNumber) {
703 throw new NullPointerException("landLineNumber is null"); //NOI18N
704 } else if (fetchedNumber.getPhoneId() == null) {
706 throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N
710 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N
712 // Init query instance
713 final DialableLandLineNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
716 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N
719 DialableLandLineNumber detachedNumber = null;
721 // Is there a difference?
722 if (!PhoneUtils.isSameLandLineNumber(landLineNumber, fetchedNumber)) {
724 detachedNumber = this.getEntityManager().merge(foundNumber);
730 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: detachedNumber={0} - EXIT!", detachedNumber)); //NOI18N
733 return detachedNumber;
737 * Returns a detached instance from given fax instance
739 * @param faxNumber Fax instance
740 * @param fetchedNumber Found fax number in database
742 * @return Detached instance
744 protected DialableFaxNumber getDetached (final DialableFaxNumber faxNumber, final DialableFaxNumber fetchedNumber) {
746 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: faxNumber={0},fetchedNumber={1} - CALLED!", faxNumber, fetchedNumber)); //NOI18N
749 if (null == faxNumber) {
751 throw new NullPointerException("faxNumber is null"); //NOI18N
752 } else if (fetchedNumber.getPhoneId() == null) {
754 throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
758 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N
760 // Init query instance
761 final DialableFaxNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
764 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N
767 DialableFaxNumber detachedNumber = null;
769 // Is there a difference?
770 if (!PhoneUtils.isSameFaxNumber(faxNumber, fetchedNumber)) {
772 detachedNumber = this.getEntityManager().merge(foundNumber);
778 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: detachedNumber={0} - EXIT!", detachedNumber)); //NOI18N
781 return detachedNumber;
785 * Returns a managed instance from given mobile number
787 * @param mobileNumber Mobile instance
788 * @param fetchedNumber Found mobile number in database
790 * @return Managed instance
792 protected DialableMobileNumber getManaged (final DialableMobileNumber mobileNumber, final DialableMobileNumber fetchedNumber) {
794 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: mobileNumber={1},fetchedNumber={2} - CALLED!", this.getClass().getSimpleName(), mobileNumber, fetchedNumber)); //NOI18N
797 if (null == mobileNumber) {
799 throw new NullPointerException("mobileNumber is null"); //NOI18N
800 } else if (null == fetchedNumber) {
802 throw new NullPointerException("fetchedNumber is null"); //NOI18N
803 } else if (fetchedNumber.getPhoneId() == null) {
805 throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
809 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N
811 // Init query instance
812 final DialableMobileNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
815 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N
818 DialableMobileNumber detachedNumber = null;
820 // Is there a difference?
821 if (!PhoneUtils.isSameMobileNumber(mobileNumber, fetchedNumber)) {
823 detachedNumber = this.getEntityManager().merge(foundNumber);
829 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: detachedNumber={1} - EXIT!", this.getClass().getSimpleName(), detachedNumber)); //NOI18N
832 return detachedNumber;
836 * Returns a managed instance from given land-line number
838 * @param landLineNumber Land-line instance
839 * @param fetchedNumber Found land-line number in database
841 * @return Managed instance
843 protected DialableLandLineNumber getManaged (final DialableLandLineNumber landLineNumber, final DialableLandLineNumber fetchedNumber) {
845 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: landLineNumber={1},fetchedNumber={2} - CALLED!", this.getClass().getSimpleName(), landLineNumber, fetchedNumber)); //NOI18N
848 if (null == landLineNumber) {
850 throw new NullPointerException("landLineNumber is null"); //NOI18N
851 } else if (null == fetchedNumber) {
853 throw new NullPointerException("fetchedNumber is null"); //NOI18N
854 } else if (fetchedNumber.getPhoneId() == null) {
856 throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N
860 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N
862 // Init query instance
863 final DialableLandLineNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
866 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N
869 DialableLandLineNumber detachedNumber = null;
871 // Is there a difference?
872 if (!PhoneUtils.isSameLandLineNumber(landLineNumber, fetchedNumber)) {
874 detachedNumber = this.getEntityManager().merge(foundNumber);
880 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), detachedNumber)); //NOI18N
883 return detachedNumber;
887 * Returns a managed instance from given fax number
889 * @param faxNumber Fax instance
890 * @param fetchedNumber Found fax number in database
892 * @return Managed instance
894 protected DialableFaxNumber getManaged (final DialableFaxNumber faxNumber, final DialableFaxNumber fetchedNumber) {
896 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: faxNumber={1},fetchedNumber={2} - CALLED!", this.getClass().getSimpleName(), faxNumber, fetchedNumber)); //NOI18N
899 if (null == faxNumber) {
901 throw new NullPointerException("faxNumber is null"); //NOI18N
902 } else if (null == fetchedNumber) {
904 throw new NullPointerException("fetchedNumber is null"); //NOI18N
905 } else if (fetchedNumber.getPhoneId() == null) {
907 throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
911 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N
913 // Init query instance
914 final DialableFaxNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
917 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N
920 DialableFaxNumber detachedNumber = null;
922 // Is there a difference?
923 if (!PhoneUtils.isSameFaxNumber(faxNumber, fetchedNumber)) {
925 detachedNumber = this.getEntityManager().merge(foundNumber);
931 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), detachedNumber)); //NOI18N
934 return detachedNumber;
938 * Merges given contact's data
940 * @param detachedContact Contact instance to merge
942 * @return Detached contact instance
944 protected Contact mergeContactData (final Contact detachedContact) {
946 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactData: contact={1} - CALLED!", this.getClass().getSimpleName(), detachedContact)); //NOI18N
948 // The contact instance must be valid
949 if (null == detachedContact) {
951 throw new NullPointerException("detachedContact is null"); //NOI18N
952 } else if (detachedContact.getContactId() == null) {
954 throw new NullPointerException("detachedContact.contactId is null"); //NOI18N //NOI18N
955 } else if (detachedContact.getContactId() < 1) {
957 throw new IllegalStateException(MessageFormat.format("{0}.detachedContact.contactId={1} is not valid.", this.getClass().getSimpleName(), detachedContact.getContactId())); //NOI18N
960 // Set updated timestamp
961 detachedContact.setContactUpdated(new Date());
963 // Get contact from it and find it
964 final Contact foundContact = this.getEntityManager().find(detachedContact.getClass(), detachedContact.getContactId());
967 assert (foundContact instanceof Contact) : MessageFormat.format("Contact with id {0} not found, but should be.", detachedContact.getContactId()); //NOI18N
970 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.updateUserPersonalData: foundContact.contactId={1}", this.getClass().getSimpleName(), foundContact.getContactId())); //NOI18N
972 // Is a fax number set?
973 if (detachedContact.getContactFaxNumber() instanceof DialableFaxNumber) {
974 // Make fax numbers managed
975 foundContact.setContactFaxNumber(this.getManaged(detachedContact.getContactFaxNumber(), detachedContact.getContactFaxNumber()));
978 // Is a land-line number set?
979 if (detachedContact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
980 // Make land-line numbers managed
981 foundContact.setContactLandLineNumber(this.getManaged(detachedContact.getContactLandLineNumber(), detachedContact.getContactLandLineNumber()));
984 // Is a mobile number set?
985 if (detachedContact.getContactMobileNumber() instanceof DialableMobileNumber) {
986 // Make mobile numbers managed
987 foundContact.setContactMobileNumber(this.getManaged(detachedContact.getContactMobileNumber(), detachedContact.getContactMobileNumber()));
990 // Merge contact instance
991 final Contact managedContact = this.getEntityManager().merge(foundContact);
994 Contacts.copyAll(detachedContact, managedContact);
997 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactData: foundContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N
999 // Return detached contact
1000 return managedContact;
1004 * Merges given (detached) contact's mobile, land-line and fax numbers
1006 * @param detachedContact Detached contact instance
1008 protected void mergeContactsMobileLandLineFaxNumbers (final Contact detachedContact) {
1010 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactsMobileLandLineFaxNumbers: detachedContact={1} - CALLED!", this.getClass().getSimpleName(), detachedContact)); //NOI18N
1012 // The contact instance must be valid
1013 if (null == detachedContact) {
1015 throw new NullPointerException("detachedContact is null"); //NOI18N
1016 } else if (detachedContact.getContactId() == null) {
1018 throw new NullPointerException("detachedContact.contactId is null"); //NOI18N //NOI18N
1019 } else if (detachedContact.getContactId() < 1) {
1021 throw new IllegalStateException(MessageFormat.format("{0}.detachedContact.contactId={1} is not valid.", this.getClass().getSimpleName(), detachedContact.getContactId())); //NOI18N
1024 // Get all instances
1025 final DialableMobileNumber mobile = detachedContact.getContactMobileNumber();
1026 final DialableLandLineNumber landLine = detachedContact.getContactLandLineNumber();
1027 final DialableFaxNumber fax = detachedContact.getContactFaxNumber();
1029 // Is there a mobile instance set?
1030 if (mobile instanceof DialableMobileNumber) {
1032 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: mobile.phoneId={0} is being updated ...", mobile.getPhoneId())); //NOI18N
1034 // Then find it, too
1035 final DialableMobileNumber foundMobile = this.getEntityManager().find(mobile.getClass(), mobile.getPhoneId());
1038 assert (foundMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", foundMobile.getPhoneId()); //NOI18N
1040 // Then merge it, too
1041 final DialableMobileNumber managedMobile = this.getEntityManager().merge(foundMobile);
1044 assert (managedMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", managedMobile.getPhoneId()); //NOI18N
1047 MobileNumbers.copyAll(detachedContact.getContactMobileNumber(), managedMobile);
1050 detachedContact.setContactMobileNumber(managedMobile);
1053 // Is there a fax instance set?
1054 if (fax instanceof DialableFaxNumber) {
1056 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: fax.phoneId={0} is being updated ...", fax.getPhoneId())); //NOI18N
1058 // Then find it, too
1059 final DialableFaxNumber foundFax = this.getEntityManager().find(fax.getClass(), fax.getPhoneId());
1062 assert (foundFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", foundFax.getPhoneId()); //NOI18N
1064 // Then merge it, too
1065 final DialableFaxNumber managedFax = this.getEntityManager().merge(foundFax);
1068 assert (managedFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", managedFax.getPhoneId()); //NOI18N
1071 FaxNumbers.copyAll(detachedContact.getContactFaxNumber(), managedFax);
1074 detachedContact.setContactFaxNumber(managedFax);
1077 // Is there a fax instance set?
1078 if (landLine instanceof DialableLandLineNumber) {
1080 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: landLine.phoneId={0} is being updated ...", landLine.getPhoneId())); //NOI18N
1082 // Then find it, too
1083 final DialableLandLineNumber foundLandLine = this.getEntityManager().find(landLine.getClass(), landLine.getPhoneId());
1086 assert (foundLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", foundLandLine.getPhoneId()); //NOI18N
1088 // Then merge it, too
1089 final DialableLandLineNumber managedLandLine = this.getEntityManager().merge(foundLandLine);
1092 assert (managedLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", managedLandLine.getPhoneId()); //NOI18N
1095 LandLineNumbers.copyAll(detachedContact.getContactLandLineNumber(), managedLandLine);
1098 detachedContact.setContactLandLineNumber(managedLandLine);
1102 this.getLoggerBeanLocal().logTrace("mergeContactsMobileLandLineFaxNumbers: EXIT!"); //NOI18N
1106 * Sends an email with given subject line, template name to given recipient
1109 * @param subjectLine Subject line
1110 * @param templateName Template name
1111 * @param user User instance
1112 * @param baseUrl Base URL
1113 * @param randomPassword A randomly-generated password or NULL if user had
1116 protected void sendEmail (final String subjectLine, final String templateName, final User user, final String baseUrl, final String randomPassword) {
1118 this.getLoggerBeanLocal().logTrace(MessageFormat.format("sendEmail: subjectLine={0},templateName={1},user={2},baseUrl={3} - CALLED!", subjectLine, templateName, user, baseUrl)); //NOI18N
1120 // All should be set
1121 if (null == subjectLine) {
1123 throw new NullPointerException("subjectLine is null"); //NOI18N
1124 } else if (subjectLine.isEmpty()) {
1126 throw new IllegalArgumentException("subjectLine is empty"); //NOI18N
1127 } else if (null == templateName) {
1129 throw new NullPointerException("templateName is null"); //NOI18N
1130 } else if (templateName.isEmpty()) {
1132 throw new IllegalArgumentException("templateName is empty"); //NOI18N
1133 } else if (null == user) {
1135 throw new NullPointerException("user is null"); //NOI18N
1136 } else if (user.getUserId() == null) {
1138 throw new NullPointerException("user.userId is null"); //NOI18N
1139 } else if (user.getUserId() < 1) {
1141 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid.", user.getUserId())); //NOI18N
1142 } else if (user.getUserName() == null) {
1144 throw new NullPointerException("user.userName is null"); //NOI18N
1145 } else if (user.getUserName().isEmpty()) {
1147 throw new IllegalArgumentException("user.userName is empty"); //NOI18N
1148 } else if (user.getUserAccountStatus() == null) {
1150 throw new NullPointerException("user.userAccountStatus is null"); //NOI18N
1151 } else if (user.getUserContact() == null) {
1153 throw new NullPointerException("user.userContact is null"); //NOI18N
1154 } else if (user.getUserContact().getContactId() == null) {
1156 throw new NullPointerException("user.userContact.contactId is null"); //NOI18N
1157 } else if (user.getUserContact().getContactId() < 1) {
1159 throw new IllegalArgumentException(MessageFormat.format("user.userContact.contactId={0} is invalid", user.getUserContact().getContactId())); //NOI18N
1160 } else if (user.getUserContact().getContactPersonalTitle() == null) {
1162 throw new NullPointerException("user.userContact.contactPersonalTitle is null"); //NOI18N
1163 } else if (user.getUserLocale() == null) {
1165 throw new NullPointerException("user.userLocale is null"); //NOI18N
1166 } else if (this.getSession() == null) {
1168 throw new NullPointerException("this.session is not set. Have you forgotten to call super(String, String) and called only super() ?"); //NOI18N
1172 final Properties variables = Users.getAllUserFields(user);
1174 // Set base URL and random password
1175 variables.put("baseUrl", baseUrl); //NOI18N
1176 variables.put("randomPassword", ""); //NOI18N
1178 // Is the random password set?
1179 if ((randomPassword instanceof String) && (!randomPassword.isEmpty())) {
1180 variables.put("randomPassword", randomPassword); //NOI18N
1184 final Address recipientAddress;
1187 // Create email address and set
1188 recipientAddress = new InternetAddress(user.getUserContact().getContactEmailAddress());
1189 } catch (final AddressException ex) {
1191 throw new EJBException(ex);
1194 // Prepare mail wrapper
1195 // @TODO Language from message bundle
1196 final WrapableEmailDelivery emailWrapper = new EmailDeliveryWrapper(recipientAddress, subjectLine, templateName, variables, user.getUserLocale());
1199 // Send out email change
1200 final ObjectMessage message = this.getSession().createObjectMessage();
1201 message.setObject(emailWrapper);
1204 this.sendMessage(message);
1205 } catch (final JMSException ex) {
1207 throw new EJBException(ex);
1211 this.getLoggerBeanLocal().logTrace("sendEmail: EXIT!"); //NOI18N
1215 * Updates all contact's phone instances from other contact, both contacts
1216 * should be the same.
1218 * @param contact Contact to set instances
1219 * @param other Other contact to get instances from
1221 protected void setAllContactPhoneEntries (final Contact contact, final Contact other) {
1223 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntries: contact={1},other={2} - CALLED!", this.getClass().getSimpleName(), contact, other)); //NOI18N
1225 // Both must be the same and not null
1226 if (null == contact) {
1228 throw new NullPointerException("contact is null"); //NOI18N
1229 } else if (null == other) {
1231 throw new NullPointerException("other is null"); //NOI18N
1232 } else if (!Objects.equals(contact, other)) {
1233 // Not same instances
1234 throw new IllegalArgumentException(MessageFormat.format("contact={0} and other={1} are not equal!", contact, other)); //NOI18N
1238 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: other.contactMobileNumber={0}", other.getContactMobileNumber())); //NOI18N
1240 // Is other mobile not set?
1241 if ((other.getContactMobileNumber() == null) || (PhoneUtils.isSameMobileNumber(contact.getContactMobileNumber(), other.getContactMobileNumber()))) {
1243 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: Copying mobile entry ...", this.getClass().getSimpleName())); //NOI18N
1245 // Is the fax number set?
1246 if (other.getContactMobileNumber() instanceof DialableMobileNumber) {
1247 // Copy mobile number
1248 contact.setContactMobileNumber(this.getManaged(other.getContactMobileNumber(), contact.getContactMobileNumber()));
1251 contact.setContactMobileNumber(null);
1256 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: other.contactLandLineNumber={0}", other.getContactLandLineNumber())); //NOI18N
1258 // Is other mobile not set?
1259 if ((other.getContactLandLineNumber() == null) || (PhoneUtils.isSameLandLineNumber(contact.getContactLandLineNumber(), other.getContactLandLineNumber()))) {
1261 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: Copying land-line entry ...", this.getClass().getSimpleName())); //NOI18N
1263 // Is the land-line number set?
1264 if (other.getContactLandLineNumber() instanceof DialableLandLineNumber) {
1265 // Copy land-line number
1266 contact.setContactLandLineNumber(this.getManaged(other.getContactLandLineNumber(), contact.getContactLandLineNumber()));
1269 contact.setContactLandLineNumber(null);
1274 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: other.contactFaxNumber={1}", this.getClass().getSimpleName(), other.getContactFaxNumber())); //NOI18N
1276 // Is other mobile not set?
1277 if ((other.getContactFaxNumber() == null) || (PhoneUtils.isSameFaxNumber(contact.getContactFaxNumber(), other.getContactFaxNumber()))) {
1279 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: Copying fax entry ...", this.getClass().getSimpleName())); //NOI18N
1281 // Is the fax number set?
1282 if (other.getContactFaxNumber() instanceof DialableFaxNumber) {
1284 contact.setContactFaxNumber(this.getManaged(other.getContactFaxNumber(), contact.getContactFaxNumber()));
1287 contact.setContactFaxNumber(null);
1292 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntries: EXIT!", this.getClass().getSimpleName())); //NOI18N
1296 * Updates all contact's phone entry's updated timestamps
1298 * @param contact Contact instance to update
1299 * @param isMobileUnlinked Whether a mobile entry has been unlinked in
1301 * @param isLandlineUnlinked Whether a land-line entry has been unlinked in
1303 * @param isFaxUnlinked Whether a fax entry has been unlinked in
1306 protected void setAllContactPhoneEntriesUpdated (final Contact contact, final boolean isMobileUnlinked, final boolean isLandlineUnlinked, final boolean isFaxUnlinked) {
1308 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: contact={1},isMobileUnlinked={2},isLandlineUnlinked={3},isFaxUnlinked={4} - CALLED", this.getClass().getSimpleName(), contact, isMobileUnlinked, isLandlineUnlinked, isFaxUnlinked)); //NOI18N
1310 // The contact instance must be valid
1311 if (null == contact) {
1313 throw new NullPointerException("contact is null"); //NOI18N
1314 } else if (contact.getContactId() == null) {
1316 throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
1317 } else if (contact.getContactId() < 1) {
1319 throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1322 // Get all phone instances
1323 final DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber();
1324 final DialableFaxNumber faxNumber = contact.getContactFaxNumber();
1325 final DialableMobileNumber mobileNumber = contact.getContactMobileNumber();
1327 // Flags and instances must be constistent
1328 if (isMobileUnlinked && mobileNumber instanceof DialableMobileNumber) {
1330 throw new IllegalStateException("isCellPhoneUnlinked is TRUE, but mobileNumber is set."); //NOI18N
1331 } else if (isLandlineUnlinked && landLineNumber instanceof DialableLandLineNumber) {
1333 throw new IllegalStateException("isLandlineUnlinked is TRUE, but landLineNumber is set."); //NOI18N
1334 } else if (isFaxUnlinked && faxNumber instanceof DialableFaxNumber) {
1336 throw new IllegalStateException("isFaxUnlinked is TRUE, but faxNumber is set."); //NOI18N
1339 // Is a phone number instance set?
1340 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() instanceof Long) && (landLineNumber.getPhoneId() > 0)) {
1342 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: Setting updated timestamp for land-line number ...", this.getClass().getSimpleName())); //NOI18N
1344 // Set updated timestamp
1345 landLineNumber.setPhoneEntryUpdated(new Date());
1348 // Is a fax number instance set?
1349 if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() instanceof Long) && (faxNumber.getPhoneId() > 0)) {
1351 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: Setting updated timestamp for fax number ...", this.getClass().getSimpleName())); //NOI18N
1353 // Set updated timestamp
1354 faxNumber.setPhoneEntryUpdated(new Date());
1357 // Is a mobile number instance set?
1358 if ((mobileNumber instanceof DialableMobileNumber) && (mobileNumber.getPhoneId() instanceof Long) && (mobileNumber.getPhoneId() > 0)) {
1360 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: Setting updated timestamp for mobile number ...", this.getClass().getSimpleName())); //NOI18N
1362 // Set updated timestamp
1363 mobileNumber.setPhoneEntryUpdated(new Date());
1367 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: EXIT!", this.getClass().getSimpleName())); //NOI18N