X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2Fjava%2Forg%2Fmxchange%2Faddressbook%2Fbeans%2Fuser%2FAddressbookUserWebSessionBean.java;h=7f369991c294c670f65401c799419a68579c2956;hb=2a5c341d985ae0a9264498de9979ae9fcce07212;hp=f20cb812c0c31ec48cca435e3cb2221603b69d2c;hpb=266040fb89a82537b788a9d38b5a9c295c3a42d3;p=addressbook-war.git diff --git a/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionBean.java b/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionBean.java index f20cb812..7f369991 100644 --- a/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionBean.java +++ b/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionBean.java @@ -35,9 +35,8 @@ import javax.naming.NamingException; import org.mxchange.addressbook.beans.contact.AddressbookContactWebSessionController; import org.mxchange.addressbook.beans.login.AddressbookUserLoginWebSessionController; import org.mxchange.jcontacts.contact.Contact; -import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber; -import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; -import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; +import org.mxchange.jcontacts.contact.ContactSessionBeanRemote; +import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent; import org.mxchange.jusercore.events.login.UserLoggedInEvent; import org.mxchange.jusercore.events.registration.UserRegisteredEvent; import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent; @@ -65,6 +64,11 @@ public class AddressbookUserWebSessionBean implements AddressbookUserWebSessionC */ private static final long serialVersionUID = 542_145_347_916L; + /** + * Contact EJB + */ + private ContactSessionBeanRemote contactBean; + /** * General contact controller */ @@ -151,12 +155,36 @@ public class AddressbookUserWebSessionBean implements AddressbookUserWebSessionC // Try to lookup this.userBean = (UserSessionBeanRemote) context.lookup("java:global/addressbook-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N + + // Try to lookup + this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/addressbook-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N } catch (final NamingException e) { // Throw again throw new FaceletException(e); } } + @Override + public void afterAdminAddedContact (@Observes final AdminAddedContactEvent event) { + // The event must be valid + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getAddedContact()== null) { + // Throw again ... + throw new NullPointerException("event.addedContact is null"); //NOI18N + } else if (event.getAddedContact().getContactId() == null) { + // ... and again + throw new NullPointerException("event.addedContact.customerId is null"); //NOI18N + } else if (event.getAddedContact().getContactId() < 1) { + // Not valid + throw new IllegalArgumentException(MessageFormat.format("event.addedContact.customerId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N //NOI18N + } + + // Call other method + this.selectableContacts.add(event.getAddedContact()); + } + @Override public void afterAdminAddedUserEvent (@Observes final AdminAddedUserEvent event) { // Trace message @@ -511,7 +539,7 @@ public class AddressbookUserWebSessionBean implements AddressbookUserWebSessionC List allUsers = this.allUsers(); // Get all contacts - List allContacts = this.contactController.allContacts(); + List allContacts = this.contactBean.getAllContacts(); // Get iterator Iterator iterator = allContacts.iterator(); @@ -698,15 +726,19 @@ public class AddressbookUserWebSessionBean implements AddressbookUserWebSessionC * @param user User instance */ private void copyUser (final User user) { + // Make sure the instance is valid + if (null == user) { + // Throw NPE + throw new NullPointerException("user is null"); //NOI18N + } else if (user.getUserContact() == null) { + // Throw again ... + throw new NullPointerException("user.userContact is null"); //NOI18N + } + // Copy all fields: // - base data this.setUserId(user.getUserId()); this.setUserProfileMode(user.getUserProfileMode()); - - // Get cellphone, phone and fax instance - DialableCellphoneNumber cellphone = user.getUserContact().getContactCellphoneNumber(); - DialableFaxNumber fax = user.getUserContact().getContactFaxNumber(); - DialableLandLineNumber phone = user.getUserContact().getContactLandLineNumber(); } /**