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.jcontacts.contact.Contact;
import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
-import org.mxchange.jphone.exceptions.FaxNumberNotLinkedException;
-import org.mxchange.jphone.exceptions.LandLineNumberNotLinkedException;
-import org.mxchange.jphone.exceptions.MobileNumberNotLinkedException;
+import org.mxchange.jphone.exceptions.PhoneNumberAlreadyLinkedException;
+import org.mxchange.jphone.exceptions.PhoneNumberNotLinkedException;
import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
* <p>
* @author Roland Haeder<rhaeder@cho-time.de>
*/
-@Stateless (name = "adminContactPhone", description = "An administrative bean handling contact's phone data")
+@Stateless (name = "adminContactPhone", description = "An administrative bean handling contact's phone (fax, land-line and mobile) data")
public class PizzaAdminContactPhoneSessionBean extends BasePizzaDatabaseBean implements AdminContactsPhoneSessionBeanRemote {
/**
private ContactSessionBeanRemote contactBean;
@Override
- public Contact unlinkFaxDataFromContact (final Contact contact, final DialableFaxNumber faxNumber) throws FaxNumberNotLinkedException {
+ 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
+ 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
+ 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
+ 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
+ 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
+ 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
+ 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
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 FaxNumberNotLinkedException(faxNumber);
+ throw new PhoneNumberNotLinkedException(faxNumber);
} else if (contact.getContactFaxNumber().getPhoneId() == null) {
// Throw NPE again
throw new NullPointerException("contact.contactFaxNumber.phoneId is null"); //NOI18N
}
@Override
- public Contact unlinkLandLineDataFromContact (final Contact contact, final DialableLandLineNumber landLineNumber) throws LandLineNumberNotLinkedException {
+ 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
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 LandLineNumberNotLinkedException(landLineNumber);
+ throw new PhoneNumberNotLinkedException(landLineNumber);
} else if (contact.getContactLandLineNumber().getPhoneId() == null) {
// Throw NPE again
throw new NullPointerException("contact.contactLandLineNumber.phoneId is null"); //NOI18N
}
@Override
- public Contact unlinkMobileDataFromContact (final Contact contact, final DialableMobileNumber mobileNumber) throws MobileNumberNotLinkedException {
+ 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
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 MobileNumberNotLinkedException(mobileNumber);
+ throw new PhoneNumberNotLinkedException(mobileNumber);
} else if (contact.getContactMobileNumber().getPhoneId() == null) {
// Throw NPE again
throw new NullPointerException("contact.contactMobileNumber.phoneId is null"); //NOI18N