From: Roland Häder <roland@mxchange.org>
Date: Thu, 25 Aug 2016 13:40:13 +0000 (+0200)
Subject: Please cherry-pick:
X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=638661ea913cbbad3047bbaf831b03ebb2a302f7;p=jjobs-ejb.git

Please cherry-pick:
- closed internal TODO: update new confirmation key in database + user instance

Signed-off-by: Roland Häder <roland@mxchange.org>
---

diff --git a/src/java/org/mxchange/jjobs/beans/resendlink/JobsResendLinkSessionBean.java b/src/java/org/mxchange/jjobs/beans/resendlink/JobsResendLinkSessionBean.java
index ee8ebb7..0411ef9 100644
--- a/src/java/org/mxchange/jjobs/beans/resendlink/JobsResendLinkSessionBean.java
+++ b/src/java/org/mxchange/jjobs/beans/resendlink/JobsResendLinkSessionBean.java
@@ -18,13 +18,20 @@ package org.mxchange.jjobs.beans.resendlink;
 
 import java.text.MessageFormat;
 import java.util.Locale;
+import javax.ejb.EJB;
 import javax.ejb.EJBException;
 import javax.ejb.Stateless;
 import javax.mail.Address;
 import javax.mail.internet.AddressException;
 import javax.mail.internet.InternetAddress;
 import org.mxchange.jjobs.database.BaseJobsDatabaseBean;
+import org.mxchange.jusercore.exceptions.UserNotFoundException;
+import org.mxchange.jusercore.exceptions.UserStatusConfirmedException;
+import org.mxchange.jusercore.exceptions.UserStatusLockedException;
+import org.mxchange.jusercore.model.register.UserRegistrationSessionBeanRemote;
+import org.mxchange.jusercore.model.user.LoginUser;
 import org.mxchange.jusercore.model.user.User;
+import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
 import org.mxchange.jusercore.model.user.status.UserAccountStatus;
 
 /**
@@ -40,8 +47,20 @@ public class JobsResendLinkSessionBean extends BaseJobsDatabaseBean implements R
 	 */
 	private static final long serialVersionUID = 71_546_726_857_195_360L;
 
+	/**
+	 * Registration bean
+	 */
+	@EJB
+	private UserRegistrationSessionBeanRemote registerBean;
+
+	/**
+	 * Regular user bean
+	 */
+	@EJB
+	private UserSessionBeanRemote userBean;
+
 	@Override
-	public void resendConfirmationLink (final User user, final Locale locale, final String baseUrl) {
+	public void resendConfirmationLink (final User user, final Locale locale, final String baseUrl) throws UserNotFoundException, UserStatusConfirmedException, UserStatusLockedException {
 		// Log trace message
 		this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.resendConfirmationLink: user={1},locale={2},baseUrl={3} - CALLED!", this.getClass().getSimpleName(), user, locale, baseUrl)); //NOI18N
 
@@ -55,25 +74,38 @@ public class JobsResendLinkSessionBean extends BaseJobsDatabaseBean implements R
 		} else if (user.getUserId() < 1) {
 			// Invalid id number
 			throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", user.getUserId())); //NOI18N
+		} else if (!this.userBean.ifUserExists(user)) {
+			// User not found
+			throw new UserNotFoundException(user);
 		} else if (user.getUserConfirmKey() == null) {
 			// Throw NPE again
 			throw new NullPointerException("this.userConfirmKey is null"); //NOI18N
-		} else if (user.getUserAccountStatus() != UserAccountStatus.UNCONFIRMED) {
+		} else if (user.getUserAccountStatus() == UserAccountStatus.CONFIRMED) {
+			// User account status is not UNCONFIRMED
+			throw new UserStatusConfirmedException(user);
+		} else if (user.getUserAccountStatus() == UserAccountStatus.LOCKED) {
 			// User account status is not UNCONFIRMED
-			throw new IllegalStateException(MessageFormat.format("Account status from user.userId={0} is not UNCONFIRMED:{1}", user.getUserId(), user.getUserAccountStatus())); //NOI18N
+			throw new UserStatusLockedException(user);
 		} else if (null == locale) {
 			// Locale should be set
 			throw new NullPointerException("locale is null"); //NOI18N
 		}
 
-		// @TODO Unfinished: Change key + merge database
+		// Get new registration key
+		String confirmationKey = this.registerBean.generateConfirmationKey(user);
+
+		// Get managed instance
+		User managedUser = this.getEntityManager().find(LoginUser.class, user.getUserId());
+
+		// Set it in user
+		managedUser.setUserConfirmKey(confirmationKey);
 
 		// Init variable
 		Address emailAddress;
 
 		try {
 			// Create email address and set
-			emailAddress = new InternetAddress(user.getUserContact().getContactEmailAddress());
+			emailAddress = new InternetAddress(managedUser.getUserContact().getContactEmailAddress());
 		} catch (final AddressException ex) {
 			// Throw again
 			throw new EJBException(ex);