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.annotation.PostConstruct;
23 import javax.ejb.Stateless;
24 import javax.faces.FacesException;
25 import javax.jms.Connection;
26 import javax.jms.JMSException;
27 import javax.jms.MessageProducer;
28 import javax.jms.ObjectMessage;
29 import javax.jms.Queue;
30 import javax.jms.QueueConnectionFactory;
31 import javax.jms.Session;
32 import javax.naming.Context;
33 import javax.naming.InitialContext;
34 import javax.naming.NamingException;
35 import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
36 import org.mxchange.jusercore.model.user.User;
37 import org.mxchange.jusercore.model.user.status.UserAccountStatus;
40 * A session-based EJB for resending confirmation links
42 * @author Roland Haeder<roland@mxchange.org>
44 @Stateless (name = "resendLink", description = "A bean resending confirmation links")
45 public class AddressbookResendLinkSessionBean extends BaseAddressbookDatabaseBean implements ResendLinkSessionBeanRemote {
50 private static final long serialVersionUID = 71_546_726_857_195_360L;
55 private Connection connection;
60 private ObjectMessage message;
65 private MessageProducer messageProducer;
68 * Mailer message queue
75 private Session session;
78 * Initialization of this bean
83 this.getLoggerBeanLocal().logTrace("init: CALLED!"); //NOI18N
86 // Get initial context
87 Context context = new InitialContext();
89 // Get factory from JMS resource
90 QueueConnectionFactory connectionFactory = (QueueConnectionFactory) context.lookup("jms/jlandingpage-queue-factory"); //NOI18N
93 this.queue = (Queue) context.lookup("jms/jlandingpage-email-queue"); //NOI18N
96 this.connection = connectionFactory.createConnection();
98 // Init session instance
99 this.session = this.connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
101 // And message producer
102 this.messageProducer = this.session.createProducer(this.queue);
104 // Finally the message instance itself
105 this.message = this.session.createObjectMessage();
106 } catch (final NamingException | JMSException e) {
107 // Continued to throw
108 throw new FacesException(e);
113 public String resendConfirmationLink (final User user, final Locale locale) {
115 this.getLoggerBeanLocal().logTrace(MessageFormat.format("resendConfirmationLink: user={0} - CALLED!", user)); //NOI18N
117 // The user instance should be valid
120 throw new NullPointerException("user is null"); //NOI18N
121 } else if (user.getUserId() == null) {
123 throw new NullPointerException("user.userId is null"); //NOI18N
124 } else if (user.getUserId() < 1) {
126 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", user.getUserId())); //NOI18N
127 } else if (user.getUserConfirmKey() == null) {
129 throw new NullPointerException("this.userConfirmKey is null"); //NOI18N
130 } else if (user.getUserAccountStatus() != UserAccountStatus.UNCONFIRMED) {
131 // User account status is not UNCONFIRMED
132 throw new IllegalStateException(MessageFormat.format("Account status from user.userId={0} is not UNCONFIRMED:{1}", user.getUserId(), user.getUserAccountStatus())); //NOI18N
133 } else if (null == locale) {
134 // Locale should be set
135 throw new NullPointerException("locale is null"); //NOI18N
140 return "resend_done"; //NOI18N