]> git.mxchange.org Git - addressbook-war.git/blobdiff - src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionBean.java
Fixed JNDI names + converter
[addressbook-war.git] / src / java / org / mxchange / addressbook / beans / user / AddressbookUserWebSessionBean.java
index f20cb812c0c31ec48cca435e3cb2221603b69d2c..7f369991c294c670f65401c799419a68579c2956 100644 (file)
@@ -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<User> allUsers = this.allUsers();
 
                // Get all contacts
-               List<Contact> allContacts = this.contactController.allContacts();
+               List<Contact> allContacts = this.contactBean.getAllContacts();
 
                // Get iterator
                Iterator<Contact> 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();
        }
 
        /**