From: Roland Häder Date: Fri, 24 Apr 2020 00:15:44 +0000 (+0200) Subject: Please cherry-pick: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=2e17991a1108a9461476550dad302f001880c1b3;p=jjobs-ejb.git Please cherry-pick: - further splitted phone (means fax & land-line numbers) from mobile numbers Signed-off-by: Roland Häder --- diff --git a/src/java/org/mxchange/jcontacts/model/mobile/FinancialsAdminContactMobileSessionBean.java b/src/java/org/mxchange/jcontacts/model/mobile/FinancialsAdminContactMobileSessionBean.java new file mode 100644 index 0000000..12aa848 --- /dev/null +++ b/src/java/org/mxchange/jcontacts/model/mobile/FinancialsAdminContactMobileSessionBean.java @@ -0,0 +1,203 @@ +/* + * Copyright (C) 2016 - 2020 Free Software Foundation + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jcontacts.model.mobile; + +import java.text.MessageFormat; +import java.util.Date; +import java.util.Objects; +import javax.ejb.EJB; +import javax.ejb.Stateless; +import org.mxchange.jcontacts.exceptions.ContactNotFoundException; +import org.mxchange.jcontacts.model.contact.Contact; +import org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote; +import org.mxchange.jfinancials.enterprise.BaseFinancialsEnterpriseBean; +import org.mxchange.jphone.exceptions.mobile.MobileNumberAlreadyLinkedException; +import org.mxchange.jphone.exceptions.mobile.MobileNumberNotLinkedException; +import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber; + +/** + * A session EJB for administrative contact's mobile number purposes + *

+ * @author Roland Häder + */ +@Stateless (name = "adminContactMobile", description = "An administrative bean handling contact's mobile data") +public class FinancialsAdminContactMobileSessionBean extends BaseFinancialsEnterpriseBean implements AdminContactsMobileSessionBeanRemote { + + /** + * Serial number + */ + private static final long serialVersionUID = 189_217_561_460_237_108L; + + /** + * Contact EJB + */ + @EJB (lookup = "java:global/jfinancials-ejb/contact!org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote") + private ContactSessionBeanRemote contactBean; + + /** + * Default constructor + */ + public FinancialsAdminContactMobileSessionBean () { + // Call super constructor + super(); + } + + @Override + public Contact linkExistingMobileNumberWithContact (final Contact contact, final DialableMobileNumber mobileNumber) throws MobileNumberAlreadyLinkedException, ContactNotFoundException { + // 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 mobile instance + throw new MobileNumberAlreadyLinkedException(mobileNumber); + } else if (null == mobileNumber) { + // Throw NPE + throw new NullPointerException("mobileNumber is null"); //NOI18N + } else if (mobileNumber.getMobileId() == null) { + // Throw it again + throw new NullPointerException("mobileNumber.mobileId is null"); //NOI18N + } else if (mobileNumber.getMobileId() < 1) { + // Invalid id + throw new IllegalArgumentException(MessageFormat.format("mobileNumber.mobileId={0} is not valid", mobileNumber.getMobileId())); //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 + final 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 linkNewMobileNumberWithContact (final Contact contact, final DialableMobileNumber mobileNumber) throws MobileNumberAlreadyLinkedException, ContactNotFoundException { + // 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 mobile instance + throw new MobileNumberAlreadyLinkedException(mobileNumber); + } else if (null == mobileNumber) { + // Throw NPE + throw new NullPointerException("mobileNumber is null"); //NOI18N + } else if (mobileNumber.getMobileId() instanceof Long) { + // Throw it again + throw new IllegalStateException(MessageFormat.format("mobileNumber.mobileId={0} is not null", mobileNumber.getMobileId())); //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.setMobileEntryCreated(new Date()); + + // Set mobile number in contact + contact.setContactMobileNumber(mobileNumber); + + // Update database + final 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 unlinkMobileDataFromContact (final Contact contact, final DialableMobileNumber mobileNumber) throws MobileNumberNotLinkedException, ContactNotFoundException { + // 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 mobile instance + throw new MobileNumberNotLinkedException(mobileNumber); + } else if (contact.getContactMobileNumber().getMobileId() == null) { + // Throw NPE again + throw new NullPointerException("contact.contactMobileNumber.mobileId is null"); //NOI18N + } else if (contact.getContactMobileNumber().getMobileId() < 1) { + // Invalid id number + throw new IllegalArgumentException(MessageFormat.format("contact.contactMobileNumber.mobileId={0} is invalid.", contact.getContactMobileNumber().getMobileId())); //NOI18N + } else if (!Objects.equals(mobileNumber.getMobileId(), contact.getContactMobileNumber().getMobileId())) { + // Not same object + throw new IllegalArgumentException(MessageFormat.format("contact.contactMobileNumber.mobileId={0} and mobileNumber.mobileId={1} are not the same.", contact.getContactMobileNumber().getMobileId(), mobileNumber.getMobileId())); //NOI18N + } + + // Remove it from contact + contact.setContactMobileNumber(null); + + // Update database + final Contact updatedContact = this.contactBean.updateContactData(contact); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkMobileDataFromContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N + + // Return it + return updatedContact; + } + +} diff --git a/src/java/org/mxchange/jcontacts/model/phone/JobsAdminContactPhoneSessionBean.java b/src/java/org/mxchange/jcontacts/model/phone/JobsAdminContactPhoneSessionBean.java index 68f3348..953073c 100644 --- a/src/java/org/mxchange/jcontacts/model/phone/JobsAdminContactPhoneSessionBean.java +++ b/src/java/org/mxchange/jcontacts/model/phone/JobsAdminContactPhoneSessionBean.java @@ -21,6 +21,7 @@ import java.util.Date; import java.util.Objects; import javax.ejb.EJB; import javax.ejb.Stateless; +import org.mxchange.jcontacts.exceptions.ContactNotFoundException; import org.mxchange.jcontacts.model.contact.Contact; import org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote; import org.mxchange.jjobs.enterprise.BaseJobsEnterpriseBean; @@ -28,7 +29,6 @@ import org.mxchange.jphone.exceptions.phone.PhoneNumberAlreadyLinkedException; import org.mxchange.jphone.exceptions.phone.PhoneNumberNotLinkedException; import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber; -import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber; /** * A session EJB for administrative contact's phone number purposes @@ -58,7 +58,7 @@ public class JobsAdminContactPhoneSessionBean extends BaseJobsEnterpriseBean imp } @Override - public Contact linkExistingFaxNumberWithContact (final Contact contact, final DialableFaxNumber faxNumber) throws PhoneNumberAlreadyLinkedException { + public Contact linkExistingFaxNumberWithContact (final Contact contact, final DialableFaxNumber faxNumber) throws PhoneNumberAlreadyLinkedException, ContactNotFoundException { // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingFaxNumberWithContact: contact={1},faxNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, faxNumber)); //NOI18N @@ -115,7 +115,7 @@ public class JobsAdminContactPhoneSessionBean extends BaseJobsEnterpriseBean imp } @Override - public Contact linkExistingLandLineNumberWithContact (final Contact contact, final DialableLandLineNumber landLineNumber) throws PhoneNumberAlreadyLinkedException { + public Contact linkExistingLandLineNumberWithContact (final Contact contact, final DialableLandLineNumber landLineNumber) throws PhoneNumberAlreadyLinkedException, ContactNotFoundException { // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingLandLineNumberWithContact: contact={1},landLineNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, landLineNumber)); //NOI18N @@ -172,58 +172,7 @@ public class JobsAdminContactPhoneSessionBean extends BaseJobsEnterpriseBean imp } @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.getMobileId() == null) { - // Throw it again - throw new NullPointerException("mobileNumber.phoneId is null"); //NOI18N - } else if (mobileNumber.getMobileId() < 1) { - // Invalid id - throw new IllegalArgumentException(MessageFormat.format("mobileNumber.phoneId={0} is not valid", mobileNumber.getMobileId())); //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 - final 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 { + public Contact linkNewFaxNumberWithContact (final Contact contact, final DialableFaxNumber faxNumber) throws PhoneNumberAlreadyLinkedException, ContactNotFoundException { // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkNewFaxNumberWithContact: contact={1},faxNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, faxNumber)); //NOI18N @@ -280,7 +229,7 @@ public class JobsAdminContactPhoneSessionBean extends BaseJobsEnterpriseBean imp } @Override - public Contact linkNewLandLineNumberWithContact (final Contact contact, final DialableLandLineNumber landLineNumber) throws PhoneNumberAlreadyLinkedException { + public Contact linkNewLandLineNumberWithContact (final Contact contact, final DialableLandLineNumber landLineNumber) throws PhoneNumberAlreadyLinkedException, ContactNotFoundException { // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkNewLandLineNumberWithContact: contact={1},landLineNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, landLineNumber)); //NOI18N @@ -337,58 +286,7 @@ public class JobsAdminContactPhoneSessionBean extends BaseJobsEnterpriseBean imp } @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.getMobileId() instanceof Long) { - // Throw it again - throw new IllegalStateException(MessageFormat.format("mobileNumber.phoneId={0} is not null", mobileNumber.getMobileId())); //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.setMobileEntryCreated(new Date()); - - // Set mobile number in contact - contact.setContactMobileNumber(mobileNumber); - - // Update database - final 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 { + public Contact unlinkFaxDataFromContact (final Contact contact, final DialableFaxNumber faxNumber) throws PhoneNumberNotLinkedException, ContactNotFoundException { // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkFaxDataFromContact: contact={1},faxNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, faxNumber)); //NOI18N @@ -430,7 +328,7 @@ public class JobsAdminContactPhoneSessionBean extends BaseJobsEnterpriseBean imp } @Override - public Contact unlinkLandLineDataFromContact (final Contact contact, final DialableLandLineNumber landLineNumber) throws PhoneNumberNotLinkedException { + public Contact unlinkLandLineDataFromContact (final Contact contact, final DialableLandLineNumber landLineNumber) throws PhoneNumberNotLinkedException, ContactNotFoundException { // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkLandLineDataFromContact: contact={1},landLineNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, landLineNumber)); //NOI18N @@ -471,46 +369,4 @@ public class JobsAdminContactPhoneSessionBean extends BaseJobsEnterpriseBean imp 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().getMobileId() == null) { - // Throw NPE again - throw new NullPointerException("contact.contactMobileNumber.phoneId is null"); //NOI18N - } else if (contact.getContactMobileNumber().getMobileId() < 1) { - // Invalid id number - throw new IllegalArgumentException(MessageFormat.format("contact.contactMobileNumber.phoneId={0} is invalid.", contact.getContactMobileNumber().getMobileId())); //NOI18N - } else if (!Objects.equals(mobileNumber.getMobileId(), contact.getContactMobileNumber().getMobileId())) { - // Not same object - throw new IllegalArgumentException(MessageFormat.format("contact.contactMobileNumber.phoneId={0} and mobileNumber.phoneId={1} are not the same.", contact.getContactMobileNumber().getMobileId(), mobileNumber.getMobileId())); //NOI18N - } - - // Remove it from contact - contact.setContactMobileNumber(null); - - // Update database - final Contact updatedContact = this.contactBean.updateContactData(contact); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkMobileDataFromContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N - - // Return it - return updatedContact; - } - }