import javax.faces.FacesException;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
-import javax.faces.view.facelets.FaceletException;
import javax.inject.Inject;
import javax.inject.Named;
import org.mxchange.jcontacts.model.contact.Contact;
import org.mxchange.jjobs.beans.contact.JobsAdminContactWebRequestController;
import org.mxchange.jjobs.beans.contact.JobsContactWebRequestController;
import org.mxchange.jjobs.beans.features.JobsFeaturesWebApplicationController;
+import org.mxchange.jjobs.beans.user.list.JobsUserListWebViewController;
import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
import org.mxchange.jusercore.events.user.created.ObservableCreatedUserEvent;
import org.mxchange.jusercore.events.user.locked.ObservableAdminLockedUserEvent;
import org.mxchange.jusercore.events.user.unlocked.AdminUnlockedUserEvent;
import org.mxchange.jusercore.events.user.unlocked.ObservableAdminUnlockedUserEvent;
-import org.mxchange.jusercore.events.user.update.AdminUpdatedUserDataEvent;
-import org.mxchange.jusercore.events.user.update.ObservableAdminUpdatedUserDataEvent;
+import org.mxchange.jusercore.events.user.update.post.AdminPostUserDataUpdatedEvent;
+import org.mxchange.jusercore.events.user.update.post.ObservableAdminPostUserDataUpdatedEvent;
import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException;
import org.mxchange.jusercore.exceptions.UserNameAlreadyRegisteredException;
import org.mxchange.jusercore.exceptions.UserNotFoundException;
*/
@Inject
@Any
- private Event<ObservableAdminUpdatedUserDataEvent> updatedUserDataEvent;
+ private Event<ObservableAdminPostUserDataUpdatedEvent> updatedUserDataEvent;
/**
* User instance
// @TODO Add password length check
if ((this.featureController.isFeatureEnabled("user_login_require_user_name")) && (this.userListController.isUserNameRegistered(newUser))) {
// User name is already used
- throw new FaceletException(new UserNameAlreadyRegisteredException(newUser));
+ throw new FacesException(new UserNameAlreadyRegisteredException(newUser));
} else if ((this.getContact() == null) && (this.contactController.isEmailAddressRegistered(newUser.getUserContact()))) {
// Email address is already used
this.showFacesMessage("admin_add_user:emailAddress", "ERROR_EMAIL_ADDRESS_ALREADY_USED", FacesMessage.SEVERITY_WARN); //NOI18N
return;
}
+ // Init variable
+ final User updatedUser;
+
try {
// Now, that all is set, call EJB
if (this.getContact() instanceof Contact) {
// Link contact with this user
- final User updatedUser = this.adminUserBean.linkUser(newUser);
-
- // Fire event
- this.userLinkedEvent.fire(new AdminLinkedUserEvent(updatedUser));
+ updatedUser = this.adminUserBean.linkUser(newUser);
} else {
// Add new user
- final User updatedUser = this.adminUserBean.addUser(newUser);
-
- // Fire event
- this.addedUserEvent.fire(new AdminAddedUserEvent(updatedUser));
+ updatedUser = this.adminUserBean.addUser(newUser);
}
} catch (final UserNameAlreadyRegisteredException | EmailAddressAlreadyRegisteredException ex) {
// Throw again
- throw new FaceletException(ex);
+ throw new FacesException(ex);
}
+ // Now, that all is set, call EJB
+ if (this.getContact() instanceof Contact) {
+ // Fire event
+ this.userLinkedEvent.fire(new AdminLinkedUserEvent(updatedUser));
+ } else {
+ // Fire event
+ this.addedUserEvent.fire(new AdminAddedUserEvent(updatedUser));
+ }
// Clear helper
this.setContact(null);
this.adminUserBean.deleteUser(this.getUser(), this.getUserDeleteReason());
} catch (final UserNotFoundException ex) {
// Should not happen, so throw again
- throw new FaceletException(ex);
+ throw new FacesException(ex);
}
// Fire event
final User updatedUser = this.userBean.updateUserData(this.getUser());
// Fire event
- this.updatedUserDataEvent.fire(new AdminUpdatedUserDataEvent(updatedUser));
+ this.updatedUserDataEvent.fire(new AdminPostUserDataUpdatedEvent(updatedUser));
}
/**
throw new FacesException(new UserStatusLockedException(this.getUser()));
} else if (this.getUser().getUserAccountStatus() == UserAccountStatus.UNCONFIRMED) {
// User account is locked
- throw new FaceletException(new UserStatusUnconfirmedException(this.getUser()));
+ throw new FacesException(new UserStatusUnconfirmedException(this.getUser()));
} else if (this.getUserLockReason() == null) {
// Throw NPE again
throw new NullPointerException("this.userLockReason is null"); //NOI18N
updatedUser = this.adminUserBean.lockUserAccount(this.getUser(), this.getUserLockReason(), baseUrl);
} catch (final UserStatusLockedException | UserStatusUnconfirmedException | UserNotFoundException ex) {
// Throw again
- throw new FaceletException(ex);
+ throw new FacesException(ex);
}
// Fire event
throw new FacesException(new UserStatusConfirmedException(this.getUser()));
} else if (this.getUser().getUserAccountStatus() == UserAccountStatus.UNCONFIRMED) {
// User account is locked
- throw new FaceletException(new UserStatusUnconfirmedException(this.getUser()));
+ throw new FacesException(new UserStatusUnconfirmedException(this.getUser()));
}
// Init updated user instance
updatedUser = this.adminUserBean.unlockUserAccount(this.getUser(), baseUrl);
} catch (final UserStatusConfirmedException | UserStatusUnconfirmedException | UserNotFoundException ex) {
// Throw again
- throw new FaceletException(ex);
+ throw new FacesException(ex);
}
// Fire event
password = UserLoginUtils.createRandomPassword(JobsUserWebRequestController.MINIMUM_PASSWORD_LENGTH);
} else if (!this.isSamePasswordEntered()) {
// Both passwords don't match
- throw new FaceletException(new UserPasswordRepeatMismatchException());
+ throw new FacesException(new UserPasswordRepeatMismatchException());
} else {
// Both match, so get it from this bean
password = this.getUserPassword();
}
// Create new instance
- final User newUser = new LoginUser(this.getUserName(), this.getUserProfileMode(), this.getUserMustChangePassword(), UserLoginUtils.encryptPassword(password), UserAccountStatus.CONFIRMED, userContact);
+ final User newUser = new LoginUser(
+ this.getUserName(),
+ this.getUserProfileMode(),
+ this.getUserMustChangePassword(),
+ UserLoginUtils.encryptPassword(password),
+ UserAccountStatus.CONFIRMED,
+ userContact
+ );
// Get locale from view-root
final Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();