]> git.mxchange.org Git - addressbook-mailer-ejb.git/blobdiff - src/java/org/mxchange/jusercore/model/register/AddressbookUserRegistrationSessionBean.java
updated jar(s)
[addressbook-mailer-ejb.git] / src / java / org / mxchange / jusercore / model / register / AddressbookUserRegistrationSessionBean.java
index 54b0b09d99f1fbd615ee049029d07f886e6c6737..ff98ffc5a6773ca4ad0744573b23a1dc12044482 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016 Roland Haeder
+ * Copyright (C) 2016, 2017 Roland Häder
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -25,22 +25,23 @@ import javax.mail.internet.AddressException;
 import javax.mail.internet.InternetAddress;
 import javax.persistence.NoResultException;
 import javax.persistence.Query;
+import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
 import org.mxchange.jcontacts.contact.Contact;
-import org.mxchange.jcoreee.database.BaseDatabaseBean;
 import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException;
 import org.mxchange.jusercore.exceptions.UserNameAlreadyRegisteredException;
+import org.mxchange.jusercore.model.user.AdminUserSessionBeanRemote;
 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.UserUtils;
 
 /**
- * A session bean for user registration
+ * A session-scoped bean for user registration
  * <p>
- * @author Roland Haeder<roland@mxchange.org>
+ * @author Roland Häder<roland@mxchange.org>
  */
 @Stateless (name = "register", description = "A bean handling the user registration")
-public class AddressbookUserRegistrationSessionBean extends BaseDatabaseBean implements UserRegistrationSessionBeanRemote {
+public class AddressbookUserRegistrationSessionBean extends BaseAddressbookDatabaseBean implements UserRegistrationSessionBeanRemote {
 
        /**
         * Serial number
@@ -48,15 +49,29 @@ public class AddressbookUserRegistrationSessionBean extends BaseDatabaseBean imp
        private static final long serialVersionUID = 12_348_958_986_818_627L;
 
        /**
-        * User EJB
+        * Administrative user bean
+        */
+       @EJB
+       private AdminUserSessionBeanRemote adminUserBean;
+
+       /**
+        * Regular user EJB
         */
        @EJB
        private UserSessionBeanRemote userBean;
 
+       /**
+        * Default constructor
+        */
+       public AddressbookUserRegistrationSessionBean () {
+               // Call super constructor
+               super();
+       }
+
        @Override
        public String generateConfirmationKey (final User user) {
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("generateConfirmationKey: user={0} - CALLED!", user)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.generateConfirmationKey: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
 
                // user should not be null
                if (null == user) {
@@ -84,7 +99,7 @@ public class AddressbookUserRegistrationSessionBean extends BaseDatabaseBean imp
                                Contact contact = (Contact) query.getSingleResult();
 
                                // Warning message
-                               this.getLoggerBeanLocal().logWarning(MessageFormat.format("generateConfirmationKey: key {0} already found: contact.contactId={1}", key, contact.getContactId())); //NOI18N
+                               this.getLoggerBeanLocal().logWarning(MessageFormat.format("{0}.generateConfirmationKey: key {1} already found: contact.contactId={2}", this.getClass().getSimpleName(), key, contact.getContactId())); //NOI18N
                        } catch (final NoResultException ex) {
                                // Not found, normal case
                                confirmationKey = key;
@@ -93,7 +108,7 @@ public class AddressbookUserRegistrationSessionBean extends BaseDatabaseBean imp
                }
 
                // Log trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("generateConfirmationKey: confirmationKey={0} - EXIT!", confirmationKey)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.generateConfirmationKey: confirmationKey={1} - EXIT!", this.getClass().getSimpleName(), confirmationKey)); //NOI18N
 
                // Return it
                return confirmationKey;
@@ -102,7 +117,7 @@ public class AddressbookUserRegistrationSessionBean extends BaseDatabaseBean imp
        @Override
        public boolean isEmailAddressRegistered (final User user) {
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("isEmailAddressRegistered: user={0} - CALLED!", user)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isEmailAddressRegistered: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
 
                // Check bean
                assert (this.userBean instanceof UserSessionBeanRemote) : "this.userBean is not set"; //NOI18N
@@ -120,7 +135,7 @@ public class AddressbookUserRegistrationSessionBean extends BaseDatabaseBean imp
        @Override
        public boolean isUserNameRegistered (final User user) {
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("isUserNameRegistered: user={0} - CALLED!", user)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isUserNameRegistered: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
 
                // Check bean
                assert (this.userBean instanceof UserSessionBeanRemote) : "this.userBean is not set"; //NOI18N
@@ -136,9 +151,9 @@ public class AddressbookUserRegistrationSessionBean extends BaseDatabaseBean imp
        }
 
        @Override
-       public User registerUser (final User user) throws UserNameAlreadyRegisteredException, EmailAddressAlreadyRegisteredException {
+       public User registerUser (final User user, final String baseUrl) throws UserNameAlreadyRegisteredException, EmailAddressAlreadyRegisteredException {
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("registerUser: user={0} - CALLED!", user)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.registerUser: user={1},baseUrl={2} - CALLED!", this.getClass().getSimpleName(), user, baseUrl)); //NOI18N
 
                // user should not be null
                if (null == user) {
@@ -165,7 +180,7 @@ public class AddressbookUserRegistrationSessionBean extends BaseDatabaseBean imp
                }
 
                // Call other EJB
-               User addedUser = this.userBean.addUser(user);
+               User addedUser = this.adminUserBean.addUser(user);
 
                // Init variable
                Address emailAddress;
@@ -179,11 +194,11 @@ public class AddressbookUserRegistrationSessionBean extends BaseDatabaseBean imp
                }
 
                // Send email
-               // TODO: Internationlize the subject line somehow
-               this.sendEmail("Registration", "registration", emailAddress, addedUser); //NOI18N
+               // @TODO: Internationlize the subject line somehow
+               this.sendEmail("Registration", "registration", emailAddress, addedUser, baseUrl); //NOI18N
 
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("registerUser: addedUser={0},addedUser.userId={1} - EXIT!", addedUser, addedUser.getUserId())); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.registerUser: addedUser={1},addedUser.userId={2} - EXIT!", this.getClass().getSimpleName(), addedUser, addedUser.getUserId())); //NOI18N
 
                // Return it
                return addedUser;