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.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
+import org.mxchange.jcontacts.contact.Contact;
+import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
+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;
/**
* A session EJB for administrative contact's phone number purposes
* <p>
* @author Roland Haeder<roland@mxchange.org>
*/
-@Stateless (name = "admincontactphone", description = "An administrative bean handling contact's phone data")
+@Stateless (name = "adminContactPhone", description = "An administrative bean handling contact's phone data")
public class AddressbookAdminContactPhoneSessionBean extends BaseAddressbookDatabaseBean implements AdminContactsPhoneSessionBeanRemote {
/**
*/
private static final long serialVersionUID = 189_217_561_460_237_108L;
+ /**
+ * Contact EJB
+ */
+ @EJB
+ private ContactSessionBeanRemote contactBean;
+
+ @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
+ 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 DialableCellphoneNumber updateCellphoneData (final DialableCellphoneNumber cellPhoneNumber) {
+ public Contact linkExistingMobileNumberWithContact (final Contact contact, final DialableMobileNumber mobileNumber) throws PhoneNumberAlreadyLinkedException {
// Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateCellphoneData: cellPhoneNumber={1} - CALLED!", this.getClass().getSimpleName(), cellPhoneNumber));
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingMobileNumberWithContact: contact={1},mobileNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, mobileNumber)); //NOI18N
- // Is all data set
- if (null == cellPhoneNumber) {
- // Not set, throw NPE
- throw new NullPointerException("cellphoneNumber is null"); //NOI18N
- } else if (cellPhoneNumber.getPhoneId() == null) {
+ // 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("cellphoneNumber.phoneId is null"); //NOI18N
- } else if (cellPhoneNumber.getPhoneId() < 1) {
- // Invalid number
- throw new IllegalArgumentException(MessageFormat.format("cellphoneNumber.phoneId={0} is not valid", cellPhoneNumber.getPhoneId())); //NOI18N
- } else if (cellPhoneNumber.getCellphoneProvider() == null) {
+ 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("cellphoneNumber.cellphoneProvider is null"); //NOI18N
- } else if (cellPhoneNumber.getCellphoneProvider().getProviderId() == null) {
- // ... throw again
- throw new NullPointerException("cellphoneNumber.cellphoneProvider.providerId is null"); //NOI18N
- } else if (cellPhoneNumber.getCellphoneProvider().getProviderId() < 1) {
- // Id not valid
- throw new IllegalArgumentException(MessageFormat.format("cellphoneNumber.cellphoneProvider.providerId={0} is not valid.", cellPhoneNumber.getCellphoneProvider().getProviderId())); //NOI18N
- } else if (cellPhoneNumber.getPhoneNumber() == null) {
+ 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("cellphoneNumber.phoneNumber is null"); //NOI18N
- } else if (cellPhoneNumber.getPhoneNumber() < 1) {
+ throw new NullPointerException("mobileNumber.mobileProvider.providerId is null"); //NOI18N
+ } else if (mobileNumber.getMobileProvider().getProviderId() < 1) {
// Throw NPE again
- throw new NullPointerException(MessageFormat.format("cellphoneNumber.phoneNumber={0} is not valid.", cellPhoneNumber.getPhoneNumber())); //NOI18N
+ throw new IllegalArgumentException(MessageFormat.format("mobileNumber.mobileProvider.providerId={0} is not valid", mobileNumber.getMobileProvider().getProviderId())); //NOI18N
}
- // Set updated timestamp
- cellPhoneNumber.setPhoneEntryUpdated(new GregorianCalendar());
+ // Set created instance
+ mobileNumber.setPhoneEntryCreated(new GregorianCalendar());
- // Get contact from it and find it
- DialableCellphoneNumber foundNumber = this.getEntityManager().find(cellPhoneNumber.getClass(), cellPhoneNumber.getPhoneId());
+ // Set mobile number in contact
+ contact.setContactMobileNumber(mobileNumber);
- // Should be found
- assert (foundNumber instanceof DialableCellphoneNumber) : MessageFormat.format("Cell phone number with id {0} not found, but should be.", cellPhoneNumber.getPhoneId()); //NOI18N
+ // 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
+
+ // 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
+ 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
+ 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
+ }
- // Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateCellphoneData: foundNumber.phoneId={0}", foundNumber.getPhoneId())); //NOI18N
+ // Remove it from contact
+ contact.setContactMobileNumber(null);
- // Merge contact instance
- DialableCellphoneNumber detachedNumber = this.getEntityManager().merge(foundNumber);
+ // Update database
+ Contact updatedContact = this.contactBean.updateContactData(contact);
// Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateCellphoneData: detachedNumber={1} - EXIT!", this.getClass().getSimpleName(), detachedNumber)); //NOI18N
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkMobileDataFromContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N
// Return it
- return detachedNumber;
+ return updatedContact;
}
}