]> git.mxchange.org Git - jfinancials-war.git/commitdiff
Continued with rewrites:
authorRoland Häder <roland@mxchange.org>
Mon, 6 Jun 2016 14:02:42 +0000 (16:02 +0200)
committerRoland Haeder <roland@mxchange.org>
Thu, 28 Jul 2016 19:29:21 +0000 (21:29 +0200)
- moved selectableContacts to contact controller, makes more sense
- fixed template for above
- introduced isGenderRequired() to make difference between general and administrative contact controller
- added new context parameter for above method
- fired event when a new user account has been linked with existing contact data
- the other event (added user) is being fired now on else path
- No more need for afterAdminAddedContact() in general user controller

Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/addressbook/beans/contact/AddressbookAdminContactWebRequestBean.java
src/java/org/mxchange/addressbook/beans/contact/AddressbookAdminContactWebRequestController.java
src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebSessionBean.java
src/java/org/mxchange/addressbook/beans/user/AddressbookAdminUserWebRequestBean.java
src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionBean.java
src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionController.java
web/admin/user/admin_user_list.xhtml

index 1151723fd5e1c7b308fdea34f884fd149cd655ed..6ff9817f414fe2e3f16abd54ada3d7b54a4313f9 100644 (file)
@@ -23,6 +23,7 @@ import javax.annotation.PostConstruct;
 import javax.enterprise.context.RequestScoped;
 import javax.enterprise.event.Event;
 import javax.enterprise.inject.Any;
+import javax.faces.context.FacesContext;
 import javax.faces.view.facelets.FaceletException;
 import javax.inject.Inject;
 import javax.inject.Named;
@@ -712,6 +713,18 @@ public class AddressbookAdminContactWebRequestBean extends BaseAddressbookContro
        public void init () {
        }
 
+       @Override
+       public boolean isGenderRequired () {
+               // Get context parameter
+               String contextParameter = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("is_admin_gender_enabled"); //NOI18N
+
+               // Is it set?
+               boolean isRequired = ((contextParameter instanceof String) && (contextParameter.toLowerCase().equals("true"))); //NOI18N
+
+               // Return value
+               return isRequired;
+       }
+
        /**
         * Clears this bean
         */
index 8d5d0a1962a61883a4f12873e9362f17151bab04..e32ca68b620f009127427aed80ee4ac9ddc59bda 100644 (file)
@@ -416,4 +416,12 @@ public interface AddressbookAdminContactWebRequestController extends Serializabl
         */
        String generateCellphoneNumber (final DialableCellphoneNumber cellphoneNumber);
 
+       /**
+        * Checks/returns whether the gender/salutation is required for this
+        * controller.
+        * <p>
+        * @return Whether gender is required
+        */
+       boolean isGenderRequired ();
+
 }
index adbda5c4895b090b87591f370a4b73139ad1e3bf..9dd53aad2ef98f15eb4ade0a78fc960805e63263 100644 (file)
@@ -224,6 +224,9 @@ public class AddressbookContactWebSessionBean extends BaseAddressbookController
 
        @Override
        public void afterAdminAddedContact (@Observes final AdminAddedContactEvent event) {
+               // Trace message
+               /* NOISY-DEBUG: */ System.out.println(MessageFormat.format("contactController.afterAdminAddedContact(): event={0} - CALLED!", event)); //NOI18N
+
                // The event must be valid
                if (null == event) {
                        // Throw NPE
@@ -469,6 +472,7 @@ public class AddressbookContactWebSessionBean extends BaseAddressbookController
 
                // Debug message
                //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: this.emailAddress={1}", this.getClass().getSimpleName(), this.getEmailAddress()));
+
                // Don't set null or wrong references
                if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getPhoneAreaCode() != null) && (this.getPhoneNumber() != null) && (this.getPhoneAreaCode() > 0) && (this.getPhoneNumber() > 0)) {
                        // Now the number must be given
index d93dc8a69f0432ed5dfc51663a7b9e9ee54c01ec..13ec9882fe2eaf8c0eb7b6d73589a45bfec888b9 100644 (file)
@@ -37,6 +37,8 @@ import org.mxchange.jusercore.container.login.UserLoginContainer;
 import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
 import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
 import org.mxchange.jusercore.events.user.add.AdminUserAddedEvent;
+import org.mxchange.jusercore.events.user.linked.AdminLinkedUserEvent;
+import org.mxchange.jusercore.events.user.linked.AdminUserLinkedEvent;
 import org.mxchange.jusercore.events.user.update.AdminUpdatedUserDataEvent;
 import org.mxchange.jusercore.events.user.update.AdminUserDataUpdatedEvent;
 import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException;
@@ -100,6 +102,14 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookControlle
        @Inject
        private AddressbookUserWebSessionController userController;
 
+       /**
+        * An event fired when the administrator has linked a user with existing
+        * contact data.
+        */
+       @Inject
+       @Any
+       private Event<AdminLinkedUserEvent> userLinkedEvent;
+
        /**
         * User name
         */
@@ -228,32 +238,29 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookControlle
                // Encrypt password and set it
                user.setUserEncryptedPassword(UserUtils.encryptPassword(password));
 
-               // Init updated user instance
-               User updatedUser = null;
-
                try {
                        // Now, that all is set, call EJB
                        if (this.beanHelper.getContact() instanceof Contact) {
                                // Link contact with this user
-                               updatedUser = this.userBean.linkUser(user);
+                               User updatedUser = this.userBean.linkUser(user);
+
+                               // Fire event
+                               this.userLinkedEvent.fire(new AdminUserLinkedEvent(updatedUser));
 
                                // Remove contact instance
                                this.beanHelper.setContact(null);
                        } else {
                                // Add new contact
-                               updatedUser = this.userBean.addUser(user);
+                               User updatedUser = this.userBean.addUser(user);
+
+                               // Fire event
+                               this.addedUserEvent.fire(new AdminUserAddedEvent(updatedUser));
                        }
                } catch (final UserNameAlreadyRegisteredException | EmailAddressAlreadyRegisteredException ex) {
                        // Throw again
                        throw new FaceletException(ex);
                }
 
-               // Clear helper
-               this.beanHelper.setContact(null);
-
-               // Fire event
-               this.addedUserEvent.fire(new AdminUserAddedEvent(updatedUser));
-
                // Clear this bean
                this.clear();
 
index 25535651d460e4622d399ca489909a6352fde26d..7d624c3ccf5a1b91bdb3d04296c13f0f7be8199c 100644 (file)
@@ -40,7 +40,6 @@ import org.mxchange.addressbook.beans.login.AddressbookUserLoginWebSessionContro
 import org.mxchange.addressbook.beans.register.AddressbookUserRegisterWebSessionController;
 import org.mxchange.jcontacts.contact.Contact;
 import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
-import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent;
 import org.mxchange.jusercore.events.confirmation.UserConfirmedAccountEvent;
 import org.mxchange.jusercore.events.login.UserLoggedInEvent;
 import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
@@ -183,27 +182,6 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp
                }
        }
 
-       @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
@@ -502,19 +480,19 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp
        @Override
        public String doChangePersonalData () {
                // This method shall only be called if the user is logged-in
-               if (!this.loginController.isUserLoggedIn()) {
+               if (!this.userLoginController.isUserLoggedIn()) {
                        // Not logged-in
                        throw new IllegalStateException("User is not logged-in"); //NOI18N
                } else if (!this.isRequiredChangePersonalDataSet()) {
                        // Not all required fields are set
                        throw new FaceletException("Not all required fields are set."); //NOI18N
-               } else if (!this.loginController.ifCurrentPasswordMatches()) {
+               } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
                        // Password not matching
                        throw new FaceletException(new UserPasswordMismatchException(this.loginController.getLoggedInUser()));
                }
 
                // Get user instance
-               User user = this.loginController.getLoggedInUser();
+               User user = this.userLoginController.getLoggedInUser();
 
                // Copy contact data to contact instance
                this.contactController.updateContactDataFromController(user.getUserContact());
@@ -614,40 +592,6 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp
                        // Initialize user list
                        this.visibleUserList = this.userBean.allPublicUsers();
                }
-
-               // Get all users
-               List<User> allUsers = this.allUsers();
-
-               // Get all contacts
-               List<Contact> allContacts = this.contactBean.getAllContacts();
-
-               // Get iterator
-               Iterator<Contact> iterator = allContacts.iterator();
-
-               // Loop through it
-               while (iterator.hasNext()) {
-                       // Get next element
-                       Contact next = iterator.next();
-
-                       // Get iterator
-                       Iterator<User> userIterator = allUsers.iterator();
-
-                       // Loop through all users
-                       while (userIterator.hasNext()) {
-                               // Get user instance
-                               User nextUser = userIterator.next();
-
-                               // Is contact same?
-                               if (Objects.equals(next, nextUser.getUserContact())) {
-                                       // Found same
-                                       iterator.remove();
-                                       break;
-                               }
-                       }
-               }
-
-               // Set contact list
-               this.selectableContacts = allContacts;
        }
 
        @Override
@@ -842,11 +786,6 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp
                return user;
        }
 
-       @Override
-       public List<Contact> selectableContacts () {
-               return Collections.unmodifiableList(this.selectableContacts);
-       }
-
        /**
         * Adds user's name to bean's internal list. It also updates the public user
         * list if the user has decided to have a public account,
index 59ca6338d29542a10c4a3bb9093656f266e039b3..e7813b3cc458927e4f995a134bce9967bdbe29a5 100644 (file)
@@ -155,14 +155,6 @@ public interface AddressbookUserWebSessionController extends Serializable {
         */
        User lookupUserByEmailAddress (final String emailAddress) throws UserEmailAddressNotFoundException;
 
-       /**
-        * Returns a list of all selectable contacts for user creation. Contacts
-        * from already existing users are excluded in this list.
-        * <p>
-        * @return A list of all selectable contacts
-        */
-       List<Contact> selectableContacts ();
-
        /**
         * Creates an instance from all properties
         * <p>
index 745b1fda97fc028372b8622289cb5236bc0c4321..fbe3d66f39173606f0fd571d551fae117e9d0787 100644 (file)
                                                                <div class="table_right_medium">
                                                                        <h:selectOneMenu styleClass="select" id="userContact" value="#{beanHelper.contact}" converter="ContactConverter">
                                                                                <f:selectItem itemValue="" itemLabel="#{msg.NONE_SELECTED}" />
-                                                                               <f:selectItems value="#{userController.selectableContacts()}" var="contact" itemValue="#{contact}" itemLabel="#{contact.contactId}: #{msg[contact.contactGender.messageKey]} #{contact.contactFirstName} #{contact.contactFamilyName}" />
+                                                                               <f:selectItems value="#{contactController.selectableContacts()}" var="contact" itemValue="#{contact}" itemLabel="#{contact.contactId}: #{msg[contact.contactGender.messageKey]} #{contact.contactFirstName} #{contact.contactFamilyName}" />
                                                                        </h:selectOneMenu>
                                                                </div>