import javax.inject.Inject;
import javax.inject.Named;
import org.mxchange.jjobs.beans.login.JobsUserLoginWebSessionController;
+import org.mxchange.jjobs.beans.user.JobsAdminUserWebRequestController;
import org.mxchange.jjobs.beans.user.JobsUserWebSessionController;
import org.mxchange.jusercore.exceptions.UserNotFoundException;
import org.mxchange.jusercore.model.user.User;
*/
private static final long serialVersionUID = 187_687_145_286_710L;
+ /**
+ * Administrative user controller
+ */
+ @Inject
+ private JobsAdminUserWebRequestController adminUserController;
+
/**
* User controller
*/
try {
// Try to get it
- u = this.userController.lookupUserById(userId);
+ u = this.adminUserController.lookupUserById(userId);
} catch (final UserNotFoundException ex) {
// Throw again
throw new FaceletException(ex);
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.mxchange.jjobs.beans.contact.JobsContactWebSessionController;
+import org.mxchange.jjobs.beans.user.JobsAdminUserWebRequestController;
import org.mxchange.jjobs.beans.user.JobsUserWebSessionController;
import org.mxchange.jusercore.events.registration.RegisteredUserEvent;
import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
*/
private static final long serialVersionUID = 47_828_986_719_691_592L;
+ /**
+ * User controller
+ */
+ @Inject
+ private JobsAdminUserWebRequestController adminUserController;
+
/**
* User controller
*/
} else if (!this.userController.isRequiredPersonalDataSet()) {
// Not all required fields are set
throw new FaceletException("Not all required fields are set."); //NOI18N
- } else if (this.userController.isUserNameRegistered(user)) {
+ } else if (this.adminUserController.isUserNameRegistered(user)) {
// User name is already used
throw new FaceletException(new UserNameAlreadyRegisteredException(user));
} else if (this.contactController.isEmailAddressRegistered(user.getUserContact())) {
import org.mxchange.jcontacts.contact.Contact;
import org.mxchange.jjobs.beans.contact.JobsContactWebSessionController;
import org.mxchange.jjobs.beans.helper.JobsAdminWebRequestController;
+import org.mxchange.jjobs.beans.login.JobsUserLoginWebSessionController;
import org.mxchange.jusercore.container.login.UserLoginContainer;
+import org.mxchange.jusercore.events.login.UserLoggedInEvent;
+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.update.AdminUpdatedUserDataEvent;
@Inject
private JobsContactWebSessionController contactController;
+ /**
+ * A list of all selectable contacts
+ */
+ private List<Contact> selectableContacts;
+
/**
* An event fired when the administrator has updated a new user
*/
*/
private List<User> userList;
+ /**
+ * Login bean (controller)
+ */
+ @Inject
+ private JobsUserLoginWebSessionController userLoginController;
+
/**
* User name
*/
private String userName;
+ /**
+ * User name list
+ */
+ private List<String> userNameList;
+
/**
* User password (unencrypted from web form)
*/
*/
private String userPasswordRepeat;
+ /**
+ * A list of all public user profiles
+ */
+ private List<User> visibleUserList;
+
/**
* Default constructor
*/
// Is the user name or email address used already?
// @TODO Add password length check
- if (this.userController.isUserNameRegistered(user)) {
+ if (this.isUserNameRegistered(user)) {
// User name is already used
throw new FaceletException(new UserNameAlreadyRegisteredException(user));
} else if ((this.adminHelper.getContact() == null) && (this.contactController.isEmailAddressRegistered(user.getUserContact()))) {
return "admin_list_user"; //NOI18N
}
+ @Override
+ public void afterRegistrationEvent (@Observes final UserRegisteredEvent event) {
+ // Trace message
+ //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterRegistration: event={0} - CALLED!", event)); //NOI18N
+
+ // event should not be null
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getRegisteredUser() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.user is null"); //NOI18N
+ } else if (event.getRegisteredUser().getUserId() == null) {
+ // userId is null
+ throw new NullPointerException("event.user.userId is null"); //NOI18N
+ } else if (event.getRegisteredUser().getUserId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
+ }
+
+ // Get user instance
+ User registeredUser = event.getRegisteredUser();
+
+ // Debug message
+ //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterRegistration: registeredUser={0}", registeredUser)); //NOI18N
+ // Add user name
+ this.addUserName(registeredUser);
+
+ // Clear all data
+ this.clear();
+
+ // Add user to local list
+ this.userList.add(registeredUser);
+
+ // Is the account public?
+ if (Objects.equals(registeredUser.getUserProfileMode(), ProfileMode.PUBLIC)) {
+ // Also add it to this list
+ this.visibleUserList.add(registeredUser);
+ }
+
+ // Trace message
+ //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterRegistration: EXIT!"); //NOI18N
+ }
+
+ @Override
+ public void afterUserLogin (final @Observes UserLoggedInEvent event) {
+ // Trace message
+ //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterUserLogin: event={0} - CALLED!", event)); //NOI18N
+
+ // event should not be null
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getLoggedInUser() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.user is null"); //NOI18N
+ } else if (event.getLoggedInUser().getUserId() == null) {
+ // userId is null
+ throw new NullPointerException("event.user.userId is null"); //NOI18N
+ } else if (event.getLoggedInUser().getUserId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
+ }
+
+ // Re-initialize list
+ this.visibleUserList = this.userBean.allMemberPublicVisibleUsers();
+
+ // Trace message
+ //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterUserLogin: this.visibleUserList.size()={0} - EXIT!", this.visibleUserList.size())); //NOI18N
+ }
+
@Override
public void afterUserUpdatedPersonalData (@Observes final UpdatedUserPersonalDataEvent event) {
// Check parameter
return Collections.unmodifiableList(this.userList);
}
+ @Override
+ public List<User> allVisibleUsers () {
+ // Return it
+ return Collections.unmodifiableList(this.visibleUserList);
+ }
+
@Override
public String editUserData () {
// Get user instance
public void init () {
// Initialize user list
this.userList = this.userBean.allUsers();
+
+ // Get full user name list for reducing EJB calls
+ this.userNameList = this.userBean.getUserNameList();
+
+ // Is the user logged-in?
+ if (this.userLoginController.isUserLoggedIn()) {
+ // Is logged-in, so load also users visible to memebers
+ this.visibleUserList = this.userBean.allMemberPublicVisibleUsers();
+ } else {
+ // Initialize user list
+ this.visibleUserList = this.userBean.allPublicUsers();
+ }
+
+ // Get all users
+ List<User> allUsers = this.allUsers();
+
+ // Get all contacts
+ List<Contact> allContacts = this.contactController.allContacts();
+
+ // 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
return isFound;
}
+ @Override
+ public boolean isUserNameRegistered (final User user) {
+ return ((this.userNameList instanceof List) && (this.userNameList.contains(user.getUserName())));
+ }
+
+ @Override
+ public boolean isVisibleUserFound () {
+ return ((this.visibleUserList instanceof List) && (this.visibleUserList.size() > 0));
+ }
+
@Override
public User lookupUserById (final Long userId) throws UserNotFoundException {
// Parameter must be valid
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,
+ * <p>
+ * @param user User instance
+ */
+ private void addUserName (final User user) {
+ // Make sure the entry is not added yet
+ if (this.userNameList.contains(user.getUserName())) {
+ // Abort here
+ throw new IllegalArgumentException(MessageFormat.format("User name {0} already added.", user.getUserName())); //NOI18N
+ } else if (this.contactController.isEmailAddressRegistered(user.getUserContact())) {
+ // Already added
+ throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", user.getUserContact().getContactEmailAddress())); //NOI18N
+ }
+
+ // Add user name
+ this.userNameList.add(user.getUserName());
+ }
+
+ /**
+ * Clears this bean
+ */
+ private void clear () {
+ // Clear all data
+ // - other data
+ this.setUserName(null);
+ this.setUserPassword(null);
+ this.setUserPasswordRepeat(null);
+ }
+
/**
* Checks if same password is entered and that they are not empty.
* <p>
import java.io.Serializable;
import java.util.List;
import org.mxchange.jcontacts.contact.Contact;
+import org.mxchange.jusercore.events.login.UserLoggedInEvent;
+import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
import org.mxchange.jusercore.events.user.update.UpdatedUserPersonalDataEvent;
import org.mxchange.jusercore.exceptions.UserNotFoundException;
import org.mxchange.jusercore.model.user.User;
*/
public interface JobsAdminUserWebRequestController extends Serializable {
+ /**
+ * Event observer for new user registrations
+ * <p>
+ * @param event User registration event
+ */
+ void afterRegistrationEvent (final UserRegisteredEvent event);
+
+ /**
+ * Event observer for logged-in user
+ * <p>
+ * @param event Event instance
+ */
+ void afterUserLogin (final UserLoggedInEvent event);
+
/**
* Listens to fired event when user updated personal data
* <p>
*/
boolean isContactFound (final Contact contact);
+ /**
+ * Checks whether a public user account is registered. This means that at
+ * least one user profile has its flag "public user profile" enabled.
+ * <p>
+ * @return Whether at least one user has a public profile
+ */
+ boolean isVisibleUserFound ();
+
+ /**
+ * Checks whether given user instance's name is used
+ * <p>
+ * @param user User instance's name to check
+ * <p>
+ * @return Whether it is already used
+ */
+ boolean isUserNameRegistered (final User user);
+
/**
* Tries to lookup user by given id number. If the user is not found or the
* account status is not CONFIRMED proper exceptions are thrown.
*/
List<User> allUsers ();
+ /**
+ * All public user profiles
+ * <p>
+ * @return A list of all public user profiles
+ */
+ List<User> allVisibleUsers ();
+
/**
* Checks whether users are registered
* <p>
*/
void setUserPasswordRepeat (final String userPasswordRepeat);
+ /**
+ * 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 ();
+
}
package org.mxchange.jjobs.beans.user;
import java.text.MessageFormat;
-import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
@Inject
private JobsContactWebSessionController contactController;
- /**
- * Login bean (controller)
- */
- @Inject
- private JobsUserLoginWebSessionController userLoginController;
-
- /**
- * A list of all selectable contacts
- */
- private List<Contact> selectableContacts;
-
/**
* Event being fired when user updated personal data
*/
private Long userId;
/**
- * User name
+ * Login bean (controller)
*/
- private String userName;
+ @Inject
+ private JobsUserLoginWebSessionController userLoginController;
/**
- * User name list
+ * User name
*/
- private List<String> userNameList;
+ private String userName;
/**
* User password (unencrypted from web form)
// Copy all data from registered->user
this.copyUser(registeredUser);
- // Add user name and email address
- this.addUserNameEmailAddress(registeredUser);
-
// Clear all data
this.clear();
// Set user id again
this.setUserId(registeredUser.getUserId());
- // Is the account public?
- if (Objects.equals(registeredUser.getUserProfileMode(), ProfileMode.PUBLIC)) {
- // Also add it to this list
- this.visibleUserList.add(registeredUser);
- }
-
// Trace message
//* NOISY-DEBUG: */ System.out.println("UserWebBean:afterRegistration: EXIT!"); //NOI18N
}
throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
}
- // Re-initialize list
- this.visibleUserList = this.userBean.allMemberPublicVisibleUsers();
-
// Copy all data to this bean
this.copyUser(event.getLoggedInUser());
//* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterUserLogin: this.visibleUserList.size()={0} - EXIT!", this.visibleUserList.size())); //NOI18N
}
- @Override
- public List<User> allVisibleUsers () {
- // Return it
- return Collections.unmodifiableList(this.visibleUserList);
- }
-
@Override
public User createUserInstance () {
// User message
*/
@PostConstruct
public void init () {
- // Get full user name list for reducing EJB calls
- this.userNameList = this.userBean.getUserNameList();
-
- // Is the user logged-in?
- if (this.userLoginController.isUserLoggedIn()) {
- // Is logged-in, so load also users visible to memebers
- this.visibleUserList = this.userBean.allMemberPublicVisibleUsers();
- } else {
- // Initialize user list
- this.visibleUserList = this.userBean.allPublicUsers();
- }
}
@Override
return ((this.getUserId() == null) || (this.getUserId() == 0));
}
- @Override
- public boolean isUserNameRegistered (final User user) {
- return ((this.userNameList instanceof List) && (this.userNameList.contains(user.getUserName())));
- }
-
- @Override
- public boolean isVisibleUserFound () {
- return ((this.visibleUserList instanceof List) && (this.visibleUserList.size() > 0));
- }
-
@Override
public User lookupUserById (final Long userId) throws UserNotFoundException {
// Init variable
return localUser;
}
- /**
- * Adds user's name and email address to bean's internal list. It also
- * updates the public user list if the user has decided to ha }
- * <p>
- * @param user User instance
- */
- private void addUserNameEmailAddress (final User user) {
- // Make sure the entry is not added yet
- if (this.userNameList.contains(user.getUserName())) {
- // Abort here
- throw new IllegalArgumentException(MessageFormat.format("User name {0} already added.", user.getUserName())); //NOI18N
- } else if (this.contactController.isEmailAddressRegistered(user.getUserContact())) {
- // Already added
- throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", user.getUserContact().getContactEmailAddress())); //NOI18N
- }
-
- // Add user name
- this.userNameList.add(user.getUserName());
-
- // Add email addres
- this.contactController.addEmailAddress(user.getUserContact().getContactEmailAddress());
- }
-
/**
* Clears this bean
*/
package org.mxchange.jjobs.beans.user;
import java.io.Serializable;
-import java.util.List;
import org.mxchange.jusercore.events.login.UserLoggedInEvent;
import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
import org.mxchange.jusercore.exceptions.UserNotFoundException;
*/
void afterUserLogin (final UserLoggedInEvent event);
- /**
- * All public user profiles
- * <p>
- * @return A list of all public user profiles
- */
- List<User> allVisibleUsers ();
-
/**
* Creates an instance from all properties
* <p>
*/
boolean isSamePasswordEntered ();
- /**
- * Checks whether given user instance's name is used
- * <p>
- * @param user User instance's name to check
- * <p>
- * @return Whether it is already used
- */
- boolean isUserNameRegistered (final User user);
-
- /**
- * Checks whether a public user account is registered. This means that at
- * least one user profile has its flag "public user profile" enabled.
- * <p>
- * @return Whether at least one user has a public profile
- */
- boolean isVisibleUserFound ();
-
/**
* Checks if the user id is empty
* <p>
<f:metadata>
<f:viewParam name="userId" value="#{adminHelper.user}" converter="UserConverter" required="true" requiredMessage="#{msg.ERROR_PARAMETER_USER_ID_NOT_SET}" />
+ <f:viewAction action="#{adminHelper.copyUserToController()}" />
</f:metadata>
<ui:composition template="/WEB-INF/templates/admin/admin_base.tpl">
<div class="table_right_medium">
<h:selectOneMenu class="select" id="userContact" value="#{adminHelper.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="#{adminUserController.selectableContacts()}" var="contact" itemValue="#{contact}" itemLabel="#{contact.contactId}: #{msg[contact.contactGender.messageKey]} #{contact.contactFirstName} #{contact.contactFamilyName}" />
</h:selectOneMenu>
</div>
<f:metadata>
<f:viewParam name="userId" value="#{adminHelper.user}" converter="UserConverter" required="true" requiredMessage="#{msg.ERROR_PARAMETER_USER_ID_NOT_SET}" />
+ <f:viewAction action="#{adminHelper.copyUserToController()}" />
</f:metadata>
<ui:composition template="/WEB-INF/templates/admin/admin_base.tpl">
<f:metadata>
<f:viewParam name="userId" value="#{adminHelper.user}" converter="UserConverter" required="true" requiredMessage="#{msg.ERROR_PARAMETER_USER_ID_NOT_SET}" />
+ <f:viewAction action="#{adminHelper.copyUserToController()}" />
</f:metadata>
<ui:composition template="/WEB-INF/templates/admin/admin_base.tpl">