X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2Fjava%2Forg%2Fmxchange%2Fjcontacts%2Fphone%2FAddressbookAdminContactPhoneSessionBean.java;h=8e4d9b91b985aaad8a78422e43aeeb946f211f1b;hb=e80ad0d5887655b45603464421805999a24f525e;hp=bd159b623e611c0632bfd9cc17ca3d668c831047;hpb=e68a17a065db056aa11cfab06200358089fccfd0;p=addressbook-mailer-ejb.git
diff --git a/src/java/org/mxchange/jcontacts/phone/AddressbookAdminContactPhoneSessionBean.java b/src/java/org/mxchange/jcontacts/phone/AddressbookAdminContactPhoneSessionBean.java
index bd159b6..8e4d9b9 100644
--- a/src/java/org/mxchange/jcontacts/phone/AddressbookAdminContactPhoneSessionBean.java
+++ b/src/java/org/mxchange/jcontacts/phone/AddressbookAdminContactPhoneSessionBean.java
@@ -16,18 +16,22 @@
*/
package org.mxchange.jcontacts.phone;
+import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
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.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
+import org.mxchange.jcontacts.contact.Contact;
+import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
+import org.mxchange.jphone.exceptions.MobileNumberNotLinkedException;
+import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
/**
* A session EJB for administrative contact's phone number purposes
*
* @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 data")
public class AddressbookAdminContactPhoneSessionBean extends BaseAddressbookDatabaseBean implements AdminContactsPhoneSessionBeanRemote {
/**
@@ -35,97 +39,52 @@ public class AddressbookAdminContactPhoneSessionBean extends BaseAddressbookData
*/
private static final long serialVersionUID = 189_217_561_460_237_108L;
- @Override
- public void deleteCellphoneData (final DialableCellphoneNumber cellPhoneNumber) {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteCellphoneData: cellPhoneNumber={1} - CALLED!", this.getClass().getSimpleName(), cellPhoneNumber));
-
- // Is all data set
- if (null == cellPhoneNumber) {
- // Not set, throw NPE
- throw new NullPointerException("cellphoneNumber is null"); //NOI18N
- } else if (cellPhoneNumber.getPhoneId() == null) {
- // Throw NPE again
- throw new NullPointerException("cellphoneNumber.phoneId is null"); //NOI18N
- } else if (cellPhoneNumber.getPhoneId() < 1) {
- // Invalid number
- throw new IllegalArgumentException(MessageFormat.format("cellphoneNumber.phoneId={0} is not valid", cellPhoneNumber.getPhoneId())); //NOI18N
- } else if (cellPhoneNumber.getCellphoneProvider() == null) {
- // Throw NPE
- throw new NullPointerException("cellphoneNumber.cellphoneProvider is null"); //NOI18N
- } else if (cellPhoneNumber.getCellphoneProvider().getProviderId() == null) {
- // ... throw again
- throw new NullPointerException("cellphoneNumber.cellphoneProvider.providerId is null"); //NOI18N
- } else if (cellPhoneNumber.getCellphoneProvider().getProviderId() < 1) {
- // Id not valid
- throw new IllegalArgumentException(MessageFormat.format("cellphoneNumber.cellphoneProvider.providerId={0} is not valid.", cellPhoneNumber.getCellphoneProvider().getProviderId())); //NOI18N
- } else if (cellPhoneNumber.getPhoneNumber() == null) {
- // Throw NPE again
- throw new NullPointerException("cellphoneNumber.phoneNumber is null"); //NOI18N
- } else if (cellPhoneNumber.getPhoneNumber() < 1) {
- // Throw NPE again
- throw new NullPointerException(MessageFormat.format("cellphoneNumber.phoneNumber={0} is not valid.", cellPhoneNumber.getPhoneNumber())); //NOI18N
- }
-
- // Remove it from database
- this.getEntityManager().remove(cellPhoneNumber);
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteCellphoneData: EXIT!", this.getClass().getSimpleName()));
- }
+ /**
+ * Contact EJB
+ */
+ @EJB
+ private ContactSessionBeanRemote contactBean;
@Override
- public DialableCellphoneNumber updateCellphoneData (final DialableCellphoneNumber cellPhoneNumber) {
+ public Contact unlinkMobileDataFromContact (final Contact contact, final DialableMobileNumber mobileNumber) throws MobileNumberNotLinkedException {
// Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateCellphoneData: cellPhoneNumber={1} - CALLED!", this.getClass().getSimpleName(), cellPhoneNumber));
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkMobileDataFromContact: contact={1},mobileNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, mobileNumber)); //NOI18N
- // Is all data set
- if (null == cellPhoneNumber) {
- // Not set, throw NPE
- throw new NullPointerException("cellphoneNumber is null"); //NOI18N
- } else if (cellPhoneNumber.getPhoneId() == null) {
- // Throw NPE again
- throw new NullPointerException("cellphoneNumber.phoneId is null"); //NOI18N
- } else if (cellPhoneNumber.getPhoneId() < 1) {
- // Invalid number
- throw new IllegalArgumentException(MessageFormat.format("cellphoneNumber.phoneId={0} is not valid", cellPhoneNumber.getPhoneId())); //NOI18N
- } else if (cellPhoneNumber.getCellphoneProvider() == null) {
+ // Is the contact set?
+ if (null == contact) {
// Throw NPE
- throw new NullPointerException("cellphoneNumber.cellphoneProvider is null"); //NOI18N
- } else if (cellPhoneNumber.getCellphoneProvider().getProviderId() == null) {
- // ... throw again
- throw new NullPointerException("cellphoneNumber.cellphoneProvider.providerId is null"); //NOI18N
- } else if (cellPhoneNumber.getCellphoneProvider().getProviderId() < 1) {
- // Id not valid
- throw new IllegalArgumentException(MessageFormat.format("cellphoneNumber.cellphoneProvider.providerId={0} is not valid.", cellPhoneNumber.getCellphoneProvider().getProviderId())); //NOI18N
- } else if (cellPhoneNumber.getPhoneNumber() == null) {
- // Throw NPE again
- throw new NullPointerException("cellphoneNumber.phoneNumber is null"); //NOI18N
- } else if (cellPhoneNumber.getPhoneNumber() < 1) {
+ 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 MobileNumberNotLinkedException(mobileNumber);
+ } else if (contact.getContactMobileNumber().getPhoneId() == null) {
// Throw NPE again
- throw new NullPointerException(MessageFormat.format("cellphoneNumber.phoneNumber={0} is not valid.", cellPhoneNumber.getPhoneNumber())); //NOI18N
+ throw new NullPointerException("contact.contactCellphoneNumber.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
+ } 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
}
- // Set updated timestamp
- cellPhoneNumber.setPhoneEntryUpdated(new GregorianCalendar());
-
- // Get contact from it and find it
- DialableCellphoneNumber foundNumber = this.getEntityManager().find(cellPhoneNumber.getClass(), cellPhoneNumber.getPhoneId());
-
- // Should be found
- assert (foundNumber instanceof DialableCellphoneNumber) : MessageFormat.format("Cell phone number with id {0} not found, but should be.", cellPhoneNumber.getPhoneId()); //NOI18N
-
- // Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateCellphoneData: foundNumber.phoneId={0}", foundNumber.getPhoneId())); //NOI18N
+ // Remove it from contact
+ contact.setContactMobileNumber(null);
- // Merge contact instance
- DialableCellphoneNumber detachedNumber = this.getEntityManager().merge(foundNumber);
+ // Update database
+ Contact updatedContact = this.contactBean.updateContactData(contact);
// Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateCellphoneData: detachedNumber={1} - EXIT!", this.getClass().getSimpleName(), detachedNumber)); //NOI18N
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkMobileDataFromContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N
// Return it
- return detachedNumber;
+ return updatedContact;
}
}