From: Roland Häder Date: Sat, 9 Sep 2017 12:49:54 +0000 (+0200) Subject: Please cherry-pick: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=37aed98d8dedbfcfbf2e46130433688635a4807e;p=addressbook-ejb.git Please cherry-pick: - re-package season has started: now all core project's entity packages do always have following format: tld.domain.project.model.foo.SomeFoo; - also fixed persistence unit Signed-off-by: Roland Häder --- diff --git a/src/conf/persistence.xml b/src/conf/persistence.xml index 9f42305..ee278be 100644 --- a/src/conf/persistence.xml +++ b/src/conf/persistence.xml @@ -5,20 +5,20 @@ org.mxchange.jaddressbook.model.addressbook.UserAddressbook org.mxchange.jaddressbook.model.addressbook.entry.UserAddressbookEntry org.mxchange.jaddressbookshare.model.addressbook.shared.AddressbookShare - org.mxchange.jcontacts.contact.UserContact - org.mxchange.jcontactsbusiness.basicdata.CompanyBasicData - org.mxchange.jcontactsbusiness.branchoffice.CompanyBranchOffice - org.mxchange.jcontactsbusiness.department.CompanyDepartment - org.mxchange.jcontactsbusiness.employee.CompanyEmployee - org.mxchange.jcontactsbusiness.headquarters.CompanyHeadquartersData - org.mxchange.jcontactsbusiness.jobposition.EmployeePosition - org.mxchange.jcontactsbusiness.logo.CompanyLogo - org.mxchange.jcontactsbusiness.opening_times.BusinessOpeningTimes - org.mxchange.jcountry.data.CountryData - org.mxchange.jphone.phonenumbers.fax.FaxNumber - org.mxchange.jphone.phonenumbers.landline.LandLineNumber - org.mxchange.jphone.phonenumbers.mobile.MobileNumber - org.mxchange.jphone.phonenumbers.mobileprovider.CellphoneProvider + org.mxchange.jcontacts.model.contact.UserContact + org.mxchange.jcontactsbusiness.model.basicdata.CompanyBasicData + org.mxchange.jcontactsbusiness.model.branchoffice.CompanyBranchOffice + org.mxchange.jcontactsbusiness.model.department.CompanyDepartment + org.mxchange.jcontactsbusiness.model.employee.CompanyEmployee + org.mxchange.jcontactsbusiness.model.headquarters.CompanyHeadquartersData + org.mxchange.jcontactsbusiness.model.jobposition.EmployeePosition + org.mxchange.jcontactsbusiness.model.logo.CompanyLogo + org.mxchange.jcontactsbusiness.model.opening_times.BusinessOpeningTimes + org.mxchange.jcountry.model.data.CountryData + org.mxchange.jphone.model.phonenumbers.fax.FaxNumber + org.mxchange.jphone.model.phonenumbers.landline.LandLineNumber + org.mxchange.jphone.model.phonenumbers.mobile.MobileNumber + org.mxchange.jphone.model.phonenumbers.mobileprovider.CellphoneProvider org.mxchange.jusercore.model.email_address.EmailAddressChange org.mxchange.jusercore.model.user.LoginUser org.mxchange.jusercore.model.user.activity.UserActivityLog diff --git a/src/java/org/mxchange/jcontacts/contact/AddressbookAdminContactSessionBean.java b/src/java/org/mxchange/jcontacts/contact/AddressbookAdminContactSessionBean.java deleted file mode 100644 index d3a3ad2..0000000 --- a/src/java/org/mxchange/jcontacts/contact/AddressbookAdminContactSessionBean.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Roland Häder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.mxchange.jcontacts.contact; - -import java.text.MessageFormat; -import java.util.GregorianCalendar; -import javax.ejb.Stateless; -import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; -import javax.persistence.NoResultException; -import javax.persistence.Query; -import org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException; -import org.mxchange.jcontacts.exceptions.ContactNotFoundException; -import org.mxchange.jcontacts.model.contact.AdminContactSessionBeanRemote; -import org.mxchange.jcontacts.model.contact.Contact; - -/** - * An administrative contact EJB - *

- * @author Roland Häder - */ -@Stateless (name = "adminContact", description = "An administrative contact EJB") -public class AddressbookAdminContactSessionBean extends BaseAddressbookDatabaseBean implements AdminContactSessionBeanRemote { - - /** - * Serial number - */ - private static final long serialVersionUID = 542_145_347_916L; - - /** - * Default constructor - */ - public AddressbookAdminContactSessionBean () { - // Call super constructor - super(); - } - - @Override - public Contact addContact (final Contact contact) throws ContactAlreadyAddedException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addContact: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N - - // Is the instance set? - if (null == contact) { - // Throw NPE - throw new NullPointerException("contact is null"); //NOI18N - } else if (contact.getContactId() != null) { - // Should be null - throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} - is not null", contact.getContactId())); //NOI18N - } else if (this.isContactFound(contact)) { - // Already registered - throw new ContactAlreadyAddedException(contact); - } - - // Set created timestamp - contact.setContactCreated(new GregorianCalendar()); - - // Set all created timestamps, if instance is there - this.setAllContactPhoneEntriesCreated(contact); - - // Persist it - this.getEntityManager().persist(contact); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addContact: contact.contactId={1} after persisting - EXIT!", this.getClass().getSimpleName(), contact.getContactId())); //NOI18N - - // Return it - return contact; - } - - @Override - public void deleteContactData (final Contact contact) throws ContactNotFoundException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteContactData: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N - - // Is the instance set? - if (null == contact) { - // Throw NPE - throw new NullPointerException("contact is null"); //NOI18N - } else if (contact.getContactId() == null) { - // Should not be null - throw new NullPointerException("contact.contactId is null"); //NOI18N - } else if (contact.getContactId() < 1) { - // Not valid - throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N - } else if (!this.isContactFound(contact)) { - // Contact not found - throw new ContactNotFoundException(contact.getContactId()); - } - - // Merge it to get a managed entity back - Contact managedContact = this.getEntityManager().getReference(contact.getClass(), contact.getContactId()); - - // Remove it from database - this.getEntityManager().remove(managedContact); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteContactData: EXIT!", this.getClass().getSimpleName())); //NOI18N - } - - /** - * Determines if the given contact is found - *

- * @param contact Contact instance - *

- * @return Whether the contact has been found - */ - private boolean isContactFound (final Contact contact) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isContactRegistered: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N - - // Create query - Query query = this.getEntityManager().createNamedQuery("SearchContact"); //NOI18N - - // Set parameter - query.setParameter("contact", contact); //NOI18N - query.setMaxResults(1); - - // Default is not found - boolean isFound = false; - - // Try it - try { - // Try to find instance - Contact dummy = (Contact) query.getSingleResult(); - - // Mark as found - isFound = true; - } catch (final NoResultException e) { - // No result found - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isContactRegistered: isFound={1} - EXIT!", this.getClass().getSimpleName(), isFound)); //NOI18N - - // Return flag - return isFound; - } - -} diff --git a/src/java/org/mxchange/jcontacts/contact/AddressbookContactSessionBean.java b/src/java/org/mxchange/jcontacts/contact/AddressbookContactSessionBean.java deleted file mode 100644 index a720285..0000000 --- a/src/java/org/mxchange/jcontacts/contact/AddressbookContactSessionBean.java +++ /dev/null @@ -1,332 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Roland Häder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.mxchange.jcontacts.contact; - -import java.text.MessageFormat; -import java.util.Iterator; -import java.util.List; -import java.util.Objects; -import javax.ejb.Stateless; -import javax.persistence.NoResultException; -import javax.persistence.Query; -import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; -import org.mxchange.jcontacts.exceptions.ContactNotFoundException; -import org.mxchange.jcontacts.model.contact.Contact; -import org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote; -import org.mxchange.jcontacts.model.contact.ContactUtils; -import org.mxchange.jcontacts.model.contact.UserContact; - -/** - * A contact EJB - *

- * @author Roland Häder - */ -@Stateless (name = "contact", description = "A bean handling contact data") -public class AddressbookContactSessionBean extends BaseAddressbookDatabaseBean implements ContactSessionBeanRemote { - - /** - * Serial number - */ - private static final long serialVersionUID = 542_145_347_916L; - - /** - * Default constructor - */ - public AddressbookContactSessionBean () { - // Call super constructor - super(); - } - - @Override - @SuppressWarnings ("unchecked") - public List allContacts () { - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getAllContacts - CALLED!", this.getClass().getSimpleName())); //NOI18N - - // Create query instance - final Query query = this.getEntityManager().createNamedQuery("AllContacts"); //NOI18N - - // Get list - final List contacts = query.getResultList(); - - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getAllContacts: contacts.size()={1} - EXIT!", this.getClass().getSimpleName(), contacts.size())); //NOI18N - - // Return it - return contacts; - } - - @Override - @SuppressWarnings ("unchecked") - public List allEmailAddresses () { - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getEmailAddressList - CALLED!", this.getClass().getSimpleName())); //NOI18N - - // Create query instance - final Query query = this.getEntityManager().createNamedQuery("AllContactEmailAddresses"); //NOI18N - - // Get list - final List emailAddresses = query.getResultList(); - - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getEmailAddressList: emailAddresses.size()={1} - EXIT!", this.getClass().getSimpleName(), emailAddresses.size())); //NOI18N - - // Return it - return emailAddresses; - } - - @Override - public Contact findContactByEmailAddress (final String emailAddress) throws ContactNotFoundException { - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findContactByEmailAddress: emailAddress={1} - CALLED!", this.getClass().getSimpleName(), emailAddress)); //NOI18N - - // The parameter must be valid - if (null == emailAddress) { - // Throw NPE - throw new NullPointerException("emailAddress is null"); //NOI18N - } else if (emailAddress.isEmpty()) { - // Not valid - throw new IllegalArgumentException("emailAddress is empty"); //NOI18N - } - - // Get query instance - final Query query = this.getEntityManager().createNamedQuery("SearchContactByEmailAddress", UserContact.class); //NOI18N - - // Set parameter and limit - query.setParameter("emailAddress", emailAddress); //NOI18N - query.setMaxResults(1); - - // Init contact instance - final Contact contact; - - // Try to find a result - try { - // Find a single result - contact = (Contact) query.getSingleResult(); - - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findContactByEmailAddress: Found contact={1}", this.getClass().getSimpleName(), contact)); //NOI18N - } catch (final NoResultException ex) { - // No result found - throw new ContactNotFoundException(emailAddress, ex); - } - - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findContactByEmailAddress: contact={1} - EXIT!", this.getClass().getSimpleName(), contact)); //NOI18N - - // Return found instance - return contact; - } - - @Override - public Contact findContactById (final Long contactId) throws ContactNotFoundException { - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findContactById: contactId={1} - CALLED!", this.getClass().getSimpleName(), contactId)); //NOI18N - - // The parameter must be valid - if (null == contactId) { - // Throw NPE - throw new NullPointerException("contactId is null"); //NOI18N - } else if (contactId < 1) { - // Not valid - throw new IllegalArgumentException(MessageFormat.format("contactId={0} is not valid", contactId)); //NOI18N - } - - // Get query instance - final Query query = this.getEntityManager().createNamedQuery("SearchContactById", UserContact.class); //NOI18N - - // Set parameter - query.setParameter("contactId", contactId); //NOI18N - query.setMaxResults(1); - - // Init contact instance - final Contact contact; - - // Try to find a result - try { - // Find a single result - contact = (Contact) query.getSingleResult(); - - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findContactById: Found contact={1}", this.getClass().getSimpleName(), contact)); //NOI18N - } catch (final NoResultException ex) { - // No result found - throw new ContactNotFoundException(contactId, ex); - } - - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findContactById: contact={1} - EXIT!", this.getClass().getSimpleName(), contact)); //NOI18N - - // Return found instance - return contact; - } - - @Override - public boolean isEmailAddressRegistered (final String emailAddress) { - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isEmailAddressRegistered: emailAddress={1} - CALLED!", this.getClass().getSimpleName(), emailAddress)); //NOI18N - - // The email address should be valid - if (null == emailAddress) { - // Is null - throw new NullPointerException("emailAddress is null"); //NOI18N - } else if (emailAddress.isEmpty()) { - // Is empty - throw new IllegalArgumentException("emailAddress is empty"); //NOI18N - } - - // Default is not found - boolean isFound = false; - - try { - // Ask other method for contact instance - final Contact contact = this.findContactByEmailAddress(emailAddress); - - // Log debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.isEmailAddressRegistered: Found contact={1} for emailAddress={2}", this.getClass().getSimpleName(), contact, emailAddress)); //NOI18N - - // It is found ... - isFound = true; - } catch (final ContactNotFoundException ex) { - // @TODO Was not found, log exception for spam check? - } - - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isEmailAddressRegistered: isFound={1} - EXIT!", this.getClass().getSimpleName(), isFound)); //NOI18N - - // Return status - return isFound; - } - - @Override - public Contact lookupContact (final Contact contact) { - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isContactFound: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N - - // Parameter should be valid - if (null == contact) { - // Throw NPE - throw new NullPointerException("contact is null"); //NOI18N - } else if (contact.getContactId() > 0) { - try { - // Id set, ask other method - return this.findContactById(contact.getContactId()); - } catch (final ContactNotFoundException ex) { - // Not found, should not happen - throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is set, but not found.", contact.getContactId()), ex); //NOI18N - } - } - - // Default is not found - Contact foundContact = null; - - // Get whole list - final List contacts = this.allContacts(); - - // Is the list empty? - if (contacts.isEmpty()) { - // Then abort here - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isContactFound: No contacts registered, returning NULL ...", this.getClass().getSimpleName())); //NOI18N - return null; - } - - // Get iterator - final Iterator iterator = contacts.iterator(); - - // Loop through all - while (iterator.hasNext()) { - // Get contact - Contact next = iterator.next(); - - // Is same contact? - if ((Objects.equals(contact, next)) || (ContactUtils.isSameContact(contact, next))) { - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.isContactFound: Found same contact: contactId={1}", this.getClass().getSimpleName(), next.getContactId())); //NOI18N - - // Found it - foundContact = next; - break; - } - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isContactFound: foundContact={1} - EXIT!", this.getClass().getSimpleName(), foundContact)); //NOI18N - - // Return found contact - return foundContact; - } - - @Override - public Contact updateContactData (final Contact contact, final boolean isMobileUnlinked, final boolean isLandlineUnlinked, final boolean isFaxUnlinked) { - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateContactData: contact={1},isMobileUnlinked={2},isLandlineUnlinked={3},isFaxUnlinked={4} - CALLED!", this.getClass().getSimpleName(), contact, isMobileUnlinked, isLandlineUnlinked, isFaxUnlinked)); //NOI18N - - // The contact instance must be valid - if (null == contact) { - // Throw NPE again - throw new NullPointerException("contact is null"); //NOI18N - } else if (contact.getContactId() == null) { - // Throw NPE again - throw new NullPointerException("contact.contactId is null"); //NOI18N - } else if (contact.getContactId() < 1) { - // Not valid - throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N - } - - // Merge cellphone, land-line and fix - Contact managedContact = this.mergeContactData(contact); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateContactData: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N - - // Return it - return managedContact; - } - - @Override - public Contact updateContactData (final Contact contact) { - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateContactData: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N - - // The contact instance must be valid - if (null == contact) { - // Throw NPE again - throw new NullPointerException("contact is null"); //NOI18N - } else if (contact.getContactId() == null) { - // Throw NPE again - throw new NullPointerException("contact.contactId is null"); //NOI18N - } else if (contact.getContactId() < 1) { - // Not valid - throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N - } - - // Is cell phone/land-line/fax number unlinked? - boolean isMobileUnlinked = (contact.getContactMobileNumber() == null); - boolean isLandLineUnlinked = (contact.getContactLandLineNumber() == null); - boolean isFaxUnlinked = (contact.getContactFaxNumber() == null); - - // Call other Method - Contact managedContact = this.updateContactData(contact, isMobileUnlinked, isLandLineUnlinked, isFaxUnlinked); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateContactData: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N - - // Return it - return managedContact; - } - -} diff --git a/src/java/org/mxchange/jcontacts/model/contact/AddressbookAdminContactSessionBean.java b/src/java/org/mxchange/jcontacts/model/contact/AddressbookAdminContactSessionBean.java new file mode 100644 index 0000000..82c88b4 --- /dev/null +++ b/src/java/org/mxchange/jcontacts/model/contact/AddressbookAdminContactSessionBean.java @@ -0,0 +1,151 @@ +/* + * Copyright (C) 2016, 2017 Roland Häder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jcontacts.model.contact; + +import java.text.MessageFormat; +import java.util.GregorianCalendar; +import javax.ejb.Stateless; +import javax.persistence.NoResultException; +import javax.persistence.Query; +import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; +import org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException; +import org.mxchange.jcontacts.exceptions.ContactNotFoundException; + +/** + * An administrative contact EJB + *

+ * @author Roland Häder + */ +@Stateless (name = "adminContact", description = "An administrative contact EJB") +public class AddressbookAdminContactSessionBean extends BaseAddressbookDatabaseBean implements AdminContactSessionBeanRemote { + + /** + * Serial number + */ + private static final long serialVersionUID = 542_145_347_916L; + + /** + * Default constructor + */ + public AddressbookAdminContactSessionBean () { + // Call super constructor + super(); + } + + @Override + public Contact addContact (final Contact contact) throws ContactAlreadyAddedException { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addContact: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N + + // Is the instance set? + if (null == contact) { + // Throw NPE + throw new NullPointerException("contact is null"); //NOI18N + } else if (contact.getContactId() != null) { + // Should be null + throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} - is not null", contact.getContactId())); //NOI18N + } else if (this.isContactFound(contact)) { + // Already registered + throw new ContactAlreadyAddedException(contact); + } + + // Set created timestamp + contact.setContactCreated(new GregorianCalendar()); + + // Set all created timestamps, if instance is there + this.setAllContactPhoneEntriesCreated(contact); + + // Persist it + this.getEntityManager().persist(contact); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addContact: contact.contactId={1} after persisting - EXIT!", this.getClass().getSimpleName(), contact.getContactId())); //NOI18N + + // Return it + return contact; + } + + @Override + public void deleteContactData (final Contact contact) throws ContactNotFoundException { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteContactData: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N + + // Is the instance set? + if (null == contact) { + // Throw NPE + throw new NullPointerException("contact is null"); //NOI18N + } else if (contact.getContactId() == null) { + // Should not be null + throw new NullPointerException("contact.contactId is null"); //NOI18N + } else if (contact.getContactId() < 1) { + // Not valid + throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N + } else if (!this.isContactFound(contact)) { + // Contact not found + throw new ContactNotFoundException(contact.getContactId()); + } + + // Merge it to get a managed entity back + Contact managedContact = this.getEntityManager().getReference(contact.getClass(), contact.getContactId()); + + // Remove it from database + this.getEntityManager().remove(managedContact); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteContactData: EXIT!", this.getClass().getSimpleName())); //NOI18N + } + + /** + * Determines if the given contact is found + *

+ * @param contact Contact instance + *

+ * @return Whether the contact has been found + */ + private boolean isContactFound (final Contact contact) { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isContactRegistered: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N + + // Create query + Query query = this.getEntityManager().createNamedQuery("SearchContact"); //NOI18N + + // Set parameter + query.setParameter("contact", contact); //NOI18N + query.setMaxResults(1); + + // Default is not found + boolean isFound = false; + + // Try it + try { + // Try to find instance + Contact dummy = (Contact) query.getSingleResult(); + + // Mark as found + isFound = true; + } catch (final NoResultException e) { + // No result found + } + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isContactRegistered: isFound={1} - EXIT!", this.getClass().getSimpleName(), isFound)); //NOI18N + + // Return flag + return isFound; + } + +} diff --git a/src/java/org/mxchange/jcontacts/model/contact/AddressbookContactSessionBean.java b/src/java/org/mxchange/jcontacts/model/contact/AddressbookContactSessionBean.java new file mode 100644 index 0000000..5bd528d --- /dev/null +++ b/src/java/org/mxchange/jcontacts/model/contact/AddressbookContactSessionBean.java @@ -0,0 +1,331 @@ +/* + * Copyright (C) 2016, 2017 Roland Häder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jcontacts.model.contact; + +import java.text.MessageFormat; +import java.util.Iterator; +import java.util.List; +import java.util.Objects; +import javax.ejb.Stateless; +import javax.persistence.NoResultException; +import javax.persistence.Query; +import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; +import org.mxchange.jcontacts.exceptions.ContactNotFoundException; + +/** + * A contact EJB + *

+ * @author Roland Häder + */ +@Stateless (name = "contact", description = "A bean handling contact data") +public class AddressbookContactSessionBean extends BaseAddressbookDatabaseBean implements ContactSessionBeanRemote { + + /** + * Serial number + */ + private static final long serialVersionUID = 542_145_347_916L; + + /** + * Default constructor + */ + public AddressbookContactSessionBean () { + // Call super constructor + super(); + } + + @Override + @SuppressWarnings ("unchecked") + public List allContacts () { + // Log trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getAllContacts - CALLED!", this.getClass().getSimpleName())); //NOI18N + + // Create query instance + final Query query = this.getEntityManager().createNamedQuery("AllContacts"); //NOI18N + + // Get list + final List contacts = query.getResultList(); + + // Log trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getAllContacts: contacts.size()={1} - EXIT!", this.getClass().getSimpleName(), contacts.size())); //NOI18N + + // Return it + return contacts; + } + + @Override + @SuppressWarnings ("unchecked") + public List allEmailAddresses () { + // Log trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getEmailAddressList - CALLED!", this.getClass().getSimpleName())); //NOI18N + + // Create query instance + final Query query = this.getEntityManager().createNamedQuery("AllContactEmailAddresses"); //NOI18N + + // Get list + final List emailAddresses = query.getResultList(); + + // Log trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getEmailAddressList: emailAddresses.size()={1} - EXIT!", this.getClass().getSimpleName(), emailAddresses.size())); //NOI18N + + // Return it + return emailAddresses; + } + + @Override + public Contact findContactByEmailAddress (final String emailAddress) throws ContactNotFoundException { + // Log trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findContactByEmailAddress: emailAddress={1} - CALLED!", this.getClass().getSimpleName(), emailAddress)); //NOI18N + + // The parameter must be valid + if (null == emailAddress) { + // Throw NPE + throw new NullPointerException("emailAddress is null"); //NOI18N + } else if (emailAddress.isEmpty()) { + // Not valid + throw new IllegalArgumentException("emailAddress is empty"); //NOI18N + } + + // Get query instance + final Query query = this.getEntityManager().createNamedQuery("SearchContactByEmailAddress", UserContact.class); //NOI18N + + // Set parameter and limit + query.setParameter("emailAddress", emailAddress); //NOI18N + query.setMaxResults(1); + + // Init contact instance + final Contact contact; + + // Try to find a result + try { + // Find a single result + contact = (Contact) query.getSingleResult(); + + // Log trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findContactByEmailAddress: Found contact={1}", this.getClass().getSimpleName(), contact)); //NOI18N + } catch (final NoResultException ex) { + // No result found + throw new ContactNotFoundException(emailAddress, ex); + } + + // Log trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findContactByEmailAddress: contact={1} - EXIT!", this.getClass().getSimpleName(), contact)); //NOI18N + + // Return found instance + return contact; + } + + @Override + public Contact findContactById (final Long contactId) throws ContactNotFoundException { + // Log trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findContactById: contactId={1} - CALLED!", this.getClass().getSimpleName(), contactId)); //NOI18N + + // The parameter must be valid + if (null == contactId) { + // Throw NPE + throw new NullPointerException("contactId is null"); //NOI18N + } else if (contactId < 1) { + // Not valid + throw new IllegalArgumentException(MessageFormat.format("contactId={0} is not valid", contactId)); //NOI18N + } + + // Get query instance + final Query query = this.getEntityManager().createNamedQuery("SearchContactById", UserContact.class); //NOI18N + + // Set parameter + query.setParameter("contactId", contactId); //NOI18N + query.setMaxResults(1); + + // Init contact instance + final Contact contact; + + // Try to find a result + try { + // Find a single result + contact = (Contact) query.getSingleResult(); + + // Log trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findContactById: Found contact={1}", this.getClass().getSimpleName(), contact)); //NOI18N + } catch (final NoResultException ex) { + // No result found + throw new ContactNotFoundException(contactId, ex); + } + + // Log trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findContactById: contact={1} - EXIT!", this.getClass().getSimpleName(), contact)); //NOI18N + + // Return found instance + return contact; + } + + @Override + public boolean isEmailAddressRegistered (final String emailAddress) { + // Log trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isEmailAddressRegistered: emailAddress={1} - CALLED!", this.getClass().getSimpleName(), emailAddress)); //NOI18N + + // The email address should be valid + if (null == emailAddress) { + // Is null + throw new NullPointerException("emailAddress is null"); //NOI18N + } else if (emailAddress.isEmpty()) { + // Is empty + throw new IllegalArgumentException("emailAddress is empty"); //NOI18N + } + + // Default is not found + boolean isFound = false; + + try { + // Ask other method for contact instance + final Contact contact = this.findContactByEmailAddress(emailAddress); + + // Log debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.isEmailAddressRegistered: Found contact={1} for emailAddress={2}", this.getClass().getSimpleName(), contact, emailAddress)); //NOI18N + + // It is found ... + isFound = true; + } catch (final ContactNotFoundException ex) { + // @TODO Was not found, log exception for spam check? + } + + // Log trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isEmailAddressRegistered: isFound={1} - EXIT!", this.getClass().getSimpleName(), isFound)); //NOI18N + + // Return status + return isFound; + } + + @Override + public Contact lookupContact (final Contact contact) { + // Log trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isContactFound: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N + + // Parameter should be valid + if (null == contact) { + // Throw NPE + throw new NullPointerException("contact is null"); //NOI18N + } else if (contact.getContactId() > 0) { + try { + // Id set, ask other method + return this.findContactById(contact.getContactId()); + } catch (final ContactNotFoundException ex) { + // Not found, should not happen + throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is set, but not found.", contact.getContactId()), ex); //NOI18N + } + } + + // Default is not found + Contact foundContact = null; + + // Get whole list + final List contacts = this.allContacts(); + + // Is the list empty? + if (contacts.isEmpty()) { + // Then abort here + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isContactFound: No contacts registered, returning NULL ...", this.getClass().getSimpleName())); //NOI18N + return null; + } + + // Get iterator + final Iterator iterator = contacts.iterator(); + + // Loop through all + while (iterator.hasNext()) { + // Get contact + Contact next = iterator.next(); + + // Is same contact? + if ((Objects.equals(contact, next)) || (ContactUtils.isSameContact(contact, next))) { + // Debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.isContactFound: Found same contact: contactId={1}", this.getClass().getSimpleName(), next.getContactId())); //NOI18N + + // Found it + foundContact = next; + break; + } + } + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isContactFound: foundContact={1} - EXIT!", this.getClass().getSimpleName(), foundContact)); //NOI18N + + // Return found contact + return foundContact; + } + + @Override + public Contact updateContactData (final Contact contact, final boolean isCellphoneUnlinked, final boolean isLandlineUnlinked, final boolean isFaxUnlinked) { + // Log trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateContactData: contact={1},isCellphoneUnlinked={2},isLandlineUnlinked={3},isFaxUnlinked={4} - CALLED!", this.getClass().getSimpleName(), contact, isCellphoneUnlinked, isLandlineUnlinked, isFaxUnlinked)); //NOI18N + + // The contact instance must be valid + if (null == contact) { + // Throw NPE again + throw new NullPointerException("contact is null"); //NOI18N + } else if (contact.getContactId() == null) { + // Throw NPE again + throw new NullPointerException("contact.contactId is null"); //NOI18N + } else if (contact.getContactId() < 1) { + // Not valid + throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N + } + + // Set updated timestamp + this.setAllContactPhoneEntriesUpdated(contact, isCellphoneUnlinked, isLandlineUnlinked, isFaxUnlinked); + + // Merge mobile, land-line and fix + Contact detachedContact = this.mergeContactData(contact); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateContactData: detachedContact={1} - EXIT!", this.getClass().getSimpleName(), detachedContact)); //NOI18N + + // Return it + return detachedContact; + } + + @Override + public Contact updateContactData (final Contact contact) { + // Log trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateContactData: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N + + // The contact instance must be valid + if (null == contact) { + // Throw NPE again + throw new NullPointerException("contact is null"); //NOI18N + } else if (contact.getContactId() == null) { + // Throw NPE again + throw new NullPointerException("contact.contactId is null"); //NOI18N + } else if (contact.getContactId() < 1) { + // Not valid + throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N + } + + // Is cell phone/land-line/fax number unlinked? + boolean isCellphoneUnlinked = (contact.getContactMobileNumber() == null); + boolean isLandLineUnlinked = (contact.getContactLandLineNumber() == null); + boolean isFaxUnlinked = (contact.getContactFaxNumber() == null); + + // Call other Method + Contact detachedContact = this.updateContactData(contact, isCellphoneUnlinked, isLandLineUnlinked, isFaxUnlinked); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateContactData: detachedContact={1} - EXIT!", this.getClass().getSimpleName(), detachedContact)); //NOI18N + + // Return it + return detachedContact; + } + +} diff --git a/src/java/org/mxchange/jcontacts/model/phone/AddressbookAdminContactPhoneSessionBean.java b/src/java/org/mxchange/jcontacts/model/phone/AddressbookAdminContactPhoneSessionBean.java new file mode 100644 index 0000000..93d130d --- /dev/null +++ b/src/java/org/mxchange/jcontacts/model/phone/AddressbookAdminContactPhoneSessionBean.java @@ -0,0 +1,516 @@ +/* + * Copyright (C) 2016, 2017 Roland Häder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jcontacts.model.phone; + +import java.text.MessageFormat; +import java.util.GregorianCalendar; +import java.util.Objects; +import javax.ejb.EJB; +import javax.ejb.Stateless; +import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; +import org.mxchange.jcontacts.model.contact.Contact; +import org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote; +import org.mxchange.jphone.exceptions.PhoneNumberAlreadyLinkedException; +import org.mxchange.jphone.exceptions.PhoneNumberNotLinkedException; +import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; +import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber; +import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber; + +/** + * A session EJB for administrative contact's phone number purposes + *

+ * @author Roland Häder + */ +@Stateless (name = "adminContactPhone", description = "An administrative bean handling contact's phone data") +public class AddressbookAdminContactPhoneSessionBean extends BaseAddressbookDatabaseBean implements AdminContactsPhoneSessionBeanRemote { + + /** + * Serial number + */ + private static final long serialVersionUID = 189_217_561_460_237_108L; + + /** + * Contact EJB + */ + @EJB + private ContactSessionBeanRemote contactBean; + + /** + * Default constructor + */ + public AddressbookAdminContactPhoneSessionBean () { + // Call super constructor + super(); + } + + @Override + public Contact linkExistingFaxNumberWithContact (final Contact contact, final DialableFaxNumber faxNumber) throws PhoneNumberAlreadyLinkedException { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingFaxNumberWithContact: contact={1},faxNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, faxNumber)); //NOI18N + + // Is the contact set? + if (null == contact) { + // Throw NPE + throw new NullPointerException("contact is null"); //NOI18N + } else if (contact.getContactId() == null) { + // ... and throw again + throw new NullPointerException("contact.contactId is null"); //NOI18N + } else if (contact.getContactId() < 1) { + // Invalid id number + throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N + } else if (contact.getContactFaxNumber() instanceof DialableFaxNumber) { + // Not set cell phone instance + throw new PhoneNumberAlreadyLinkedException(faxNumber); + } else if (null == faxNumber) { + // Throw NPE + throw new NullPointerException("faxNumber is null"); //NOI18N + } else if (faxNumber.getPhoneId() == null) { + // Throw it again + throw new NullPointerException("faxNumber.phoneId is null"); //NOI18N + } else if (faxNumber.getPhoneId() < 1) { + // Invalid id + throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneId={0} is not valid", faxNumber.getPhoneId())); //NOI18N + } else if (faxNumber.getPhoneCountry() == null) { + // ... and again + throw new NullPointerException("faxNumber.phoneCountry is null"); //NOI18N + } else if (faxNumber.getPhoneAreaCode() == null) { + // Throw it again + throw new NullPointerException("faxNumber.phoneAreaCode is null"); //NOI18N + } else if (faxNumber.getPhoneAreaCode() < 1) { + // Invalid id + throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneAreaCode={0} is not valid", faxNumber.getPhoneAreaCode())); //NOI18N + } else if (faxNumber.getPhoneNumber() == null) { + // Throw it again + throw new NullPointerException("faxNumber.phoneNumber is null"); //NOI18N + } else if (faxNumber.getPhoneNumber() < 1) { + // Invalid id + throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneNumber={0} is not valid", faxNumber.getPhoneNumber())); //NOI18N + } + + // Set fax number in contact + contact.setContactFaxNumber(faxNumber); + + // Update database + final Contact updatedContact = this.contactBean.updateContactData(contact); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingFaxNumberWithContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N + + // Return it + return updatedContact; + } + + @Override + public Contact linkExistingLandLineNumberWithContact (final Contact contact, final DialableLandLineNumber landLineNumber) throws PhoneNumberAlreadyLinkedException { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingLandLineNumberWithContact: contact={1},landLineNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, landLineNumber)); //NOI18N + + // Is the contact set? + if (null == contact) { + // Throw NPE + throw new NullPointerException("contact is null"); //NOI18N + } else if (contact.getContactId() == null) { + // ... and throw again + throw new NullPointerException("contact.contactId is null"); //NOI18N + } else if (contact.getContactId() < 1) { + // Invalid id number + throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N + } else if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) { + // Not set cell phone instance + throw new PhoneNumberAlreadyLinkedException(landLineNumber); + } else if (null == landLineNumber) { + // Throw NPE + throw new NullPointerException("landLineNumber is null"); //NOI18N + } else if (landLineNumber.getPhoneId() == null) { + // Throw it again + throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N + } else if (landLineNumber.getPhoneId() < 1) { + // Invalid id + throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneId={0} is not valid", landLineNumber.getPhoneId())); //NOI18N + } else if (landLineNumber.getPhoneCountry() == null) { + // ... and again + throw new NullPointerException("landLineNumber.phoneCountry is null"); //NOI18N + } else if (landLineNumber.getPhoneAreaCode() == null) { + // Throw it again + throw new NullPointerException("landLineNumber.phoneAreaCode is null"); //NOI18N + } else if (landLineNumber.getPhoneAreaCode() < 1) { + // Invalid id + throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneAreaCode={0} is not valid", landLineNumber.getPhoneAreaCode())); //NOI18N + } else if (landLineNumber.getPhoneNumber() == null) { + // Throw it again + throw new NullPointerException("landLineNumber.phoneNumber is null"); //NOI18N + } else if (landLineNumber.getPhoneNumber() < 1) { + // Invalid id + throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneNumber={0} is not valid", landLineNumber.getPhoneNumber())); //NOI18N + } + + // Set land-line number in contact + contact.setContactLandLineNumber(landLineNumber); + + // Update database + final Contact updatedContact = this.contactBean.updateContactData(contact); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingLandLineNumberWithContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N + + // Return it + return updatedContact; + } + + @Override + public Contact linkExistingMobileNumberWithContact (final Contact contact, final DialableMobileNumber mobileNumber) throws PhoneNumberAlreadyLinkedException { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingMobileNumberWithContact: contact={1},mobileNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, mobileNumber)); //NOI18N + + // Is the contact set? + if (null == contact) { + // Throw NPE + throw new NullPointerException("contact is null"); //NOI18N + } else if (contact.getContactId() == null) { + // ... and throw again + throw new NullPointerException("contact.contactId is null"); //NOI18N + } else if (contact.getContactId() < 1) { + // Invalid id number + throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N + } else if (contact.getContactMobileNumber() instanceof DialableMobileNumber) { + // Not set cell phone instance + throw new PhoneNumberAlreadyLinkedException(mobileNumber); + } else if (null == mobileNumber) { + // Throw NPE + throw new NullPointerException("mobileNumber is null"); //NOI18N + } else if (mobileNumber.getPhoneId() == null) { + // Throw it again + throw new NullPointerException("mobileNumber.phoneId is null"); //NOI18N + } else if (mobileNumber.getPhoneId() < 1) { + // Invalid id + throw new IllegalArgumentException(MessageFormat.format("mobileNumber.phoneId={0} is not valid", mobileNumber.getPhoneId())); //NOI18N + } else if (mobileNumber.getMobileProvider() == null) { + // Throw NPE again + throw new NullPointerException("mobileNumber.mobileProvider is null"); //NOI18N + } else if (mobileNumber.getMobileProvider().getProviderId() == null) { + // Throw NPE again + throw new NullPointerException("mobileNumber.mobileProvider.providerId is null"); //NOI18N + } else if (mobileNumber.getMobileProvider().getProviderId() < 1) { + // Throw NPE again + throw new IllegalArgumentException(MessageFormat.format("mobileNumber.mobileProvider.providerId={0} is not valid", mobileNumber.getMobileProvider().getProviderId())); //NOI18N + } + + // Set mobile number in contact + contact.setContactMobileNumber(mobileNumber); + + // Update database + final Contact updatedContact = this.contactBean.updateContactData(contact); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingMobileNumberWithContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N + + // Return it + return updatedContact; + } + + @Override + public Contact linkNewFaxNumberWithContact (final Contact contact, final DialableFaxNumber faxNumber) throws PhoneNumberAlreadyLinkedException { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkNewFaxNumberWithContact: contact={1},faxNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, faxNumber)); //NOI18N + + // Is the contact set? + if (null == contact) { + // Throw NPE + throw new NullPointerException("contact is null"); //NOI18N + } else if (contact.getContactId() == null) { + // ... and throw again + throw new NullPointerException("contact.contactId is null"); //NOI18N + } else if (contact.getContactId() < 1) { + // Invalid id number + throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N + } else if (contact.getContactFaxNumber() instanceof DialableFaxNumber) { + // Not set cell phone instance + throw new PhoneNumberAlreadyLinkedException(faxNumber); + } else if (null == faxNumber) { + // Throw NPE + throw new NullPointerException("faxNumber is null"); //NOI18N + } else if (faxNumber.getPhoneId() instanceof Long) { + // Throw it again + throw new IllegalStateException(MessageFormat.format("faxNumber.phoneId={0} is not null", faxNumber.getPhoneId())); //NOI18N + } else if (faxNumber.getPhoneCountry() == null) { + // ... and again + throw new NullPointerException("faxNumber.phoneCountry is null"); //NOI18N + } else if (faxNumber.getPhoneAreaCode() == null) { + // Throw it again + throw new NullPointerException("faxNumber.phoneAreaCode is null"); //NOI18N + } else if (faxNumber.getPhoneAreaCode() < 1) { + // Invalid id + throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneAreaCode={0} is not valid", faxNumber.getPhoneAreaCode())); //NOI18N + } else if (faxNumber.getPhoneNumber() == null) { + // Throw it again + throw new NullPointerException("faxNumber.phoneNumber is null"); //NOI18N + } else if (faxNumber.getPhoneNumber() < 1) { + // Invalid id + throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneNumber={0} is not valid", faxNumber.getPhoneNumber())); //NOI18N + } + + // Set created instance + faxNumber.setPhoneEntryCreated(new GregorianCalendar()); + + // Set fax number in contact + contact.setContactFaxNumber(faxNumber); + + // Update database + final Contact updatedContact = this.contactBean.updateContactData(contact); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkNewFaxNumberWithContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N + + // Return it + return updatedContact; + } + + @Override + public Contact linkNewLandLineNumberWithContact (final Contact contact, final DialableLandLineNumber landLineNumber) throws PhoneNumberAlreadyLinkedException { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkNewLandLineNumberWithContact: contact={1},landLineNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, landLineNumber)); //NOI18N + + // Is the contact set? + if (null == contact) { + // Throw NPE + throw new NullPointerException("contact is null"); //NOI18N + } else if (contact.getContactId() == null) { + // ... and throw again + throw new NullPointerException("contact.contactId is null"); //NOI18N + } else if (contact.getContactId() < 1) { + // Invalid id number + throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N + } else if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) { + // Not set cell phone instance + throw new PhoneNumberAlreadyLinkedException(landLineNumber); + } else if (null == landLineNumber) { + // Throw NPE + throw new NullPointerException("landLineNumber is null"); //NOI18N + } else if (landLineNumber.getPhoneId() instanceof Long) { + // Throw it again + throw new IllegalStateException(MessageFormat.format("landLineNumber.phoneId={0} is not null", landLineNumber.getPhoneId())); //NOI18N + } else if (landLineNumber.getPhoneCountry() == null) { + // ... and again + throw new NullPointerException("landLineNumber.phoneCountry is null"); //NOI18N + } else if (landLineNumber.getPhoneAreaCode() == null) { + // Throw it again + throw new NullPointerException("landLineNumber.phoneAreaCode is null"); //NOI18N + } else if (landLineNumber.getPhoneAreaCode() < 1) { + // Invalid id + throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneAreaCode={0} is not valid", landLineNumber.getPhoneAreaCode())); //NOI18N + } else if (landLineNumber.getPhoneNumber() == null) { + // Throw it again + throw new NullPointerException("landLineNumber.phoneNumber is null"); //NOI18N + } else if (landLineNumber.getPhoneNumber() < 1) { + // Invalid id + throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneNumber={0} is not valid", landLineNumber.getPhoneNumber())); //NOI18N + } + + // Set created instance + landLineNumber.setPhoneEntryCreated(new GregorianCalendar()); + + // Set landLine number in contact + contact.setContactLandLineNumber(landLineNumber); + + // Update database + final Contact updatedContact = this.contactBean.updateContactData(contact); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkNewLandLineNumberWithContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N + + // Return it + return updatedContact; + } + + @Override + public Contact linkNewMobileNumberWithContact (final Contact contact, final DialableMobileNumber mobileNumber) throws PhoneNumberAlreadyLinkedException { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkNewMobileNumberWithContact: contact={1},mobileNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, mobileNumber)); //NOI18N + + // Is the contact set? + if (null == contact) { + // Throw NPE + throw new NullPointerException("contact is null"); //NOI18N + } else if (contact.getContactId() == null) { + // ... and throw again + throw new NullPointerException("contact.contactId is null"); //NOI18N + } else if (contact.getContactId() < 1) { + // Invalid id number + throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N + } else if (contact.getContactMobileNumber() instanceof DialableMobileNumber) { + // Not set cell phone instance + throw new PhoneNumberAlreadyLinkedException(mobileNumber); + } else if (null == mobileNumber) { + // Throw NPE + throw new NullPointerException("mobileNumber is null"); //NOI18N + } else if (mobileNumber.getPhoneId() instanceof Long) { + // Throw it again + throw new IllegalStateException(MessageFormat.format("mobileNumber.phoneId={0} is not null", mobileNumber.getPhoneId())); //NOI18N + } else if (mobileNumber.getMobileProvider() == null) { + // Throw NPE again + throw new NullPointerException("mobileNumber.mobileProvider is null"); //NOI18N + } else if (mobileNumber.getMobileProvider().getProviderId() == null) { + // Throw NPE again + throw new NullPointerException("mobileNumber.mobileProvider.providerId is null"); //NOI18N + } else if (mobileNumber.getMobileProvider().getProviderId() < 1) { + // Throw NPE again + throw new IllegalArgumentException(MessageFormat.format("mobileNumber.mobileProvider.providerId={0} is not valid", mobileNumber.getMobileProvider().getProviderId())); //NOI18N + } + + // Set created instance + mobileNumber.setPhoneEntryCreated(new GregorianCalendar()); + + // Set mobile number in contact + contact.setContactMobileNumber(mobileNumber); + + // Update database + final Contact updatedContact = this.contactBean.updateContactData(contact); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkNewMobileNumberWithContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N + + // Return it + return updatedContact; + } + + @Override + public Contact unlinkFaxDataFromContact (final Contact contact, final DialableFaxNumber faxNumber) throws PhoneNumberNotLinkedException { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkFaxDataFromContact: contact={1},faxNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, faxNumber)); //NOI18N + + // Is the contact set? + if (null == contact) { + // Throw NPE + throw new NullPointerException("contact is null"); //NOI18N + } else if (contact.getContactId() == null) { + // ... and throw again + throw new NullPointerException("contact.contactId is null"); //NOI18N + } else if (contact.getContactId() < 1) { + // Invalid id number + throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N + } else if (contact.getContactFaxNumber() == null) { + // Not set cell phone instance + throw new PhoneNumberNotLinkedException(faxNumber); + } else if (contact.getContactFaxNumber().getPhoneId() == null) { + // Throw NPE again + throw new NullPointerException("contact.contactFaxNumber.phoneId is null"); //NOI18N + } else if (contact.getContactFaxNumber().getPhoneId() < 1) { + // Invalid id number + throw new IllegalArgumentException(MessageFormat.format("contact.contactFaxNumber.phoneId={0} is invalid.", contact.getContactFaxNumber().getPhoneId())); //NOI18N + } else if (!Objects.equals(faxNumber.getPhoneId(), contact.getContactFaxNumber().getPhoneId())) { + // Not same object + throw new IllegalArgumentException(MessageFormat.format("contact.contactFaxNumber.phoneId={0} and faxNumber.phoneId={1} are not the same.", contact.getContactFaxNumber().getPhoneId(), faxNumber.getPhoneId())); //NOI18N + } + + // Remove it from contact + contact.setContactFaxNumber(null); + + // Update database + final Contact updatedContact = this.contactBean.updateContactData(contact); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkFaxDataFromContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N + + // Return it + return updatedContact; + } + + @Override + public Contact unlinkLandLineDataFromContact (final Contact contact, final DialableLandLineNumber landLineNumber) throws PhoneNumberNotLinkedException { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkLandLineDataFromContact: contact={1},landLineNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, landLineNumber)); //NOI18N + + // Is the contact set? + if (null == contact) { + // Throw NPE + throw new NullPointerException("contact is null"); //NOI18N + } else if (contact.getContactId() == null) { + // ... and throw again + throw new NullPointerException("contact.contactId is null"); //NOI18N + } else if (contact.getContactId() < 1) { + // Invalid id number + throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N + } else if (contact.getContactLandLineNumber() == null) { + // Not set cell phone instance + throw new PhoneNumberNotLinkedException(landLineNumber); + } else if (contact.getContactLandLineNumber().getPhoneId() == null) { + // Throw NPE again + throw new NullPointerException("contact.contactLandLineNumber.phoneId is null"); //NOI18N + } else if (contact.getContactLandLineNumber().getPhoneId() < 1) { + // Invalid id number + throw new IllegalArgumentException(MessageFormat.format("contact.contactLandLineNumber.phoneId={0} is invalid.", contact.getContactLandLineNumber().getPhoneId())); //NOI18N + } else if (!Objects.equals(landLineNumber.getPhoneId(), contact.getContactLandLineNumber().getPhoneId())) { + // Not same object + throw new IllegalArgumentException(MessageFormat.format("contact.contactLandLineNumber.phoneId={0} and landLineNumber.phoneId={1} are not the same.", contact.getContactLandLineNumber().getPhoneId(), landLineNumber.getPhoneId())); //NOI18N + } + + // Remove it from contact + contact.setContactLandLineNumber(null); + + // Update database + final Contact updatedContact = this.contactBean.updateContactData(contact); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkLandLineDataFromContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N + + // Return it + return updatedContact; + } + + @Override + public Contact unlinkMobileDataFromContact (final Contact contact, final DialableMobileNumber mobileNumber) throws PhoneNumberNotLinkedException { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkMobileDataFromContact: contact={1},mobileNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, mobileNumber)); //NOI18N + + // Is the contact set? + if (null == contact) { + // Throw NPE + throw new NullPointerException("contact is null"); //NOI18N + } else if (contact.getContactId() == null) { + // ... and throw again + throw new NullPointerException("contact.contactId is null"); //NOI18N + } else if (contact.getContactId() < 1) { + // Invalid id number + throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N + } else if (contact.getContactMobileNumber() == null) { + // Not set cell phone instance + throw new PhoneNumberNotLinkedException(mobileNumber); + } else if (contact.getContactMobileNumber().getPhoneId() == null) { + // Throw NPE again + throw new NullPointerException("contact.contactMobileNumber.phoneId is null"); //NOI18N + } else if (contact.getContactMobileNumber().getPhoneId() < 1) { + // Invalid id number + throw new IllegalArgumentException(MessageFormat.format("contact.contactMobileNumber.phoneId={0} is invalid.", contact.getContactMobileNumber().getPhoneId())); //NOI18N + } else if (!Objects.equals(mobileNumber.getPhoneId(), contact.getContactMobileNumber().getPhoneId())) { + // Not same object + throw new IllegalArgumentException(MessageFormat.format("contact.contactMobileNumber.phoneId={0} and mobileNumber.phoneId={1} are not the same.", contact.getContactMobileNumber().getPhoneId(), mobileNumber.getPhoneId())); //NOI18N + } + + // Remove it from contact + contact.setContactMobileNumber(null); + + // Update database + final Contact updatedContact = this.contactBean.updateContactData(contact); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkMobileDataFromContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N + + // Return it + return updatedContact; + } + +} diff --git a/src/java/org/mxchange/jcontacts/phone/AddressbookAdminContactPhoneSessionBean.java b/src/java/org/mxchange/jcontacts/phone/AddressbookAdminContactPhoneSessionBean.java deleted file mode 100644 index b520b1f..0000000 --- a/src/java/org/mxchange/jcontacts/phone/AddressbookAdminContactPhoneSessionBean.java +++ /dev/null @@ -1,517 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Roland Häder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.mxchange.jcontacts.phone; - -import java.text.MessageFormat; -import java.util.GregorianCalendar; -import java.util.Objects; -import javax.ejb.EJB; -import javax.ejb.Stateless; -import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; -import org.mxchange.jcontacts.model.contact.Contact; -import org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote; -import org.mxchange.jcontacts.model.phone.AdminContactsPhoneSessionBeanRemote; -import org.mxchange.jphone.exceptions.PhoneNumberAlreadyLinkedException; -import org.mxchange.jphone.exceptions.PhoneNumberNotLinkedException; -import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; -import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber; -import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber; - -/** - * A session EJB for administrative contact's phone number purposes - *

- * @author Roland Häder - */ -@Stateless (name = "adminContactPhone", description = "An administrative bean handling contact's phone data") -public class AddressbookAdminContactPhoneSessionBean extends BaseAddressbookDatabaseBean implements AdminContactsPhoneSessionBeanRemote { - - /** - * Serial number - */ - private static final long serialVersionUID = 189_217_561_460_237_108L; - - /** - * Contact EJB - */ - @EJB - private ContactSessionBeanRemote contactBean; - - /** - * Default constructor - */ - public AddressbookAdminContactPhoneSessionBean () { - // Call super constructor - super(); - } - - @Override - public Contact linkExistingFaxNumberWithContact (final Contact contact, final DialableFaxNumber faxNumber) throws PhoneNumberAlreadyLinkedException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingFaxNumberWithContact: contact={1},faxNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, faxNumber)); //NOI18N - - // Is the contact set? - if (null == contact) { - // Throw NPE - throw new NullPointerException("contact is null"); //NOI18N - } else if (contact.getContactId() == null) { - // ... and throw again - throw new NullPointerException("contact.contactId is null"); //NOI18N - } else if (contact.getContactId() < 1) { - // Invalid id number - throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N - } else if (contact.getContactFaxNumber() instanceof DialableFaxNumber) { - // Not set cell phone instance - throw new PhoneNumberAlreadyLinkedException(faxNumber); - } else if (null == faxNumber) { - // Throw NPE - throw new NullPointerException("faxNumber is null"); //NOI18N - } else if (faxNumber.getPhoneId() == null) { - // Throw it again - throw new NullPointerException("faxNumber.phoneId is null"); //NOI18N - } else if (faxNumber.getPhoneId() < 1) { - // Invalid id - throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneId={0} is not valid", faxNumber.getPhoneId())); //NOI18N - } else if (faxNumber.getPhoneCountry() == null) { - // ... and again - throw new NullPointerException("faxNumber.phoneCountry is null"); //NOI18N - } else if (faxNumber.getPhoneAreaCode() == null) { - // Throw it again - throw new NullPointerException("faxNumber.phoneAreaCode is null"); //NOI18N - } else if (faxNumber.getPhoneAreaCode() < 1) { - // Invalid id - throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneAreaCode={0} is not valid", faxNumber.getPhoneAreaCode())); //NOI18N - } else if (faxNumber.getPhoneNumber() == null) { - // Throw it again - throw new NullPointerException("faxNumber.phoneNumber is null"); //NOI18N - } else if (faxNumber.getPhoneNumber() < 1) { - // Invalid id - throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneNumber={0} is not valid", faxNumber.getPhoneNumber())); //NOI18N - } - - // Set fax number in contact - contact.setContactFaxNumber(faxNumber); - - // Update database - final Contact updatedContact = this.contactBean.updateContactData(contact); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingFaxNumberWithContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N - - // Return it - return updatedContact; - } - - @Override - public Contact linkExistingLandLineNumberWithContact (final Contact contact, final DialableLandLineNumber landLineNumber) throws PhoneNumberAlreadyLinkedException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingLandLineNumberWithContact: contact={1},landLineNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, landLineNumber)); //NOI18N - - // Is the contact set? - if (null == contact) { - // Throw NPE - throw new NullPointerException("contact is null"); //NOI18N - } else if (contact.getContactId() == null) { - // ... and throw again - throw new NullPointerException("contact.contactId is null"); //NOI18N - } else if (contact.getContactId() < 1) { - // Invalid id number - throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N - } else if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) { - // Not set cell phone instance - throw new PhoneNumberAlreadyLinkedException(landLineNumber); - } else if (null == landLineNumber) { - // Throw NPE - throw new NullPointerException("landLineNumber is null"); //NOI18N - } else if (landLineNumber.getPhoneId() == null) { - // Throw it again - throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N - } else if (landLineNumber.getPhoneId() < 1) { - // Invalid id - throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneId={0} is not valid", landLineNumber.getPhoneId())); //NOI18N - } else if (landLineNumber.getPhoneCountry() == null) { - // ... and again - throw new NullPointerException("landLineNumber.phoneCountry is null"); //NOI18N - } else if (landLineNumber.getPhoneAreaCode() == null) { - // Throw it again - throw new NullPointerException("landLineNumber.phoneAreaCode is null"); //NOI18N - } else if (landLineNumber.getPhoneAreaCode() < 1) { - // Invalid id - throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneAreaCode={0} is not valid", landLineNumber.getPhoneAreaCode())); //NOI18N - } else if (landLineNumber.getPhoneNumber() == null) { - // Throw it again - throw new NullPointerException("landLineNumber.phoneNumber is null"); //NOI18N - } else if (landLineNumber.getPhoneNumber() < 1) { - // Invalid id - throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneNumber={0} is not valid", landLineNumber.getPhoneNumber())); //NOI18N - } - - // Set land-line number in contact - contact.setContactLandLineNumber(landLineNumber); - - // Update database - final Contact updatedContact = this.contactBean.updateContactData(contact); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingLandLineNumberWithContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N - - // Return it - return updatedContact; - } - - @Override - public Contact linkExistingMobileNumberWithContact (final Contact contact, final DialableMobileNumber mobileNumber) throws PhoneNumberAlreadyLinkedException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingMobileNumberWithContact: contact={1},mobileNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, mobileNumber)); //NOI18N - - // Is the contact set? - if (null == contact) { - // Throw NPE - throw new NullPointerException("contact is null"); //NOI18N - } else if (contact.getContactId() == null) { - // ... and throw again - throw new NullPointerException("contact.contactId is null"); //NOI18N - } else if (contact.getContactId() < 1) { - // Invalid id number - throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N - } else if (contact.getContactMobileNumber() instanceof DialableMobileNumber) { - // Not set cell phone instance - throw new PhoneNumberAlreadyLinkedException(mobileNumber); - } else if (null == mobileNumber) { - // Throw NPE - throw new NullPointerException("mobileNumber is null"); //NOI18N - } else if (mobileNumber.getPhoneId() == null) { - // Throw it again - throw new NullPointerException("mobileNumber.phoneId is null"); //NOI18N - } else if (mobileNumber.getPhoneId() < 1) { - // Invalid id - throw new IllegalArgumentException(MessageFormat.format("mobileNumber.phoneId={0} is not valid", mobileNumber.getPhoneId())); //NOI18N - } else if (mobileNumber.getMobileProvider() == null) { - // Throw NPE again - throw new NullPointerException("mobileNumber.mobileProvider is null"); //NOI18N - } else if (mobileNumber.getMobileProvider().getProviderId() == null) { - // Throw NPE again - throw new NullPointerException("mobileNumber.mobileProvider.providerId is null"); //NOI18N - } else if (mobileNumber.getMobileProvider().getProviderId() < 1) { - // Throw NPE again - throw new IllegalArgumentException(MessageFormat.format("mobileNumber.mobileProvider.providerId={0} is not valid", mobileNumber.getMobileProvider().getProviderId())); //NOI18N - } - - // Set mobile number in contact - contact.setContactMobileNumber(mobileNumber); - - // Update database - final Contact updatedContact = this.contactBean.updateContactData(contact); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingMobileNumberWithContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N - - // Return it - return updatedContact; - } - - @Override - public Contact linkNewFaxNumberWithContact (final Contact contact, final DialableFaxNumber faxNumber) throws PhoneNumberAlreadyLinkedException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkNewFaxNumberWithContact: contact={1},faxNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, faxNumber)); //NOI18N - - // Is the contact set? - if (null == contact) { - // Throw NPE - throw new NullPointerException("contact is null"); //NOI18N - } else if (contact.getContactId() == null) { - // ... and throw again - throw new NullPointerException("contact.contactId is null"); //NOI18N - } else if (contact.getContactId() < 1) { - // Invalid id number - throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N - } else if (contact.getContactFaxNumber() instanceof DialableFaxNumber) { - // Not set cell phone instance - throw new PhoneNumberAlreadyLinkedException(faxNumber); - } else if (null == faxNumber) { - // Throw NPE - throw new NullPointerException("faxNumber is null"); //NOI18N - } else if (faxNumber.getPhoneId() instanceof Long) { - // Throw it again - throw new IllegalStateException(MessageFormat.format("faxNumber.phoneId={0} is not null", faxNumber.getPhoneId())); //NOI18N - } else if (faxNumber.getPhoneCountry() == null) { - // ... and again - throw new NullPointerException("faxNumber.phoneCountry is null"); //NOI18N - } else if (faxNumber.getPhoneAreaCode() == null) { - // Throw it again - throw new NullPointerException("faxNumber.phoneAreaCode is null"); //NOI18N - } else if (faxNumber.getPhoneAreaCode() < 1) { - // Invalid id - throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneAreaCode={0} is not valid", faxNumber.getPhoneAreaCode())); //NOI18N - } else if (faxNumber.getPhoneNumber() == null) { - // Throw it again - throw new NullPointerException("faxNumber.phoneNumber is null"); //NOI18N - } else if (faxNumber.getPhoneNumber() < 1) { - // Invalid id - throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneNumber={0} is not valid", faxNumber.getPhoneNumber())); //NOI18N - } - - // Set created instance - faxNumber.setPhoneEntryCreated(new GregorianCalendar()); - - // Set fax number in contact - contact.setContactFaxNumber(faxNumber); - - // Update database - final Contact updatedContact = this.contactBean.updateContactData(contact); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkNewFaxNumberWithContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N - - // Return it - return updatedContact; - } - - @Override - public Contact linkNewLandLineNumberWithContact (final Contact contact, final DialableLandLineNumber landLineNumber) throws PhoneNumberAlreadyLinkedException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkNewLandLineNumberWithContact: contact={1},landLineNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, landLineNumber)); //NOI18N - - // Is the contact set? - if (null == contact) { - // Throw NPE - throw new NullPointerException("contact is null"); //NOI18N - } else if (contact.getContactId() == null) { - // ... and throw again - throw new NullPointerException("contact.contactId is null"); //NOI18N - } else if (contact.getContactId() < 1) { - // Invalid id number - throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N - } else if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) { - // Not set cell phone instance - throw new PhoneNumberAlreadyLinkedException(landLineNumber); - } else if (null == landLineNumber) { - // Throw NPE - throw new NullPointerException("landLineNumber is null"); //NOI18N - } else if (landLineNumber.getPhoneId() instanceof Long) { - // Throw it again - throw new IllegalStateException(MessageFormat.format("landLineNumber.phoneId={0} is not null", landLineNumber.getPhoneId())); //NOI18N - } else if (landLineNumber.getPhoneCountry() == null) { - // ... and again - throw new NullPointerException("landLineNumber.phoneCountry is null"); //NOI18N - } else if (landLineNumber.getPhoneAreaCode() == null) { - // Throw it again - throw new NullPointerException("landLineNumber.phoneAreaCode is null"); //NOI18N - } else if (landLineNumber.getPhoneAreaCode() < 1) { - // Invalid id - throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneAreaCode={0} is not valid", landLineNumber.getPhoneAreaCode())); //NOI18N - } else if (landLineNumber.getPhoneNumber() == null) { - // Throw it again - throw new NullPointerException("landLineNumber.phoneNumber is null"); //NOI18N - } else if (landLineNumber.getPhoneNumber() < 1) { - // Invalid id - throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneNumber={0} is not valid", landLineNumber.getPhoneNumber())); //NOI18N - } - - // Set created instance - landLineNumber.setPhoneEntryCreated(new GregorianCalendar()); - - // Set landLine number in contact - contact.setContactLandLineNumber(landLineNumber); - - // Update database - final Contact updatedContact = this.contactBean.updateContactData(contact); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkNewLandLineNumberWithContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N - - // Return it - return updatedContact; - } - - @Override - public Contact linkNewMobileNumberWithContact (final Contact contact, final DialableMobileNumber mobileNumber) throws PhoneNumberAlreadyLinkedException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkNewMobileNumberWithContact: contact={1},mobileNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, mobileNumber)); //NOI18N - - // Is the contact set? - if (null == contact) { - // Throw NPE - throw new NullPointerException("contact is null"); //NOI18N - } else if (contact.getContactId() == null) { - // ... and throw again - throw new NullPointerException("contact.contactId is null"); //NOI18N - } else if (contact.getContactId() < 1) { - // Invalid id number - throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N - } else if (contact.getContactMobileNumber() instanceof DialableMobileNumber) { - // Not set cell phone instance - throw new PhoneNumberAlreadyLinkedException(mobileNumber); - } else if (null == mobileNumber) { - // Throw NPE - throw new NullPointerException("mobileNumber is null"); //NOI18N - } else if (mobileNumber.getPhoneId() instanceof Long) { - // Throw it again - throw new IllegalStateException(MessageFormat.format("mobileNumber.phoneId={0} is not null", mobileNumber.getPhoneId())); //NOI18N - } else if (mobileNumber.getMobileProvider() == null) { - // Throw NPE again - throw new NullPointerException("mobileNumber.mobileProvider is null"); //NOI18N - } else if (mobileNumber.getMobileProvider().getProviderId() == null) { - // Throw NPE again - throw new NullPointerException("mobileNumber.mobileProvider.providerId is null"); //NOI18N - } else if (mobileNumber.getMobileProvider().getProviderId() < 1) { - // Throw NPE again - throw new IllegalArgumentException(MessageFormat.format("mobileNumber.mobileProvider.providerId={0} is not valid", mobileNumber.getMobileProvider().getProviderId())); //NOI18N - } - - // Set created instance - mobileNumber.setPhoneEntryCreated(new GregorianCalendar()); - - // Set mobile number in contact - contact.setContactMobileNumber(mobileNumber); - - // Update database - final Contact updatedContact = this.contactBean.updateContactData(contact); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkNewMobileNumberWithContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N - - // Return it - return updatedContact; - } - - @Override - public Contact unlinkFaxDataFromContact (final Contact contact, final DialableFaxNumber faxNumber) throws PhoneNumberNotLinkedException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkFaxDataFromContact: contact={1},faxNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, faxNumber)); //NOI18N - - // Is the contact set? - if (null == contact) { - // Throw NPE - throw new NullPointerException("contact is null"); //NOI18N - } else if (contact.getContactId() == null) { - // ... and throw again - throw new NullPointerException("contact.contactId is null"); //NOI18N - } else if (contact.getContactId() < 1) { - // Invalid id number - throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N - } else if (contact.getContactFaxNumber() == null) { - // Not set cell phone instance - throw new PhoneNumberNotLinkedException(faxNumber); - } else if (contact.getContactFaxNumber().getPhoneId() == null) { - // Throw NPE again - throw new NullPointerException("contact.contactFaxNumber.phoneId is null"); //NOI18N - } else if (contact.getContactFaxNumber().getPhoneId() < 1) { - // Invalid id number - throw new IllegalArgumentException(MessageFormat.format("contact.contactFaxNumber.phoneId={0} is invalid.", contact.getContactFaxNumber().getPhoneId())); //NOI18N - } else if (!Objects.equals(faxNumber.getPhoneId(), contact.getContactFaxNumber().getPhoneId())) { - // Not same object - throw new IllegalArgumentException(MessageFormat.format("contact.contactFaxNumber.phoneId={0} and faxNumber.phoneId={1} are not the same.", contact.getContactFaxNumber().getPhoneId(), faxNumber.getPhoneId())); //NOI18N - } - - // Remove it from contact - contact.setContactFaxNumber(null); - - // Update database - final Contact updatedContact = this.contactBean.updateContactData(contact); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkFaxDataFromContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N - - // Return it - return updatedContact; - } - - @Override - public Contact unlinkLandLineDataFromContact (final Contact contact, final DialableLandLineNumber landLineNumber) throws PhoneNumberNotLinkedException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkLandLineDataFromContact: contact={1},landLineNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, landLineNumber)); //NOI18N - - // Is the contact set? - if (null == contact) { - // Throw NPE - throw new NullPointerException("contact is null"); //NOI18N - } else if (contact.getContactId() == null) { - // ... and throw again - throw new NullPointerException("contact.contactId is null"); //NOI18N - } else if (contact.getContactId() < 1) { - // Invalid id number - throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N - } else if (contact.getContactLandLineNumber() == null) { - // Not set cell phone instance - throw new PhoneNumberNotLinkedException(landLineNumber); - } else if (contact.getContactLandLineNumber().getPhoneId() == null) { - // Throw NPE again - throw new NullPointerException("contact.contactLandLineNumber.phoneId is null"); //NOI18N - } else if (contact.getContactLandLineNumber().getPhoneId() < 1) { - // Invalid id number - throw new IllegalArgumentException(MessageFormat.format("contact.contactLandLineNumber.phoneId={0} is invalid.", contact.getContactLandLineNumber().getPhoneId())); //NOI18N - } else if (!Objects.equals(landLineNumber.getPhoneId(), contact.getContactLandLineNumber().getPhoneId())) { - // Not same object - throw new IllegalArgumentException(MessageFormat.format("contact.contactLandLineNumber.phoneId={0} and landLineNumber.phoneId={1} are not the same.", contact.getContactLandLineNumber().getPhoneId(), landLineNumber.getPhoneId())); //NOI18N - } - - // Remove it from contact - contact.setContactLandLineNumber(null); - - // Update database - final Contact updatedContact = this.contactBean.updateContactData(contact); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkLandLineDataFromContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N - - // Return it - return updatedContact; - } - - @Override - public Contact unlinkMobileDataFromContact (final Contact contact, final DialableMobileNumber mobileNumber) throws PhoneNumberNotLinkedException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkMobileDataFromContact: contact={1},mobileNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, mobileNumber)); //NOI18N - - // Is the contact set? - if (null == contact) { - // Throw NPE - throw new NullPointerException("contact is null"); //NOI18N - } else if (contact.getContactId() == null) { - // ... and throw again - throw new NullPointerException("contact.contactId is null"); //NOI18N - } else if (contact.getContactId() < 1) { - // Invalid id number - throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N - } else if (contact.getContactMobileNumber() == null) { - // Not set cell phone instance - throw new PhoneNumberNotLinkedException(mobileNumber); - } else if (contact.getContactMobileNumber().getPhoneId() == null) { - // Throw NPE again - throw new NullPointerException("contact.contactMobileNumber.phoneId is null"); //NOI18N - } else if (contact.getContactMobileNumber().getPhoneId() < 1) { - // Invalid id number - throw new IllegalArgumentException(MessageFormat.format("contact.contactMobileNumber.phoneId={0} is invalid.", contact.getContactMobileNumber().getPhoneId())); //NOI18N - } else if (!Objects.equals(mobileNumber.getPhoneId(), contact.getContactMobileNumber().getPhoneId())) { - // Not same object - throw new IllegalArgumentException(MessageFormat.format("contact.contactMobileNumber.phoneId={0} and mobileNumber.phoneId={1} are not the same.", contact.getContactMobileNumber().getPhoneId(), mobileNumber.getPhoneId())); //NOI18N - } - - // Remove it from contact - contact.setContactMobileNumber(null); - - // Update database - final Contact updatedContact = this.contactBean.updateContactData(contact); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkMobileDataFromContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N - - // Return it - return updatedContact; - } - -} diff --git a/src/java/org/mxchange/jcontactsbusiness/basicdata/AddressbookAdminBusinessDataSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/basicdata/AddressbookAdminBusinessDataSessionBean.java deleted file mode 100644 index cf8d545..0000000 --- a/src/java/org/mxchange/jcontactsbusiness/basicdata/AddressbookAdminBusinessDataSessionBean.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (C) 2017 Roland Häder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.mxchange.jcontactsbusiness.basicdata; - -import java.text.MessageFormat; -import java.util.GregorianCalendar; -import java.util.List; -import java.util.Objects; -import javax.ejb.EJB; -import javax.ejb.Stateless; -import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; -import org.mxchange.jcontactsbusiness.exceptions.basicdata.BusinessDataAlreadyAddedException; -import org.mxchange.jcontactsbusiness.model.basicdata.AdminBusinessDataSessionBeanRemote; -import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData; -import org.mxchange.jcontactsbusiness.model.basicdata.BusinessDataSessionBeanRemote; -import org.mxchange.jcontactsbusiness.model.employee.Employee; -import org.mxchange.jusercore.model.user.User; - -/** - * An administrative stateless session bean for business data - *

- * @author Roland Häder - */ -@Stateless (name = "adminBusinessData", description = "An administrative statless bean for handling business data (all)") -public class AddressbookAdminBusinessDataSessionBean extends BaseAddressbookDatabaseBean implements AdminBusinessDataSessionBeanRemote { - - /** - * Serial number - */ - private static final long serialVersionUID = 56_389_504_892_184_572L; - - /** - * Administrative EJB - */ - @EJB - private BusinessDataSessionBeanRemote businessDataBean; - - /** - * Default constructor - */ - public AddressbookAdminBusinessDataSessionBean () { - // Call super constructor - super(); - } - - @Override - public BusinessBasicData addCompanyBasicData (final BusinessBasicData basicData) throws BusinessDataAlreadyAddedException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addBusinessBasicData: basicData={1} - CALLED!", this.getClass().getSimpleName(), basicData)); //NOI18N - - // Is the instance set? - if (null == basicData) { - // Throw NPE - throw new NullPointerException("basicData is null"); //NOI18N - } else if (basicData.getBasicDataId() != null) { - // Should be null - throw new IllegalArgumentException(MessageFormat.format("basicData.basicDataId={0} - is not null", basicData.getBasicDataId())); //NOI18N - } else if (this.isSameCompanyNameAdded(basicData)) { - // Throw exception - throw new BusinessDataAlreadyAddedException(basicData); - } - - // Now add current date - basicData.setCompanyCreated(new GregorianCalendar()); - - // Is there a owner set? - if (basicData.getCompanyUserOwner() instanceof User) { - // Get managed instance - final User managedUser = this.createManaged(basicData.getCompanyUserOwner()); - - // Set it back - basicData.setCompanyUserOwner(managedUser); - } - - // Is a founder set? - if (basicData.getCompanyFounder() instanceof Employee) { - // Get managed instance - final Employee managedEmployee = this.createManaged(basicData.getCompanyFounder()); - - // Set it back - basicData.setCompanyFounder(managedEmployee); - } - - // Is a contact person set? - if (basicData.getCompanyContactEmployee() instanceof Employee) { - // Get managed instance - final Employee managedEmployee = this.createManaged(basicData.getCompanyContactEmployee()); - - // Set it back - basicData.setCompanyContactEmployee(managedEmployee); - } - - // Persist it - this.getEntityManager().persist(basicData); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addBusinessBasicData: basicData.basicDataId={1} - EXIT!", this.getClass().getSimpleName(), basicData.getBasicDataId())); //NOI18N - - // Return updated instance - return basicData; - } - - /** - * Checks if given basic data is already added by it's company name - *

- * @param basicData Basic data to be checked - * - * @return Whether same company name has been used - */ - private boolean isSameCompanyNameAdded (final BusinessBasicData basicData) { - // Get all available entries - final List list = this.businessDataBean.allCompanyBasicData(); - - // Default is not found - boolean isFound = false; - - // Then check each entry - for (final BusinessBasicData entry : list) { - // Is the company name matching? - if (Objects.equals(entry.getCompanyName(), basicData.getCompanyName())) { - // Found match - isFound = true; - } - } - - // Return flag - return isFound; - } - -} diff --git a/src/java/org/mxchange/jcontactsbusiness/basicdata/AddressbookBusinessDataSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/basicdata/AddressbookBusinessDataSessionBean.java deleted file mode 100644 index 33d84f6..0000000 --- a/src/java/org/mxchange/jcontactsbusiness/basicdata/AddressbookBusinessDataSessionBean.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (C) 2017 Roland Häder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.mxchange.jcontactsbusiness.basicdata; - -import java.text.MessageFormat; -import java.util.List; -import java.util.Objects; -import javax.ejb.Stateless; -import javax.persistence.NoResultException; -import javax.persistence.Query; -import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; -import org.mxchange.jcontactsbusiness.exceptions.basicdata.BusinessDataNotFoundException; -import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData; -import org.mxchange.jcontactsbusiness.model.basicdata.BusinessDataSessionBeanRemote; -import org.mxchange.jcontactsbusiness.model.basicdata.CompanyBasicData; - -/** - * A stateless session bean for business data - *

- * @author Roland Häder - */ -@Stateless (name = "businessData", description = "A general statless bean for handling business data (all)") -public class AddressbookBusinessDataSessionBean extends BaseAddressbookDatabaseBean implements BusinessDataSessionBeanRemote { - - /** - * Serial number - */ - private static final long serialVersionUID = 56_389_504_892_184_571L; - - /** - * Default constructor - */ - public AddressbookBusinessDataSessionBean () { - // Call super constructor - super(); - } - - @Override - @SuppressWarnings ("unchecked") - public List allCompanyBasicData () { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allBusinessContacts: CALLED!", this.getClass().getSimpleName())); //NOI18N - - // Get query - final Query query = this.getEntityManager().createNamedQuery("AllBusinessData"); //NOI18N - - // Get list from it - final List list = query.getResultList(); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allBusinessContacts: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N - - // Return it - return list; - } - - @Override - public BusinessBasicData findBasicDataById (final Long basicDataId) throws BusinessDataNotFoundException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findBasicDataById: CALLED!", this.getClass().getSimpleName())); //NOI18N - - // Get query - final Query query = this.getEntityManager().createNamedQuery("SearchBusinessDataById", CompanyBasicData.class); //NOI18N - - // Set parameter - query.setParameter("basicDataId", basicDataId); //NOI18N - - // Get single instance - final BusinessBasicData basicData; - - // Try to find a result - try { - // Find a single result - basicData = (BusinessBasicData) query.getSingleResult(); - - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findBasicDataById: Found basicData={1}", this.getClass().getSimpleName(), basicData)); //NOI18N - } catch (final NoResultException ex) { - // No result found - throw new BusinessDataNotFoundException(basicDataId, ex); - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findBasicDataById: basicData={1} - EXIT!", this.getClass().getSimpleName(), basicData)); //NOI18N - - // Return it - return basicData; - } - - @Override - public Boolean isCompanyNameUsed (final String companyName) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isCompanyNameUsed: companyName={1} - CALLED!", this.getClass().getSimpleName(), companyName)); //NOI18N - - // Is the parameter valid? - if (null == companyName) { - // Throw NPE - throw new NullPointerException("companyName is null"); //NOI18N - } else if (companyName.isEmpty()) { - // Throw IAE - throw new IllegalArgumentException("companyName is empty"); //NOI18N - } - - // Default is not found - Boolean isCompanyNameUsed = Boolean.FALSE; - - // Get whole list - final List list = this.allCompanyBasicData(); - - // Check whole list - for (final BusinessBasicData basicData : list) { - // Is name used? - if (Objects.equals(basicData.getCompanyName(), companyName)) { - // Found one - isCompanyNameUsed = Boolean.TRUE; - - // Abort search - break; - } - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isCompanyNameUsed: isCompanyNameUsed={1} - EXIT!", this.getClass().getSimpleName(), isCompanyNameUsed)); //NOI18N - - // Return it - return isCompanyNameUsed; - } - -} diff --git a/src/java/org/mxchange/jcontactsbusiness/branchoffice/AddressbookAdminBranchOfficeSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/branchoffice/AddressbookAdminBranchOfficeSessionBean.java deleted file mode 100644 index 020d0ba..0000000 --- a/src/java/org/mxchange/jcontactsbusiness/branchoffice/AddressbookAdminBranchOfficeSessionBean.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright (C) 2017 Roland Häder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.mxchange.jcontactsbusiness.branchoffice; - -import java.text.MessageFormat; -import java.util.GregorianCalendar; -import java.util.List; -import javax.ejb.EJB; -import javax.ejb.Stateless; -import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; -import org.mxchange.jcontactsbusiness.exceptions.branchoffice.BranchOfficeAlreadyAddedException; -import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData; -import org.mxchange.jcontactsbusiness.model.branchoffice.AdminBranchOfficeSessionBeanRemote; -import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice; -import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOfficeSessionBeanRemote; -import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffices; -import org.mxchange.jcountry.model.data.Country; -import org.mxchange.jusercore.model.user.User; - -/** - * A stateless session bean for administrative branch office purposes - *

- * @author Roland Häder - */ -@Stateless (name = "adminBranchOffice", description = "An administrative statless bean for handling branch office data (all)") -public class AddressbookAdminBranchOfficeSessionBean extends BaseAddressbookDatabaseBean implements AdminBranchOfficeSessionBeanRemote { - - /** - * Serial number - */ - private static final long serialVersionUID = 58_467_386_571_701L; - - /** - * General branch office bean - */ - @EJB - private BranchOfficeSessionBeanRemote branchOfficeBean; - - /** - * Default constructor - */ - public AddressbookAdminBranchOfficeSessionBean () { - // Call super constructor - super(); - } - - @Override - public BranchOffice addBranchOffice (final BranchOffice branchOffice) throws BranchOfficeAlreadyAddedException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addBranchOffice(): branchOffice={1} - CALLED!", this.getClass().getSimpleName(), branchOffice)); //NOI18N - - // Validate parameter - if (null == branchOffice) { - // Throw NPE - throw new NullPointerException("branchOffice is null"); //NOI18N - } else if (branchOffice.getBranchId() instanceof Long) { - // Should not happen - throw new IllegalArgumentException("branchOffice.branchId should not be set."); //NOI18N - } else if (this.isBranchOfficeFound(branchOffice)) { - // Already added, abort here - throw new BranchOfficeAlreadyAddedException(branchOffice); - } - - // Add created timestamp - branchOffice.setBranchCreated(new GregorianCalendar()); - - // Is user instance set? - if (branchOffice.getBranchCompany() instanceof BusinessBasicData) { - // Get managed instance back - final BusinessBasicData managedBasicData = this.createManaged(branchOffice.getBranchCompany()); - - // Set it back in branch office - branchOffice.setBranchCompany(managedBasicData); - } - - // Is user instance set? - if (branchOffice.getBranchUserOwner() instanceof User) { - // Get managed instance back - final User managedUser = this.createManaged(branchOffice.getBranchUserOwner()); - - // Set it back in branch office - branchOffice.setBranchUserOwner(managedUser); - } - - // Is user instance set? - if (branchOffice.getBranchCountry() instanceof Country) { - // Get managed instance back - final Country managedCountry = this.createManaged(branchOffice.getBranchCountry()); - - // Set it back in branch office - branchOffice.setBranchCountry(managedCountry); - } - - // Persist it - this.getEntityManager().persist(branchOffice); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addBranchOffice(): branchOffice.branchId={1} - EXIT!", this.getClass().getSimpleName(), branchOffice.getBranchId())); //NOI18N - - // Return updated instance - return branchOffice; - } - - /** - * Checks if given branch office's address is already persisted. The whole - * (persisted) list is being loaded and each address is being matched - * against the given branch office's address. - *

- * @param branchOffice Branch office being checked - *

- * @return Whether it has been found - */ - private boolean isBranchOfficeFound (final BranchOffice branchOffice) { - // Get whole list - final List branchOffices = this.branchOfficeBean.allBranchOffices(); - - // Default is not found - boolean isFound = false; - - // Check all single addresses - for (final BranchOffice bo : branchOffices) { - // Is the same address found? - if (BranchOffices.isSameAddress(bo, branchOffice)) { - // Found one - isFound = true; - break; - } - } - - // Return flag - return isFound; - } - -} diff --git a/src/java/org/mxchange/jcontactsbusiness/branchoffice/AddressbookBranchOfficeSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/branchoffice/AddressbookBranchOfficeSessionBean.java deleted file mode 100644 index 3fe167a..0000000 --- a/src/java/org/mxchange/jcontactsbusiness/branchoffice/AddressbookBranchOfficeSessionBean.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2017 Roland Häder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.mxchange.jcontactsbusiness.branchoffice; - -import java.text.MessageFormat; -import java.util.List; -import javax.ejb.Stateless; -import javax.persistence.Query; -import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; -import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice; -import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOfficeSessionBeanRemote; - -/** - * A stateless session bean for general branch office purposes - *

- * @author Roland Häder - */ -@Stateless (name = "branchOffice", description = "A general statless bean for handling branch office data (all)") -public class AddressbookBranchOfficeSessionBean extends BaseAddressbookDatabaseBean implements BranchOfficeSessionBeanRemote { - - /** - * Serial number - */ - private static final long serialVersionUID = 58_467_386_571_701L; - - @Override - @SuppressWarnings ("unchecked") - public List allBranchOffices () { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allBranchOffices: CALLED!", this.getClass().getSimpleName())); //NOI18N - - // Get query - final Query query = this.getEntityManager().createNamedQuery("AllBranchOffices"); //NOI18N - - // Get list from it - final List list = query.getResultList(); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allBranchOffices: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N - - // Return it - return list; - } - -} diff --git a/src/java/org/mxchange/jcontactsbusiness/employee/AddressbookAdminCompanyEmployeeSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/employee/AddressbookAdminCompanyEmployeeSessionBean.java deleted file mode 100644 index 27bd364..0000000 --- a/src/java/org/mxchange/jcontactsbusiness/employee/AddressbookAdminCompanyEmployeeSessionBean.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) 2017 Roland Häder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.mxchange.jcontactsbusiness.employee; - -import javax.ejb.Stateless; -import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; -import org.mxchange.jcontactsbusiness.model.employee.AdminCompanyEmployeeSessionBeanRemote; - -/** - * A stateless bean for administrative purposes for company employees. - *

- * @author Roland Häder - */ -@Stateless (name = "adminCompanyEmployee", description = "An administrative statless bean for handling company employees") -public class AddressbookAdminCompanyEmployeeSessionBean extends BaseAddressbookDatabaseBean implements AdminCompanyEmployeeSessionBeanRemote { - - /** - * Serial number - */ - private static final long serialVersionUID = 26_458_796_703_761L; - - /** - * Default constructor - */ - public AddressbookAdminCompanyEmployeeSessionBean () { - super(); - } - -} diff --git a/src/java/org/mxchange/jcontactsbusiness/employee/AddressbookCompanyEmployeeSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/employee/AddressbookCompanyEmployeeSessionBean.java deleted file mode 100644 index 5c19171..0000000 --- a/src/java/org/mxchange/jcontactsbusiness/employee/AddressbookCompanyEmployeeSessionBean.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (C) 2017 Roland Häder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.mxchange.jcontactsbusiness.employee; - -import java.text.MessageFormat; -import java.util.List; -import javax.ejb.Stateless; -import javax.persistence.NoResultException; -import javax.persistence.Query; -import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; -import org.mxchange.jcontactsbusiness.exceptions.employee.CompanyEmployeeNotFoundException; -import org.mxchange.jcontactsbusiness.model.employee.CompanyEmployeeSessionBeanRemote; -import org.mxchange.jcontactsbusiness.model.employee.Employee; - -/** - * A stateless bean for general purposes for company employees. - *

- * @author Roland Häder - */ -@Stateless (name = "companyEmployee", description = "A general statless bean for handling company employees") -public class AddressbookCompanyEmployeeSessionBean extends BaseAddressbookDatabaseBean implements CompanyEmployeeSessionBeanRemote { - - /** - * Serial number - */ - private static final long serialVersionUID = 26_458_796_703_761L; - - /** - * Default constructor - */ - public AddressbookCompanyEmployeeSessionBean () { - super(); - } - - @Override - @SuppressWarnings ("unchecked") - public List allCompanyEmployees () { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allCompanyEmployees(): CALLED!", this.getClass().getSimpleName())); //NOI18N - - // Get named query - final Query query = this.getEntityManager().createNamedQuery("AllCompanyEmployees"); //NOI18N - - // Get list form it - final List employees = query.getResultList(); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allCompanyEmployees(): employees.size()={1} - EXIT!", this.getClass().getSimpleName(), employees.size())); //NOI18N - - // Return it - return employees; - } - - @Override - public Employee findCompanyEmployeeById (final Long employeeId) throws CompanyEmployeeNotFoundException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findCompanyEmployeeById(): employeeId={1} - CALLED!", this.getClass().getSimpleName(), employeeId)); //NOI18N - - // Is the employee id valid? - if (null == employeeId) { - // Throw NPE - throw new NullPointerException("employeeId is null"); //NOI18N - } else if (employeeId < 1) { - // Not valid - throw new IllegalArgumentException(MessageFormat.format("employeeId={0} is not valid", employeeId)); //NOI18N - } - - // Now get named query - final Query query = this.getEntityManager().createNamedQuery("SearchCompanyEmployeeById"); //NOI18N - - // Set parameter - query.setParameter("employeeId", employeeId); //NOI18N - - // Declare instance - final Employee employee; - - // Try to find a result - try { - // Find a single result - employee = (Employee) query.getSingleResult(); - - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findCompanyEmployeeById: Found employee={1}", this.getClass().getSimpleName(), employee)); //NOI18N - } catch (final NoResultException ex) { - // No result found - throw new CompanyEmployeeNotFoundException(employeeId, ex); - } - - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findCompanyEmployeeById: employee={1} - EXIT!", this.getClass().getSimpleName(), employee)); //NOI18N - - // Return found instance - return employee; - } - -} diff --git a/src/java/org/mxchange/jcontactsbusiness/model/basicdata/AddressbookAdminBusinessDataSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/basicdata/AddressbookAdminBusinessDataSessionBean.java new file mode 100644 index 0000000..39a8358 --- /dev/null +++ b/src/java/org/mxchange/jcontactsbusiness/model/basicdata/AddressbookAdminBusinessDataSessionBean.java @@ -0,0 +1,141 @@ +/* + * Copyright (C) 2017 Roland Häder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jcontactsbusiness.model.basicdata; + +import java.text.MessageFormat; +import java.util.GregorianCalendar; +import java.util.List; +import java.util.Objects; +import javax.ejb.EJB; +import javax.ejb.Stateless; +import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; +import org.mxchange.jcontactsbusiness.exceptions.basicdata.BusinessDataAlreadyAddedException; +import org.mxchange.jcontactsbusiness.model.employee.Employee; +import org.mxchange.jusercore.model.user.User; + +/** + * An administrative stateless session bean for business data + *

+ * @author Roland Häder + */ +@Stateless (name = "adminBusinessData", description = "An administrative statless bean for handling business data (all)") +public class AddressbookAdminBusinessDataSessionBean extends BaseAddressbookDatabaseBean implements AdminBusinessDataSessionBeanRemote { + + /** + * Serial number + */ + private static final long serialVersionUID = 56_389_504_892_184_572L; + + /** + * Administrative EJB + */ + @EJB + private BusinessDataSessionBeanRemote businessDataBean; + + /** + * Default constructor + */ + public AddressbookAdminBusinessDataSessionBean () { + // Call super constructor + super(); + } + + @Override + public BusinessBasicData addCompanyBasicData (final BusinessBasicData basicData) throws BusinessDataAlreadyAddedException { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addBusinessBasicData: basicData={1} - CALLED!", this.getClass().getSimpleName(), basicData)); //NOI18N + + // Is the instance set? + if (null == basicData) { + // Throw NPE + throw new NullPointerException("basicData is null"); //NOI18N + } else if (basicData.getBasicDataId() != null) { + // Should be null + throw new IllegalArgumentException(MessageFormat.format("basicData.basicDataId={0} - is not null", basicData.getBasicDataId())); //NOI18N + } else if (this.isSameCompanyNameAdded(basicData)) { + // Throw exception + throw new BusinessDataAlreadyAddedException(basicData); + } + + // Now add current date + basicData.setCompanyCreated(new GregorianCalendar()); + + // Is there a owner set? + if (basicData.getCompanyUserOwner() instanceof User) { + // Get managed instance + final User managedUser = this.createManaged(basicData.getCompanyUserOwner()); + + // Set it back + basicData.setCompanyUserOwner(managedUser); + } + + // Is a founder set? + if (basicData.getCompanyFounder() instanceof Employee) { + // Get managed instance + final Employee managedEmployee = this.createManaged(basicData.getCompanyFounder()); + + // Set it back + basicData.setCompanyFounder(managedEmployee); + } + + // Is a contact person set? + if (basicData.getCompanyContactEmployee() instanceof Employee) { + // Get managed instance + final Employee managedEmployee = this.createManaged(basicData.getCompanyContactEmployee()); + + // Set it back + basicData.setCompanyContactEmployee(managedEmployee); + } + + // Persist it + this.getEntityManager().persist(basicData); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addBusinessBasicData: basicData.basicDataId={1} - EXIT!", this.getClass().getSimpleName(), basicData.getBasicDataId())); //NOI18N + + // Return updated instance + return basicData; + } + + /** + * Checks if given basic data is already added by it's company name + *

+ * @param basicData Basic data to be checked + * + * @return Whether same company name has been used + */ + private boolean isSameCompanyNameAdded (final BusinessBasicData basicData) { + // Get all available entries + final List list = this.businessDataBean.allCompanyBasicData(); + + // Default is not found + boolean isFound = false; + + // Then check each entry + for (final BusinessBasicData entry : list) { + // Is the company name matching? + if (Objects.equals(entry.getCompanyName(), basicData.getCompanyName())) { + // Found match + isFound = true; + } + } + + // Return flag + return isFound; + } + +} diff --git a/src/java/org/mxchange/jcontactsbusiness/model/basicdata/AddressbookBusinessDataSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/basicdata/AddressbookBusinessDataSessionBean.java new file mode 100644 index 0000000..dff08e5 --- /dev/null +++ b/src/java/org/mxchange/jcontactsbusiness/model/basicdata/AddressbookBusinessDataSessionBean.java @@ -0,0 +1,140 @@ +/* + * Copyright (C) 2017 Roland Häder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jcontactsbusiness.model.basicdata; + +import java.text.MessageFormat; +import java.util.List; +import java.util.Objects; +import javax.ejb.Stateless; +import javax.persistence.NoResultException; +import javax.persistence.Query; +import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; +import org.mxchange.jcontactsbusiness.exceptions.basicdata.BusinessDataNotFoundException; + +/** + * A stateless session bean for business data + *

+ * @author Roland Häder + */ +@Stateless (name = "businessData", description = "A general statless bean for handling business data (all)") +public class AddressbookBusinessDataSessionBean extends BaseAddressbookDatabaseBean implements BusinessDataSessionBeanRemote { + + /** + * Serial number + */ + private static final long serialVersionUID = 56_389_504_892_184_571L; + + /** + * Default constructor + */ + public AddressbookBusinessDataSessionBean () { + // Call super constructor + super(); + } + + @Override + @SuppressWarnings ("unchecked") + public List allCompanyBasicData () { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allBusinessContacts: CALLED!", this.getClass().getSimpleName())); //NOI18N + + // Get query + final Query query = this.getEntityManager().createNamedQuery("AllBusinessData"); //NOI18N + + // Get list from it + final List list = query.getResultList(); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allBusinessContacts: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N + + // Return it + return list; + } + + @Override + public BusinessBasicData findBasicDataById (final Long basicDataId) throws BusinessDataNotFoundException { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findBasicDataById: CALLED!", this.getClass().getSimpleName())); //NOI18N + + // Get query + final Query query = this.getEntityManager().createNamedQuery("SearchBusinessDataById", CompanyBasicData.class); //NOI18N + + // Set parameter + query.setParameter("basicDataId", basicDataId); //NOI18N + + // Get single instance + final BusinessBasicData basicData; + + // Try to find a result + try { + // Find a single result + basicData = (BusinessBasicData) query.getSingleResult(); + + // Log trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findBasicDataById: Found basicData={1}", this.getClass().getSimpleName(), basicData)); //NOI18N + } catch (final NoResultException ex) { + // No result found + throw new BusinessDataNotFoundException(basicDataId, ex); + } + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findBasicDataById: basicData={1} - EXIT!", this.getClass().getSimpleName(), basicData)); //NOI18N + + // Return it + return basicData; + } + + @Override + public Boolean isCompanyNameUsed (final String companyName) { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isCompanyNameUsed: companyName={1} - CALLED!", this.getClass().getSimpleName(), companyName)); //NOI18N + + // Is the parameter valid? + if (null == companyName) { + // Throw NPE + throw new NullPointerException("companyName is null"); //NOI18N + } else if (companyName.isEmpty()) { + // Throw IAE + throw new IllegalArgumentException("companyName is empty"); //NOI18N + } + + // Default is not found + Boolean isCompanyNameUsed = Boolean.FALSE; + + // Get whole list + final List list = this.allCompanyBasicData(); + + // Check whole list + for (final BusinessBasicData basicData : list) { + // Is name used? + if (Objects.equals(basicData.getCompanyName(), companyName)) { + // Found one + isCompanyNameUsed = Boolean.TRUE; + + // Abort search + break; + } + } + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isCompanyNameUsed: isCompanyNameUsed={1} - EXIT!", this.getClass().getSimpleName(), isCompanyNameUsed)); //NOI18N + + // Return it + return isCompanyNameUsed; + } + +} diff --git a/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/AddressbookAdminBranchOfficeSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/AddressbookAdminBranchOfficeSessionBean.java new file mode 100644 index 0000000..9040c22 --- /dev/null +++ b/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/AddressbookAdminBranchOfficeSessionBean.java @@ -0,0 +1,144 @@ +/* + * Copyright (C) 2017 Roland Häder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jcontactsbusiness.model.branchoffice; + +import java.text.MessageFormat; +import java.util.GregorianCalendar; +import java.util.List; +import javax.ejb.EJB; +import javax.ejb.Stateless; +import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; +import org.mxchange.jcontactsbusiness.exceptions.branchoffice.BranchOfficeAlreadyAddedException; +import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData; +import org.mxchange.jcountry.model.data.Country; +import org.mxchange.jusercore.model.user.User; + +/** + * A stateless session bean for administrative branch office purposes + *

+ * @author Roland Häder + */ +@Stateless (name = "adminBranchOffice", description = "An administrative statless bean for handling branch office data (all)") +public class AddressbookAdminBranchOfficeSessionBean extends BaseAddressbookDatabaseBean implements AdminBranchOfficeSessionBeanRemote { + + /** + * Serial number + */ + private static final long serialVersionUID = 58_467_386_571_701L; + + /** + * General branch office bean + */ + @EJB + private BranchOfficeSessionBeanRemote branchOfficeBean; + + /** + * Default constructor + */ + public AddressbookAdminBranchOfficeSessionBean () { + // Call super constructor + super(); + } + + @Override + public BranchOffice addBranchOffice (final BranchOffice branchOffice) throws BranchOfficeAlreadyAddedException { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addBranchOffice(): branchOffice={1} - CALLED!", this.getClass().getSimpleName(), branchOffice)); //NOI18N + + // Validate parameter + if (null == branchOffice) { + // Throw NPE + throw new NullPointerException("branchOffice is null"); //NOI18N + } else if (branchOffice.getBranchId() instanceof Long) { + // Should not happen + throw new IllegalArgumentException("branchOffice.branchId should not be set."); //NOI18N + } else if (this.isBranchOfficeFound(branchOffice)) { + // Already added, abort here + throw new BranchOfficeAlreadyAddedException(branchOffice); + } + + // Add created timestamp + branchOffice.setBranchCreated(new GregorianCalendar()); + + // Is user instance set? + if (branchOffice.getBranchCompany() instanceof BusinessBasicData) { + // Get managed instance back + final BusinessBasicData managedBasicData = this.createManaged(branchOffice.getBranchCompany()); + + // Set it back in branch office + branchOffice.setBranchCompany(managedBasicData); + } + + // Is user instance set? + if (branchOffice.getBranchUserOwner() instanceof User) { + // Get managed instance back + final User managedUser = this.createManaged(branchOffice.getBranchUserOwner()); + + // Set it back in branch office + branchOffice.setBranchUserOwner(managedUser); + } + + // Is user instance set? + if (branchOffice.getBranchCountry() instanceof Country) { + // Get managed instance back + final Country managedCountry = this.createManaged(branchOffice.getBranchCountry()); + + // Set it back in branch office + branchOffice.setBranchCountry(managedCountry); + } + + // Persist it + this.getEntityManager().persist(branchOffice); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addBranchOffice(): branchOffice.branchId={1} - EXIT!", this.getClass().getSimpleName(), branchOffice.getBranchId())); //NOI18N + + // Return updated instance + return branchOffice; + } + + /** + * Checks if given branch office's address is already persisted. The whole + * (persisted) list is being loaded and each address is being matched + * against the given branch office's address. + *

+ * @param branchOffice Branch office being checked + *

+ * @return Whether it has been found + */ + private boolean isBranchOfficeFound (final BranchOffice branchOffice) { + // Get whole list + final List branchOffices = this.branchOfficeBean.allBranchOffices(); + + // Default is not found + boolean isFound = false; + + // Check all single addresses + for (final BranchOffice bo : branchOffices) { + // Is the same address found? + if (BranchOffices.isSameAddress(bo, branchOffice)) { + // Found one + isFound = true; + break; + } + } + + // Return flag + return isFound; + } + +} diff --git a/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/AddressbookBranchOfficeSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/AddressbookBranchOfficeSessionBean.java new file mode 100644 index 0000000..1aa258d --- /dev/null +++ b/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/AddressbookBranchOfficeSessionBean.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2017 Roland Häder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jcontactsbusiness.model.branchoffice; + +import java.text.MessageFormat; +import java.util.List; +import javax.ejb.Stateless; +import javax.persistence.Query; +import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; + +/** + * A stateless session bean for general branch office purposes + *

+ * @author Roland Häder + */ +@Stateless (name = "branchOffice", description = "A general statless bean for handling branch office data (all)") +public class AddressbookBranchOfficeSessionBean extends BaseAddressbookDatabaseBean implements BranchOfficeSessionBeanRemote { + + /** + * Serial number + */ + private static final long serialVersionUID = 58_467_386_571_701L; + + @Override + @SuppressWarnings ("unchecked") + public List allBranchOffices () { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allBranchOffices: CALLED!", this.getClass().getSimpleName())); //NOI18N + + // Get query + final Query query = this.getEntityManager().createNamedQuery("AllBranchOffices"); //NOI18N + + // Get list from it + final List list = query.getResultList(); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allBranchOffices: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N + + // Return it + return list; + } + +} diff --git a/src/java/org/mxchange/jcontactsbusiness/model/employee/AddressbookAdminCompanyEmployeeSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/employee/AddressbookAdminCompanyEmployeeSessionBean.java new file mode 100644 index 0000000..3cd42fc --- /dev/null +++ b/src/java/org/mxchange/jcontactsbusiness/model/employee/AddressbookAdminCompanyEmployeeSessionBean.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2017 Roland Häder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jcontactsbusiness.model.employee; + +import javax.ejb.Stateless; +import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; +import org.mxchange.jcontactsbusiness.model.employee.AdminCompanyEmployeeSessionBeanRemote; + +/** + * A stateless bean for administrative purposes for company employees. + *

+ * @author Roland Häder + */ +@Stateless (name = "adminCompanyEmployee", description = "An administrative statless bean for handling company employees") +public class AddressbookAdminCompanyEmployeeSessionBean extends BaseAddressbookDatabaseBean implements AdminCompanyEmployeeSessionBeanRemote { + + /** + * Serial number + */ + private static final long serialVersionUID = 26_458_796_703_761L; + + /** + * Default constructor + */ + public AddressbookAdminCompanyEmployeeSessionBean () { + super(); + } + +} diff --git a/src/java/org/mxchange/jcontactsbusiness/model/employee/AddressbookCompanyEmployeeSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/employee/AddressbookCompanyEmployeeSessionBean.java new file mode 100644 index 0000000..3f6b8b2 --- /dev/null +++ b/src/java/org/mxchange/jcontactsbusiness/model/employee/AddressbookCompanyEmployeeSessionBean.java @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2017 Roland Häder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jcontactsbusiness.model.employee; + +import java.text.MessageFormat; +import java.util.List; +import javax.ejb.Stateless; +import javax.persistence.NoResultException; +import javax.persistence.Query; +import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; +import org.mxchange.jcontactsbusiness.exceptions.employee.CompanyEmployeeNotFoundException; + +/** + * A stateless bean for general purposes for company employees. + *

+ * @author Roland Häder + */ +@Stateless (name = "companyEmployee", description = "A general statless bean for handling company employees") +public class AddressbookCompanyEmployeeSessionBean extends BaseAddressbookDatabaseBean implements CompanyEmployeeSessionBeanRemote { + + /** + * Serial number + */ + private static final long serialVersionUID = 26_458_796_703_761L; + + /** + * Default constructor + */ + public AddressbookCompanyEmployeeSessionBean () { + super(); + } + + @Override + @SuppressWarnings ("unchecked") + public List allCompanyEmployees () { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allCompanyEmployees(): CALLED!", this.getClass().getSimpleName())); //NOI18N + + // Get named query + final Query query = this.getEntityManager().createNamedQuery("AllCompanyEmployees"); //NOI18N + + // Get list form it + final List employees = query.getResultList(); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allCompanyEmployees(): employees.size()={1} - EXIT!", this.getClass().getSimpleName(), employees.size())); //NOI18N + + // Return it + return employees; + } + + @Override + public Employee findCompanyEmployeeById (final Long employeeId) throws CompanyEmployeeNotFoundException { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findCompanyEmployeeById(): employeeId={1} - CALLED!", this.getClass().getSimpleName(), employeeId)); //NOI18N + + // Is the employee id valid? + if (null == employeeId) { + // Throw NPE + throw new NullPointerException("employeeId is null"); //NOI18N + } else if (employeeId < 1) { + // Not valid + throw new IllegalArgumentException(MessageFormat.format("employeeId={0} is not valid", employeeId)); //NOI18N + } + + // Now get named query + final Query query = this.getEntityManager().createNamedQuery("SearchCompanyEmployeeById"); //NOI18N + + // Set parameter + query.setParameter("employeeId", employeeId); //NOI18N + + // Declare instance + final Employee employee; + + // Try to find a result + try { + // Find a single result + employee = (Employee) query.getSingleResult(); + + // Log trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findCompanyEmployeeById: Found employee={1}", this.getClass().getSimpleName(), employee)); //NOI18N + } catch (final NoResultException ex) { + // No result found + throw new CompanyEmployeeNotFoundException(employeeId, ex); + } + + // Log trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findCompanyEmployeeById: employee={1} - EXIT!", this.getClass().getSimpleName(), employee)); //NOI18N + + // Return found instance + return employee; + } + +} diff --git a/src/java/org/mxchange/jcountry/data/AddressbookCountrySingletonBean.java b/src/java/org/mxchange/jcountry/data/AddressbookCountrySingletonBean.java deleted file mode 100644 index 0aad3fd..0000000 --- a/src/java/org/mxchange/jcountry/data/AddressbookCountrySingletonBean.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Roland Häder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . -*/ -package org.mxchange.jcountry.data; - -import java.text.MessageFormat; -import java.util.GregorianCalendar; -import java.util.List; -import javax.ejb.Singleton; -import javax.ejb.Startup; -import javax.persistence.NoResultException; -import javax.persistence.Query; -import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; -import org.mxchange.jcountry.exceptions.CountryAlreadyAddedException; -import org.mxchange.jcountry.model.data.Country; -import org.mxchange.jcountry.model.data.CountryData; -import org.mxchange.jcountry.model.data.CountrySingletonBeanRemote; - -/** - * A singleton EJB for country informations - *

- * @author Roland Häder - */ -@Startup -@Singleton (name = "country", description = "A singleton session-scoped bean for country informations") -public class AddressbookCountrySingletonBean extends BaseAddressbookDatabaseBean implements CountrySingletonBeanRemote { - - /** - * Serial number - */ - private static final long serialVersionUID = 15_846_983_298_691_207L; - - /** - * Default constructor - */ - public AddressbookCountrySingletonBean () { - // Call super constructor - super(); - } - - @Override - public Country addCountry (final Country country) throws CountryAlreadyAddedException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addCountry: country={1} - CALLED!", this.getClass().getSimpleName(), country)); //NOI18N - - // Is it already there? - if (null == country) { - // Throw NPE - throw new NullPointerException("country is null"); //NOI18N - } else if (country.getCountryCode().isEmpty()) { - // Code is not set - throw new IllegalArgumentException("country.countryCode is empty"); //NOI18N - } else if (country.getCountryI18nKey().isEmpty()) { - // I18n key is not set - throw new IllegalArgumentException("country.countryI18nKey is empty"); //NOI18N - } else if (country.getCountryId() != null) { - // Should be null - throw new IllegalArgumentException(MessageFormat.format("country.countryId is not null ({0})", country.getCountryId())); //NOI18N - } else if (this.isCountryAdded(country)) { - // Yes, then abort here - throw new CountryAlreadyAddedException(country); - } - - // Add timestamp - country.setCountryEntryCreated(new GregorianCalendar()); - - // It is not added, so persist it - this.getEntityManager().persist(country); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addCountry: country={1} - EXIT!", this.getClass().getSimpleName(), country)); //NOI18N - - // Return updated instance - return country; - } - - @Override - @SuppressWarnings ("unchecked") - public List allCountries () { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allCountries: CALLED!", this.getClass().getSimpleName())); //NOI18N - - // Init query - final Query query = this.getEntityManager().createNamedQuery("AllCountries", CountryData.class); //NOI18N - - // Get list - final List countries = query.getResultList(); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allCountries: countries.size()={1} - EXIT!", this.getClass().getSimpleName(), countries.size())); //NOI18N - - // Return it - return countries; - } - - /** - * Checks whether given country is already added by i18n key or country - * code, what comes first. - *

- * @param country Country instance to check - *

- * @return Whether the country was found - */ - private boolean isCountryAdded (final Country country) { - if (null == country) { - // Throw NPE - throw new NullPointerException("country is null"); //NOI18N - } else if (country.getCountryCode().isEmpty()) { - // Code is not set - throw new IllegalArgumentException("country.countryCode is empty"); //NOI18N - } else if (country.getCountryI18nKey().isEmpty()) { - // I18n key is not set - throw new IllegalArgumentException("country.countryI18nKey is empty"); //NOI18N - } else if (country.getCountryId() != null) { - // Should be null - throw new IllegalArgumentException(MessageFormat.format("country.countryId is not null ({0})", country.getCountryId())); //NOI18N - } - - // Default is not found - boolean isAdded = false; - - // Get query instance - final Query query = this.getEntityManager().createNamedQuery("SearchCountryByCodeI18nKey", CountryData.class); //NOI18N - - // Assign all parameters - query.setParameter("code", country.getCountryCode()); //NOI18N - query.setParameter("key", country.getCountryI18nKey()); //NOI18N - - // Try to get a single result - try { - // Get single result - final Country foundCountry = (Country) query.getSingleResult(); - - // Found it? - isAdded = (foundCountry instanceof Country); - } catch (final NoResultException ex) { - // Not found, don't log this - } - - // Return result - return isAdded; - } - -} diff --git a/src/java/org/mxchange/jcountry/model/data/AddressbookCountrySingletonBean.java b/src/java/org/mxchange/jcountry/model/data/AddressbookCountrySingletonBean.java new file mode 100644 index 0000000..d2029c9 --- /dev/null +++ b/src/java/org/mxchange/jcountry/model/data/AddressbookCountrySingletonBean.java @@ -0,0 +1,154 @@ +/* + * Copyright (C) 2016, 2017 Roland Häder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . +*/ +package org.mxchange.jcountry.model.data; + +import java.text.MessageFormat; +import java.util.GregorianCalendar; +import java.util.List; +import javax.ejb.Singleton; +import javax.ejb.Startup; +import javax.persistence.NoResultException; +import javax.persistence.Query; +import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; +import org.mxchange.jcountry.exceptions.CountryAlreadyAddedException; + +/** + * A singleton EJB for country informations + *

+ * @author Roland Häder + */ +@Startup +@Singleton (name = "country", description = "A singleton session-scoped bean for country informations") +public class AddressbookCountrySingletonBean extends BaseAddressbookDatabaseBean implements CountrySingletonBeanRemote { + + /** + * Serial number + */ + private static final long serialVersionUID = 15_846_983_298_691_207L; + + /** + * Default constructor + */ + public AddressbookCountrySingletonBean () { + // Call super constructor + super(); + } + + @Override + public Country addCountry (final Country country) throws CountryAlreadyAddedException { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addCountry: country={1} - CALLED!", this.getClass().getSimpleName(), country)); //NOI18N + + // Is it already there? + if (null == country) { + // Throw NPE + throw new NullPointerException("country is null"); //NOI18N + } else if (country.getCountryCode().isEmpty()) { + // Code is not set + throw new IllegalArgumentException("country.countryCode is empty"); //NOI18N + } else if (country.getCountryI18nKey().isEmpty()) { + // I18n key is not set + throw new IllegalArgumentException("country.countryI18nKey is empty"); //NOI18N + } else if (country.getCountryId() != null) { + // Should be null + throw new IllegalArgumentException(MessageFormat.format("country.countryId is not null ({0})", country.getCountryId())); //NOI18N + } else if (this.isCountryAdded(country)) { + // Yes, then abort here + throw new CountryAlreadyAddedException(country); + } + + // Add timestamp + country.setCountryEntryCreated(new GregorianCalendar()); + + // It is not added, so persist it + this.getEntityManager().persist(country); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addCountry: country={1} - EXIT!", this.getClass().getSimpleName(), country)); //NOI18N + + // Return updated instance + return country; + } + + @Override + @SuppressWarnings ("unchecked") + public List allCountries () { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allCountries: CALLED!", this.getClass().getSimpleName())); //NOI18N + + // Init query + final Query query = this.getEntityManager().createNamedQuery("AllCountries", CountryData.class); //NOI18N + + // Get list + final List countries = query.getResultList(); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allCountries: countries.size()={1} - EXIT!", this.getClass().getSimpleName(), countries.size())); //NOI18N + + // Return it + return countries; + } + + /** + * Checks whether given country is already added by i18n key or country + * code, what comes first. + *

+ * @param country Country instance to check + *

+ * @return Whether the country was found + */ + private boolean isCountryAdded (final Country country) { + if (null == country) { + // Throw NPE + throw new NullPointerException("country is null"); //NOI18N + } else if (country.getCountryCode().isEmpty()) { + // Code is not set + throw new IllegalArgumentException("country.countryCode is empty"); //NOI18N + } else if (country.getCountryI18nKey().isEmpty()) { + // I18n key is not set + throw new IllegalArgumentException("country.countryI18nKey is empty"); //NOI18N + } else if (country.getCountryId() != null) { + // Should be null + throw new IllegalArgumentException(MessageFormat.format("country.countryId is not null ({0})", country.getCountryId())); //NOI18N + } + + // Default is not found + boolean isAdded = false; + + // Get query instance + final Query query = this.getEntityManager().createNamedQuery("SearchCountryByCodeI18nKey", CountryData.class); //NOI18N + + // Assign all parameters + query.setParameter("code", country.getCountryCode()); //NOI18N + query.setParameter("key", country.getCountryI18nKey()); //NOI18N + + // Try to get a single result + try { + // Get single result + final Country foundCountry = (Country) query.getSingleResult(); + + // Found it? + isAdded = (foundCountry instanceof Country); + } catch (final NoResultException ex) { + // Not found, don't log this + } + + // Return result + return isAdded; + } + +} diff --git a/src/java/org/mxchange/jphone/model/phonenumbers/mobileprovider/AddressbookAdminMobileProviderSessionBean.java b/src/java/org/mxchange/jphone/model/phonenumbers/mobileprovider/AddressbookAdminMobileProviderSessionBean.java new file mode 100644 index 0000000..135172d --- /dev/null +++ b/src/java/org/mxchange/jphone/model/phonenumbers/mobileprovider/AddressbookAdminMobileProviderSessionBean.java @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2016, 2017 Roland Häder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jphone.model.phonenumbers.mobileprovider; + +import java.text.MessageFormat; +import java.util.GregorianCalendar; +import javax.ejb.Stateless; +import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; +import org.mxchange.jphone.exceptions.MobileProviderAlreadyAddedException; + +/** + * An administrative singleton EJB for mobile provider informations + *

+ * @author Roland Häder + */ +@Stateless (name = "adminMobileProvider", description = "A singleton session-scoped bean for mobile provider informations, admin-edition") +public class AddressbookAdminMobileProviderSessionBean extends BaseAddressbookDatabaseBean implements AdminMobileProviderSessionBeanRemote { + + /** + * Serial number + */ + private static final long serialVersionUID = 15_846_983_298_691_207L; + + /** + * Default constructor + */ + public AddressbookAdminMobileProviderSessionBean () { + // Call super constructor + super(); + } + + @Override + public MobileProvider addMobileProvider (final MobileProvider mobileProvider) throws MobileProviderAlreadyAddedException { + // Log trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addMobileProvider: mobileProvider={1} - CALLED!", this.getClass().getSimpleName(), mobileProvider)); //NOI18N + + // Is the instance valid? + if (null == mobileProvider) { + // Throw NPE + throw new NullPointerException("mobileProvider is null"); //NOI18N + } else if (mobileProvider.getProviderDialPrefix() == null) { + // Throw NPE again + throw new NullPointerException("mobileProvider.providerDialPrefix is null"); //NOI18N + } else if (mobileProvider.getProviderDialPrefix() < 1) { + // Not valid + throw new IllegalArgumentException(MessageFormat.format("mobileProvider.providerDialPrefix={0} is not valid.", mobileProvider.getProviderDialPrefix())); //NOI18N + } else if (mobileProvider.getProviderCountry() == null) { + // Throw again a NPE + throw new NullPointerException("mobileProvider.providerCountry is null"); //NOI18N + } else if (mobileProvider.getProviderMailPattern() == null) { + // ... and again ... + throw new NullPointerException("mobileProvider.providerMailPattern is null"); //NOI18N + } else if (mobileProvider.getProviderMailPattern().isEmpty()) { + // Empty pattern set (not allowed) + throw new IllegalArgumentException("mobileProvider.providerMailPattern is empty."); //NOI18N + } else if (!mobileProvider.getProviderMailPattern().contains("%s")) { //NOI18N + // No place-holder found + throw new IllegalArgumentException(MessageFormat.format("mobileProvider.providerMailPattern={0} does not contain '%s' which is need to be replaced with the full mobile number.", mobileProvider.getProviderMailPattern())); //NOI18N + } else if (mobileProvider.getProviderName() == null) { + // Throw NPE again + throw new NullPointerException("mobileProvider.providerName is null"); //NOI18N + } else if (mobileProvider.getProviderName().isEmpty()) { + // Empty name is not allowed + throw new IllegalArgumentException("mobileProvider.providerName is empty"); //NOI18N + } + + // Set creation timestamp + mobileProvider.setProviderEntryCreated(new GregorianCalendar()); + + // Persist it + this.getEntityManager().persist(mobileProvider); + + // Log trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addMobileProvider: mobileProvider.providerId={1} - EXIT!", this.getClass().getSimpleName(), mobileProvider.getProviderId())); //NOI18N + + // Return updated + return mobileProvider; + } + +} diff --git a/src/java/org/mxchange/jphone/model/phonenumbers/mobileprovider/AddressbookMobileProviderSingletonBean.java b/src/java/org/mxchange/jphone/model/phonenumbers/mobileprovider/AddressbookMobileProviderSingletonBean.java new file mode 100644 index 0000000..b277e3b --- /dev/null +++ b/src/java/org/mxchange/jphone/model/phonenumbers/mobileprovider/AddressbookMobileProviderSingletonBean.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2016, 2017 Roland Häder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jphone.model.phonenumbers.mobileprovider; + +import java.text.MessageFormat; +import java.util.List; +import javax.ejb.Singleton; +import javax.ejb.Startup; +import javax.persistence.Query; +import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; + +/** + * A singleton EJB for mobile provider informations + *

+ * @author Roland Häder + */ +@Startup +@Singleton (name = "mobileprovider", description = "A singleton session-scoped bean for SMS provider informations") +public class AddressbookMobileProviderSingletonBean extends BaseAddressbookDatabaseBean implements MobileProviderSingletonBeanRemote { + + /** + * Serial number + */ + private static final long serialVersionUID = 15_846_983_298_691_207L; + + /** + * Default constructor + */ + public AddressbookMobileProviderSingletonBean () { + // Call super constructor + super(); + } + + @Override + @SuppressWarnings ("unchecked") + public List allMobileProviders () { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allMobileProvider: CALLED!", this.getClass().getSimpleName())); //NOI18N + + // Init query + final Query query = this.getEntityManager().createNamedQuery("AllMobileProvider", CellphoneProvider.class); //NOI18N + + // Get list from it + final List mobileProviders = query.getResultList(); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allMobileProvider: mobileProviders.size()={1} - EXIT!", this.getClass().getSimpleName(), mobileProviders.size())); //NOI18N + + // Return it + return mobileProviders; + } + +} diff --git a/src/java/org/mxchange/jphone/model/phonenumbers/phone/AddressbookAdminPhoneSessionBean.java b/src/java/org/mxchange/jphone/model/phonenumbers/phone/AddressbookAdminPhoneSessionBean.java new file mode 100644 index 0000000..9010a8c --- /dev/null +++ b/src/java/org/mxchange/jphone/model/phonenumbers/phone/AddressbookAdminPhoneSessionBean.java @@ -0,0 +1,357 @@ +/* + * Copyright (C) 2016, 2017 Roland Häder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jphone.model.phonenumbers.phone; + +import java.text.MessageFormat; +import java.util.GregorianCalendar; +import javax.ejb.Stateless; +import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; +import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; +import org.mxchange.jphone.model.phonenumbers.fax.FaxNumbers; +import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber; +import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumbers; +import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber; +import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumbers; + +/** + * An EJB for administrative phone purposes + *

+ * @author Roland Häder + */ +@Stateless (name = "adminPhone", description = "An administrative bean handling phone data") +public class AddressbookAdminPhoneSessionBean extends BaseAddressbookDatabaseBean implements AdminPhoneSessionBeanRemote { + + /** + * Serial number + */ + private static final long serialVersionUID = 18_597_165_817_401_853L; + + /** + * Default constructor + */ + public AddressbookAdminPhoneSessionBean () { + // Call super constructor + super(); + } + + @Override + public void deleteFaxData (final DialableFaxNumber faxNumber) { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteFaxData: faxNumber={1} - CALLED!", this.getClass().getSimpleName(), faxNumber)); + + // Is all data set + if (faxNumber == null) { + // Not set, throw NPE + throw new NullPointerException("faxNumber is null"); //NOI18N + } else if (faxNumber.getPhoneId() == null) { + // Throw NPE again + throw new NullPointerException("faxNumber.phoneId is null"); //NOI18N + } else if (faxNumber.getPhoneId() < 1) { + // Invalid number + throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneId={0} is not valid", faxNumber.getPhoneId())); //NOI18N + } else if (faxNumber.getPhoneCountry() == null) { + // Throw NPE + throw new NullPointerException("faxNumber.phoneCountry is null"); //NOI18N + } else if (faxNumber.getPhoneCountry().getCountryId() == null) { + // Throw NPE + throw new NullPointerException("faxNumber.phoneCountry.countryId is null"); //NOI18N + } else if (faxNumber.getPhoneCountry().getCountryId() < 1) { + // Throw NPE + throw new NullPointerException(MessageFormat.format("faxNumber.phoneCountry.countryId={0} is not valid", faxNumber.getPhoneCountry().getCountryId())); //NOI18N + } else if (faxNumber.getPhoneAreaCode() == null) { + // ... throw again + throw new NullPointerException("faxNumber.phoneAreaCode is null"); //NOI18N + } else if (faxNumber.getPhoneAreaCode() < 1) { + // Id not valid + throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneAreaCode={0} is not valid.", faxNumber.getPhoneAreaCode())); //NOI18N + } else if (faxNumber.getPhoneNumber() == null) { + // Throw NPE again + throw new NullPointerException("faxNumber.phoneNumber is null"); //NOI18N + } else if (faxNumber.getPhoneNumber() < 1) { + // Throw NPE again + throw new NullPointerException(MessageFormat.format("faxNumber.phoneNumber={0} is not valid.", faxNumber.getPhoneNumber())); //NOI18N + } + + // Get a managed instance + final DialableFaxNumber managedNumber = this.getEntityManager().getReference(faxNumber.getClass(), faxNumber.getPhoneId()); + + // Remove it from database + this.getEntityManager().remove(managedNumber); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteMobileData: EXIT!", this.getClass().getSimpleName())); + } + + @Override + public void deleteLandLineData (final DialableLandLineNumber landLineNumber) { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteLandLineData: landLineNumber={1} - CALLED!", this.getClass().getSimpleName(), landLineNumber)); + + // Is all data set + if (landLineNumber == null) { + // Not set, throw NPE + throw new NullPointerException("landLineNumber is null"); //NOI18N + } else if (landLineNumber.getPhoneId() == null) { + // Throw NPE again + throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N + } else if (landLineNumber.getPhoneId() < 1) { + // Invalid number + throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneId={0} is not valid", landLineNumber.getPhoneId())); //NOI18N + } else if (landLineNumber.getPhoneCountry() == null) { + // Throw NPE + throw new NullPointerException("landLineNumber.phoneCountry is null"); //NOI18N + } else if (landLineNumber.getPhoneCountry().getCountryId() == null) { + // Throw NPE + throw new NullPointerException("landLineNumber.phoneCountry.countryId is null"); //NOI18N + } else if (landLineNumber.getPhoneCountry().getCountryId() < 1) { + // Throw NPE + throw new NullPointerException(MessageFormat.format("landLineNumber.phoneCountry.countryId={0} is not valid", landLineNumber.getPhoneCountry().getCountryId())); //NOI18N + } else if (landLineNumber.getPhoneAreaCode() == null) { + // ... throw again + throw new NullPointerException("landLineNumber.phoneAreaCode is null"); //NOI18N + } else if (landLineNumber.getPhoneAreaCode() < 1) { + // Id not valid + throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneAreaCode={0} is not valid.", landLineNumber.getPhoneAreaCode())); //NOI18N + } else if (landLineNumber.getPhoneNumber() == null) { + // Throw NPE again + throw new NullPointerException("landLineNumber.phoneNumber is null"); //NOI18N + } else if (landLineNumber.getPhoneNumber() < 1) { + // Throw NPE again + throw new NullPointerException(MessageFormat.format("landLineNumber.phoneNumber={0} is not valid.", landLineNumber.getPhoneNumber())); //NOI18N + } + + // Get a managed instance + final DialableLandLineNumber managedNumber = this.getEntityManager().getReference(landLineNumber.getClass(), landLineNumber.getPhoneId()); + + // Remove it from database + this.getEntityManager().remove(managedNumber); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteMobileData: EXIT!", this.getClass().getSimpleName())); + } + + @Override + public void deleteMobileData (final DialableMobileNumber mobileNumber) { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteMobileData: mobileNumber={1} - CALLED!", this.getClass().getSimpleName(), mobileNumber)); + + // Is all data set + if (null == mobileNumber) { + // Not set, throw NPE + throw new NullPointerException("mobileNumber is null"); //NOI18N + } else if (mobileNumber.getPhoneId() == null) { + // Throw NPE again + throw new NullPointerException("mobileNumber.phoneId is null"); //NOI18N + } else if (mobileNumber.getPhoneId() < 1) { + // Invalid number + throw new IllegalArgumentException(MessageFormat.format("mobileNumber.phoneId={0} is not valid", mobileNumber.getPhoneId())); //NOI18N + } else if (mobileNumber.getMobileProvider() == null) { + // Throw NPE + throw new NullPointerException("mobileNumber.cellphoneProvider is null"); //NOI18N + } else if (mobileNumber.getMobileProvider().getProviderId() == null) { + // ... throw again + throw new NullPointerException("mobileNumber.cellphoneProvider.providerId is null"); //NOI18N + } else if (mobileNumber.getMobileProvider().getProviderId() < 1) { + // Id not valid + throw new IllegalArgumentException(MessageFormat.format("mobileNumber.cellphoneProvider.providerId={0} is not valid.", mobileNumber.getMobileProvider().getProviderId())); //NOI18N + } else if (mobileNumber.getPhoneNumber() == null) { + // Throw NPE again + throw new NullPointerException("mobileNumber.phoneNumber is null"); //NOI18N + } else if (mobileNumber.getPhoneNumber() < 1) { + // Throw NPE again + throw new NullPointerException(MessageFormat.format("mobileNumber.phoneNumber={0} is not valid.", mobileNumber.getPhoneNumber())); //NOI18N + } + + // Get a managed instance + final DialableMobileNumber managedNumber = this.getEntityManager().getReference(mobileNumber.getClass(), mobileNumber.getPhoneId()); + + // Remove it from database + this.getEntityManager().remove(managedNumber); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteMobileData: EXIT!", this.getClass().getSimpleName())); + } + + @Override + public DialableFaxNumber updateFaxData (final DialableFaxNumber faxNumber) { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateFaxData: faxNumber={1} - CALLED!", this.getClass().getSimpleName(), faxNumber)); + + // Is all data set + if (faxNumber == null) { + // Not set, throw NPE + throw new NullPointerException("faxNumber is null"); //NOI18N + } else if (faxNumber.getPhoneId() == null) { + // Throw NPE again + throw new NullPointerException("faxNumber.phoneId is null"); //NOI18N + } else if (faxNumber.getPhoneId() < 1) { + // Invalid number + throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneId={0} is not valid", faxNumber.getPhoneId())); //NOI18N + } else if (faxNumber.getPhoneCountry() == null) { + // Throw NPE + throw new NullPointerException("faxNumber.phoneCountry is null"); //NOI18N + } else if (faxNumber.getPhoneCountry().getCountryId() == null) { + // Throw NPE + throw new NullPointerException("faxNumber.phoneCountry.countryId is null"); //NOI18N + } else if (faxNumber.getPhoneCountry().getCountryId() < 1) { + // Throw NPE + throw new NullPointerException(MessageFormat.format("faxNumber.phoneCountry.countryId={0} is not valid", faxNumber.getPhoneCountry().getCountryId())); //NOI18N + } else if (faxNumber.getPhoneAreaCode() == null) { + // ... throw again + throw new NullPointerException("faxNumber.phoneAreaCode is null"); //NOI18N + } else if (faxNumber.getPhoneAreaCode() < 1) { + // Id not valid + throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneAreaCode={0} is not valid.", faxNumber.getPhoneAreaCode())); //NOI18N + } else if (faxNumber.getPhoneNumber() == null) { + // Throw NPE again + throw new NullPointerException("faxNumber.phoneNumber is null"); //NOI18N + } else if (faxNumber.getPhoneNumber() < 1) { + // Throw NPE again + throw new NullPointerException(MessageFormat.format("faxNumber.phoneNumber={0} is not valid.", faxNumber.getPhoneNumber())); //NOI18N + } + + // Get contact from it and find it + final DialableFaxNumber managedNumber = this.getEntityManager().find(faxNumber.getClass(), faxNumber.getPhoneId()); + + // Should be found + assert (managedNumber instanceof DialableFaxNumber) : MessageFormat.format("Cell phone number with id {0} not found, but should be.", faxNumber.getPhoneId()); //NOI18N + + // Debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.updateFaxData: managedNumber.phoneId={1}", this.getClass().getSimpleName(), managedNumber.getPhoneId())); //NOI18N + + // Set updated timestamp + FaxNumbers.copyAll(faxNumber, managedNumber); + managedNumber.setPhoneEntryUpdated(new GregorianCalendar()); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateFaxData: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N + + // Return it + return managedNumber; + } + + @Override + public DialableLandLineNumber updateLandLineData (final DialableLandLineNumber landLineNumber) { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateLandLineData: landLineNumber={1} - CALLED!", this.getClass().getSimpleName(), landLineNumber)); + + // Is all data set + if (landLineNumber == null) { + // Not set, throw NPE + throw new NullPointerException("landLineNumber is null"); //NOI18N + } else if (landLineNumber.getPhoneId() == null) { + // Throw NPE again + throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N + } else if (landLineNumber.getPhoneId() < 1) { + // Invalid number + throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneId={0} is not valid", landLineNumber.getPhoneId())); //NOI18N + } else if (landLineNumber.getPhoneCountry() == null) { + // Throw NPE + throw new NullPointerException("landLineNumber.phoneCountry is null"); //NOI18N + } else if (landLineNumber.getPhoneCountry().getCountryId() == null) { + // Throw NPE + throw new NullPointerException("landLineNumber.phoneCountry.countryId is null"); //NOI18N + } else if (landLineNumber.getPhoneCountry().getCountryId() < 1) { + // Throw NPE + throw new NullPointerException(MessageFormat.format("landLineNumber.phoneCountry.countryId={0} is not valid", landLineNumber.getPhoneCountry().getCountryId())); //NOI18N + } else if (landLineNumber.getPhoneAreaCode() == null) { + // ... throw again + throw new NullPointerException("landLineNumber.phoneAreaCode is null"); //NOI18N + } else if (landLineNumber.getPhoneAreaCode() < 1) { + // Id not valid + throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneAreaCode={0} is not valid.", landLineNumber.getPhoneAreaCode())); //NOI18N + } else if (landLineNumber.getPhoneNumber() == null) { + // Throw NPE again + throw new NullPointerException("landLineNumber.phoneNumber is null"); //NOI18N + } else if (landLineNumber.getPhoneNumber() < 1) { + // Throw NPE again + throw new NullPointerException(MessageFormat.format("landLineNumber.phoneNumber={0} is not valid.", landLineNumber.getPhoneNumber())); //NOI18N + } + + // Get contact from it and find it + final DialableLandLineNumber managedNumber = this.getEntityManager().find(landLineNumber.getClass(), landLineNumber.getPhoneId()); + + // Should be found + assert (managedNumber instanceof DialableLandLineNumber) : MessageFormat.format("Cell phone number with id {0} not found, but should be.", landLineNumber.getPhoneId()); //NOI18N + + // Debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.updateLandLineData: managedNumber.phoneId={1}", this.getClass().getSimpleName(), managedNumber.getPhoneId())); //NOI18N + + // Set updated timestamp + LandLineNumbers.copyAll(landLineNumber, managedNumber); + managedNumber.setPhoneEntryUpdated(new GregorianCalendar()); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateLandLineData: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N + + // Return it + return managedNumber; + } + + @Override + public DialableMobileNumber updateMobileData (final DialableMobileNumber mobileNumber) { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateMobileData: mobileNumber={1} - CALLED!", this.getClass().getSimpleName(), mobileNumber)); + + // Is all data set + if (null == mobileNumber) { + // Not set, throw NPE + throw new NullPointerException("mobileNumber is null"); //NOI18N + } else if (mobileNumber.getPhoneId() == null) { + // Throw NPE again + throw new NullPointerException("mobileNumber.phoneId is null"); //NOI18N + } else if (mobileNumber.getPhoneId() < 1) { + // Invalid number + throw new IllegalArgumentException(MessageFormat.format("mobileNumber.phoneId={0} is not valid", mobileNumber.getPhoneId())); //NOI18N + } else if (mobileNumber.getMobileProvider() == null) { + // Throw NPE + throw new NullPointerException("mobileNumber.cellphoneProvider is null"); //NOI18N + } else if (mobileNumber.getMobileProvider().getProviderId() == null) { + // ... throw again + throw new NullPointerException("mobileNumber.cellphoneProvider.providerId is null"); //NOI18N + } else if (mobileNumber.getMobileProvider().getProviderId() < 1) { + // Id not valid + throw new IllegalArgumentException(MessageFormat.format("mobileNumber.cellphoneProvider.providerId={0} is not valid.", mobileNumber.getMobileProvider().getProviderId())); //NOI18N + } else if (mobileNumber.getPhoneNumber() == null) { + // Throw NPE again + throw new NullPointerException("mobileNumber.phoneNumber is null"); //NOI18N + } else if (mobileNumber.getPhoneNumber() < 1) { + // Throw NPE again + throw new NullPointerException(MessageFormat.format("mobileNumber.phoneNumber={0} is not valid.", mobileNumber.getPhoneNumber())); //NOI18N + } + + // Get contact from it and find it + final DialableMobileNumber managedNumber = this.getEntityManager().find(mobileNumber.getClass(), mobileNumber.getPhoneId()); + + // Should be found + assert (managedNumber instanceof DialableMobileNumber) : MessageFormat.format("Cell phone number with id {0} not found, but should be.", mobileNumber.getPhoneId()); //NOI18N + + // Debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.updateMobileData: managedNumber.phoneId={1}", this.getClass().getSimpleName(), managedNumber.getPhoneId())); //NOI18N + + // Set updated timestamp + MobileNumbers.copyAll(mobileNumber, managedNumber); + managedNumber.setPhoneEntryUpdated(new GregorianCalendar()); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateMobileData: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N + + // Return it + return managedNumber; + } + +} diff --git a/src/java/org/mxchange/jphone/model/phonenumbers/phone/AddressbookPhoneSessionBean.java b/src/java/org/mxchange/jphone/model/phonenumbers/phone/AddressbookPhoneSessionBean.java new file mode 100644 index 0000000..c1ddc99 --- /dev/null +++ b/src/java/org/mxchange/jphone/model/phonenumbers/phone/AddressbookPhoneSessionBean.java @@ -0,0 +1,228 @@ +/* + * Copyright (C) 2016, 2017 Roland Häder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jphone.model.phonenumbers.phone; + +import java.text.MessageFormat; +import java.util.List; +import javax.ejb.Stateless; +import javax.persistence.NoResultException; +import javax.persistence.Query; +import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; +import org.mxchange.jphone.exceptions.PhoneEntityNotFoundException; +import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; +import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber; +import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber; +import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumber; +import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber; +import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumber; + +/** + * A general phone EJB + *

+ * @author Roland Häder + */ +@Stateless (name = "phone", description = "A bean handling phone data") +public class AddressbookPhoneSessionBean extends BaseAddressbookDatabaseBean implements PhoneSessionBeanRemote { + + /** + * Serial number + */ + private static final long serialVersionUID = 134_945_698_127_601L; + + /** + * Default constructor + */ + public AddressbookPhoneSessionBean () { + // Call super constructor + super(); + } + + @SuppressWarnings ("unchecked") + @Override + public List allFaxNumbers () { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allFaxNumbers: CALLED!", this.getClass().getSimpleName())); //NOI18N + + // Get query + final Query query = this.getEntityManager().createNamedQuery("AllFaxNumbers", FaxNumber.class); //NOI18N + + // Get list from it + final List list = query.getResultList(); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allFaxNumbers: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N + + // Return it + return list; + } + + @SuppressWarnings ("unchecked") + @Override + public List allLandLineNumbers () { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allLandLineNumbers: CALLED!", this.getClass().getSimpleName())); //NOI18N + + // Get query + final Query query = this.getEntityManager().createNamedQuery("AllLandLineNumbers", LandLineNumber.class); //NOI18N + + // Get list from it + final List list = query.getResultList(); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allLandLineNumbers: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N + + // Return it + return list; + } + + @SuppressWarnings ("unchecked") + @Override + public List allMobileNumbers () { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allMobileNumbers: CALLED!", this.getClass().getSimpleName())); //NOI18N + + // Get query + final Query query = this.getEntityManager().createNamedQuery("AllMobileNumbers", MobileNumber.class); //NOI18N + + // Get list from it + final List list = query.getResultList(); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allMobileNumbers: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N + + // Return it + return list; + } + + @Override + public DialableFaxNumber findFaxNumberById (final Long faxNumberId) throws PhoneEntityNotFoundException { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findFaxNumberById: mobileNumberId={1} - CALLED!", this.getClass().getSimpleName(), faxNumberId)); //NOI18N + + // The id number should be valid + if (null == faxNumberId) { + // Throw NPE + throw new NullPointerException("faxNumberId is null"); //NOI18N + } else if (faxNumberId < 1) { + // Not valid + throw new IllegalArgumentException(MessageFormat.format("faxNumberId={0} is not valid.", faxNumberId)); //NOI18N + } + + // Now find it + final Query query = this.getEntityManager().createNamedQuery("SearchFaxNumberId", FaxNumber.class); //NOI18N + + // Set parameter + query.setParameter("faxNumberId", faxNumberId); //NOI18N + + // Init instance + final DialableFaxNumber faxNumber; + + // Try to get a result + try { + // Get a single result + faxNumber = (DialableFaxNumber) query.getSingleResult(); + } catch (NoResultException ex) { + // The entry was not found, so throw it again + throw new PhoneEntityNotFoundException(faxNumberId, ex); + } + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findFaxNumberById: mobile={1} - EXIT!", this.getClass().getSimpleName(), faxNumber)); //NOI18N + + // Return found instance + return faxNumber; + } + + @Override + public DialableLandLineNumber findLandLineNumberById (final Long landLineNumberId) throws PhoneEntityNotFoundException { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findLandLineNumberById: mobileNumberId={1} - CALLED!", this.getClass().getSimpleName(), landLineNumberId)); //NOI18N + + // The id number should be valid + if (null == landLineNumberId) { + // Throw NPE + throw new NullPointerException("landLineNumberId is null"); //NOI18N + } else if (landLineNumberId < 1) { + // Not valid + throw new IllegalArgumentException(MessageFormat.format("landLineNumberId={0} is not valid.", landLineNumberId)); //NOI18N + } + + // Now find it + final Query query = this.getEntityManager().createNamedQuery("SearchLandLineNumberId", LandLineNumber.class); //NOI18N + + // Set parameter + query.setParameter("landLineNumberId", landLineNumberId); //NOI18N + + // Init instance + final DialableLandLineNumber landLineNumber; + + // Try to get a result + try { + // Get a single result + landLineNumber = (DialableLandLineNumber) query.getSingleResult(); + } catch (NoResultException ex) { + // The entry was not found, so throw it again + throw new PhoneEntityNotFoundException(landLineNumberId, ex); + } + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findLandLineNumberById: mobile={1} - EXIT!", this.getClass().getSimpleName(), landLineNumber)); //NOI18N + + // Return found instance + return landLineNumber; + } + + @Override + public DialableMobileNumber findMobileNumberById (final Long mobileNumberId) throws PhoneEntityNotFoundException { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findMobileNumberById: mobileNumberId={1} - CALLED!", this.getClass().getSimpleName(), mobileNumberId)); //NOI18N + + // The id number should be valid + if (null == mobileNumberId) { + // Throw NPE + throw new NullPointerException("mobileNumberId is null"); //NOI18N + } else if (mobileNumberId < 1) { + // Not valid + throw new IllegalArgumentException(MessageFormat.format("mobileNumberId={0} is not valid.", mobileNumberId)); //NOI18N + } + + // Now find it + final Query query = this.getEntityManager().createNamedQuery("SearchMobileNumberId", MobileNumber.class); //NOI18N + + // Set parameter + query.setParameter("mobileNumberId", mobileNumberId); //NOI18N + + // Init instance + final DialableMobileNumber mobile; + + // Try to get a result + try { + // Get a single result + mobile = (DialableMobileNumber) query.getSingleResult(); + } catch (NoResultException ex) { + // The entry was not found, so throw it again + throw new PhoneEntityNotFoundException(mobileNumberId, ex); + } + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findMobileNumberById: mobile={1} - EXIT!", this.getClass().getSimpleName(), mobile)); //NOI18N + + // Return found instance + return mobile; + } + +} diff --git a/src/java/org/mxchange/jphone/phonenumbers/mobileprovider/AddressbookAdminMobileProviderSessionBean.java b/src/java/org/mxchange/jphone/phonenumbers/mobileprovider/AddressbookAdminMobileProviderSessionBean.java deleted file mode 100644 index e36dc5d..0000000 --- a/src/java/org/mxchange/jphone/phonenumbers/mobileprovider/AddressbookAdminMobileProviderSessionBean.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Roland Häder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.mxchange.jphone.phonenumbers.mobileprovider; - -import java.text.MessageFormat; -import java.util.GregorianCalendar; -import javax.ejb.Stateless; -import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; -import org.mxchange.jphone.exceptions.MobileProviderAlreadyAddedException; -import org.mxchange.jphone.model.phonenumbers.mobileprovider.AdminMobileProviderSessionBeanRemote; -import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider; - -/** - * An administrative singleton EJB for mobile provider informations - *

- * @author Roland Häder - */ -@Stateless (name = "adminMobileProvider", description = "A singleton session-scoped bean for mobile provider informations, admin-edition") -public class AddressbookAdminMobileProviderSessionBean extends BaseAddressbookDatabaseBean implements AdminMobileProviderSessionBeanRemote { - - /** - * Serial number - */ - private static final long serialVersionUID = 15_846_983_298_691_207L; - - /** - * Default constructor - */ - public AddressbookAdminMobileProviderSessionBean () { - // Call super constructor - super(); - } - - @Override - public MobileProvider addMobileProvider (final MobileProvider mobileProvider) throws MobileProviderAlreadyAddedException { - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addMobileProvider: mobileProvider={1} - CALLED!", this.getClass().getSimpleName(), mobileProvider)); //NOI18N - - // Is the instance valid? - if (null == mobileProvider) { - // Throw NPE - throw new NullPointerException("mobileProvider is null"); //NOI18N - } else if (mobileProvider.getProviderDialPrefix() == null) { - // Throw NPE again - throw new NullPointerException("mobileProvider.providerDialPrefix is null"); //NOI18N - } else if (mobileProvider.getProviderDialPrefix() < 1) { - // Not valid - throw new IllegalArgumentException(MessageFormat.format("mobileProvider.providerDialPrefix={0} is not valid.", mobileProvider.getProviderDialPrefix())); //NOI18N - } else if (mobileProvider.getProviderCountry() == null) { - // Throw again a NPE - throw new NullPointerException("mobileProvider.providerCountry is null"); //NOI18N - } else if (mobileProvider.getProviderMailPattern() == null) { - // ... and again ... - throw new NullPointerException("mobileProvider.providerMailPattern is null"); //NOI18N - } else if (mobileProvider.getProviderMailPattern().isEmpty()) { - // Empty pattern set (not allowed) - throw new IllegalArgumentException("mobileProvider.providerMailPattern is empty."); //NOI18N - } else if (!mobileProvider.getProviderMailPattern().contains("%s")) { //NOI18N - // No place-holder found - throw new IllegalArgumentException(MessageFormat.format("mobileProvider.providerMailPattern={0} does not contain '%s' which is need to be replaced with the full mobile number.", mobileProvider.getProviderMailPattern())); //NOI18N - } else if (mobileProvider.getProviderName() == null) { - // Throw NPE again - throw new NullPointerException("mobileProvider.providerName is null"); //NOI18N - } else if (mobileProvider.getProviderName().isEmpty()) { - // Empty name is not allowed - throw new IllegalArgumentException("mobileProvider.providerName is empty"); //NOI18N - } - - // Set creation timestamp - mobileProvider.setProviderEntryCreated(new GregorianCalendar()); - - // Persist it - this.getEntityManager().persist(mobileProvider); - - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addMobileProvider: mobileProvider.providerId={1} - EXIT!", this.getClass().getSimpleName(), mobileProvider.getProviderId())); //NOI18N - - // Return updated - return mobileProvider; - } - -} diff --git a/src/java/org/mxchange/jphone/phonenumbers/mobileprovider/AddressbookMobileProviderSingletonBean.java b/src/java/org/mxchange/jphone/phonenumbers/mobileprovider/AddressbookMobileProviderSingletonBean.java deleted file mode 100644 index 5877721..0000000 --- a/src/java/org/mxchange/jphone/phonenumbers/mobileprovider/AddressbookMobileProviderSingletonBean.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Roland Häder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.mxchange.jphone.phonenumbers.mobileprovider; - -import java.text.MessageFormat; -import java.util.List; -import javax.ejb.Singleton; -import javax.ejb.Startup; -import javax.persistence.Query; -import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; -import org.mxchange.jphone.model.phonenumbers.mobileprovider.CellphoneProvider; -import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider; -import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProviderSingletonBeanRemote; - -/** - * A singleton EJB for mobile provider informations - *

- * @author Roland Häder - */ -@Startup -@Singleton (name = "mobileprovider", description = "A singleton session-scoped bean for SMS provider informations") -public class AddressbookMobileProviderSingletonBean extends BaseAddressbookDatabaseBean implements MobileProviderSingletonBeanRemote { - - /** - * Serial number - */ - private static final long serialVersionUID = 15_846_983_298_691_207L; - - /** - * Default constructor - */ - public AddressbookMobileProviderSingletonBean () { - // Call super constructor - super(); - } - - @Override - @SuppressWarnings ("unchecked") - public List allMobileProviders () { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allMobileProvider: CALLED!", this.getClass().getSimpleName())); //NOI18N - - // Init query - final Query query = this.getEntityManager().createNamedQuery("AllMobileProvider", CellphoneProvider.class); //NOI18N - - // Get list from it - final List mobileProviders = query.getResultList(); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allMobileProvider: mobileProviders.size()={1} - EXIT!", this.getClass().getSimpleName(), mobileProviders.size())); //NOI18N - - // Return it - return mobileProviders; - } - -} diff --git a/src/java/org/mxchange/jphone/phonenumbers/phone/AddressbookAdminPhoneSessionBean.java b/src/java/org/mxchange/jphone/phonenumbers/phone/AddressbookAdminPhoneSessionBean.java deleted file mode 100644 index bee9e5b..0000000 --- a/src/java/org/mxchange/jphone/phonenumbers/phone/AddressbookAdminPhoneSessionBean.java +++ /dev/null @@ -1,358 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Roland Häder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.mxchange.jphone.phonenumbers.phone; - -import java.text.MessageFormat; -import java.util.GregorianCalendar; -import javax.ejb.Stateless; -import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; -import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; -import org.mxchange.jphone.model.phonenumbers.fax.FaxNumbers; -import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber; -import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumbers; -import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber; -import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumbers; -import org.mxchange.jphone.model.phonenumbers.phone.AdminPhoneSessionBeanRemote; - -/** - * An EJB for administrative phone purposes - *

- * @author Roland Häder - */ -@Stateless (name = "adminPhone", description = "An administrative bean handling phone data") -public class AddressbookAdminPhoneSessionBean extends BaseAddressbookDatabaseBean implements AdminPhoneSessionBeanRemote { - - /** - * Serial number - */ - private static final long serialVersionUID = 18_597_165_817_401_853L; - - /** - * Default constructor - */ - public AddressbookAdminPhoneSessionBean () { - // Call super constructor - super(); - } - - @Override - public void deleteFaxData (final DialableFaxNumber faxNumber) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteFaxData: faxNumber={1} - CALLED!", this.getClass().getSimpleName(), faxNumber)); - - // Is all data set - if (faxNumber == null) { - // Not set, throw NPE - throw new NullPointerException("faxNumber is null"); //NOI18N - } else if (faxNumber.getPhoneId() == null) { - // Throw NPE again - throw new NullPointerException("faxNumber.phoneId is null"); //NOI18N - } else if (faxNumber.getPhoneId() < 1) { - // Invalid number - throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneId={0} is not valid", faxNumber.getPhoneId())); //NOI18N - } else if (faxNumber.getPhoneCountry() == null) { - // Throw NPE - throw new NullPointerException("faxNumber.phoneCountry is null"); //NOI18N - } else if (faxNumber.getPhoneCountry().getCountryId() == null) { - // Throw NPE - throw new NullPointerException("faxNumber.phoneCountry.countryId is null"); //NOI18N - } else if (faxNumber.getPhoneCountry().getCountryId() < 1) { - // Throw NPE - throw new NullPointerException(MessageFormat.format("faxNumber.phoneCountry.countryId={0} is not valid", faxNumber.getPhoneCountry().getCountryId())); //NOI18N - } else if (faxNumber.getPhoneAreaCode() == null) { - // ... throw again - throw new NullPointerException("faxNumber.phoneAreaCode is null"); //NOI18N - } else if (faxNumber.getPhoneAreaCode() < 1) { - // Id not valid - throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneAreaCode={0} is not valid.", faxNumber.getPhoneAreaCode())); //NOI18N - } else if (faxNumber.getPhoneNumber() == null) { - // Throw NPE again - throw new NullPointerException("faxNumber.phoneNumber is null"); //NOI18N - } else if (faxNumber.getPhoneNumber() < 1) { - // Throw NPE again - throw new NullPointerException(MessageFormat.format("faxNumber.phoneNumber={0} is not valid.", faxNumber.getPhoneNumber())); //NOI18N - } - - // Get a managed instance - final DialableFaxNumber managedNumber = this.getEntityManager().getReference(faxNumber.getClass(), faxNumber.getPhoneId()); - - // Remove it from database - this.getEntityManager().remove(managedNumber); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteMobileData: EXIT!", this.getClass().getSimpleName())); - } - - @Override - public void deleteLandLineData (final DialableLandLineNumber landLineNumber) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteLandLineData: landLineNumber={1} - CALLED!", this.getClass().getSimpleName(), landLineNumber)); - - // Is all data set - if (landLineNumber == null) { - // Not set, throw NPE - throw new NullPointerException("landLineNumber is null"); //NOI18N - } else if (landLineNumber.getPhoneId() == null) { - // Throw NPE again - throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N - } else if (landLineNumber.getPhoneId() < 1) { - // Invalid number - throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneId={0} is not valid", landLineNumber.getPhoneId())); //NOI18N - } else if (landLineNumber.getPhoneCountry() == null) { - // Throw NPE - throw new NullPointerException("landLineNumber.phoneCountry is null"); //NOI18N - } else if (landLineNumber.getPhoneCountry().getCountryId() == null) { - // Throw NPE - throw new NullPointerException("landLineNumber.phoneCountry.countryId is null"); //NOI18N - } else if (landLineNumber.getPhoneCountry().getCountryId() < 1) { - // Throw NPE - throw new NullPointerException(MessageFormat.format("landLineNumber.phoneCountry.countryId={0} is not valid", landLineNumber.getPhoneCountry().getCountryId())); //NOI18N - } else if (landLineNumber.getPhoneAreaCode() == null) { - // ... throw again - throw new NullPointerException("landLineNumber.phoneAreaCode is null"); //NOI18N - } else if (landLineNumber.getPhoneAreaCode() < 1) { - // Id not valid - throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneAreaCode={0} is not valid.", landLineNumber.getPhoneAreaCode())); //NOI18N - } else if (landLineNumber.getPhoneNumber() == null) { - // Throw NPE again - throw new NullPointerException("landLineNumber.phoneNumber is null"); //NOI18N - } else if (landLineNumber.getPhoneNumber() < 1) { - // Throw NPE again - throw new NullPointerException(MessageFormat.format("landLineNumber.phoneNumber={0} is not valid.", landLineNumber.getPhoneNumber())); //NOI18N - } - - // Get a managed instance - final DialableLandLineNumber managedNumber = this.getEntityManager().getReference(landLineNumber.getClass(), landLineNumber.getPhoneId()); - - // Remove it from database - this.getEntityManager().remove(managedNumber); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteMobileData: EXIT!", this.getClass().getSimpleName())); - } - - @Override - public void deleteMobileData (final DialableMobileNumber mobileNumber) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteMobileData: mobileNumber={1} - CALLED!", this.getClass().getSimpleName(), mobileNumber)); - - // Is all data set - if (null == mobileNumber) { - // Not set, throw NPE - throw new NullPointerException("mobileNumber is null"); //NOI18N - } else if (mobileNumber.getPhoneId() == null) { - // Throw NPE again - throw new NullPointerException("mobileNumber.phoneId is null"); //NOI18N - } else if (mobileNumber.getPhoneId() < 1) { - // Invalid number - throw new IllegalArgumentException(MessageFormat.format("mobileNumber.phoneId={0} is not valid", mobileNumber.getPhoneId())); //NOI18N - } else if (mobileNumber.getMobileProvider() == null) { - // Throw NPE - throw new NullPointerException("mobileNumber.cellphoneProvider is null"); //NOI18N - } else if (mobileNumber.getMobileProvider().getProviderId() == null) { - // ... throw again - throw new NullPointerException("mobileNumber.cellphoneProvider.providerId is null"); //NOI18N - } else if (mobileNumber.getMobileProvider().getProviderId() < 1) { - // Id not valid - throw new IllegalArgumentException(MessageFormat.format("mobileNumber.cellphoneProvider.providerId={0} is not valid.", mobileNumber.getMobileProvider().getProviderId())); //NOI18N - } else if (mobileNumber.getPhoneNumber() == null) { - // Throw NPE again - throw new NullPointerException("mobileNumber.phoneNumber is null"); //NOI18N - } else if (mobileNumber.getPhoneNumber() < 1) { - // Throw NPE again - throw new NullPointerException(MessageFormat.format("mobileNumber.phoneNumber={0} is not valid.", mobileNumber.getPhoneNumber())); //NOI18N - } - - // Get a managed instance - final DialableMobileNumber managedNumber = this.getEntityManager().getReference(mobileNumber.getClass(), mobileNumber.getPhoneId()); - - // Remove it from database - this.getEntityManager().remove(managedNumber); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteMobileData: EXIT!", this.getClass().getSimpleName())); - } - - @Override - public DialableFaxNumber updateFaxData (final DialableFaxNumber faxNumber) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateFaxData: faxNumber={1} - CALLED!", this.getClass().getSimpleName(), faxNumber)); - - // Is all data set - if (faxNumber == null) { - // Not set, throw NPE - throw new NullPointerException("faxNumber is null"); //NOI18N - } else if (faxNumber.getPhoneId() == null) { - // Throw NPE again - throw new NullPointerException("faxNumber.phoneId is null"); //NOI18N - } else if (faxNumber.getPhoneId() < 1) { - // Invalid number - throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneId={0} is not valid", faxNumber.getPhoneId())); //NOI18N - } else if (faxNumber.getPhoneCountry() == null) { - // Throw NPE - throw new NullPointerException("faxNumber.phoneCountry is null"); //NOI18N - } else if (faxNumber.getPhoneCountry().getCountryId() == null) { - // Throw NPE - throw new NullPointerException("faxNumber.phoneCountry.countryId is null"); //NOI18N - } else if (faxNumber.getPhoneCountry().getCountryId() < 1) { - // Throw NPE - throw new NullPointerException(MessageFormat.format("faxNumber.phoneCountry.countryId={0} is not valid", faxNumber.getPhoneCountry().getCountryId())); //NOI18N - } else if (faxNumber.getPhoneAreaCode() == null) { - // ... throw again - throw new NullPointerException("faxNumber.phoneAreaCode is null"); //NOI18N - } else if (faxNumber.getPhoneAreaCode() < 1) { - // Id not valid - throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneAreaCode={0} is not valid.", faxNumber.getPhoneAreaCode())); //NOI18N - } else if (faxNumber.getPhoneNumber() == null) { - // Throw NPE again - throw new NullPointerException("faxNumber.phoneNumber is null"); //NOI18N - } else if (faxNumber.getPhoneNumber() < 1) { - // Throw NPE again - throw new NullPointerException(MessageFormat.format("faxNumber.phoneNumber={0} is not valid.", faxNumber.getPhoneNumber())); //NOI18N - } - - // Get contact from it and find it - final DialableFaxNumber managedNumber = this.getEntityManager().find(faxNumber.getClass(), faxNumber.getPhoneId()); - - // Should be found - assert (managedNumber instanceof DialableFaxNumber) : MessageFormat.format("Cell phone number with id {0} not found, but should be.", faxNumber.getPhoneId()); //NOI18N - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.updateFaxData: managedNumber.phoneId={1}", this.getClass().getSimpleName(), managedNumber.getPhoneId())); //NOI18N - - // Set updated timestamp - FaxNumbers.copyAll(faxNumber, managedNumber); - managedNumber.setPhoneEntryUpdated(new GregorianCalendar()); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateFaxData: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N - - // Return it - return managedNumber; - } - - @Override - public DialableLandLineNumber updateLandLineData (final DialableLandLineNumber landLineNumber) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateLandLineData: landLineNumber={1} - CALLED!", this.getClass().getSimpleName(), landLineNumber)); - - // Is all data set - if (landLineNumber == null) { - // Not set, throw NPE - throw new NullPointerException("landLineNumber is null"); //NOI18N - } else if (landLineNumber.getPhoneId() == null) { - // Throw NPE again - throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N - } else if (landLineNumber.getPhoneId() < 1) { - // Invalid number - throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneId={0} is not valid", landLineNumber.getPhoneId())); //NOI18N - } else if (landLineNumber.getPhoneCountry() == null) { - // Throw NPE - throw new NullPointerException("landLineNumber.phoneCountry is null"); //NOI18N - } else if (landLineNumber.getPhoneCountry().getCountryId() == null) { - // Throw NPE - throw new NullPointerException("landLineNumber.phoneCountry.countryId is null"); //NOI18N - } else if (landLineNumber.getPhoneCountry().getCountryId() < 1) { - // Throw NPE - throw new NullPointerException(MessageFormat.format("landLineNumber.phoneCountry.countryId={0} is not valid", landLineNumber.getPhoneCountry().getCountryId())); //NOI18N - } else if (landLineNumber.getPhoneAreaCode() == null) { - // ... throw again - throw new NullPointerException("landLineNumber.phoneAreaCode is null"); //NOI18N - } else if (landLineNumber.getPhoneAreaCode() < 1) { - // Id not valid - throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneAreaCode={0} is not valid.", landLineNumber.getPhoneAreaCode())); //NOI18N - } else if (landLineNumber.getPhoneNumber() == null) { - // Throw NPE again - throw new NullPointerException("landLineNumber.phoneNumber is null"); //NOI18N - } else if (landLineNumber.getPhoneNumber() < 1) { - // Throw NPE again - throw new NullPointerException(MessageFormat.format("landLineNumber.phoneNumber={0} is not valid.", landLineNumber.getPhoneNumber())); //NOI18N - } - - // Get contact from it and find it - final DialableLandLineNumber managedNumber = this.getEntityManager().find(landLineNumber.getClass(), landLineNumber.getPhoneId()); - - // Should be found - assert (managedNumber instanceof DialableLandLineNumber) : MessageFormat.format("Cell phone number with id {0} not found, but should be.", landLineNumber.getPhoneId()); //NOI18N - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.updateLandLineData: managedNumber.phoneId={1}", this.getClass().getSimpleName(), managedNumber.getPhoneId())); //NOI18N - - // Set updated timestamp - LandLineNumbers.copyAll(landLineNumber, managedNumber); - managedNumber.setPhoneEntryUpdated(new GregorianCalendar()); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateLandLineData: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N - - // Return it - return managedNumber; - } - - @Override - public DialableMobileNumber updateMobileData (final DialableMobileNumber mobileNumber) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateMobileData: mobileNumber={1} - CALLED!", this.getClass().getSimpleName(), mobileNumber)); - - // Is all data set - if (null == mobileNumber) { - // Not set, throw NPE - throw new NullPointerException("mobileNumber is null"); //NOI18N - } else if (mobileNumber.getPhoneId() == null) { - // Throw NPE again - throw new NullPointerException("mobileNumber.phoneId is null"); //NOI18N - } else if (mobileNumber.getPhoneId() < 1) { - // Invalid number - throw new IllegalArgumentException(MessageFormat.format("mobileNumber.phoneId={0} is not valid", mobileNumber.getPhoneId())); //NOI18N - } else if (mobileNumber.getMobileProvider() == null) { - // Throw NPE - throw new NullPointerException("mobileNumber.cellphoneProvider is null"); //NOI18N - } else if (mobileNumber.getMobileProvider().getProviderId() == null) { - // ... throw again - throw new NullPointerException("mobileNumber.cellphoneProvider.providerId is null"); //NOI18N - } else if (mobileNumber.getMobileProvider().getProviderId() < 1) { - // Id not valid - throw new IllegalArgumentException(MessageFormat.format("mobileNumber.cellphoneProvider.providerId={0} is not valid.", mobileNumber.getMobileProvider().getProviderId())); //NOI18N - } else if (mobileNumber.getPhoneNumber() == null) { - // Throw NPE again - throw new NullPointerException("mobileNumber.phoneNumber is null"); //NOI18N - } else if (mobileNumber.getPhoneNumber() < 1) { - // Throw NPE again - throw new NullPointerException(MessageFormat.format("mobileNumber.phoneNumber={0} is not valid.", mobileNumber.getPhoneNumber())); //NOI18N - } - - // Get contact from it and find it - final DialableMobileNumber managedNumber = this.getEntityManager().find(mobileNumber.getClass(), mobileNumber.getPhoneId()); - - // Should be found - assert (managedNumber instanceof DialableMobileNumber) : MessageFormat.format("Cell phone number with id {0} not found, but should be.", mobileNumber.getPhoneId()); //NOI18N - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.updateMobileData: managedNumber.phoneId={1}", this.getClass().getSimpleName(), managedNumber.getPhoneId())); //NOI18N - - // Set updated timestamp - MobileNumbers.copyAll(mobileNumber, managedNumber); - managedNumber.setPhoneEntryUpdated(new GregorianCalendar()); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateMobileData: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N - - // Return it - return managedNumber; - } - -} diff --git a/src/java/org/mxchange/jphone/phonenumbers/phone/AddressbookPhoneSessionBean.java b/src/java/org/mxchange/jphone/phonenumbers/phone/AddressbookPhoneSessionBean.java deleted file mode 100644 index 54259d7..0000000 --- a/src/java/org/mxchange/jphone/phonenumbers/phone/AddressbookPhoneSessionBean.java +++ /dev/null @@ -1,229 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Roland Häder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.mxchange.jphone.phonenumbers.phone; - -import java.text.MessageFormat; -import java.util.List; -import javax.ejb.Stateless; -import javax.persistence.NoResultException; -import javax.persistence.Query; -import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; -import org.mxchange.jphone.exceptions.PhoneEntityNotFoundException; -import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; -import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber; -import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber; -import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumber; -import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber; -import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumber; -import org.mxchange.jphone.model.phonenumbers.phone.PhoneSessionBeanRemote; - -/** - * A general phone EJB - *

- * @author Roland Häder - */ -@Stateless (name = "phone", description = "A bean handling phone data") -public class AddressbookPhoneSessionBean extends BaseAddressbookDatabaseBean implements PhoneSessionBeanRemote { - - /** - * Serial number - */ - private static final long serialVersionUID = 134_945_698_127_601L; - - /** - * Default constructor - */ - public AddressbookPhoneSessionBean () { - // Call super constructor - super(); - } - - @SuppressWarnings ("unchecked") - @Override - public List allFaxNumbers () { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allFaxNumbers: CALLED!", this.getClass().getSimpleName())); //NOI18N - - // Get query - final Query query = this.getEntityManager().createNamedQuery("AllFaxNumbers", FaxNumber.class); //NOI18N - - // Get list from it - final List list = query.getResultList(); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allFaxNumbers: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N - - // Return it - return list; - } - - @SuppressWarnings ("unchecked") - @Override - public List allLandLineNumbers () { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allLandLineNumbers: CALLED!", this.getClass().getSimpleName())); //NOI18N - - // Get query - final Query query = this.getEntityManager().createNamedQuery("AllLandLineNumbers", LandLineNumber.class); //NOI18N - - // Get list from it - final List list = query.getResultList(); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allLandLineNumbers: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N - - // Return it - return list; - } - - @SuppressWarnings ("unchecked") - @Override - public List allMobileNumbers () { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allMobileNumbers: CALLED!", this.getClass().getSimpleName())); //NOI18N - - // Get query - final Query query = this.getEntityManager().createNamedQuery("AllMobileNumbers", MobileNumber.class); //NOI18N - - // Get list from it - final List list = query.getResultList(); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allMobileNumbers: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N - - // Return it - return list; - } - - @Override - public DialableFaxNumber findFaxNumberById (final Long faxNumberId) throws PhoneEntityNotFoundException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findFaxNumberById: mobileNumberId={1} - CALLED!", this.getClass().getSimpleName(), faxNumberId)); //NOI18N - - // The id number should be valid - if (null == faxNumberId) { - // Throw NPE - throw new NullPointerException("faxNumberId is null"); //NOI18N - } else if (faxNumberId < 1) { - // Not valid - throw new IllegalArgumentException(MessageFormat.format("faxNumberId={0} is not valid.", faxNumberId)); //NOI18N - } - - // Now find it - final Query query = this.getEntityManager().createNamedQuery("SearchFaxNumberId", FaxNumber.class); //NOI18N - - // Set parameter - query.setParameter("faxNumberId", faxNumberId); //NOI18N - - // Init instance - final DialableFaxNumber faxNumber; - - // Try to get a result - try { - // Get a single result - faxNumber = (DialableFaxNumber) query.getSingleResult(); - } catch (NoResultException ex) { - // The entry was not found, so throw it again - throw new PhoneEntityNotFoundException(faxNumberId, ex); - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findFaxNumberById: mobile={1} - EXIT!", this.getClass().getSimpleName(), faxNumber)); //NOI18N - - // Return found instance - return faxNumber; - } - - @Override - public DialableLandLineNumber findLandLineNumberById (final Long landLineNumberId) throws PhoneEntityNotFoundException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findLandLineNumberById: mobileNumberId={1} - CALLED!", this.getClass().getSimpleName(), landLineNumberId)); //NOI18N - - // The id number should be valid - if (null == landLineNumberId) { - // Throw NPE - throw new NullPointerException("landLineNumberId is null"); //NOI18N - } else if (landLineNumberId < 1) { - // Not valid - throw new IllegalArgumentException(MessageFormat.format("landLineNumberId={0} is not valid.", landLineNumberId)); //NOI18N - } - - // Now find it - final Query query = this.getEntityManager().createNamedQuery("SearchLandLineNumberId", LandLineNumber.class); //NOI18N - - // Set parameter - query.setParameter("landLineNumberId", landLineNumberId); //NOI18N - - // Init instance - final DialableLandLineNumber landLineNumber; - - // Try to get a result - try { - // Get a single result - landLineNumber = (DialableLandLineNumber) query.getSingleResult(); - } catch (NoResultException ex) { - // The entry was not found, so throw it again - throw new PhoneEntityNotFoundException(landLineNumberId, ex); - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findLandLineNumberById: mobile={1} - EXIT!", this.getClass().getSimpleName(), landLineNumber)); //NOI18N - - // Return found instance - return landLineNumber; - } - - @Override - public DialableMobileNumber findMobileNumberById (final Long mobileNumberId) throws PhoneEntityNotFoundException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findMobileNumberById: mobileNumberId={1} - CALLED!", this.getClass().getSimpleName(), mobileNumberId)); //NOI18N - - // The id number should be valid - if (null == mobileNumberId) { - // Throw NPE - throw new NullPointerException("mobileNumberId is null"); //NOI18N - } else if (mobileNumberId < 1) { - // Not valid - throw new IllegalArgumentException(MessageFormat.format("mobileNumberId={0} is not valid.", mobileNumberId)); //NOI18N - } - - // Now find it - final Query query = this.getEntityManager().createNamedQuery("SearchMobileNumberId", MobileNumber.class); //NOI18N - - // Set parameter - query.setParameter("mobileNumberId", mobileNumberId); //NOI18N - - // Init instance - final DialableMobileNumber mobile; - - // Try to get a result - try { - // Get a single result - mobile = (DialableMobileNumber) query.getSingleResult(); - } catch (NoResultException ex) { - // The entry was not found, so throw it again - throw new PhoneEntityNotFoundException(mobileNumberId, ex); - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findMobileNumberById: mobile={1} - EXIT!", this.getClass().getSimpleName(), mobile)); //NOI18N - - // Return found instance - return mobile; - } - -}