From 451e34d2a064a7b3831094f44f61ba631530b171 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 6 Jun 2016 16:02:42 +0200 Subject: [PATCH] Continued with rewrites: - 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 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../JobsAdminContactWebRequestBean.java | 13 ++++++++ .../JobsAdminContactWebRequestController.java | 8 +++++ .../contact/JobsContactWebSessionBean.java | 3 ++ .../user/JobsAdminUserWebRequestBean.java | 13 +++++++- .../beans/user/JobsUserWebSessionBean.java | 31 ------------------- web/admin/user/admin_user_list.xhtml | 2 +- 6 files changed, 37 insertions(+), 33 deletions(-) diff --git a/src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestBean.java index 420ae887..8b93305b 100644 --- a/src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestBean.java @@ -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; @@ -728,6 +729,18 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement 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 */ diff --git a/src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestController.java b/src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestController.java index af2c64b7..e4c9484a 100644 --- a/src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestController.java +++ b/src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestController.java @@ -431,4 +431,12 @@ public interface JobsAdminContactWebRequestController extends Serializable { */ String generateCellphoneNumber (final DialableCellphoneNumber cellphoneNumber); + /** + * Checks/returns whether the gender/salutation is required for this + * controller. + *

+ * @return Whether gender is required + */ + boolean isGenderRequired (); + } diff --git a/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionBean.java b/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionBean.java index f40bb6f3..99117f9f 100644 --- a/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionBean.java +++ b/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionBean.java @@ -243,6 +243,9 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job @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 diff --git a/src/java/org/mxchange/jjobs/beans/user/JobsAdminUserWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/user/JobsAdminUserWebRequestBean.java index 682bdb2b..022e2b98 100644 --- a/src/java/org/mxchange/jjobs/beans/user/JobsAdminUserWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/user/JobsAdminUserWebRequestBean.java @@ -39,6 +39,7 @@ 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; @@ -119,6 +120,14 @@ public class JobsAdminUserWebRequestBean extends BaseJobsController implements J @Inject private JobsUserWebSessionController userController; + /** + * An event fired when the administrator has linked a user with existing + * contact data. + */ + @Inject + @Any + private Event userLinkedEvent; + /** * User lock reason */ @@ -284,6 +293,9 @@ public class JobsAdminUserWebRequestBean extends BaseJobsController implements J // Clear helper this.beanHelper.setContact(null); + // Clear this bean + this.clear(); + // Return to user list (for now) return "admin_list_user"; //NOI18N } @@ -313,7 +325,6 @@ public class JobsAdminUserWebRequestBean extends BaseJobsController implements J // Debug message //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterRegistration: registeredUser={0}", registeredUser)); //NOI18N - // Clear all data this.clear(); diff --git a/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java b/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java index c962011b..2040fcd4 100644 --- a/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java +++ b/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java @@ -597,37 +597,6 @@ public class JobsUserWebSessionBean extends BaseJobsController implements JobsUs // Initialize user list this.visibleUserList = this.userBean.allPublicUsers(); } - - // Get all users - List allUsers = this.allUsers(); - - // Get all contacts - List allContacts = this.contactBean.getAllContacts(); - - // Get iterator - Iterator iterator = allContacts.iterator(); - - // Loop through it - while (iterator.hasNext()) { - // Get next element - Contact next = iterator.next(); - - // Get iterator - Iterator 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; - } - } - } } @Override diff --git a/web/admin/user/admin_user_list.xhtml b/web/admin/user/admin_user_list.xhtml index 19327c8f..d00e40f1 100644 --- a/web/admin/user/admin_user_list.xhtml +++ b/web/admin/user/admin_user_list.xhtml @@ -105,7 +105,7 @@

- +
-- 2.39.5