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.addressbook.beans.resendlink;
19 import de.chotime.landingpage.beans.resendlink.ResendLinkSessionBeanRemote;
20 import java.text.MessageFormat;
21 import java.util.Locale;
22 import javax.ejb.EJBException;
23 import javax.ejb.Stateless;
24 import javax.mail.Address;
25 import javax.mail.internet.AddressException;
26 import javax.mail.internet.InternetAddress;
27 import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
28 import org.mxchange.jusercore.model.user.User;
29 import org.mxchange.jusercore.model.user.status.UserAccountStatus;
32 * A session-based EJB for resending confirmation links
34 * @author Roland Haeder<roland@mxchange.org>
36 @Stateless (name = "resendLink", description = "A bean resending confirmation links")
37 public class AddressbookResendLinkSessionBean extends BaseAddressbookDatabaseBean implements ResendLinkSessionBeanRemote {
42 private static final long serialVersionUID = 71_546_726_857_195_360L;
45 public String resendConfirmationLink (final User user, final Locale locale) {
47 this.getLoggerBeanLocal().logTrace(MessageFormat.format("resendConfirmationLink: user={0},locale={1} - CALLED!", user, locale)); //NOI18N
49 // The user instance should be valid
52 throw new NullPointerException("user is null"); //NOI18N
53 } else if (user.getUserId() == null) {
55 throw new NullPointerException("user.userId is null"); //NOI18N
56 } else if (user.getUserId() < 1) {
58 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", user.getUserId())); //NOI18N
59 } else if (user.getUserConfirmKey() == null) {
61 throw new NullPointerException("this.userConfirmKey is null"); //NOI18N
62 } else if (user.getUserAccountStatus() != UserAccountStatus.UNCONFIRMED) {
63 // User account status is not UNCONFIRMED
64 throw new IllegalStateException(MessageFormat.format("Account status from user.userId={0} is not UNCONFIRMED:{1}", user.getUserId(), user.getUserAccountStatus())); //NOI18N
65 } else if (null == locale) {
66 // Locale should be set
67 throw new NullPointerException("locale is null"); //NOI18N
70 // @TODO Unfinished: Change key + merge database
76 // Create email address and set
77 emailAddress = new InternetAddress(user.getUserContact().getContactEmailAddress());
78 } catch (final AddressException ex) {
80 throw new EJBException(ex);
84 // TODO: Internationlize the subject line somehow
85 this.sendEmail("Resend confirmation link", "resend_confirmation_link", emailAddress, user); //NOI18N
88 this.getLoggerBeanLocal().logTrace("resendConfirmationLink: CALLED!"); //NOI18N
91 return "resend_done"; //NOI18N