From 298810c61de7ca4ee039ade9487cc169d5c2d1a4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 18 Aug 2016 17:05:12 +0200 Subject: [PATCH] Continued a bit: (please cherry-pick) - implemented missing methods - these include a lot tests and are currently untested (may not work) - some to specific exceptions has been replaced by a more generic exception (which is fine here) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../PizzaAdminContactPhoneSessionBean.java | 350 +++++++++++++++++- 1 file changed, 340 insertions(+), 10 deletions(-) diff --git a/src/java/org/mxchange/jcontacts/phone/PizzaAdminContactPhoneSessionBean.java b/src/java/org/mxchange/jcontacts/phone/PizzaAdminContactPhoneSessionBean.java index f4badc3..96754d1 100644 --- a/src/java/org/mxchange/jcontacts/phone/PizzaAdminContactPhoneSessionBean.java +++ b/src/java/org/mxchange/jcontacts/phone/PizzaAdminContactPhoneSessionBean.java @@ -17,14 +17,14 @@ package org.mxchange.jcontacts.phone; import java.text.MessageFormat; +import java.util.GregorianCalendar; import java.util.Objects; import javax.ejb.EJB; import javax.ejb.Stateless; import org.mxchange.jcontacts.contact.Contact; import org.mxchange.jcontacts.contact.ContactSessionBeanRemote; -import org.mxchange.jphone.exceptions.FaxNumberNotLinkedException; -import org.mxchange.jphone.exceptions.LandLineNumberNotLinkedException; -import org.mxchange.jphone.exceptions.MobileNumberNotLinkedException; +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; @@ -35,7 +35,7 @@ import org.mxchange.pizzaaplication.database.BasePizzaDatabaseBean; *

* @author Roland Haeder */ -@Stateless (name = "adminContactPhone", description = "An administrative bean handling contact's phone data") +@Stateless (name = "adminContactPhone", description = "An administrative bean handling contact's phone (fax, land-line and mobile) data") public class PizzaAdminContactPhoneSessionBean extends BasePizzaDatabaseBean implements AdminContactsPhoneSessionBeanRemote { /** @@ -50,7 +50,337 @@ public class PizzaAdminContactPhoneSessionBean extends BasePizzaDatabaseBean imp private ContactSessionBeanRemote contactBean; @Override - public Contact unlinkFaxDataFromContact (final Contact contact, final DialableFaxNumber faxNumber) throws FaxNumberNotLinkedException { + 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 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.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("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("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("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.setPhoneEntryCreated(new GregorianCalendar()); + + // Set mobile number in contact + contact.setContactMobileNumber(mobileNumber); + + // 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 @@ -66,7 +396,7 @@ public class PizzaAdminContactPhoneSessionBean extends BasePizzaDatabaseBean imp 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); + throw new PhoneNumberNotLinkedException(faxNumber); } else if (contact.getContactFaxNumber().getPhoneId() == null) { // Throw NPE again throw new NullPointerException("contact.contactFaxNumber.phoneId is null"); //NOI18N @@ -92,7 +422,7 @@ public class PizzaAdminContactPhoneSessionBean extends BasePizzaDatabaseBean imp } @Override - public Contact unlinkLandLineDataFromContact (final Contact contact, final DialableLandLineNumber landLineNumber) throws LandLineNumberNotLinkedException { + 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 @@ -108,7 +438,7 @@ public class PizzaAdminContactPhoneSessionBean extends BasePizzaDatabaseBean imp 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); + throw new PhoneNumberNotLinkedException(landLineNumber); } else if (contact.getContactLandLineNumber().getPhoneId() == null) { // Throw NPE again throw new NullPointerException("contact.contactLandLineNumber.phoneId is null"); //NOI18N @@ -134,7 +464,7 @@ public class PizzaAdminContactPhoneSessionBean extends BasePizzaDatabaseBean imp } @Override - public Contact unlinkMobileDataFromContact (final Contact contact, final DialableMobileNumber mobileNumber) throws MobileNumberNotLinkedException { + 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 @@ -150,7 +480,7 @@ public class PizzaAdminContactPhoneSessionBean extends BasePizzaDatabaseBean imp 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 MobileNumberNotLinkedException(mobileNumber); + throw new PhoneNumberNotLinkedException(mobileNumber); } else if (contact.getContactMobileNumber().getPhoneId() == null) { // Throw NPE again throw new NullPointerException("contact.contactMobileNumber.phoneId is null"); //NOI18N -- 2.39.5