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=93a52e5fb9b569676512b5001c692bcc56fe346e;hpb=689450faac9a73646d7ded0b3995e696467ee457;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 93a52e5f..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 @@ -364,6 +392,33 @@ public class AddressbookUserWebSessionBean implements AddressbookUserWebSessionC return localUser; } + @Override + public User createUserLogin () { + // Trace message + //* NOISY-DEBUG */ System.out.println(MessageFormat.format("{0}.createUserLogin: CALLED!", this.getClass().getSimpleName())); + + // Is all data set? + if (this.getUserName() == null) { + // Throw NPE + throw new NullPointerException("recruiterName is null"); //NOI18N + } else if (this.getUserName().isEmpty()) { + // Is empty + throw new IllegalStateException("recruiterName is empty."); //NOI18N + } + + // Create new recruiter instance + User recruiter = new LoginUser(); + + // Update all data ... + recruiter.setUserName(this.getUserName()); + + // Trace message + //* NOISY-DEBUG */ System.out.println(MessageFormat.format("{0}.createUserLogin: recruiter={1} - EXIT!", this.getClass().getSimpleName(), recruiter)); + + // Return the new instance + return recruiter; + } + @Override public String doChangePersonalData () { // This method shall only be called if the user is logged-in @@ -484,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(); @@ -671,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(); } /**