]> git.mxchange.org Git - pizzaservice-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:24:52 +0000 (21:24 +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/pizzaapplication/beans/contact/PizzaAdminContactWebRequestBean.java
src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestController.java
src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionBean.java
src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestBean.java
src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionBean.java
src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionController.java
web/admin/user/admin_user_list.xhtml

index 492105b43b0bd71e3394d6ca5b1b7cbefb38ea1c..d695462cddf4ac73ef1a20c4ca606224f9c57b43 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;
@@ -794,6 +795,18 @@ public class PizzaAdminContactWebRequestBean extends BasePizzaController impleme
        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 d05e34cd0f2709f1eb1a39ff25aef2612aa8da5e..905e64d51cf85844d93ae198cbe8d3aabe70884d 100644 (file)
@@ -448,4 +448,12 @@ public interface PizzaAdminContactWebRequestController extends Serializable {
         */
        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 e4a8e9f617c2d12bdcca68ceedd92fd80c4f7336..7af3f8523b497a6bc0f8cddb1a27f81736e0915c 100644 (file)
@@ -243,6 +243,9 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P
 
        @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
@@ -489,6 +492,7 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P
 
                // 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
@@ -548,6 +552,7 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P
 
                // Trace message
                //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: contact={1} - EXIT!", this.getClass().getSimpleName(), contact));
+
                // Return it
                return contact;
        }
index 6aaa25a2e8e4574a4cf9f2769d7bb0e026e5a5c5..74b127eb8bb0be7ead3d141aa92f489927ac1065 100644 (file)
@@ -34,6 +34,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 PizzaAdminUserWebRequestBean extends BasePizzaController implements
        @Inject
        private PizzaUserWebSessionController 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 PizzaAdminUserWebRequestBean extends BasePizzaController implements
                // 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 9f105bc4b2b227935551dd04dc31347e403a79bd..154e63e5785ea9326a7c6b82793bb380d89e8938 100644 (file)
@@ -35,7 +35,6 @@ import javax.naming.InitialContext;
 import javax.naming.NamingException;
 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;
@@ -172,27 +171,6 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz
                }
        }
 
-       @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
@@ -492,13 +470,13 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz
        @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.userLoginController.getLoggedInUser()));
                } else if (!this.featureController.isFeatureEnabled("edit_user_data")) {
@@ -507,7 +485,7 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz
                }
 
                // Get user instance
-               User user = this.loginController.getLoggedInUser();
+               User user = this.userLoginController.getLoggedInUser();
 
                // Copy contact data to contact instance
                this.contactController.updateContactDataFromController(user.getUserContact());
@@ -607,40 +585,6 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz
                        // 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
@@ -835,11 +779,6 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz
                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 63cbf2f4e274192e9db86167e9b6788ad60ab882..7d1275689b5217bb1cc8c80ddffe5311dd0cc1f3 100644 (file)
@@ -164,14 +164,6 @@ public interface PizzaUserWebSessionController 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 00a2eefe943676516000ab6a3e0c7ea72676f147..89f6c70dcdf08bac7cae6aa5225b6762c14e83f3 100644 (file)
                                                                        <h:selectOneMenu styleClass="select" id="userContact" value="#{beanHelper.contact}">
                                                                                <f:converter converterId="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>