+++ /dev/null
-/*
- * Copyright (C) 2016, 2017 Roland Häder
- *
- * 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 <http://www.gnu.org/licenses/>.
- */
-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.addressbook.database.BaseAddressbookDatabaseBean;
-import org.mxchange.jcontacts.contact.Contact;
-import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
-import org.mxchange.jcontacts.contact.UserContact;
-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;
-
-/**
- * A session EJB for administrative contact's phone number purposes
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@Stateless (name = "adminContactPhone", description = "An administrative bean handling contact's phone data")
-public class AddressbookAdminContactPhoneSessionBean extends BaseAddressbookDatabaseBean implements AdminContactsPhoneSessionBeanRemote {
-
- /**
- * Serial number
- */
- private static final long serialVersionUID = 189_217_561_460_237_108L;
-
- /**
- * Contact EJB
- */
- @EJB
- private ContactSessionBeanRemote contactBean;
-
- /**
- * Default constructor
- */
- public AddressbookAdminContactPhoneSessionBean () {
- // Call super constructor
- super();
- }
-
- @Override
- 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
- }
-
- // Find contact
- Contact managedContact = this.getEntityManager().find(UserContact.class, contact.getContactId());
-
- // Merge phone number
- DialableFaxNumber managedNumber = this.getEntityManager().merge(faxNumber);
-
- // Set fax number in contact
- managedContact.setContactFaxNumber(managedNumber);
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingFaxNumberWithContact: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N
-
- // Return it
- return managedContact;
- }
-
- @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
- }
-
- // Find contact
- Contact managedContact = this.getEntityManager().find(UserContact.class, contact.getContactId());
-
- // Merge phone number
- DialableLandLineNumber managedNumber = this.getEntityManager().merge(landLineNumber);
-
- // Set fax number in contact
- managedContact.setContactLandLineNumber(managedNumber);
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingLandLineNumberWithContact: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N
-
- // Return it
- return managedContact;
- }
-
- @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
- }
-
- // Find contact
- Contact managedContact = this.getEntityManager().find(UserContact.class, contact.getContactId());
-
- // Merge phone number
- DialableMobileNumber managedNumber = this.getEntityManager().merge(mobileNumber);
-
- // Set fax number in contact
- managedContact.setContactMobileNumber(managedNumber);
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingMobileNumberWithContact: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N
-
- // Return it
- return managedContact;
- }
-
- @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());
-
- // Persist it
- this.getEntityManager().persist(faxNumber);
-
- // Flush it
- this.getEntityManager().flush();
-
- // Find contact
- Contact managedContact = this.getEntityManager().find(UserContact.class, contact.getContactId());
-
- // Set fax number in contact
- managedContact.setContactFaxNumber(faxNumber);
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkNewFaxNumberWithContact: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N
-
- // Return it
- return managedContact;
- }
-
- @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());
-
- // Persist it
- this.getEntityManager().persist(landLineNumber);
-
- // Flush it
- this.getEntityManager().flush();
-
- // Find contact
- Contact managedContact = this.getEntityManager().find(UserContact.class, contact.getContactId());
-
- // Set land-line number in contact
- managedContact.setContactLandLineNumber(landLineNumber);
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkNewLandLineNumberWithContact: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N
-
- // Return it
- return managedContact;
- }
-
- @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());
-
- // Persist it
- this.getEntityManager().persist(mobileNumber);
-
- // Flush it
- this.getEntityManager().flush();
-
- // Find contact
- Contact managedContact = this.getEntityManager().find(UserContact.class, contact.getContactId());
-
- // Set land-line number in contact
- managedContact.setContactMobileNumber(mobileNumber);
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkNewMobileNumberWithContact: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N
-
- // Return it
- return managedContact;
- }
-
- @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
-
- // 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 PhoneNumberNotLinkedException(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
- }
-
- // Find contact
- Contact managedContact = this.getEntityManager().find(UserContact.class, contact.getContactId());
-
- // Remove it from contact
- managedContact.setContactFaxNumber(null);
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkFaxDataFromContact: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N
-
- // Return it
- return managedContact;
- }
-
- @Override
- 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
-
- // 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 PhoneNumberNotLinkedException(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
- }
-
- // Find contact
- Contact managedContact = this.getEntityManager().find(UserContact.class, contact.getContactId());
-
- // Remove it from contact
- managedContact.setContactLandLineNumber(null);
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkLandLineDataFromContact: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N
-
- // Return it
- return managedContact;
- }
-
- @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().getPhoneId() == null) {
- // Throw NPE again
- throw new NullPointerException("contact.contactMobileNumber.phoneId is null"); //NOI18N
- } else if (contact.getContactMobileNumber().getPhoneId() < 1) {
- // Invalid id number
- 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.contactMobileNumber.phoneId={0} and mobileNumber.phoneId={1} are not the same.", contact.getContactMobileNumber().getPhoneId(), mobileNumber.getPhoneId())); //NOI18N
- }
-
- // Find contact
- Contact managedContact = this.getEntityManager().find(UserContact.class, contact.getContactId());
-
- // Remove it from contact
- managedContact.setContactMobileNumber(null);
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkMobileDataFromContact: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N
-
- // Return it
- return managedContact;
- }
-
-}