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.pizzaaplication.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.contact.Contacts;
32 import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
33 import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData;
34 import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
35 import org.mxchange.jcontactsbusiness.model.branchoffice.BusinessBranchOffice;
36 import org.mxchange.jcontactsbusiness.model.employee.BusinessEmployee;
37 import org.mxchange.jcontactsbusiness.model.employee.Employable;
38 import org.mxchange.jcontactsbusiness.model.headquarters.BusinessHeadquarters;
39 import org.mxchange.jcontactsbusiness.model.headquarters.Headquarter;
40 import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime;
41 import org.mxchange.jcoreee.database.BaseEnterpriseBean;
42 import org.mxchange.jcountry.model.data.Country;
43 import org.mxchange.jcountry.model.data.CountryData;
44 import org.mxchange.jmailee.model.delivery.wrapper.EmailDeliveryWrapper;
45 import org.mxchange.jmailee.model.delivery.wrapper.WrapableEmailDelivery;
46 import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
47 import org.mxchange.jphone.model.phonenumbers.fax.FaxNumbers;
48 import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
49 import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumbers;
50 import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
51 import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumbers;
52 import org.mxchange.jphone.utils.PhoneUtils;
53 import org.mxchange.jusercore.model.user.LoginUser;
54 import org.mxchange.jusercore.model.user.User;
55 import org.mxchange.jusercore.model.user.Users;
58 * A helper class for beans that access the database.
60 * @author Roland Häder<roland@mxchange.org>
62 public abstract class BasePizzaEnterpriseBean extends BaseEnterpriseBean {
67 private static final long serialVersionUID = 12_895_410_275_811_963L;
70 * Protected constructor
72 protected BasePizzaEnterpriseBean () {
73 // Call super constructor
78 * Constructor with queue factory JNDI and queue JNDI names
80 * @param factoryJndi JNDI name for queue factory
81 * @param queueJndi JNDI name for email queue
83 protected BasePizzaEnterpriseBean (final String factoryJndi, final String queueJndi) {
84 // Call super constructor
85 super(factoryJndi, queueJndi);
89 * Get back a managed instance from given contact
91 * @param contact Unmanaged/detached contact instance
93 * @return Managed contact instance
95 protected Contact createManaged (final Contact contact) {
97 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N
99 // user should not be null
100 if (null == contact) {
102 throw new NullPointerException("contact is null"); //NOI18N
103 } else if (contact.getContactId() == null) {
105 throw new NullPointerException("contact.contactId is null"); //NOI18N
106 } else if (contact.getContactId() < 1) {
108 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is null", contact.getContactId())); //NOI18N
111 // Try to find it (should be there)
112 final Contact managedContact = this.getEntityManager().find(UserContact.class, contact.getContactId());
115 assert (managedContact instanceof Contact) : "managedContact is null"; //NOI18N
118 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N
121 return managedContact;
125 * Get back a managed instance from given country
127 * @param country Unmanaged/detached country instance
129 * @return Managed country instance
131 protected Country createManaged (final Country country) {
133 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: country={1} - CALLED!", this.getClass().getSimpleName(), country)); //NOI18N
135 // user should not be null
136 if (null == country) {
138 throw new NullPointerException("country is null"); //NOI18N
139 } else if (country.getCountryId() == null) {
141 throw new NullPointerException("country.countryId is null"); //NOI18N
142 } else if (country.getCountryId() < 1) {
144 throw new IllegalArgumentException(MessageFormat.format("country.countryId={0} is null", country.getCountryId())); //NOI18N
147 // Try to find it (should be there)
148 final Country managedCountry = this.getEntityManager().find(CountryData.class, country.getCountryId());
151 assert (managedCountry instanceof Country) : "managedCountry is null"; //NOI18N
154 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedCountry={1} - EXIT!", this.getClass().getSimpleName(), managedCountry)); //NOI18N
157 return managedCountry;
161 * Get back a managed instance from given basic data
163 * @param basicData Unmanaged/detached basic data instance
165 * @return Managed basic data instance
167 protected BusinessBasicData createManaged (final BusinessBasicData basicData) {
169 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: basicData={1} - CALLED!", this.getClass().getSimpleName(), basicData)); //NOI18N
171 // user should not be null
172 if (null == basicData) {
174 throw new NullPointerException("basicData is null"); //NOI18N
175 } else if (basicData.getBasicDataId() == null) {
177 throw new NullPointerException("basicData.basicDataId is null"); //NOI18N
178 } else if (basicData.getBasicDataId() < 1) {
180 throw new IllegalArgumentException(MessageFormat.format("basicData.basicDataId={0} is null", basicData.getBasicDataId())); //NOI18N
183 // Try to find it (should be there)
184 final BusinessBasicData managedBasicData = this.getEntityManager().find(CompanyBasicData.class, basicData.getBasicDataId());
187 assert (managedBasicData instanceof BusinessBasicData) : "managedBasicData is null"; //NOI18N
190 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedBasicData={1} - EXIT!", this.getClass().getSimpleName(), managedBasicData)); //NOI18N
193 return managedBasicData;
197 * Get back a managed instance from given employee
199 * @param employee Unmanaged/detached employee instance
201 * @return Managed employee instance
203 protected Employee createManaged (final Employee employee) {
205 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: employee={1} - CALLED!", this.getClass().getSimpleName(), employee)); //NOI18N
207 // user should not be null
208 if (null == employee) {
210 throw new NullPointerException("employee is null"); //NOI18N
211 } else if (employee.getEmployeeId() == null) {
213 throw new NullPointerException("employee.employeeId is null"); //NOI18N
214 } else if (employee.getEmployeeId() < 1) {
216 throw new IllegalArgumentException(MessageFormat.format("employee.employeeId={0} is null", employee.getEmployeeId())); //NOI18N
219 // Try to find it (should be there)
220 final Employee managedEmployee = this.getEntityManager().find(CompanyEmployee.class, employee.getEmployeeId());
223 assert (managedEmployee instanceof Employee) : "managedEmployee is null"; //NOI18N
226 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedEmployee={1} - EXIT!", this.getClass().getSimpleName(), managedEmployee)); //NOI18N
229 return managedEmployee;
233 * Get back a managed instance from given user
235 * @param user Unmanaged/detached user instance
237 * @return Managed user instance
239 protected User createManaged (final User user) {
241 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
243 // user should not be null
246 throw new NullPointerException("user is null"); //NOI18N
247 } else if (user.getUserId() == null) {
249 throw new NullPointerException("user.userId is null"); //NOI18N
250 } else if (user.getUserId() < 1) {
252 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is null", user.getUserId())); //NOI18N
253 } else if (user.getUserContact() == null) {
255 throw new NullPointerException("user.userContact is null"); //NOI18N
256 } else if (user.getUserContact().getContactId() == null) {
258 throw new NullPointerException("user.userContact.contactId is null"); //NOI18N
259 } else if (user.getUserContact().getContactId() < 1) {
260 // Not valid id number
261 throw new IllegalArgumentException(MessageFormat.format("user.userContact.contactId={0} is not valid", user.getUserContact().getContactId())); //NOI18N#
264 // Try to find it (should be there)
265 final User managedUser = this.getEntityManager().find(LoginUser.class, user.getUserId());
268 assert (managedUser instanceof User) : "managedUser is null"; //NOI18N
271 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedUser={1} - EXIT!", this.getClass().getSimpleName(), managedUser)); //NOI18N
278 * Updates all contact's phone entry's created timestamps
280 * @param contact Contact instance to update
282 protected void setAllContactPhoneEntriesCreated (final Contact contact) {
284 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N
286 // The contact instance must be valid
287 if (null == contact) {
289 throw new NullPointerException("contact is null"); //NOI18N
292 // Get all phone instances
293 final DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber();
294 final DialableFaxNumber faxNumber = contact.getContactFaxNumber();
295 final DialableMobileNumber mobileNumber = contact.getContactMobileNumber();
298 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: landLineNumber={1},faxNumber={2},mobileNumber={3}", this.getClass().getSimpleName(), landLineNumber, faxNumber, mobileNumber)); //NOI18N
300 // Is a phone number instance set?
301 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() == null)) {
303 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for land-line number ...", this.getClass().getSimpleName())); //NOI18N
305 // Set updated timestamp
306 landLineNumber.setPhoneEntryCreated(new Date());
309 // Is a fax number instance set?
310 if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() == null)) {
312 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for fax number ...", this.getClass().getSimpleName())); //NOI18N
314 // Set updated timestamp
315 faxNumber.setPhoneEntryCreated(new Date());
318 // Is a mobile number instance set?
319 if ((mobileNumber instanceof DialableMobileNumber) && (mobileNumber.getPhoneId() == null)) {
321 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for mobile number ...", this.getClass().getSimpleName())); //NOI18N
323 // Set updated timestamp
324 mobileNumber.setPhoneEntryCreated(new Date());
328 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: EXIT!", this.getClass().getSimpleName())); //NOI18N
332 * Returns a managed instance from given mobile number
334 * @param mobileNumber Mobile instance
335 * @param fetchedNumber Found mobile number in database
337 * @return Managed instance
339 protected DialableMobileNumber createManaged (final DialableMobileNumber mobileNumber, final DialableMobileNumber fetchedNumber) {
341 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: mobileNumber={1},fetchedNumber={2} - CALLED!", this.getClass().getSimpleName(), mobileNumber, fetchedNumber)); //NOI18N
344 if (null == mobileNumber) {
346 throw new NullPointerException("mobileNumber is null"); //NOI18N
347 } else if (null == fetchedNumber) {
349 throw new NullPointerException("fetchedNumber is null"); //NOI18N
350 } else if (fetchedNumber.getPhoneId() == null) {
352 throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
356 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N
358 // Init query instance
359 final DialableMobileNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
362 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N
365 DialableMobileNumber detachedNumber = null;
367 // Is there a difference?
368 if (!PhoneUtils.isSameMobileNumber(mobileNumber, fetchedNumber)) {
370 detachedNumber = this.getEntityManager().merge(foundNumber);
376 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: detachedNumber={1} - EXIT!", this.getClass().getSimpleName(), detachedNumber)); //NOI18N
379 return detachedNumber;
383 * Returns a managed instance from given land-line number
385 * @param landLineNumber Land-line instance
386 * @param fetchedNumber Found land-line number in database
388 * @return Managed instance
390 protected DialableLandLineNumber createManaged (final DialableLandLineNumber landLineNumber, final DialableLandLineNumber fetchedNumber) {
392 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: landLineNumber={1},fetchedNumber={2} - CALLED!", this.getClass().getSimpleName(), landLineNumber, fetchedNumber)); //NOI18N
395 if (null == landLineNumber) {
397 throw new NullPointerException("landLineNumber is null"); //NOI18N
398 } else if (null == fetchedNumber) {
400 throw new NullPointerException("fetchedNumber is null"); //NOI18N
401 } else if (fetchedNumber.getPhoneId() == null) {
403 throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N
407 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N
409 // Init query instance
410 final DialableLandLineNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
413 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N
416 DialableLandLineNumber detachedNumber = null;
418 // Is there a difference?
419 if (!PhoneUtils.isSameLandLineNumber(landLineNumber, fetchedNumber)) {
421 detachedNumber = this.getEntityManager().merge(foundNumber);
427 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: detachedNumber={1} - EXIT!", this.getClass().getSimpleName(), detachedNumber)); //NOI18N
430 return detachedNumber;
434 * Returns a managed instance from given fax number
436 * @param faxNumber Fax instance
437 * @param fetchedNumber Found fax number in database
439 * @return Managed instance
441 protected DialableFaxNumber createManaged (final DialableFaxNumber faxNumber, final DialableFaxNumber fetchedNumber) {
443 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: faxNumber={1},fetchedNumber={2} - CALLED!", this.getClass().getSimpleName(), faxNumber, fetchedNumber)); //NOI18N
446 if (null == faxNumber) {
448 throw new NullPointerException("faxNumber is null"); //NOI18N
449 } else if (null == fetchedNumber) {
451 throw new NullPointerException("fetchedNumber is null"); //NOI18N
452 } else if (fetchedNumber.getPhoneId() == null) {
454 throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
458 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N
460 // Init query instance
461 final DialableFaxNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
464 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N
467 DialableFaxNumber detachedNumber = null;
469 // Is there a difference?
470 if (!PhoneUtils.isSameFaxNumber(faxNumber, fetchedNumber)) {
472 detachedNumber = this.getEntityManager().merge(foundNumber);
478 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: detachedNumber={1} - EXIT!", this.getClass().getSimpleName(), detachedNumber)); //NOI18N
481 return detachedNumber;
485 * Get back a managed instance from given contact
487 * @param contact Unmanaged/detached contact instance
489 * @return Managed contact instance
491 protected Contact createManaged (final Contact contact) {
493 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N
495 // user should not be null
496 if (null == contact) {
498 throw new NullPointerException("contact is null"); //NOI18N
499 } else if (contact.getContactId() == null) {
501 throw new NullPointerException("contact.contactId is null"); //NOI18N
502 } else if (contact.getContactId() < 1) {
504 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
507 // Try to find it (should be there)
508 final Contact managedContact = this.getEntityManager().find(UserContact.class, contact.getContactId());
511 assert (managedContact instanceof Contact) : "managedContact is null"; //NOI18N
514 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N
517 return managedContact;
521 * Get back a managed instance from given country
523 * @param country Unmanaged/detached country instance
525 * @return Managed country instance
527 protected Country createManaged (final Country country) {
529 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: country={1} - CALLED!", this.getClass().getSimpleName(), country)); //NOI18N
531 // user should not be null
532 if (null == country) {
534 throw new NullPointerException("country is null"); //NOI18N
535 } else if (country.getCountryId() == null) {
537 throw new NullPointerException("country.countryId is null"); //NOI18N
538 } else if (country.getCountryId() < 1) {
540 throw new IllegalArgumentException(MessageFormat.format("country.countryId={0} is invalid", country.getCountryId())); //NOI18N
543 // Try to find it (should be there)
544 final Country managedCountry = this.getEntityManager().find(CountryData.class, country.getCountryId());
547 assert (managedCountry instanceof Country) : "managedCountry is null"; //NOI18N
550 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedCountry={1} - EXIT!", this.getClass().getSimpleName(), managedCountry)); //NOI18N
553 return managedCountry;
557 * Get back a managed instance from given basic data
559 * @param basicData Unmanaged/detached basic data instance
561 * @return Managed basic data instance
563 protected BasicData createManaged (final BasicData basicData) {
565 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: basicData={1} - CALLED!", this.getClass().getSimpleName(), basicData)); //NOI18N
567 // user should not be null
568 if (null == basicData) {
570 throw new NullPointerException("basicData is null"); //NOI18N
571 } else if (basicData.getBasicDataId() == null) {
573 throw new NullPointerException("basicData.basicDataId is null"); //NOI18N
574 } else if (basicData.getBasicDataId() < 1) {
576 throw new IllegalArgumentException(MessageFormat.format("basicData.basicDataId={0} is invalid", basicData.getBasicDataId())); //NOI18N
579 // Try to find it (should be there)
580 final BasicData managedBasicData = this.getEntityManager().find(BusinessBasicData.class, basicData.getBasicDataId());
583 assert (managedBasicData instanceof BasicData) : "managedBasicData is null"; //NOI18N
586 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedBasicData={1} - EXIT!", this.getClass().getSimpleName(), managedBasicData)); //NOI18N
589 return managedBasicData;
593 * Get back a managed instance from given branch office
595 * @param headquarter Unmanaged/detached branch office instance
597 * @return Managed basic data instance
599 protected BranchOffice createManaged (final BranchOffice headquarter) {
601 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: headquarter={1} - CALLED!", this.getClass().getSimpleName(), headquarter)); //NOI18N
603 // user should not be null
604 if (null == headquarter) {
606 throw new NullPointerException("headquarter is null"); //NOI18N
607 } else if (headquarter.getBranchId() == null) {
609 throw new NullPointerException("headquarter.headquarterId is null"); //NOI18N
610 } else if (headquarter.getBranchId() < 1) {
612 throw new IllegalArgumentException(MessageFormat.format("headquarter.headquarterId={0} is invalid", headquarter.getBranchId())); //NOI18N
615 // Try to find it (should be there)
616 final BranchOffice managedBranchOffice = this.getEntityManager().find(BusinessBranchOffice.class, headquarter.getBranchId());
619 assert (managedBranchOffice instanceof BasicData) : "managedBranchOffice is null"; //NOI18N
622 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedBranchOffice={1} - EXIT!", this.getClass().getSimpleName(), managedBranchOffice)); //NOI18N
625 return managedBranchOffice;
629 * Get back a managed instance from given employee
631 * @param employee Unmanaged/detached employee instance
633 * @return Managed employee instance
635 protected Employable createManaged (final Employable employee) {
637 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: employee={1} - CALLED!", this.getClass().getSimpleName(), employee)); //NOI18N
639 // user should not be null
640 if (null == employee) {
642 throw new NullPointerException("employee is null"); //NOI18N
643 } else if (employee.getEmployeeId() == null) {
645 throw new NullPointerException("employee.employeeId is null"); //NOI18N
646 } else if (employee.getEmployeeId() < 1) {
648 throw new IllegalArgumentException(MessageFormat.format("employee.employeeId={0} is invalid", employee.getEmployeeId())); //NOI18N
651 // Try to find it (should be there)
652 final Employable managedEmployee = this.getEntityManager().find(BusinessEmployee.class, employee.getEmployeeId());
655 assert (managedEmployee instanceof Employable) : "managedEmployee is null"; //NOI18N
658 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedEmployee={1} - EXIT!", this.getClass().getSimpleName(), managedEmployee)); //NOI18N
661 return managedEmployee;
665 * Get back a managed instance from given headquarters
667 * @param headquarter Unmanaged/detached headquarter instance
669 * @return Managed basic data instance
671 protected Headquarter createManaged (final Headquarter headquarter) {
673 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: headquarter={1} - CALLED!", this.getClass().getSimpleName(), headquarter)); //NOI18N
675 // user should not be null
676 if (null == headquarter) {
678 throw new NullPointerException("headquarter is null"); //NOI18N
679 } else if (headquarter.getHeadquartersId() == null) {
681 throw new NullPointerException("headquarter.headquarterId is null"); //NOI18N
682 } else if (headquarter.getHeadquartersId() < 1) {
684 throw new IllegalArgumentException(MessageFormat.format("headquarter.headquarterId={0} is invalid", headquarter.getHeadquartersId())); //NOI18N
687 // Try to find it (should be there)
688 final Headquarter managedHeadquarter = this.getEntityManager().find(BusinessHeadquarters.class, headquarter.getHeadquartersId());
691 assert (managedHeadquarter instanceof Headquarter) : "managedHeadquarter is null"; //NOI18N
694 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedHeadquarter={1} - EXIT!", this.getClass().getSimpleName(), managedHeadquarter)); //NOI18N
697 return managedHeadquarter;
701 * Get back a managed instance from given user
703 * @param user Unmanaged/detached user instance
705 * @return Managed user instance
707 protected User createManaged (final User user) {
709 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
711 // user should not be null
714 throw new NullPointerException("user is null"); //NOI18N
715 } else if (user.getUserId() == null) {
717 throw new NullPointerException("user.userId is null"); //NOI18N
718 } else if (user.getUserId() < 1) {
720 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); //NOI18N
721 } else if (user.getUserContact() == null) {
723 throw new NullPointerException("user.userContact is null"); //NOI18N
724 } else if (user.getUserContact().getContactId() == null) {
726 throw new NullPointerException("user.userContact.contactId is null"); //NOI18N
727 } else if (user.getUserContact().getContactId() < 1) {
728 // Not valid id number
729 throw new IllegalArgumentException(MessageFormat.format("user.userContact.contactId={0} is not valid", user.getUserContact().getContactId())); //NOI18N#
732 // Try to find it (should be there)
733 final User managedUser = this.getEntityManager().find(LoginUser.class, user.getUserId());
736 assert (managedUser instanceof User) : "managedUser is null"; //NOI18N
739 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedUser={1} - EXIT!", this.getClass().getSimpleName(), managedUser)); //NOI18N
746 * Sets created timestamp on all opening times.
748 * @param openingTimes Opening times list
750 * @throws NullPointerException If given list is null
751 * @throws IllegalArgumentException If given list is empty
752 * @throws IllegalStateException If openingId is not null
754 protected void setAllOpeningTimesCreated (final List<OpeningTime> openingTimes) {
755 // Validate parameter
756 if (null == openingTimes) {
758 throw new NullPointerException("openingTimes is null");
759 } else if (openingTimes.isEmpty()) {
761 throw new IllegalArgumentException("openingTimes is empty");
764 // Walk through whole list
765 for (final OpeningTime openingTime : openingTimes) {
766 // Id should not be set
767 if (openingTime.getOpeningTimeId() != null) {
769 throw new IllegalStateException("openingTime.openingId is not null");
772 // Set created timestamp
773 openingTime.setOpeningTimeEntryCreated(new Date());
778 * Updates all contact's phone entry's created timestamps
780 * @param contact Contact instance to update
782 protected void setAllPhoneEntriesCreated (final Contact contact) {
784 this.getLoggerBeanLocal().logTrace(MessageFormat.format("setAllPhoneEntriesCreated: contact={0} - CALLED!", contact)); //NOI18N
786 // The contact instance must be valid
787 if (null == contact) {
789 throw new NullPointerException("contact is null"); //NOI18N
790 } else if (contact.getContactId() != null) {
792 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is unexpected.", contact.getContactId()));
795 // Get all phone instances
796 final DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber();
797 final DialableFaxNumber faxNumber = contact.getContactFaxNumber();
798 final DialableMobileNumber mobileNumber = contact.getContactMobileNumber();
801 this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllPhoneEntriesCreated: landLineNumber={0},faxNumber={1},mobileNumber={2}", landLineNumber, faxNumber, mobileNumber)); //NOI18N
803 // Is a phone number instance set?
804 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() == null)) {
806 this.getLoggerBeanLocal().logDebug("setAllPhoneEntriesCreated: Setting created timestamp for land-line number ..."); //NOI18N
808 // Set updated timestamp
809 landLineNumber.setPhoneEntryCreated(new Date());
812 // Is a fax number instance set?
813 if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() == null)) {
815 this.getLoggerBeanLocal().logDebug("setAllPhoneEntriesCreated: Setting created timestamp for fax number ..."); //NOI18N
817 // Set updated timestamp
818 faxNumber.setPhoneEntryCreated(new Date());
821 // Is a mobile number instance set?
822 if ((mobileNumber instanceof DialableMobileNumber) && (mobileNumber.getMobileId() == null)) {
824 this.getLoggerBeanLocal().logDebug("setAllPhoneEntriesCreated: Setting created timestamp for mobile number ..."); //NOI18N
826 // Set updated timestamp
827 mobileNumber.setMobileEntryCreated(new Date());
831 this.getLoggerBeanLocal().logTrace("setAllPhoneEntriesCreated: EXIT!"); //NOI18N
835 * Updates all branch office's phone entry's created timestamps
837 * @param branchOffice Branch office instance to update
839 protected void setAllPhoneEntriesCreated (final BranchOffice branchOffice) {
841 this.getLoggerBeanLocal().logTrace(MessageFormat.format("setAllPhoneEntriesCreated: branchOffice={0} - CALLED!", branchOffice)); //NOI18N
843 // The contact instance must be valid
844 if (null == branchOffice) {
846 throw new NullPointerException("branchOffice is null"); //NOI18N
847 } else if (branchOffice.getBranchId() != null) {
849 throw new IllegalArgumentException(MessageFormat.format("branchOffice.branchId={0} is unexpected.", branchOffice.getBranchId()));
852 // Get all phone instances
853 final DialableLandLineNumber landLineNumber = branchOffice.getBranchLandLineNumber();
854 final DialableFaxNumber faxNumber = branchOffice.getBranchFaxNumber();
857 this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllPhoneEntriesCreated: landLineNumber={0},faxNumber={1}", landLineNumber, faxNumber)); //NOI18N
859 // Is a phone number instance set?
860 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() == null)) {
862 this.getLoggerBeanLocal().logDebug("setAllPhoneEntriesCreated: Setting created timestamp for land-line number ..."); //NOI18N
864 // Set updated timestamp
865 landLineNumber.setPhoneEntryCreated(new Date());
868 // Is a fax number instance set?
869 if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() == null)) {
871 this.getLoggerBeanLocal().logDebug("setAllPhoneEntriesCreated: Setting created timestamp for fax number ..."); //NOI18N
873 // Set updated timestamp
874 faxNumber.setPhoneEntryCreated(new Date());
878 this.getLoggerBeanLocal().logTrace("setAllPhoneEntriesCreated: EXIT!"); //NOI18N
882 * Updates all branch office's phone entry's created timestamps
884 * @param headquarter Headquarters instance to update
886 protected void setAllPhoneEntriesCreated (final Headquarter headquarter) {
888 this.getLoggerBeanLocal().logTrace(MessageFormat.format("setAllPhoneEntriesCreated: headquarter={0} - CALLED!", headquarter)); //NOI18N
890 // The contact instance must be valid
891 if (null == headquarter) {
893 throw new NullPointerException("headquarter is null"); //NOI18N
894 } else if (headquarter.getHeadquartersId() != null) {
896 throw new IllegalArgumentException(MessageFormat.format("headquarter.branchId={0} is unexpected.", headquarter.getHeadquartersId()));
899 // Get all phone instances
900 final DialableLandLineNumber landLineNumber = headquarter.getHeadquartersLandLineNumber();
901 final DialableFaxNumber faxNumber = headquarter.getHeadquartersFaxNumber();
904 this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllPhoneEntriesCreated: landLineNumber={0},faxNumber={1}", landLineNumber, faxNumber)); //NOI18N
906 // Is a phone number instance set?
907 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() == null)) {
909 this.getLoggerBeanLocal().logDebug("setAllPhoneEntriesCreated: Setting created timestamp for land-line number ..."); //NOI18N
911 // Set updated timestamp
912 landLineNumber.setPhoneEntryCreated(new Date());
915 // Is a fax number instance set?
916 if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() == null)) {
918 this.getLoggerBeanLocal().logDebug("setAllPhoneEntriesCreated: Setting created timestamp for fax number ..."); //NOI18N
920 // Set updated timestamp
921 faxNumber.setPhoneEntryCreated(new Date());
925 this.getLoggerBeanLocal().logTrace("setAllPhoneEntriesCreated: EXIT!"); //NOI18N
929 * Updates all company's phone entry's created timestamps
931 * @param basicData Company basic data instance to update
933 protected void setAllPhoneEntriesCreated (final BasicData basicData) {
935 this.getLoggerBeanLocal().logTrace(MessageFormat.format("setAllPhoneEntriesCreated: basicData={0} - CALLED!", basicData)); //NOI18N
937 // The contact instance must be valid
938 if (null == basicData) {
940 throw new NullPointerException("basicData is null"); //NOI18N
941 } else if (basicData.getBasicDataId() != null) {
943 throw new IllegalArgumentException(MessageFormat.format("basicData.basicDataId={0} is unexpected.", basicData.getBasicDataId()));
946 // Get all phone instances
947 final DialableLandLineNumber landLineNumber = basicData.getCompanyLandLineNumber();
948 final DialableFaxNumber faxNumber = basicData.getCompanyFaxNumber();
951 this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllPhoneEntriesCreated: landLineNumber={0},faxNumber={1}", landLineNumber, faxNumber)); //NOI18N
953 // Is a phone number instance set?
954 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() == null)) {
956 this.getLoggerBeanLocal().logDebug("setAllPhoneEntriesCreated: Setting created timestamp for land-line number ..."); //NOI18N
958 // Set updated timestamp
959 landLineNumber.setPhoneEntryCreated(new Date());
961 // Set it back in basic data
962 basicData.setCompanyLandLineNumber(landLineNumber);
965 // Is a fax number instance set?
966 if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() == null)) {
968 this.getLoggerBeanLocal().logDebug("setAllPhoneEntriesCreated: Setting created timestamp for fax number ..."); //NOI18N
970 // Set updated timestamp
971 faxNumber.setPhoneEntryCreated(new Date());
973 // Set it back in basic data
974 basicData.setCompanyFaxNumber(faxNumber);
978 this.getLoggerBeanLocal().logTrace("setAllPhoneEntriesCreated: EXIT!"); //NOI18N
982 * Returns a detached instance from given mobile instance
984 * @param mobileNumber Mobile instance
985 * @param fetchedNumber Found mobile number in database
987 * @return Detached instance
989 protected DialableMobileNumber getDetached (final DialableMobileNumber mobileNumber, final DialableMobileNumber fetchedNumber) {
991 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: mobileNumber={0},fetchedNumber={1} - CALLED!", mobileNumber, fetchedNumber)); //NOI18N
994 if (null == mobileNumber) {
996 throw new NullPointerException("mobileNumber is null"); //NOI18N
997 } else if (fetchedNumber.getMobileId() == null) {
999 throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
1002 // Init query instance
1003 final DialableLandLineNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
1006 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N
1009 DialableLandLineNumber detachedNumber = null;
1011 // Is there a difference?
1012 if (!LandLineNumbers.isSameLandLineNumber(landLineNumber, fetchedNumber)) {
1013 // @TODO Copy all to foundNumber, then merge
1016 detachedNumber = this.getEntityManager().merge(foundNumber);
1021 // Set updated timestamp
1022 managedBranchOffice.setBranchEntryUpdated(new Date());
1025 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: detachedNumber={0} - EXIT!", detachedNumber)); //NOI18N
1028 return detachedNumber;
1032 * Returns a detached instance from given fax instance
1034 * @param faxNumber Fax instance
1035 * @param fetchedNumber Found fax number in database
1037 * @return Detached instance
1039 protected DialableFaxNumber getDetached (final DialableFaxNumber faxNumber, final DialableFaxNumber fetchedNumber) {
1041 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: faxNumber={0},fetchedNumber={1} - CALLED!", faxNumber, fetchedNumber)); //NOI18N
1044 if (null == faxNumber) {
1046 throw new NullPointerException("faxNumber is null"); //NOI18N
1047 } else if (fetchedNumber.getPhoneId() == null) {
1049 throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
1053 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N
1055 // Init query instance
1056 final DialableFaxNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
1059 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N
1062 DialableFaxNumber detachedNumber = null;
1064 // Is there a difference?
1065 if (!FaxNumbers.isSameFaxNumber(faxNumber, fetchedNumber)) {
1066 // @TODO Copy all to foundNumber, then merge
1069 detachedNumber = this.getEntityManager().merge(foundNumber);
1075 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: detachedNumber={0} - EXIT!", detachedNumber)); //NOI18N
1078 return detachedNumber;
1082 * Merges given contact's data
1084 * @param detachedContact Contact instance to merge
1086 * @return Detached contact instance
1088 protected Contact mergeContactData (final Contact detachedContact) {
1090 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactData: contact={1} - CALLED!", this.getClass().getSimpleName(), detachedContact)); //NOI18N
1092 // The contact instance must be valid
1093 if (null == detachedContact) {
1095 throw new NullPointerException("detachedContact is null"); //NOI18N
1096 } else if (detachedContact.getContactId() == null) {
1098 throw new NullPointerException("detachedContact.contactId is null"); //NOI18N //NOI18N
1099 } else if (detachedContact.getContactId() < 1) {
1101 throw new IllegalStateException(MessageFormat.format("{0}.detachedContact.contactId={1} is not valid.", this.getClass().getSimpleName(), detachedContact.getContactId())); //NOI18N
1104 // Get contact from it and find it
1105 final Contact foundContact = this.createManaged(detachedContact);
1108 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.updateUserPersonalData: foundContact.contactId={1}", this.getClass().getSimpleName(), foundContact.getContactId())); //NOI18N
1111 Contacts.copyContactData(detachedContact, foundContact);
1113 // Merge contact instance
1114 final Contact managedContact = this.getEntityManager().merge(foundContact);
1116 // Set updated timestamp
1117 managedContact.setContactEntryUpdated(new Date());
1120 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactData: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N
1122 // Return detached contact
1123 return managedContact;
1127 * Merges given (detached) contact's mobile, land-line and fax numbers
1129 * @param detachedContact Detached contact instance
1131 protected void mergeContactsMobileLandLineFaxNumbers (final Contact detachedContact) {
1133 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactsMobileLandLineFaxNumbers: detachedContact={1} - CALLED!", this.getClass().getSimpleName(), detachedContact)); //NOI18N
1135 // The contact instance must be valid
1136 if (null == detachedContact) {
1138 throw new NullPointerException("detachedContact is null"); //NOI18N
1139 } else if (detachedContact.getContactId() == null) {
1141 throw new NullPointerException("detachedContact.contactId is null"); //NOI18N //NOI18N
1142 } else if (detachedContact.getContactId() < 1) {
1144 throw new IllegalStateException(MessageFormat.format("{0}.detachedContact.contactId={1} is not valid.", this.getClass().getSimpleName(), detachedContact.getContactId())); //NOI18N
1147 // Get all instances
1148 final DialableMobileNumber mobileNumber = detachedContact.getContactMobileNumber();
1149 final DialableLandLineNumber landLineNumber = detachedContact.getContactLandLineNumber();
1150 final DialableFaxNumber faxNumber = detachedContact.getContactFaxNumber();
1152 // Is there a mobile instance set?
1153 if (mobileNumber instanceof DialableMobileNumber) {
1155 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: mobile.phoneId={0} is being updated ...", mobileNumber.getMobileId())); //NOI18N
1157 // Then find it, too
1158 final DialableMobileNumber foundMobile = this.getEntityManager().find(mobileNumber.getClass(), mobileNumber.getMobileId());
1161 assert (foundMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", foundMobile.getMobileId()); //NOI18N
1164 MobileNumbers.copyMobileNumberData(detachedContact.getContactMobileNumber(), foundMobile);
1166 // Then merge it, too
1167 final DialableMobileNumber managedMobile = this.getEntityManager().merge(foundMobile);
1170 assert (managedMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", managedMobile.getMobileId()); //NOI18N
1173 MobileNumbers.copyAll(detachedContact.getContactMobileNumber(), managedMobile);
1176 detachedContact.setContactMobileNumber(managedMobile);
1179 // Is there a fax instance set?
1180 if (faxNumber instanceof DialableFaxNumber) {
1182 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: fax.phoneId={0} is being updated ...", faxNumber.getPhoneId())); //NOI18N
1184 // Then find it, too
1185 final DialableFaxNumber foundFax = this.getEntityManager().find(faxNumber.getClass(), faxNumber.getPhoneId());
1188 assert (foundFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", foundFax.getPhoneId()); //NOI18N
1191 FaxNumbers.copyFaxNumberData(detachedContact.getContactFaxNumber(), foundFax);
1193 // Then merge it, too
1194 final DialableFaxNumber managedFax = this.getEntityManager().merge(foundFax);
1197 assert (managedFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", managedFax.getPhoneId()); //NOI18N
1200 FaxNumbers.copyAll(detachedContact.getContactFaxNumber(), managedFax);
1203 detachedContact.setContactFaxNumber(managedFax);
1206 // Is there a fax instance set?
1207 if (landLineNumber instanceof DialableLandLineNumber) {
1209 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: landLine.phoneId={0} is being updated ...", landLineNumber.getPhoneId())); //NOI18N
1211 // Then find it, too
1212 final DialableLandLineNumber foundLandLine = this.getEntityManager().find(landLineNumber.getClass(), landLineNumber.getPhoneId());
1215 assert (foundLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", foundLandLine.getPhoneId()); //NOI18N
1218 LandLineNumbers.copyLandLineNumberData(detachedContact.getContactLandLineNumber(), foundLandLine);
1220 // Then merge it, too
1221 final DialableLandLineNumber managedLandLine = this.getEntityManager().merge(foundLandLine);
1224 assert (managedLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", managedLandLine.getPhoneId()); //NOI18N
1227 LandLineNumbers.copyAll(detachedContact.getContactLandLineNumber(), managedLandLine);
1230 detachedContact.setContactLandLineNumber(managedLandLine);
1234 this.getLoggerBeanLocal().logTrace("mergeContactsMobileLandLineFaxNumbers: EXIT!"); //NOI18N
1238 * Merges given department's data
1240 * @param detachedDepartment Department instance to merge
1242 * @return Detached contact instance
1244 protected Department mergeDepartmentData (final Department detachedDepartment) {
1246 this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeDepartmentData: detachedDepartment={0} - CALLED!", detachedDepartment)); //NOI18N
1248 // The contact instance must be valid
1249 if (null == detachedDepartment) {
1251 throw new NullPointerException("detachedDepartment is null"); //NOI18N
1252 } else if (detachedDepartment.getDepartmentId() == null) {
1254 throw new NullPointerException("detachedDepartment.departmentId is null"); //NOI18N
1255 } else if (detachedDepartment.getDepartmentId() < 1) {
1257 throw new IllegalStateException(MessageFormat.format("detachedDepartment.departmentId ={0} is not valid.", detachedDepartment.getDepartmentId())); //NOI18N
1260 // Get contact from it and find it
1261 final Department foundDepartment = this.createManaged(detachedDepartment);
1264 this.getLoggerBeanLocal().logDebug(MessageFormat.format("mergeDepartmentData: foundContact.contactId={0}", foundDepartment.getDepartmentId())); //NOI18N
1267 Departments.copyDepartmentData(detachedDepartment, foundDepartment);
1269 // Merge contact instance
1270 final Department managedDepartment = this.getEntityManager().merge(foundDepartment);
1272 // Set updated timestamp
1273 managedDepartment.setDepartmentEntryUpdated(new Date());
1276 this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeDepartmentData: managedDepartment={0} - EXIT!", managedDepartment)); //NOI18N
1278 // Return detached contact
1279 return managedDepartment;
1283 * Returns a detached instance from given fax instance merged into current.
1285 * @param faxNumber Fax instance
1286 * @param fetchedNumber Found fax number in database
1288 * @return Detached instance
1290 protected DialableFaxNumber mergeFaxNumberData (final DialableFaxNumber faxNumber, final DialableFaxNumber fetchedNumber) {
1292 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: faxNumber={0},fetchedNumber={1} - CALLED!", faxNumber, fetchedNumber)); //NOI18N
1295 if (null == faxNumber) {
1297 throw new NullPointerException("faxNumber is null"); //NOI18N
1298 } else if (fetchedNumber.getPhoneId() == null) {
1300 throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
1304 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N
1306 // Init query instance
1307 final DialableFaxNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
1310 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N
1313 DialableFaxNumber detachedNumber = null;
1315 // Is there a difference?
1316 if (!FaxNumbers.isSameFaxNumber(faxNumber, fetchedNumber)) {
1317 // @TODO Copy all to foundNumber, then merge
1320 detachedNumber = this.getEntityManager().merge(foundNumber);
1324 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: detachedNumber={0} - EXIT!", detachedNumber)); //NOI18N
1327 return detachedNumber;
1331 * Returns a detached instance from given land-line instance merged with
1334 * @param landLineNumber Land-line instance
1335 * @param fetchedNumber Found land-line number in database
1337 * @return Detached instance
1339 protected DialableLandLineNumber mergeLandLineNumberData (final DialableLandLineNumber landLineNumber, final DialableLandLineNumber fetchedNumber) {
1341 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: landLineNumber={0},fetchedNumber={1} - CALLED!", landLineNumber, fetchedNumber)); //NOI18N
1344 if (null == landLineNumber) {
1346 throw new NullPointerException("landLineNumber is null"); //NOI18N
1347 } else if (fetchedNumber.getPhoneId() == null) {
1349 throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N
1353 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N
1355 // Init query instance
1356 final DialableLandLineNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
1359 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N
1362 DialableLandLineNumber detachedNumber = null;
1364 // Is there a difference?
1365 if (!LandLineNumbers.isSameLandLineNumber(landLineNumber, fetchedNumber)) {
1366 // @TODO Copy all to foundNumber, then merge
1369 detachedNumber = this.getEntityManager().merge(foundNumber);
1373 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: detachedNumber={0} - EXIT!", detachedNumber)); //NOI18N
1376 return detachedNumber;
1380 * Returns a detached instance from given mobile instance merged with
1383 * @param mobileNumber Mobile instance
1384 * @param fetchedNumber Found mobile number in database
1386 * @return Detached instance
1388 protected DialableMobileNumber mergeMobileNumberData (final DialableMobileNumber mobileNumber, final DialableMobileNumber fetchedNumber) {
1390 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: mobileNumber={0},fetchedNumber={1} - CALLED!", mobileNumber, fetchedNumber)); //NOI18N
1393 if (null == mobileNumber) {
1395 throw new NullPointerException("mobileNumber is null"); //NOI18N
1396 } else if (fetchedNumber.getMobileId() == null) {
1398 throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
1402 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getMobileId())); //NOI18N
1404 // Init query instance
1405 final DialableMobileNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getMobileId());
1408 this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N
1411 DialableMobileNumber detachedNumber = null;
1413 // Is there a difference?
1414 if (!MobileNumbers.isSameMobileNumber(mobileNumber, fetchedNumber)) {
1415 // @TODO Copy all to foundNumber, then merge
1418 detachedNumber = this.getEntityManager().merge(foundNumber);
1422 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: detachedNumber={0} - EXIT!", detachedNumber)); //NOI18N
1425 return detachedNumber;
1429 * Sends an email with given subject line, template name to given recipient
1432 * @param subjectLine Subject line
1433 * @param templateName Template name
1434 * @param user User instance
1435 * @param baseUrl Base URL
1436 * @param randomPassword A randomly-generated password or NULL if user had
1439 protected void sendEmail (final String subjectLine, final String templateName, final User user, final String baseUrl, final String randomPassword) {
1441 this.getLoggerBeanLocal().logTrace(MessageFormat.format("sendEmail: subjectLine={0},templateName={1},user={2},baseUrl={3} - CALLED!", subjectLine, templateName, user, baseUrl)); //NOI18N
1443 // All should be set
1444 if (null == subjectLine) {
1446 throw new NullPointerException("subjectLine is null"); //NOI18N
1447 } else if (subjectLine.isEmpty()) {
1449 throw new IllegalArgumentException("subjectLine is empty"); //NOI18N
1450 } else if (null == templateName) {
1452 throw new NullPointerException("templateName is null"); //NOI18N
1453 } else if (templateName.isEmpty()) {
1455 throw new IllegalArgumentException("templateName is empty"); //NOI18N
1456 } else if (null == user) {
1458 throw new NullPointerException("user is null"); //NOI18N
1459 } else if (user.getUserId() == null) {
1461 throw new NullPointerException("user.userId is null"); //NOI18N
1462 } else if (user.getUserId() < 1) {
1464 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid.", user.getUserId())); //NOI18N
1465 } else if (user.getUserName() == null) {
1467 throw new NullPointerException("user.userName is null"); //NOI18N
1468 } else if (user.getUserName().isEmpty()) {
1470 throw new IllegalArgumentException("user.userName is empty"); //NOI18N
1471 } else if (user.getUserAccountStatus() == null) {
1473 throw new NullPointerException("user.userAccountStatus is null"); //NOI18N
1474 } else if (user.getUserContact() == null) {
1476 throw new NullPointerException("user.userContact is null"); //NOI18N
1477 } else if (user.getUserContact().getContactId() == null) {
1479 throw new NullPointerException("user.userContact.contactId is null"); //NOI18N
1480 } else if (user.getUserContact().getContactId() < 1) {
1482 throw new IllegalArgumentException(MessageFormat.format("user.userContact.contactId={0} is invalid", user.getUserContact().getContactId())); //NOI18N
1483 } else if (user.getUserContact().getContactPersonalTitle() == null) {
1485 throw new NullPointerException("user.userContact.contactPersonalTitle is null"); //NOI18N
1486 } else if (user.getUserLocale() == null) {
1488 throw new NullPointerException("user.userLocale is null"); //NOI18N
1489 } else if (this.getSession() == null) {
1491 throw new NullPointerException("this.session is not set. Have you forgotten to call super(String, String) and called only super() ?"); //NOI18N
1492 } else if (null == baseUrl) {
1494 throw new NullPointerException("baseUrl is null"); //NOI18N
1495 } else if (baseUrl.isEmpty()) {
1497 throw new IllegalArgumentException("baseUrl is empty"); //NOI18N
1501 final Properties variables = Users.getAllUserFields(user);
1503 // Set base URL and random password
1504 variables.put("baseUrl", baseUrl); //NOI18N
1505 variables.put("randomPassword", ""); //NOI18N
1507 // Is the random password set?
1508 if ((randomPassword instanceof String) && (!randomPassword.isEmpty())) {
1509 variables.put("randomPassword", randomPassword); //NOI18N
1513 final Address recipientAddress;
1516 // Create email address and set
1517 recipientAddress = new InternetAddress(user.getUserContact().getContactEmailAddress());
1518 } catch (final AddressException ex) {
1520 throw new EJBException(ex);
1523 // Prepare mail wrapper
1524 // @TODO Language from message bundle
1525 final WrapableEmailDelivery emailWrapper = new EmailDeliveryWrapper(recipientAddress, subjectLine, templateName, variables, user.getUserLocale());
1528 // Send out email change
1529 final ObjectMessage message = this.getSession().createObjectMessage();
1530 message.setObject(emailWrapper);
1533 this.sendMessage(message);
1534 } catch (final JMSException ex) {
1536 throw new EJBException(ex);
1540 this.getLoggerBeanLocal().logTrace("sendEmail: EXIT!"); //NOI18N
1544 * Updates all contact's phone instances from other contact, both contacts
1545 * should be the same.
1547 * @param contact Contact to set instances
1548 * @param other Other contact to get instances from
1550 protected void setAllContactPhoneEntries (final Contact contact, final Contact other) {
1552 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntries: contact={1},other={2} - CALLED!", this.getClass().getSimpleName(), contact, other)); //NOI18N
1554 // Both must be the same and not null
1555 if (null == contact) {
1557 throw new NullPointerException("contact is null"); //NOI18N
1558 } else if (null == other) {
1560 throw new NullPointerException("other is null"); //NOI18N
1561 } else if (!Objects.equals(contact, other)) {
1562 // Not same instances
1563 throw new IllegalArgumentException(MessageFormat.format("contact={0} and other={1} are not equal!", contact, other)); //NOI18N
1567 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: other.contactMobileNumber={0}", other.getContactMobileNumber())); //NOI18N
1569 // Is other mobile not set?
1570 if ((other.getContactMobileNumber() == null) || (MobileNumbers.isSameMobileNumber(contact.getContactMobileNumber(), other.getContactMobileNumber()))) {
1572 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: Copying mobile entry ...", this.getClass().getSimpleName())); //NOI18N
1574 // Is the fax number set?
1575 if (other.getContactMobileNumber() instanceof DialableMobileNumber) {
1576 // Copy mobile number
1577 contact.setContactMobileNumber(this.createManaged(other.getContactMobileNumber(), contact.getContactMobileNumber()));
1580 contact.setContactMobileNumber(null);
1585 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: other.contactLandLineNumber={0}", other.getContactLandLineNumber())); //NOI18N
1587 // Is other mobile not set?
1588 if ((other.getContactLandLineNumber() == null) || (LandLineNumbers.isSameLandLineNumber(contact.getContactLandLineNumber(), other.getContactLandLineNumber()))) {
1590 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: Copying land-line entry ...", this.getClass().getSimpleName())); //NOI18N
1592 // Is the land-line number set?
1593 if (other.getContactLandLineNumber() instanceof DialableLandLineNumber) {
1594 // Copy land-line number
1595 contact.setContactLandLineNumber(this.createManaged(other.getContactLandLineNumber(), contact.getContactLandLineNumber()));
1598 contact.setContactLandLineNumber(null);
1603 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: other.contactFaxNumber={1}", this.getClass().getSimpleName(), other.getContactFaxNumber())); //NOI18N
1605 // Is other mobile not set?
1606 if ((other.getContactFaxNumber() == null) || (FaxNumbers.isSameFaxNumber(contact.getContactFaxNumber(), other.getContactFaxNumber()))) {
1608 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: Copying fax entry ...", this.getClass().getSimpleName())); //NOI18N
1610 // Is the fax number set?
1611 if (other.getContactFaxNumber() instanceof DialableFaxNumber) {
1613 contact.setContactFaxNumber(this.createManaged(other.getContactFaxNumber(), contact.getContactFaxNumber()));
1616 contact.setContactFaxNumber(null);
1621 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntries: EXIT!", this.getClass().getSimpleName())); //NOI18N
1625 * Updates all contact's phone entry's updated timestamps
1627 * @param contact Contact instance to update
1628 * @param isMobileUnlinked Whether a mobile entry has been unlinked in
1630 * @param isLandlineUnlinked Whether a land-line entry has been unlinked in
1632 * @param isFaxUnlinked Whether a fax entry has been unlinked in
1635 protected void setAllContactPhoneEntriesUpdated (final Contact contact, final boolean isMobileUnlinked, final boolean isLandlineUnlinked, final boolean isFaxUnlinked) {
1637 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: contact={1},isMobileUnlinked={2},isLandlineUnlinked={3},isFaxUnlinked={4} - CALLED", this.getClass().getSimpleName(), contact, isMobileUnlinked, isLandlineUnlinked, isFaxUnlinked)); //NOI18N
1639 // The contact instance must be valid
1640 if (null == contact) {
1642 throw new NullPointerException("contact is null"); //NOI18N
1643 } else if (contact.getContactId() == null) {
1645 throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
1646 } else if (contact.getContactId() < 1) {
1648 throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1651 // Get all phone instances
1652 final DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber();
1653 final DialableFaxNumber faxNumber = contact.getContactFaxNumber();
1654 final DialableMobileNumber mobileNumber = contact.getContactMobileNumber();
1656 // Flags and instances must be constistent
1657 if (isMobileUnlinked && mobileNumber instanceof DialableMobileNumber) {
1659 throw new IllegalStateException("isCellPhoneUnlinked is TRUE, but mobileNumber is set."); //NOI18N
1660 } else if (isLandlineUnlinked && landLineNumber instanceof DialableLandLineNumber) {
1662 throw new IllegalStateException("isLandlineUnlinked is TRUE, but landLineNumber is set."); //NOI18N
1663 } else if (isFaxUnlinked && faxNumber instanceof DialableFaxNumber) {
1665 throw new IllegalStateException("isFaxUnlinked is TRUE, but faxNumber is set."); //NOI18N
1668 // Is a phone number instance set?
1669 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() instanceof Long) && (landLineNumber.getPhoneId() > 0)) {
1671 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: Setting updated timestamp for land-line number ...", this.getClass().getSimpleName())); //NOI18N
1673 // Set updated timestamp
1674 landLineNumber.setPhoneEntryUpdated(new Date());
1677 // Is a fax number instance set?
1678 if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() instanceof Long) && (faxNumber.getPhoneId() > 0)) {
1680 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: Setting updated timestamp for fax number ...", this.getClass().getSimpleName())); //NOI18N
1682 // Set updated timestamp
1683 faxNumber.setPhoneEntryUpdated(new Date());
1686 // Is a mobile number instance set?
1687 if ((mobileNumber instanceof DialableMobileNumber) && (mobileNumber.getMobileId() instanceof Long) && (mobileNumber.getMobileId() > 0)) {
1689 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: Setting updated timestamp for mobile number ...", this.getClass().getSimpleName())); //NOI18N
1691 // Set updated timestamp
1692 mobileNumber.setMobileEntryUpdated(new Date());
1696 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: EXIT!", this.getClass().getSimpleName())); //NOI18N