From b5549f45d36164237e1f31ec267cb8e4313354db Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 17 Aug 2016 15:21:18 +0200 Subject: [PATCH] Please cherry-pick: - implemented business methods unlinkFaxDataFromContact(), unlinkLandLineDataFromContact() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../JobsAdminContactPhoneSessionBean.java | 94 ++++++++++++++++++- 1 file changed, 91 insertions(+), 3 deletions(-) diff --git a/src/java/org/mxchange/jcontacts/phone/JobsAdminContactPhoneSessionBean.java b/src/java/org/mxchange/jcontacts/phone/JobsAdminContactPhoneSessionBean.java index 745e860..01abe32 100644 --- a/src/java/org/mxchange/jcontacts/phone/JobsAdminContactPhoneSessionBean.java +++ b/src/java/org/mxchange/jcontacts/phone/JobsAdminContactPhoneSessionBean.java @@ -23,7 +23,11 @@ import javax.ejb.Stateless; 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; /** @@ -45,6 +49,90 @@ public class JobsAdminContactPhoneSessionBean extends BaseJobsDatabaseBean imple @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 @@ -65,13 +153,13 @@ public class JobsAdminContactPhoneSessionBean extends BaseJobsDatabaseBean imple 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 -- 2.39.5