/*
- * Copyright (C) 2016, 2017 Roland Häder
+ * 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.Stateless;
-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.UserStatusLockedException;
import org.mxchange.jusercore.exceptions.UserStatusUnconfirmedException;
import org.mxchange.jusercore.model.user.status.UserAccountStatus;
-import org.mxchange.juserlogincore.model.user.register.UserRegistrationSessionBeanRemote;
/**
* An administrative user EJB
* @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;
/**
// 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 mobile, land-line and fax instance
- this.setAllContactPhoneEntriesCreated(user.getUserContact());
+ this.setAllPhoneEntriesCreated(user.getUserContact());
// Persist it
this.getEntityManager().persist(user);
// 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
user.setUserContact(foundContact);
// Set timestamp
- user.setUserCreated(new GregorianCalendar());
+ user.setUserEntryCreated(new Date());
// Perist it
this.getEntityManager().persist(user);
} 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
} 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