import org.mxchange.jphone.exceptions.phone.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
}
@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.getMobileId() == null) {
- // Throw it again
- throw new NullPointerException("mobileNumber.phoneId is null"); //NOI18N
- } else if (mobileNumber.getMobileId() < 1) {
- // Invalid id
- throw new IllegalArgumentException(MessageFormat.format("mobileNumber.phoneId={0} is not valid", mobileNumber.getMobileId())); //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 {
+ public Contact linkNewFaxNumberWithContact (final Contact contact, final DialableFaxNumber faxNumber) throws PhoneNumberAlreadyLinkedException, ContactNotFoundException {
// Trace message
this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkNewFaxNumberWithContact: contact={1},faxNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, faxNumber)); //NOI18N
}
@Override
- public Contact linkNewLandLineNumberWithContact (final Contact contact, final DialableLandLineNumber landLineNumber) throws PhoneNumberAlreadyLinkedException {
+ public Contact linkNewLandLineNumberWithContact (final Contact contact, final DialableLandLineNumber landLineNumber) throws PhoneNumberAlreadyLinkedException, ContactNotFoundException {
// Trace message
this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkNewLandLineNumberWithContact: contact={1},landLineNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, landLineNumber)); //NOI18N
}
@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.getMobileId() instanceof Long) {
- // Throw it again
- throw new IllegalStateException(MessageFormat.format("mobileNumber.phoneId={0} is not null", mobileNumber.getMobileId())); //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.setMobileEntryCreated(new Date());
-
- // 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 {
+ public Contact unlinkFaxDataFromContact (final Contact contact, final DialableFaxNumber faxNumber) throws PhoneNumberNotLinkedException, ContactNotFoundException {
// Trace message
this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkFaxDataFromContact: contact={1},faxNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, faxNumber)); //NOI18N
}
@Override
- public Contact unlinkLandLineDataFromContact (final Contact contact, final DialableLandLineNumber landLineNumber) throws PhoneNumberNotLinkedException {
+ public Contact unlinkLandLineDataFromContact (final Contact contact, final DialableLandLineNumber landLineNumber) throws PhoneNumberNotLinkedException, ContactNotFoundException {
// Trace message
this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkLandLineDataFromContact: contact={1},landLineNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, landLineNumber)); //NOI18N
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().getMobileId() == null) {
- // Throw NPE again
- throw new NullPointerException("contact.contactMobileNumber.phoneId is null"); //NOI18N
- } else if (contact.getContactMobileNumber().getMobileId() < 1) {
- // Invalid id number
- throw new IllegalArgumentException(MessageFormat.format("contact.contactMobileNumber.phoneId={0} is invalid.", contact.getContactMobileNumber().getMobileId())); //NOI18N
- } else if (!Objects.equals(mobileNumber.getMobileId(), contact.getContactMobileNumber().getMobileId())) {
- // Not same object
- throw new IllegalArgumentException(MessageFormat.format("contact.contactMobileNumber.phoneId={0} and mobileNumber.phoneId={1} are not the same.", contact.getContactMobileNumber().getMobileId(), mobileNumber.getMobileId())); //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;
- }
-
}