From: Roland Häder Date: Wed, 10 Jun 2020 18:29:00 +0000 (+0200) Subject: Don't cherry-pick: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=a8d66ab35545453b98e6c945e58834db200fe9ab;p=jjobs-ejb.git Don't cherry-pick: - fixed name of class and import 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 deleted file mode 100644 index 12aa848..0000000 --- a/src/java/org/mxchange/jcontacts/model/mobile/FinancialsAdminContactMobileSessionBean.java +++ /dev/null @@ -1,203 +0,0 @@ -/* - * 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/mobile/JobsAdminContactMobileSessionBean.java b/src/java/org/mxchange/jcontacts/model/mobile/JobsAdminContactMobileSessionBean.java new file mode 100644 index 0000000..99ff6ec --- /dev/null +++ b/src/java/org/mxchange/jcontacts/model/mobile/JobsAdminContactMobileSessionBean.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.jjobs.enterprise.BaseJobsEnterpriseBean; +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 JobsAdminContactMobileSessionBean extends BaseJobsEnterpriseBean 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 JobsAdminContactMobileSessionBean () { + // 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; + } + +}