*/
void copyUserToController ();
+ /**
+ * Returns a message key depending on if this contact is a user and/or a
+ * contact. If this contact is unused, a default key is returned.
+ * <p>
+ * @param contact Contact instance to check
+ * <p>
+ * @return Message key
+ */
+ String getContactUsageMessageKey (final Contact contact);
+
/**
* Getter for contact instance
* <p>
private static final long serialVersionUID = 17_258_793_567_145_701L;
/**
- * Admin contact controller
+ * Administrative contact controller
*/
@Inject
private AddressbookAdminContactWebRequestController adminContactController;
/**
- * Admin user controller
+ * Administrative user controller
*/
@Inject
private AddressbookAdminUserWebRequestController adminUserController;
@Override
public void copyContactToController () {
// Log message
- System.out.println("AdminHelper::copyContactToController - CALLED!"); //NOI18N
+ //* NOISY-DEBUG: */ System.out.println("AdminHelper::copyContactToController - CALLED!"); //NOI18N
// Validate user instance
if (this.getContact() == null) {
this.adminContactController.copyContactToController(this.getContact());
// Log message
- System.out.println("AdminHelper::copyContactToController - EXIT!"); //NOI18N
+ //* NOISY-DEBUG: */ System.out.println("AdminHelper::copyContactToController - EXIT!"); //NOI18N
}
@Override
public void copyUserToController () {
+ // Log message
+ //* NOISY-DEBUG: */ System.out.println("AdminHelper::copyUserToController - CALLED!"); //NOI18N
+
// Validate user instance
if (this.getUser() == null) {
// Throw NPE
- throw new NullPointerException("this.user is null");
+ throw new NullPointerException("this.user is null"); //NOI18N
} else if (this.getUser().getUserId() == null) {
// Throw NPE again
- throw new NullPointerException("this.user.userId is null");
+ throw new NullPointerException("this.user.userId is null"); //NOI18N
} else if (this.getUser().getUserId() < 1) {
// Not valid
- throw new IllegalStateException(MessageFormat.format("this.user.userId={0} is not valid.", this.getUser().getUserId()));
+ throw new IllegalStateException(MessageFormat.format("this.user.userId={0} is not valid.", this.getUser().getUserId())); //NOI18N
}
// Set all fields: user
this.adminUserController.setUserName(this.getUser().getUserName());
// Log message
- System.out.println("AdminHelper::copyUserToController - EXIT!"); //NOI18N
+ //* NOISY-DEBUG: */ System.out.println("AdminHelper::copyUserToController - EXIT!"); //NOI18N
}
@Override
this.contact = contact;
}
+ @Override
+ public String getContactUsageMessageKey (final Contact contact) {
+ // The contact must be valid
+ if (null == contact) {
+ // Throw NPE
+ throw new NullPointerException("contact is null"); //NOI18N
+ } else if (contact.getContactId() == null) {
+ // Throw again ...
+ throw new NullPointerException("contact.contactId is null"); //NOI18N
+ } else if (contact.getContactId() < 1) {
+ // Not valid
+ throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
+ }
+
+ // Default key is "unused"
+ String messageKey = "CONTACT_IS_UNUSED"; //NOI18N
+
+ // Check user/customer
+ boolean isUserContact = this.adminUserController.isContactFound(contact);
+
+ // Check user first
+ if (isUserContact) {
+ // Only user
+ messageKey = "CONTACT_IS_USER"; //NOI18N
+ }
+
+ // Return message key
+ return messageKey;
+ }
+
@Override
public User getUser () {
return this.user;
import javax.inject.Inject;
import javax.inject.Named;
import org.mxchange.addressbook.beans.login.AddressbookUserLoginWebSessionController;
-import org.mxchange.addressbook.beans.user.AddressbookUserWebSessionController;
+import org.mxchange.addressbook.beans.user.AddressbookAdminUserWebRequestController;
import org.mxchange.jusercore.exceptions.UserNotFoundException;
import org.mxchange.jusercore.model.user.User;
import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
private static final long serialVersionUID = 187_687_145_286_710L;
/**
- * Login controller
+ * User controller
*/
@Inject
- private AddressbookUserLoginWebSessionController loginController;
+ private AddressbookAdminUserWebRequestController adminUserController;
/**
- * User controller
+ * Login controller
*/
@Inject
- private AddressbookUserWebSessionController userController;
+ private AddressbookUserLoginWebSessionController loginController;
@Override
public boolean isProfileLinkVisibleById (final Long userId) {
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);
} 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 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 AddressbookAdminUserWebRequestController 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>
package org.mxchange.addressbook.beans.user;
import java.text.MessageFormat;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
import java.util.Objects;
import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
import org.mxchange.jusercore.events.user.update.UpdatedUserPersonalDataEvent;
import org.mxchange.jusercore.events.user.update.UserUpdatedPersonalDataEvent;
-import org.mxchange.jusercore.exceptions.UserNotFoundException;
import org.mxchange.jusercore.exceptions.UserPasswordMismatchException;
import org.mxchange.jusercore.model.user.LoginUser;
import org.mxchange.jusercore.model.user.User;
*/
private String userName;
- /**
- * User name list
- */
- private List<String> userNameList;
-
/**
* User password (unencrypted from web form)
*/
*/
private ProfileMode userProfileMode;
- /**
- * A list of all public user profiles
- */
- private List<User> visibleUserList;
-
/**
* Default constructor
*/
// 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
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());
// Trace message
- 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
*/
@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.loginController.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
- User localUser = null;
-
- // Clear this bean
- this.clear();
-
- // Try to lookup it in visible user list
- for (final Iterator<User> iterator = this.visibleUserList.iterator(); iterator.hasNext();) {
- // Get next user
- User next = iterator.next();
-
- // Is the user id found?
- if (Objects.equals(next.getUserId(), userId)) {
- // Copy to other variable
- localUser = next;
- break;
- }
- }
-
- // Is it still null?
- if (null == localUser) {
- // Not visible for the current user
- throw new UserNotFoundException(userId);
- }
-
- // Copy all data to this bean
- this.copyUser(localUser);
-
- // Return it
- 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.addressbook.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;
import org.mxchange.jusercore.model.user.User;
import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
*/
public static final Integer MINIMUM_PASSWORD_LENGTH = 5;
- /**
- * 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.
- * <p>
- * @param userId User id
- * <p>
- * @return User instance
- * <p>
- * @throws UserNotFoundException If the user is not found
- */
- User lookupUserById (final Long userId) throws UserNotFoundException;
-
/**
* Event observer for new user registrations
* <p>
*/
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>