From: Roland Häder Date: Wed, 17 Aug 2016 13:21:18 +0000 (+0200) Subject: Please cherry-pick: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=5d7a27082f027f5245d4aeddcb27ab04175431ba;p=pizzaservice-ejb.git Please cherry-pick: - implemented business methods unlinkFaxDataFromContact(), unlinkLandLineDataFromContact() Signed-off-by: Roland Häder --- diff --git a/src/java/org/mxchange/jcontacts/phone/PizzaAdminContactPhoneSessionBean.java b/src/java/org/mxchange/jcontacts/phone/PizzaAdminContactPhoneSessionBean.java index 6a58401..f4badc3 100644 --- a/src/java/org/mxchange/jcontacts/phone/PizzaAdminContactPhoneSessionBean.java +++ b/src/java/org/mxchange/jcontacts/phone/PizzaAdminContactPhoneSessionBean.java @@ -22,9 +22,13 @@ import javax.ejb.EJB; import javax.ejb.Stateless; import org.mxchange.jcontacts.contact.Contact; import org.mxchange.jcontacts.contact.ContactSessionBeanRemote; -import org.mxchange.pizzaaplication.database.BasePizzaDatabaseBean; +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; +import org.mxchange.pizzaaplication.database.BasePizzaDatabaseBean; /** * A session EJB for administrative contact's phone number purposes @@ -45,6 +49,90 @@ public class PizzaAdminContactPhoneSessionBean extends BasePizzaDatabaseBean imp @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 PizzaAdminContactPhoneSessionBean extends BasePizzaDatabaseBean imp 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