2 * Copyright (C) 2016 - 2022 Free Software Foundation
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.enterprise;
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.utils.ContactUtils;
32 import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
33 import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
34 import org.mxchange.jcontactsbusiness.model.department.Department;
35 import org.mxchange.jcontactsbusiness.model.employee.Employable;
36 import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter;
37 import org.mxchange.jcontactsbusiness.model.jobposition.HireableJobPosition;
38 import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime;
39 import org.mxchange.jcontactsbusiness.model.utils.BranchOfficeUtils;
40 import org.mxchange.jcontactsbusiness.model.utils.DepartmentUtils;
41 import org.mxchange.jcoreee.bean.ejb.BaseEnterpriseBean;
42 import org.mxchange.jcountry.model.data.Country;
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.landline.DialableLandLineNumber;
47 import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
48 import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider;
49 import org.mxchange.jphone.model.utils.FaxNumberUtils;
50 import org.mxchange.jphone.model.utils.LandLineNumberUtils;
51 import org.mxchange.jphone.model.utils.MobileNumberUtils;
52 import org.mxchange.jusercore.model.user.User;
53 import org.mxchange.jusercore.model.utils.UserUtils;
56 * A helper class for beans that access the database.
58 * @author Roland Häder<roland@mxchange.org>
60 public abstract class BaseJobsEnterpriseBean extends BaseEnterpriseBean {
65 private static final long serialVersionUID = 12_895_410_275_811_963L;
68 * Protected constructor
70 protected BaseJobsEnterpriseBean () {
71 // Call super contructor
76 * Constructor with queue factory JNDI and queue JNDI names
78 * @param factoryJndi JNDI name for queue factory
79 * @param queueJndi JNDI name for email queue
81 protected BaseJobsEnterpriseBean (final String factoryJndi, final String queueJndi) {
82 // Call super constructor
83 super(factoryJndi, queueJndi);
87 * Get back a managed instance from given contact
89 * @param contact Unmanaged/detached contact instance
91 * @return Managed contact instance
93 protected Contact createManaged (final Contact contact) {
95 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N
97 // user should not be null
98 if (null == contact) {
100 throw new NullPointerException("contact is null"); //NOI18N
101 } else if (contact.getContactId() == null) {
103 throw new NullPointerException("contact.branchId is null"); //NOI18N
104 } else if (contact.getContactId() < 1) {
106 throw new IllegalArgumentException(MessageFormat.format("contact.branchId={0} is invalid", contact.getContactId())); //NOI18N
109 // Try to find it (should be there)
110 final Contact managedContact = this.getEntityManager().find(contact.getClass(), contact.getContactId());
113 assert (managedContact instanceof Contact) : "managedContact is null"; //NOI18N
116 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N
119 return managedContact;
123 * Get back a managed instance from given country
125 * @param country Unmanaged/detached country instance
127 * @return Managed country instance
129 protected Country createManaged (final Country country) {
131 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: country={1} - CALLED!", this.getClass().getSimpleName(), country)); //NOI18N
133 // user should not be null
134 if (null == country) {
136 throw new NullPointerException("country is null"); //NOI18N
137 } else if (country.getCountryId() == null) {
139 throw new NullPointerException("country.countryId is null"); //NOI18N
140 } else if (country.getCountryId() < 1) {
142 throw new IllegalArgumentException(MessageFormat.format("country.countryId={0} is invalid", country.getCountryId())); //NOI18N
145 // Try to find it (should be there)
146 final Country managedCountry = this.getEntityManager().find(country.getClass(), country.getCountryId());
149 assert (managedCountry instanceof Country) : "managedCountry is null"; //NOI18N
152 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedCountry={1} - EXIT!", this.getClass().getSimpleName(), managedCountry)); //NOI18N
155 return managedCountry;
159 * Get back a managed instance from given basic data
161 * @param basicData Unmanaged/detached basic data instance
163 * @return Managed basic data instance
165 protected BasicData createManaged (final BasicData basicData) {
167 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: basicData={1} - CALLED!", this.getClass().getSimpleName(), basicData)); //NOI18N
169 // user should not be null
170 if (null == basicData) {
172 throw new NullPointerException("basicData is null"); //NOI18N
173 } else if (basicData.getBasicDataId() == null) {
175 throw new NullPointerException("basicData.basicDataId is null"); //NOI18N
176 } else if (basicData.getBasicDataId() < 1) {
178 throw new IllegalArgumentException(MessageFormat.format("basicData.basicDataId={0} is invalid", basicData.getBasicDataId())); //NOI18N
181 // Try to find it (should be there)
182 final BasicData managedBasicData = this.getEntityManager().find(basicData.getClass(), basicData.getBasicDataId());
185 assert (managedBasicData instanceof BasicData) : "managedBasicData is null"; //NOI18N
188 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedBasicData={1} - EXIT!", this.getClass().getSimpleName(), managedBasicData)); //NOI18N
191 return managedBasicData;
195 * Get back a managed instance from given branch office
197 * @param branchOffice Unmanaged/detached branch office instance
199 * @return Managed branch office instance
201 protected BranchOffice createManaged (final BranchOffice branchOffice) {
203 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: branchOffice={1} - CALLED!", this.getClass().getSimpleName(), branchOffice)); //NOI18N
205 // user should not be null
206 if (null == branchOffice) {
208 throw new NullPointerException("branchOffice is null"); //NOI18N
209 } else if (branchOffice.getBranchId() == null) {
211 throw new NullPointerException("branchOffice.branchId is null"); //NOI18N
212 } else if (branchOffice.getBranchId() < 1) {
214 throw new IllegalArgumentException(MessageFormat.format("branchOffice.branchId={0} is invalid", branchOffice.getBranchId())); //NOI18N
217 // Try to find it (should be there)
218 final BranchOffice managedBranchOffice = this.getEntityManager().find(branchOffice.getClass(), branchOffice.getBranchId());
221 assert (managedBranchOffice instanceof BranchOffice) : "managedBranchOffice is null"; //NOI18N
224 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedBranchOffice={1} - EXIT!", this.getClass().getSimpleName(), managedBranchOffice)); //NOI18N
227 return managedBranchOffice;
231 * Get back a managed instance from given department
233 * @param department Unmanaged/detached department instance
235 * @return Managed department instance
237 protected Department createManaged (final Department department) {
239 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: department={1} - CALLED!", this.getClass().getSimpleName(), department)); //NOI18N
241 // user should not be null
242 if (null == department) {
244 throw new NullPointerException("department is null"); //NOI18N
245 } else if (department.getDepartmentId() == null) {
247 throw new NullPointerException("department.departmentId is null"); //NOI18N
248 } else if (department.getDepartmentId() < 1) {
250 throw new IllegalArgumentException(MessageFormat.format("department.departmentId={0} is invalid", department.getDepartmentId())); //NOI18N
253 // Try to find it (should be there)
254 final Department managedDepartment = this.getEntityManager().find(department.getClass(), department.getDepartmentId());
257 assert (managedDepartment instanceof Department) : "managedDepartment is null"; //NOI18N
260 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedDepartment={1} - EXIT!", this.getClass().getSimpleName(), managedDepartment)); //NOI18N
263 return managedDepartment;
267 * Get back a managed instance from given employee
269 * @param employee Unmanaged/detached employee instance
271 * @return Managed employee instance
273 protected Employable createManaged (final Employable employee) {
275 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: employee={1} - CALLED!", this.getClass().getSimpleName(), employee)); //NOI18N
277 // user should not be null
278 if (null == employee) {
280 throw new NullPointerException("employee is null"); //NOI18N
281 } else if (employee.getEmployeeId() == null) {
283 throw new NullPointerException("employee.employeeId is null"); //NOI18N
284 } else if (employee.getEmployeeId() < 1) {
286 throw new IllegalArgumentException(MessageFormat.format("employee.employeeId={0} is invalid", employee.getEmployeeId())); //NOI18N
289 // Try to find it (should be there)
290 final Employable managedEmployee = this.getEntityManager().find(employee.getClass(), employee.getEmployeeId());
293 assert (managedEmployee instanceof Employable) : "managedEmployee is null"; //NOI18N
296 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedEmployee={1} - EXIT!", this.getClass().getSimpleName(), managedEmployee)); //NOI18N
299 return managedEmployee;
303 * Get back a managed instance from given jobPosition
305 * @param jobPosition Unmanaged/detached job position instance
307 * @return Managed job position instance
309 protected HireableJobPosition createManaged (final HireableJobPosition jobPosition) {
311 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: jobPosition={1} - CALLED!", this.getClass().getSimpleName(), jobPosition)); //NOI18N
313 // user should not be null
314 if (null == jobPosition) {
316 throw new NullPointerException("jobPosition is null"); //NOI18N
317 } else if (jobPosition.getJobPositionId() == null) {
319 throw new NullPointerException("jobPosition.jobPositionId is null"); //NOI18N
320 } else if (jobPosition.getJobPositionId() < 1) {
322 throw new IllegalArgumentException(MessageFormat.format("jobPosition.jobPositionId={0} is invalid", jobPosition.getJobPositionId())); //NOI18N
325 // Try to find it (should be there)
326 final HireableJobPosition managedJobPosition = this.getEntityManager().find(jobPosition.getClass(), jobPosition.getJobPositionId());
329 assert (managedJobPosition instanceof HireableJobPosition) : "managedJobPosition is null"; //NOI18N
332 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedJobPosition={1} - EXIT!", this.getClass().getSimpleName(), managedJobPosition)); //NOI18N
335 return managedJobPosition;
339 * Get back a managed instance from given headquarter
341 * @param headquarter Unmanaged/detached headquarter instance
343 * @return Managed basic data instance
345 protected Headquarter createManaged (final Headquarter headquarter) {
347 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: headquarter={1} - CALLED!", this.getClass().getSimpleName(), headquarter)); //NOI18N
349 // user should not be null
350 if (null == headquarter) {
352 throw new NullPointerException("headquarter is null"); //NOI18N
353 } else if (headquarter.getHeadquarterId() == null) {
355 throw new NullPointerException("headquarter.headquarterId is null"); //NOI18N
356 } else if (headquarter.getHeadquarterId() < 1) {
358 throw new IllegalArgumentException(MessageFormat.format("headquarter.headquarterId={0} is invalid", headquarter.getHeadquarterId())); //NOI18N
361 // Try to find it (should be there)
362 final Headquarter managedHeadquarter = this.getEntityManager().find(headquarter.getClass(), headquarter.getHeadquarterId());
365 assert (managedHeadquarter instanceof Headquarter) : "managedHeadquarter is null"; //NOI18N
368 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedHeadquarter={1} - EXIT!", this.getClass().getSimpleName(), managedHeadquarter)); //NOI18N
371 return managedHeadquarter;
375 * Get back a managed instance from given mobile provider
377 * @param mobileProvider Unmanaged/detached mobile provider instance
379 * @return Managed mobile provider instance
381 protected MobileProvider createManaged (final MobileProvider mobileProvider) {
383 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: mobileProvider={1} - CALLED!", this.getClass().getSimpleName(), mobileProvider)); //NOI18N
385 // user should not be null
386 if (null == mobileProvider) {
388 throw new NullPointerException("mobileProvider is null"); //NOI18N
389 } else if (mobileProvider.getProviderId() == null) {
391 throw new NullPointerException("mobileProvider.providerId is null"); //NOI18N
392 } else if (mobileProvider.getProviderId() < 1) {
394 throw new IllegalArgumentException(MessageFormat.format("mobileProvider.providerId={0} is invalid", mobileProvider.getProviderId())); //NOI18N
397 // Try to find it (should be there)
398 final MobileProvider managedMobileProvider = this.getEntityManager().find(mobileProvider.getClass(), mobileProvider.getProviderId());
401 assert (managedMobileProvider instanceof MobileProvider) : "managedMobileProvider is null"; //NOI18N
404 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedMobileProvider={1} - EXIT!", this.getClass().getSimpleName(), managedMobileProvider)); //NOI18N
407 return managedMobileProvider;
411 * Get back a managed instance from given user
413 * @param user Unmanaged/detached user instance
415 * @return Managed user instance
417 protected User createManaged (final User user) {
419 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
421 // user should not be null
424 throw new NullPointerException("user is null"); //NOI18N
425 } else if (user.getUserId() == null) {
427 throw new NullPointerException("user.userId is null"); //NOI18N
428 } else if (user.getUserId() < 1) {
430 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); //NOI18N
431 } else if (user.getUserContact() == null) {
433 throw new NullPointerException("user.userContact is null"); //NOI18N
434 } else if (user.getUserContact().getContactId() == null) {
436 throw new NullPointerException("user.userContact.contactId is null"); //NOI18N
437 } else if (user.getUserContact().getContactId() < 1) {
438 // Not valid id number
439 throw new IllegalArgumentException(MessageFormat.format("user.userContact.contactId={0} is not valid", user.getUserContact().getContactId())); //NOI18N#
442 // Try to find it (should be there)
443 final User managedUser = this.getEntityManager().find(user.getClass(), user.getUserId());
446 assert (managedUser instanceof User) : "managedUser is null"; //NOI18N
449 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedUser={1} - EXIT!", this.getClass().getSimpleName(), managedUser)); //NOI18N
456 * Sets created timestamp on all opening times.
458 * @param openingTimes Opening times list
460 * @throws NullPointerException If given list is null
461 * @throws IllegalArgumentException If given list is empty
462 * @throws IllegalStateException If openingId is not null
464 protected void setAllOpeningTimesCreated (final List<OpeningTime> openingTimes) {
465 // Validate parameter
466 if (null == openingTimes) {
468 throw new NullPointerException("openingTimes is null"); //NOI18N
469 } else if (openingTimes.isEmpty()) {
471 throw new IllegalArgumentException("openingTimes is empty"); //NOI18N
474 // Walk through whole list
475 for (final OpeningTime openingTime : openingTimes) {
476 // Id should not be set
477 if (openingTime.getOpeningTimeId() != null) {
479 throw new IllegalStateException("openingTime.openingId is not null"); //NOI18N
482 // Set created timestamp
483 openingTime.setOpeningTimeEntryCreated(new Date());
488 * Updates all contact's phone entry's created timestamps
490 * @param contact Contact instance to update
492 protected void setAllPhoneEntriesCreated (final Contact contact) {
494 this.getLoggerBeanLocal().logTrace(MessageFormat.format("setAllPhoneEntriesCreated: contact={0} - CALLED!", contact)); //NOI18N
496 // The contact instance must be valid
497 if (null == contact) {
499 throw new NullPointerException("contact is null"); //NOI18N
500 } else if (contact.getContactId() != null) {
502 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is unexpected.", contact.getContactId())); //NOI18N
505 // Get all phone instances
506 final DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber();
507 final DialableFaxNumber faxNumber = contact.getContactFaxNumber();
508 final DialableMobileNumber mobileNumber = contact.getContactMobileNumber();
511 this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllPhoneEntriesCreated: landLineNumber={0},faxNumber={1},mobileNumber={2}", landLineNumber, faxNumber, mobileNumber)); //NOI18N
513 // Is a phone number instance set?
514 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() == null)) {
516 this.getLoggerBeanLocal().logDebug("setAllPhoneEntriesCreated: Setting created timestamp for land-line number ..."); //NOI18N
518 // Set updated timestamp
519 landLineNumber.setPhoneEntryCreated(new Date());
522 // Is a fax number instance set?
523 if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() == null)) {
525 this.getLoggerBeanLocal().logDebug("setAllPhoneEntriesCreated: Setting created timestamp for fax number ..."); //NOI18N
527 // Set updated timestamp
528 faxNumber.setPhoneEntryCreated(new Date());
531 // Is a mobile number instance set?
532 if ((mobileNumber instanceof DialableMobileNumber) && (mobileNumber.getMobileId() == null)) {
534 this.getLoggerBeanLocal().logDebug("setAllPhoneEntriesCreated: Setting created timestamp for mobile number ..."); //NOI18N
536 // Set updated timestamp
537 mobileNumber.setMobileEntryCreated(new Date());
541 this.getLoggerBeanLocal().logTrace("setAllPhoneEntriesCreated: EXIT!"); //NOI18N
545 * Updates all branch office's phone entry's created timestamps
547 * @param branchOffice Branch office instance to update
549 protected void setAllPhoneEntriesCreated (final BranchOffice branchOffice) {
551 this.getLoggerBeanLocal().logTrace(MessageFormat.format("setAllPhoneEntriesCreated: branchOffice={0} - CALLED!", branchOffice)); //NOI18N
553 // The contact instance must be valid
554 if (null == branchOffice) {
556 throw new NullPointerException("branchOffice is null"); //NOI18N
557 } else if (branchOffice.getBranchId() != null) {
559 throw new IllegalArgumentException(MessageFormat.format("branchOffice.branchId={0} is unexpected.", branchOffice.getBranchId())); //NOI18N
562 // Get all phone instances
563 final DialableLandLineNumber landLineNumber = branchOffice.getBranchLandLineNumber();
564 final DialableFaxNumber faxNumber = branchOffice.getBranchFaxNumber();
567 this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllPhoneEntriesCreated: landLineNumber={0},faxNumber={1}", landLineNumber, faxNumber)); //NOI18N
569 // Is a phone number instance set?
570 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() == null)) {
572 this.getLoggerBeanLocal().logDebug("setAllPhoneEntriesCreated: Setting created timestamp for land-line number ..."); //NOI18N
574 // Set updated timestamp
575 landLineNumber.setPhoneEntryCreated(new Date());
578 // Is a fax number instance set?
579 if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() == null)) {
581 this.getLoggerBeanLocal().logDebug("setAllPhoneEntriesCreated: Setting created timestamp for fax number ..."); //NOI18N
583 // Set updated timestamp
584 faxNumber.setPhoneEntryCreated(new Date());
588 this.getLoggerBeanLocal().logTrace("setAllPhoneEntriesCreated: EXIT!"); //NOI18N
592 * Updates all branch office's phone entry's created timestamps
594 * @param headquarter Headquarter instance to update
596 protected void setAllPhoneEntriesCreated (final Headquarter headquarter) {
598 this.getLoggerBeanLocal().logTrace(MessageFormat.format("setAllPhoneEntriesCreated: headquarter={0} - CALLED!", headquarter)); //NOI18N
600 // The contact instance must be valid
601 if (null == headquarter) {
603 throw new NullPointerException("headquarter is null"); //NOI18N
604 } else if (headquarter.getHeadquarterId() != null) {
606 throw new IllegalArgumentException(MessageFormat.format("headquarter.branchId={0} is unexpected.", headquarter.getHeadquarterId())); //NOI18N
609 // Get all phone instances
610 final DialableLandLineNumber landLineNumber = headquarter.getHeadquarterLandLineNumber();
611 final DialableFaxNumber faxNumber = headquarter.getHeadquarterFaxNumber();
614 this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllPhoneEntriesCreated: landLineNumber={0},faxNumber={1}", landLineNumber, faxNumber)); //NOI18N
616 // Is a phone number instance set?
617 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() == null)) {
619 this.getLoggerBeanLocal().logDebug("setAllPhoneEntriesCreated: Setting created timestamp for land-line number ..."); //NOI18N
621 // Set updated timestamp
622 landLineNumber.setPhoneEntryCreated(new Date());
625 // Is a fax number instance set?
626 if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() == null)) {
628 this.getLoggerBeanLocal().logDebug("setAllPhoneEntriesCreated: Setting created timestamp for fax number ..."); //NOI18N
630 // Set updated timestamp
631 faxNumber.setPhoneEntryCreated(new Date());
635 this.getLoggerBeanLocal().logTrace("setAllPhoneEntriesCreated: EXIT!"); //NOI18N
639 * Updates all company's phone entry's created timestamps
641 * @param basicData Company basic data instance to update
643 protected void setAllPhoneEntriesCreated (final BasicData basicData) {
645 this.getLoggerBeanLocal().logTrace(MessageFormat.format("setAllPhoneEntriesCreated: basicData={0} - CALLED!", basicData)); //NOI18N
647 // The contact instance must be valid
648 if (null == basicData) {
650 throw new NullPointerException("basicData is null"); //NOI18N
651 } else if (basicData.getBasicDataId() != null) {
653 throw new IllegalArgumentException(MessageFormat.format("basicData.basicDataId={0} is unexpected.", basicData.getBasicDataId())); //NOI18N
656 // Get all phone instances
657 final DialableLandLineNumber landLineNumber = basicData.getCompanyLandLineNumber();
658 final DialableFaxNumber faxNumber = basicData.getCompanyFaxNumber();
661 this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllPhoneEntriesCreated: landLineNumber={0},faxNumber={1}", landLineNumber, faxNumber)); //NOI18N
663 // Is a phone number instance set?
664 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() == null)) {
666 this.getLoggerBeanLocal().logDebug("setAllPhoneEntriesCreated: Setting created timestamp for land-line number ..."); //NOI18N
668 // Set updated timestamp
669 landLineNumber.setPhoneEntryCreated(new Date());
671 // Set it back in basic data
672 basicData.setCompanyLandLineNumber(landLineNumber);
675 // Is a fax number instance set?
676 if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() == null)) {
678 this.getLoggerBeanLocal().logDebug("setAllPhoneEntriesCreated: Setting created timestamp for fax number ..."); //NOI18N
680 // Set updated timestamp
681 faxNumber.setPhoneEntryCreated(new Date());
683 // Set it back in basic data
684 basicData.setCompanyFaxNumber(faxNumber);
688 this.getLoggerBeanLocal().logTrace("setAllPhoneEntriesCreated: EXIT!"); //NOI18N
692 * Returns a detached instance from given mobile instance
694 * @param mobileNumber Mobile instance
695 * @param fetchedNumber Found mobile number in database
697 * @return Detached instance
699 protected DialableMobileNumber getDetached (final DialableMobileNumber mobileNumber, final DialableMobileNumber fetchedNumber) {
701 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: mobileNumber={0},fetchedNumber={1} - CALLED!", mobileNumber, fetchedNumber)); //NOI18N
704 if (null == mobileNumber) {
706 throw new NullPointerException("mobileNumber is null"); //NOI18N
707 } else if (fetchedNumber.getMobileId() == null) {
709 throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
712 // Get contact from it and find it
713 final DialableMobileNumber foundBranchOffice = this.getEntityManager().find(mobileNumber.getClass(), mobileNumber.getMobileId());
716 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: foundBranchOffice={0} - EXIT!", foundBranchOffice)); //NOI18N
719 return foundBranchOffice;
723 * Returns a detached instance from given fax instance
725 * @param faxNumber Fax instance
726 * @param fetchedNumber Found fax number in database
728 * @return Detached instance
730 protected DialableFaxNumber getDetached (final DialableFaxNumber faxNumber, final DialableFaxNumber fetchedNumber) {
732 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: faxNumber={0},fetchedNumber={1} - CALLED!", faxNumber, fetchedNumber)); //NOI18N
735 if (null == faxNumber) {
737 throw new NullPointerException("faxNumber is null"); //NOI18N
738 } else if (fetchedNumber.getPhoneId() == null) {
740 throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
744 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N
746 // Init query instance
747 final DialableFaxNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
750 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N
753 DialableFaxNumber detachedNumber = null;
755 // Is there a difference?
756 if (!FaxNumbers.isSameFaxNumber(faxNumber, fetchedNumber)) {
757 // @TODO Copy all to foundNumber, then merge
760 detachedNumber = this.getEntityManager().merge(foundNumber);
764 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: detachedNumber={0} - EXIT!", detachedNumber)); //NOI18N
767 return detachedNumber;
771 * Merges given branch office's data
773 * @param detachedBranchOffice Branch office instance to merge
775 * @return Detached contact instance
777 protected BranchOffice mergeBranchOfficeData (final BranchOffice detachedBranchOffice) {
779 this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeBranchOfficeData: detachedBranchOffice={0} - CALLED!", detachedBranchOffice)); //NOI18N
781 // The contact instance must be valid
782 if (null == detachedBranchOffice) {
784 throw new NullPointerException("detachedBranchOffice is null"); //NOI18N
785 } else if (detachedBranchOffice.getBranchId() == null) {
787 throw new NullPointerException("detachedBranchOffice.branchId is null"); //NOI18N //NOI18N
788 } else if (detachedBranchOffice.getBranchId() < 1) {
790 throw new IllegalStateException(MessageFormat.format("detachedBranchOffice.branchId ={0} is not valid.", detachedBranchOffice.getBranchId())); //NOI18N
793 // Set updated timestamp
794 detachedBranchOffice.setBranchEntryUpdated(new Date());
796 // Get contact from it and find it
797 final BranchOffice foundBranchOffice = this.getEntityManager().find(detachedBranchOffice.getClass(), detachedBranchOffice.getBranchId());
800 assert (foundBranchOffice instanceof BranchOffice) : MessageFormat.format("Branch office with id {0} not found, but should be.", detachedBranchOffice.getBranchId()); //NOI18N
803 this.getLoggerBeanLocal().logDebug(MessageFormat.format("mergeBranchOfficeData: foundContact.contactId={0}", foundBranchOffice.getBranchId())); //NOI18N
806 BranchOfficeUtils.copyBranchOfficeData(detachedBranchOffice, foundBranchOffice);
808 // Merge contact instance
809 final BranchOffice managedBranchOffice = this.getEntityManager().merge(foundBranchOffice);
812 this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeBranchOfficeData: managedBranchOffice={0} - EXIT!", managedBranchOffice)); //NOI18N
814 // Return detached contact
815 return managedBranchOffice;
819 * Merges given contact's data
821 * @param detachedContact Contact instance to merge
823 * @return Detached contact instance
825 protected Contact mergeContactData (final Contact detachedContact) {
827 this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeContactData: detachedContact={0} - CALLED!", detachedContact)); //NOI18N
829 // The contact instance must be valid
830 if (null == detachedContact) {
832 throw new NullPointerException("detachedContact is null"); //NOI18N
833 } else if (detachedContact.getContactId() == null) {
835 throw new NullPointerException("detachedContact.contactId is null"); //NOI18N //NOI18N
836 } else if (detachedContact.getContactId() < 1) {
838 throw new IllegalStateException(MessageFormat.format("detachedContact.contactId={0} is not valid.", detachedContact.getContactId())); //NOI18N
841 // Get contact from it and find it
842 final Contact foundContact = this.createManaged(detachedContact);
845 this.getLoggerBeanLocal().logDebug(MessageFormat.format("mergeContactData: foundContact.contactId={0}", foundContact.getContactId())); //NOI18N
848 ContactUtils.copyContactData(detachedContact, foundContact);
850 // Merge contact instance
851 final Contact managedContact = this.getEntityManager().merge(foundContact);
853 // Set updated timestamp
854 managedContact.setContactEntryUpdated(new Date());
857 this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeContactData: managedContact={0} - EXIT!", managedContact)); //NOI18N
859 // Return detached contact
860 return managedContact;
864 * Merges given (detached) contact's mobile, land-line and fax numbers
866 * @param detachedContact Detached contact instance
868 protected void mergeContactsMobileLandLineFaxNumbers (final Contact detachedContact) {
870 this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeContactsMobileLandLineFaxNumbers: detachedContact={0} - CALLED!", detachedContact)); //NOI18N
872 // The contact instance must be valid
873 if (null == detachedContact) {
875 throw new NullPointerException("detachedContact is null"); //NOI18N
876 } else if (detachedContact.getContactId() == null) {
878 throw new NullPointerException("detachedContact.contactId is null"); //NOI18N //NOI18N
879 } else if (detachedContact.getContactId() < 1) {
881 throw new IllegalStateException(MessageFormat.format("detachedContact.contactId={0} is not valid.", detachedContact.getContactId())); //NOI18N
885 final DialableMobileNumber mobileNumber = detachedContact.getContactMobileNumber();
886 final DialableLandLineNumber landLineNumber = detachedContact.getContactLandLineNumber();
887 final DialableFaxNumber faxNumber = detachedContact.getContactFaxNumber();
889 // Is there a mobile instance set?
890 if (mobileNumber instanceof DialableMobileNumber) {
892 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: mobile.phoneId={0} is being updated ...", mobileNumber.getMobileId())); //NOI18N
895 final DialableMobileNumber foundMobile = this.getEntityManager().find(mobileNumber.getClass(), mobileNumber.getMobileId());
898 assert (foundMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", foundMobile.getMobileId()); //NOI18N
901 MobileNumberUtils.copyMobileNumberData(detachedContact.getContactMobileNumber(), foundMobile);
903 // Then merge it, too
904 final DialableMobileNumber managedMobile = this.getEntityManager().merge(foundMobile);
907 assert (managedMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", managedMobile.getMobileId()); //NOI18N
910 detachedContact.setContactMobileNumber(managedMobile);
913 // Is there a fax instance set?
914 if (faxNumber instanceof DialableFaxNumber) {
916 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: fax.phoneId={0} is being updated ...", faxNumber.getPhoneId())); //NOI18N
919 final DialableFaxNumber foundFax = this.getEntityManager().find(faxNumber.getClass(), faxNumber.getPhoneId());
922 assert (foundFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", foundFax.getPhoneId()); //NOI18N
925 FaxNumberUtils.copyFaxNumberData(detachedContact.getContactFaxNumber(), foundFax);
927 // Then merge it, too
928 final DialableFaxNumber managedFax = this.getEntityManager().merge(foundFax);
931 assert (managedFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", managedFax.getPhoneId()); //NOI18N
934 detachedContact.setContactFaxNumber(managedFax);
937 // Is there a fax instance set?
938 if (landLineNumber instanceof DialableLandLineNumber) {
940 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: landLine.phoneId={0} is being updated ...", landLineNumber.getPhoneId())); //NOI18N
943 final DialableLandLineNumber foundLandLine = this.getEntityManager().find(landLineNumber.getClass(), landLineNumber.getPhoneId());
946 assert (foundLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", foundLandLine.getPhoneId()); //NOI18N
949 LandLineNumberUtils.copyLandLineNumberData(detachedContact.getContactLandLineNumber(), foundLandLine);
951 // Then merge it, too
952 final DialableLandLineNumber managedLandLine = this.getEntityManager().merge(foundLandLine);
955 assert (managedLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", managedLandLine.getPhoneId()); //NOI18N
958 detachedContact.setContactLandLineNumber(managedLandLine);
962 this.getLoggerBeanLocal().logTrace("mergeContactsMobileLandLineFaxNumbers: EXIT!"); //NOI18N
966 * Merges given department's data
968 * @param detachedDepartment Department instance to merge
970 * @return Detached contact instance
972 protected Department mergeDepartmentData (final Department detachedDepartment) {
974 this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeDepartmentData: detachedDepartment={0} - CALLED!", detachedDepartment)); //NOI18N
976 // The contact instance must be valid
977 if (null == detachedDepartment) {
979 throw new NullPointerException("detachedDepartment is null"); //NOI18N
980 } else if (detachedDepartment.getDepartmentId() == null) {
982 throw new NullPointerException("detachedDepartment.departmentId is null"); //NOI18N
983 } else if (detachedDepartment.getDepartmentId() < 1) {
985 throw new IllegalStateException(MessageFormat.format("detachedDepartment.departmentId ={0} is not valid.", detachedDepartment.getDepartmentId())); //NOI18N
988 // Get contact from it and find it
989 final Department foundDepartment = this.createManaged(detachedDepartment);
992 this.getLoggerBeanLocal().logDebug(MessageFormat.format("mergeDepartmentData: foundContact.contactId={0}", foundDepartment.getDepartmentId())); //NOI18N
995 DepartmentUtils.copyDepartmentData(detachedDepartment, foundDepartment);
997 // Merge contact instance
998 final Department managedDepartment = this.getEntityManager().merge(foundDepartment);
1000 // Set updated timestamp
1001 managedDepartment.setDepartmentEntryUpdated(new Date());
1004 this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeDepartmentData: managedDepartment={0} - EXIT!", managedDepartment)); //NOI18N
1006 // Return detached contact
1007 return managedDepartment;
1011 * Returns a detached instance from given fax instance merged into current.
1013 * @param faxNumber Fax instance
1014 * @param fetchedNumber Found fax number in database
1016 * @return Detached instance
1018 protected DialableFaxNumber mergeFaxNumberData (final DialableFaxNumber faxNumber, final DialableFaxNumber fetchedNumber) {
1020 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: faxNumber={0},fetchedNumber={1} - CALLED!", faxNumber, fetchedNumber)); //NOI18N
1023 if (null == faxNumber) {
1025 throw new NullPointerException("faxNumber is null"); //NOI18N
1026 } else if (fetchedNumber.getPhoneId() == null) {
1028 throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
1032 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N
1034 // Init query instance
1035 final DialableFaxNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
1038 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N
1041 DialableFaxNumber detachedNumber = null;
1043 // Is there a difference?
1044 if (!FaxNumberUtils.isSameFaxNumber(faxNumber, fetchedNumber)) {
1045 // @TODO Copy all to foundNumber, then merge
1048 detachedNumber = this.getEntityManager().merge(foundNumber);
1052 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: detachedNumber={0} - EXIT!", detachedNumber)); //NOI18N
1055 return detachedNumber;
1059 * Returns a detached instance from given land-line instance merged with
1062 * @param landLineNumber Land-line instance
1063 * @param fetchedNumber Found land-line number in database
1065 * @return Detached instance
1067 protected DialableLandLineNumber mergeLandLineNumberData (final DialableLandLineNumber landLineNumber, final DialableLandLineNumber fetchedNumber) {
1069 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: landLineNumber={0},fetchedNumber={1} - CALLED!", landLineNumber, fetchedNumber)); //NOI18N
1072 if (null == landLineNumber) {
1074 throw new NullPointerException("landLineNumber is null"); //NOI18N
1075 } else if (fetchedNumber.getPhoneId() == null) {
1077 throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N
1081 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N
1083 // Init query instance
1084 final DialableLandLineNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
1087 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N
1090 DialableLandLineNumber detachedNumber = null;
1092 // Is there a difference?
1093 if (!LandLineNumberUtils.isSameLandLineNumber(landLineNumber, fetchedNumber)) {
1094 // @TODO Copy all to foundNumber, then merge
1097 detachedNumber = this.getEntityManager().merge(foundNumber);
1101 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: detachedNumber={0} - EXIT!", detachedNumber)); //NOI18N
1104 return detachedNumber;
1108 * Returns a detached instance from given mobile instance merged with
1111 * @param mobileNumber Mobile instance
1112 * @param fetchedNumber Found mobile number in database
1114 * @return Detached instance
1116 protected DialableMobileNumber mergeMobileNumberData (final DialableMobileNumber mobileNumber, final DialableMobileNumber fetchedNumber) {
1118 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: mobileNumber={0},fetchedNumber={1} - CALLED!", mobileNumber, fetchedNumber)); //NOI18N
1121 if (null == mobileNumber) {
1123 throw new NullPointerException("mobileNumber is null"); //NOI18N
1124 } else if (fetchedNumber.getMobileId() == null) {
1126 throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
1130 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getMobileId())); //NOI18N
1132 // Init query instance
1133 final DialableMobileNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getMobileId());
1136 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N
1139 DialableMobileNumber detachedNumber = null;
1141 // Is there a difference?
1142 if (!MobileNumberUtils.isSameMobileNumber(mobileNumber, fetchedNumber)) {
1143 // @TODO Copy all to foundNumber, then merge
1146 detachedNumber = this.getEntityManager().merge(foundNumber);
1150 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: detachedNumber={0} - EXIT!", detachedNumber)); //NOI18N
1153 return detachedNumber;
1157 * Sends an email with given subject line, template name to given recipient
1160 * @param subjectLine Subject line
1161 * @param templateName Template name
1162 * @param user User instance
1163 * @param baseUrl Base URL
1164 * @param randomPassword A randomly-generated password or NULL if user had
1167 protected void sendEmail (final String subjectLine, final String templateName, final User user, final String baseUrl, final String randomPassword) {
1169 this.getLoggerBeanLocal().logTrace(MessageFormat.format("sendEmail: subjectLine={0},templateName={1},user={2},baseUrl={3} - CALLED!", subjectLine, templateName, user, baseUrl)); //NOI18N
1171 // All should be set
1172 if (null == subjectLine) {
1174 throw new NullPointerException("subjectLine is null"); //NOI18N
1175 } else if (subjectLine.isEmpty()) {
1177 throw new IllegalArgumentException("subjectLine is empty"); //NOI18N
1178 } else if (null == templateName) {
1180 throw new NullPointerException("templateName is null"); //NOI18N
1181 } else if (templateName.isEmpty()) {
1183 throw new IllegalArgumentException("templateName is empty"); //NOI18N
1184 } else if (null == user) {
1186 throw new NullPointerException("user is null"); //NOI18N
1187 } else if (user.getUserId() == null) {
1189 throw new NullPointerException("user.userId is null"); //NOI18N
1190 } else if (user.getUserId() < 1) {
1192 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid.", user.getUserId())); //NOI18N
1193 } else if (user.getUserName() == null) {
1195 throw new NullPointerException("user.userName is null"); //NOI18N
1196 } else if (user.getUserName().isEmpty()) {
1198 throw new IllegalArgumentException("user.userName is empty"); //NOI18N
1199 } else if (user.getUserAccountStatus() == null) {
1201 throw new NullPointerException("user.userAccountStatus is null"); //NOI18N
1202 } else if (user.getUserContact() == null) {
1204 throw new NullPointerException("user.userContact is null"); //NOI18N
1205 } else if (user.getUserContact().getContactId() == null) {
1207 throw new NullPointerException("user.userContact.contactId is null"); //NOI18N
1208 } else if (user.getUserContact().getContactId() < 1) {
1210 throw new IllegalArgumentException(MessageFormat.format("user.userContact.contactId={0} is invalid", user.getUserContact().getContactId())); //NOI18N
1211 } else if (user.getUserContact().getContactPersonalTitle() == null) {
1213 throw new NullPointerException("user.userContact.contactPersonalTitle is null"); //NOI18N
1214 } else if (user.getUserLocale() == null) {
1216 throw new NullPointerException("user.userLocale is null"); //NOI18N
1217 } else if (this.getSession() == null) {
1219 throw new NullPointerException("this.session is not set. Have you forgotten to call super(String, String) and called only super() ?"); //NOI18N
1223 final Properties variables = UserUtils.getAllUserFields(user);
1225 // Set base URL and random password
1226 variables.put("baseUrl", baseUrl); //NOI18N
1227 variables.put("randomPassword", ""); //NOI18N
1229 // Is the random password set?
1230 if ((randomPassword instanceof String) && (!randomPassword.isEmpty())) {
1231 variables.put("randomPassword", randomPassword); //NOI18N
1235 final Address recipientAddress;
1238 // Create email address and set
1239 recipientAddress = new InternetAddress(user.getUserContact().getContactEmailAddress());
1240 } catch (final AddressException ex) {
1242 throw new EJBException(ex);
1245 // Prepare mail wrapper
1246 // @TODO Language from message bundle
1247 final WrapableEmailDelivery emailWrapper = new EmailDeliveryWrapper(recipientAddress, subjectLine, templateName, variables, user.getUserLocale());
1250 // Send out email change
1251 final ObjectMessage message = this.getSession().createObjectMessage();
1252 message.setObject(emailWrapper);
1255 this.sendMessage(message);
1256 } catch (final JMSException ex) {
1258 throw new EJBException(ex);
1262 this.getLoggerBeanLocal().logTrace("sendEmail: EXIT!"); //NOI18N
1266 * Updates all contact's phone instances from other contact, both contacts
1267 * should be the same.
1269 * @param contact Contact to set instances
1270 * @param other Other contact to get instances from
1272 protected void setAllContactPhoneEntries (final Contact contact, final Contact other) {
1274 this.getLoggerBeanLocal().logTrace(MessageFormat.format("setAllContactPhoneEntries: contact={0},other={1} - CALLED!", contact, other)); //NOI18N
1276 // Both must be the same and not null
1277 if (null == contact) {
1279 throw new NullPointerException("contact is null"); //NOI18N
1280 } else if (null == other) {
1282 throw new NullPointerException("other is null"); //NOI18N
1283 } else if (!Objects.equals(contact, other)) {
1284 // Not same instances
1285 throw new IllegalArgumentException(MessageFormat.format("contact={0} and other={1} are not equal!", contact, other)); //NOI18N
1289 this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllContactPhoneEntries: other.contactMobileNumber={0}", other.getContactMobileNumber())); //NOI18N
1291 // Is other mobile not set?
1292 if ((other.getContactMobileNumber() == null) || (MobileNumberUtils.isSameMobileNumber(contact.getContactMobileNumber(), other.getContactMobileNumber()))) {
1294 this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntries: Copying mobile entry ..."); //NOI18N
1296 // Is the fax number set?
1297 if (other.getContactMobileNumber() instanceof DialableMobileNumber) {
1298 // Copy mobile number
1299 contact.setContactMobileNumber(this.getDetached(other.getContactMobileNumber(), contact.getContactMobileNumber()));
1302 contact.setContactMobileNumber(null);
1307 this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllContactPhoneEntries: other.contactLandLineNumber={0}", other.getContactLandLineNumber())); //NOI18N
1309 // Is other mobile not set?
1310 if ((other.getContactLandLineNumber() == null) || (LandLineNumberUtils.isSameLandLineNumber(contact.getContactLandLineNumber(), other.getContactLandLineNumber()))) {
1312 this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntries: Copying land-line entry ..."); //NOI18N
1314 // Is the land-line number set?
1315 if (other.getContactLandLineNumber() instanceof DialableLandLineNumber) {
1316 // Copy land-line number
1317 contact.setContactLandLineNumber(this.mergeLandLineNumberData(other.getContactLandLineNumber(), contact.getContactLandLineNumber()));
1320 contact.setContactLandLineNumber(null);
1325 this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllContactPhoneEntries: other.contactFaxNumber={0}", other.getContactFaxNumber())); //NOI18N
1327 // Is other mobile not set?
1328 if ((other.getContactFaxNumber() == null) || (FaxNumberUtils.isSameFaxNumber(contact.getContactFaxNumber(), other.getContactFaxNumber()))) {
1330 this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntries: Copying fax entry ..."); //NOI18N
1332 // Is the fax number set?
1333 if (other.getContactFaxNumber() instanceof DialableFaxNumber) {
1335 contact.setContactFaxNumber(this.getDetached(other.getContactFaxNumber(), contact.getContactFaxNumber()));
1338 contact.setContactFaxNumber(null);
1343 this.getLoggerBeanLocal().logTrace("setAllContactPhoneEntries: EXIT!"); //NOI18N
1347 * Updates all contact's phone entry's updated timestamps
1349 * @param contact Contact instance to update
1350 * @param isMobileUnlinked Whether a mobile entry has been unlinked in
1352 * @param isLandlineUnlinked Whether a land-line entry has been unlinked in
1354 * @param isFaxUnlinked Whether a fax entry has been unlinked in
1357 protected void setAllContactPhoneEntriesUpdated (final Contact contact, final boolean isMobileUnlinked, final boolean isLandlineUnlinked, final boolean isFaxUnlinked) {
1359 this.getLoggerBeanLocal().logTrace(MessageFormat.format("setAllContactPhoneEntriesUpdated: contact={0},isMobileUnlinked={1},isLandlineUnlinked={2},isFaxUnlinked={3} - CALLED", contact, isMobileUnlinked, isLandlineUnlinked, isFaxUnlinked)); //NOI18N
1361 // The contact instance must be valid
1362 if (null == contact) {
1364 throw new NullPointerException("contact is null"); //NOI18N
1365 } else if (contact.getContactId() == null) {
1367 throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
1368 } else if (contact.getContactId() < 1) {
1370 throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1373 // Get all phone instances
1374 final DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber();
1375 final DialableFaxNumber faxNumber = contact.getContactFaxNumber();
1376 final DialableMobileNumber mobileNumber = contact.getContactMobileNumber();
1378 // Flags and instances must be constistent
1379 if (isMobileUnlinked && mobileNumber instanceof DialableMobileNumber) {
1381 throw new IllegalStateException("isCellPhoneUnlinked is TRUE, but mobileNumber is set."); //NOI18N
1382 } else if (isLandlineUnlinked && landLineNumber instanceof DialableLandLineNumber) {
1384 throw new IllegalStateException("isLandlineUnlinked is TRUE, but landLineNumber is set."); //NOI18N
1385 } else if (isFaxUnlinked && faxNumber instanceof DialableFaxNumber) {
1387 throw new IllegalStateException("isFaxUnlinked is TRUE, but faxNumber is set."); //NOI18N
1390 // Is a phone number instance set?
1391 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() instanceof Long) && (landLineNumber.getPhoneId() > 0)) {
1393 this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntriesUpdated: Setting updated timestamp for land-line number ..."); //NOI18N
1395 // Set updated timestamp
1396 landLineNumber.setPhoneEntryUpdated(new Date());
1399 // Is a fax number instance set?
1400 if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() instanceof Long) && (faxNumber.getPhoneId() > 0)) {
1402 this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntriesUpdated: Setting updated timestamp for fax number ..."); //NOI18N
1404 // Set updated timestamp
1405 faxNumber.setPhoneEntryUpdated(new Date());
1408 // Is a mobile number instance set?
1409 if ((mobileNumber instanceof DialableMobileNumber) && (mobileNumber.getMobileId() instanceof Long) && (mobileNumber.getMobileId() > 0)) {
1411 this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntriesUpdated: Setting updated timestamp for mobile number ..."); //NOI18N
1413 // Set updated timestamp
1414 mobileNumber.setMobileEntryUpdated(new Date());
1418 this.getLoggerBeanLocal().logTrace("setAllContactPhoneEntriesUpdated: EXIT!"); //NOI18N