import org.mxchange.jcontacts.contact.Contact;
import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
import org.mxchange.jjobs.database.BaseJobsDatabaseBean;
+import org.mxchange.jphone.exceptions.FaxNumberNotLinkedException;
+import org.mxchange.jphone.exceptions.LandLineNumberNotLinkedException;
import org.mxchange.jphone.exceptions.MobileNumberNotLinkedException;
+import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
+import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
/**
@EJB
private ContactSessionBeanRemote contactBean;
+ @Override
+ public Contact unlinkFaxDataFromContact (final Contact contact, final DialableFaxNumber faxNumber) throws FaxNumberNotLinkedException {
+ // 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 FaxNumberNotLinkedException(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 LandLineNumberNotLinkedException {
+ // 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 LandLineNumberNotLinkedException(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 MobileNumberNotLinkedException {
// Trace message
throw new MobileNumberNotLinkedException(mobileNumber);
} else if (contact.getContactMobileNumber().getPhoneId() == null) {
// Throw NPE again
- throw new NullPointerException("contact.contactCellphoneNumber.phoneId is null"); //NOI18N
+ throw new NullPointerException("contact.contactMobileNumber.phoneId is null"); //NOI18N
} else if (contact.getContactMobileNumber().getPhoneId() < 1) {
// Invalid id number
- throw new IllegalArgumentException(MessageFormat.format("contact.contactCellphoneNumber.phoneId={0} is invalid.", contact.getContactMobileNumber().getPhoneId())); //NOI18N
+ 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.contactCellphoneNumber.phoneId={0} and mobileNumber.phoneId={1} are not the same.", contact.getContactMobileNumber().getPhoneId(), mobileNumber.getPhoneId())); //NOI18N
+ 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