2 * Copyright (C) 2016 Roland Haeder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation, either version 3 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
14 * You should have received a copy of the GNU Affero General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.jjobs.beans.resendlink;
19 import java.text.MessageFormat;
20 import java.util.Locale;
21 import javax.ejb.EJBException;
22 import javax.ejb.Stateless;
23 import javax.mail.Address;
24 import javax.mail.internet.AddressException;
25 import javax.mail.internet.InternetAddress;
26 import org.mxchange.jjobs.database.BaseJobsDatabaseBean;
27 import org.mxchange.jusercore.model.user.User;
28 import org.mxchange.jusercore.model.user.status.UserAccountStatus;
31 * A session-based EJB for resending confirmation links
33 * @author Roland Haeder<roland@mxchange.org>
35 @Stateless (name = "resendLink", description = "A bean resending confirmation links")
36 public class JobsResendLinkSessionBean extends BaseJobsDatabaseBean implements ResendLinkSessionBeanRemote {
41 private static final long serialVersionUID = 71_546_726_857_195_360L;
44 public String resendConfirmationLink (final User user, final Locale locale) {
46 this.getLoggerBeanLocal().logTrace(MessageFormat.format("resendConfirmationLink: user={0},locale={1} - CALLED!", user, locale)); //NOI18N
48 // The user instance should be valid
51 throw new NullPointerException("user is null"); //NOI18N
52 } else if (user.getUserId() == null) {
54 throw new NullPointerException("user.userId is null"); //NOI18N
55 } else if (user.getUserId() < 1) {
57 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", user.getUserId())); //NOI18N
58 } else if (user.getUserConfirmKey() == null) {
60 throw new NullPointerException("this.userConfirmKey is null"); //NOI18N
61 } else if (user.getUserAccountStatus() != UserAccountStatus.UNCONFIRMED) {
62 // User account status is not UNCONFIRMED
63 throw new IllegalStateException(MessageFormat.format("Account status from user.userId={0} is not UNCONFIRMED:{1}", user.getUserId(), user.getUserAccountStatus())); //NOI18N
64 } else if (null == locale) {
65 // Locale should be set
66 throw new NullPointerException("locale is null"); //NOI18N
69 // @TODO Unfinished: Change key + merge database
75 // Create email address and set
76 emailAddress = new InternetAddress(user.getUserContact().getContactEmailAddress());
77 } catch (final AddressException ex) {
79 throw new EJBException(ex);
83 // TODO: Internationlize the subject line somehow
84 this.sendEmail("Resend confirmation link", "resend_confirmation_link", emailAddress, user); //NOI18N
87 this.getLoggerBeanLocal().logTrace("resendConfirmationLink: CALLED!"); //NOI18N
90 return "resend_done"; //NOI18N