/*
- * Copyright (C) 2016 Roland Haeder
+ * Copyright (C) 2016 - 2024 Free Software Foundation
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
package org.mxchange.jusercore.model.user;
import java.text.MessageFormat;
-import java.util.GregorianCalendar;
+import java.util.Date;
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.jcontacts.contact.Contact;
-import org.mxchange.jjobs.database.BaseJobsDatabaseBean;
+import org.mxchange.jcontacts.model.contact.Contact;
+import org.mxchange.jjobs.enterprise.BaseJobsEnterpriseBean;
import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException;
import org.mxchange.jusercore.exceptions.UserNameAlreadyRegisteredException;
import org.mxchange.jusercore.exceptions.UserNotFoundException;
import org.mxchange.jusercore.exceptions.UserStatusConfirmedException;
import org.mxchange.jusercore.exceptions.UserStatusLockedException;
import org.mxchange.jusercore.exceptions.UserStatusUnconfirmedException;
-import org.mxchange.jusercore.model.register.UserRegistrationSessionBeanRemote;
import org.mxchange.jusercore.model.user.status.UserAccountStatus;
/**
* An administrative user EJB
* <p>
- * @author Roland Haeder<roland@mxchange.org>
+ * @author Roland Hรคder<roland@mxchange.org>
*/
@Stateless (name = "adminUser", description = "A bean handling the user data")
-public class JobsAdminUserSessionBean extends BaseJobsDatabaseBean implements AdminUserSessionBeanRemote {
+public class JobsAdminUserSessionBean extends BaseJobsEnterpriseBean implements AdminUserSessionBeanRemote {
/**
* Serial number
*/
- private static final long serialVersionUID = 542_145_347_916L;
-
- /**
- * Registration EJB
- */
- @EJB
- private UserRegistrationSessionBeanRemote registerBean;
+ private static final long serialVersionUID = 542_145_349_001L;
/**
* Regular user bean
*/
- @EJB
+ @EJB (lookup = "java:global/jjobs-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote")
private UserSessionBeanRemote userBean;
/**
* Default constructor
*/
public JobsAdminUserSessionBean () {
+ // Call super constructor
+ super("jms/jjobs-queue-factory", "jms/jjobs-email-queue"); //NOI18N
}
@Override
// Trace message
this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addUser: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
- // user should not be null
+ // Validate parameter
if (null == user) {
// Abort here
throw new NullPointerException("user is null"); //NOI18N
} else if (user.getUserId() instanceof Long) {
// Not allowed here
throw new IllegalStateException(MessageFormat.format("user.userId must be null, is: {0}", user.getUserId())); //NOI18N
+ } else if (null == user.getUserContact()) {
+ // Abort here
+ throw new NullPointerException("user.contact is null"); //NOI18N
+ } else if (user.getUserContact().getContactId() != null) {
+ // Not allowed here
+ throw new IllegalStateException(MessageFormat.format("user.userContact.contactId must be null, is: {0}", user.getUserId())); //NOI18N
}
// Check if user is registered
- if (this.registerBean.isUserNameRegistered(user)) {
+ if (this.userBean.isUserNameRegistered(user)) {
// Abort here
throw new UserNameAlreadyRegisteredException(user);
- } else if (this.registerBean.isEmailAddressRegistered(user)) {
+ } else if (this.userBean.isEmailAddressRegistered(user)) {
// Abort here
throw new EmailAddressAlreadyRegisteredException(user);
}
// Set created timestamp
- user.setUserCreated(new GregorianCalendar());
- user.getUserContact().setContactCreated(new GregorianCalendar());
+ user.setUserEntryCreated(new Date());
+ user.getUserContact().setContactEntryCreated(new Date());
- // Update cellphone, land-line and fax instance
- this.setAllContactPhoneEntriesCreated(user.getUserContact());
+ // Update mobile, land-line and fax instance
+ this.setAllPhoneEntriesCreated(user.getUserContact());
// Persist it
this.getEntityManager().persist(user);
- // Flush to get id back
- this.getEntityManager().flush();
-
// Trace message
this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addUser: user={1},user.userId={2} - EXIT!", this.getClass().getSimpleName(), user, user.getUserId())); //NOI18N
// Trace message
this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteUser: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
- // user should not be null
+ // Validate parameters
if (null == user) {
// Abort here
throw new NullPointerException("user is null"); //NOI18N
}
// Get a managed instance
- User managedUser = this.getManagedUser(user);
+ final User managedUser = this.createManaged(user);
// Should be found!
assert (managedUser instanceof User) : MessageFormat.format("User with id {0} not found, but should be.", user.getUserId()); //NOI18N
}
// Try to find the contact
- Contact managedContact = this.getEntityManager().find(user.getUserContact().getClass(), user.getUserContact().getContactId());
-
- // Should be found!
- assert (managedContact instanceof Contact) : MessageFormat.format("Contact with id {0} not found, but should be.", user.getUserContact().getContactId()); //NOI18N
+ final Contact foundContact = this.getEntityManager().find(user.getUserContact().getClass(), user.getUserContact().getContactId());
// Set detached object in rexcruiter instance
- user.setUserContact(managedContact);
+ user.setUserContact(foundContact);
// Set timestamp
- user.setUserCreated(new GregorianCalendar());
+ user.setUserEntryCreated(new Date());
// Perist it
this.getEntityManager().persist(user);
- // Flush it to get updated instance back
- this.getEntityManager().flush();
-
// Log trace message
this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkUser: user={1} - EXIT!", this.getClass().getSimpleName(), user)); //NOI18N
} else if (userLockReason.isEmpty()) {
// Is empty
throw new IllegalArgumentException("userLockReason is empty"); //NOI18N
+ } else if (null == baseUrl) {
+ // Throw NPE again
+ throw new NullPointerException("baseUrl is null"); //NOI18N
+ } else if (baseUrl.isEmpty()) {
+ // Throw IAE
+ throw new IllegalArgumentException("baseUrl is empty"); //NOI18N
}
// Remove contact instance as this is not updated
// Set as locked, set timestamp and lock reason
user.setUserAccountStatus(UserAccountStatus.LOCKED);
- user.setUserLastLocked(new GregorianCalendar());
+ user.setUserLastLocked(new Date());
user.setUserLastLockedReason(userLockReason);
// Update user
- User managedUser = this.userBean.updateUserData(user);
+ final User managedUser = this.userBean.updateUserData(user);
// @TODO Create user lock history entry
- // Init variable
- Address emailAddress;
-
- try {
- // Create email address and set
- emailAddress = new InternetAddress(managedUser.getUserContact().getContactEmailAddress());
- } catch (final AddressException ex) {
- // Throw again
- throw new EJBException(ex);
- }
-
// Send out email
// @TODO externalize subject line
- this.sendEmail("Account locked", "account_locked", emailAddress, managedUser, baseUrl); //NOI18N
+ this.sendEmail("User account locked", "user_account_locked", managedUser, baseUrl, null); //NOI18N
// Trace message
this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.lockUserAccount: managedUser={1} - EXIT!", this.getClass().getSimpleName(), managedUser)); //NOI18N
} else if (user.getUserAccountStatus() == UserAccountStatus.UNCONFIRMED) {
// Account is unconfirmed
throw new UserStatusUnconfirmedException(user);
+ } else if (null == baseUrl) {
+ // Throw NPE again
+ throw new NullPointerException("baseUrl is null"); //NOI18N
+ } else if (baseUrl.isEmpty()) {
+ // Throw IAE
+ throw new IllegalArgumentException("baseUrl is empty"); //NOI18N
}
// Remove contact instance as this is not updated
user.setUserAccountStatus(UserAccountStatus.CONFIRMED);
// Update user
- User managedUser = this.userBean.updateUserData(user);
+ final User managedUser = this.userBean.updateUserData(user);
// @TODO Create user lock history entry
- // Init variable
- Address emailAddress;
-
- try {
- // Create email address and set
- emailAddress = new InternetAddress(managedUser.getUserContact().getContactEmailAddress());
- } catch (final AddressException ex) {
- // Throw again
- throw new EJBException(ex);
- }
-
// Send out email
// @TODO externalize subject line
- this.sendEmail("Account unlocked", "account_unlocked", emailAddress, managedUser, baseUrl); //NOI18N
+ this.sendEmail("User account unlocked", "user_account_unlocked", managedUser, baseUrl, null); //NOI18N
// Trace message
this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.lockUserAccount: managedUser={1} - EXIT!", this.getClass().getSimpleName(), managedUser)); //NOI18N