2 * Copyright (C) 2016 - 2024 Free Software Foundation
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation, either version 3 of the
7 * License, or (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 Affero General Public License for more details.
14 * You should have received a copy of the GNU Affero General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.jcontacts.model.contact;
19 import java.text.MessageFormat;
20 import java.util.List;
21 import javax.ejb.Stateless;
22 import javax.persistence.Query;
23 import org.mxchange.addressbook.enterprise.BaseAddressbookEnterpriseBean;
28 * @author Roland Häder<roland@mxchange.org>
30 @Stateless (name = "contact", description = "A bean handling contact data")
31 public class AddressbookContactSessionBean extends BaseAddressbookEnterpriseBean implements ContactSessionBeanRemote {
36 private static final long serialVersionUID = 542_145_348_001L;
41 public AddressbookContactSessionBean () {
42 // Call super constructor
47 @SuppressWarnings ("unchecked")
48 public List<Contact> fetchAllContacts () {
50 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getAllContacts - CALLED!", this.getClass().getSimpleName())); //NOI18N
52 // Create query instance
53 final Query query = this.getEntityManager().createNamedQuery("AllContacts"); //NOI18N
56 final List<Contact> contacts = query.getResultList();
59 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getAllContacts: contacts.size()={1} - EXIT!", this.getClass().getSimpleName(), contacts.size())); //NOI18N
66 public Contact updateContactData (final Contact contact, final boolean isMobileUnlinked, final boolean isLandlineUnlinked, final boolean isFaxUnlinked) {
68 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateContactData: contact={1},isMobileUnlinked={2},isLandlineUnlinked={3},isFaxUnlinked={4} - CALLED!", this.getClass().getSimpleName(), contact, isMobileUnlinked, isLandlineUnlinked, isFaxUnlinked)); //NOI18N
70 // The contact instance must be valid
71 if (null == contact) {
73 throw new NullPointerException("contact is null"); //NOI18N
74 } else if (contact.getContactId() == null) {
76 throw new NullPointerException("contact.contactId is null"); //NOI18N
77 } else if (contact.getContactId() < 1) {
79 throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
82 // Set updated timestamp
83 this.setAllContactPhoneEntriesUpdated(contact, isMobileUnlinked, isLandlineUnlinked, isFaxUnlinked);
85 // Merge mobile, land-line and fix
86 final Contact detachedContact = this.mergeContactData(contact);
89 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateContactData: detachedContact={1} - EXIT!", this.getClass().getSimpleName(), detachedContact)); //NOI18N
92 return detachedContact;
96 public Contact updateContactData (final Contact contact) {
98 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateContactData: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N
100 // The contact instance must be valid
101 if (null == contact) {
103 throw new NullPointerException("contact is null"); //NOI18N
104 } else if (contact.getContactId() == null) {
106 throw new NullPointerException("contact.contactId is null"); //NOI18N
107 } else if (contact.getContactId() < 1) {
109 throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
112 // Is cell phone/land-line/fax number unlinked?
113 final boolean isCellphoneUnlinked = (contact.getContactMobileNumber() == null);
114 final boolean isLandLineUnlinked = (contact.getContactLandLineNumber() == null);
115 final boolean isFaxUnlinked = (contact.getContactFaxNumber() == null);
118 final Contact detachedContact = this.updateContactData(contact, isCellphoneUnlinked, isLandLineUnlinked, isFaxUnlinked);
121 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateContactData: detachedContact={1} - EXIT!", this.getClass().getSimpleName(), detachedContact)); //NOI18N
124 return detachedContact;