/*
- * Copyright (C) 2016 - 2020 Free Software Foundation
+ * Copyright (C) 2016 - 2022 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
import java.util.Date;
import java.util.List;
import java.util.Objects;
-import javax.ejb.EJB;
import javax.ejb.EJBException;
import javax.ejb.Stateless;
import javax.persistence.Query;
import org.mxchange.jcontacts.model.contact.Contact;
import org.mxchange.jjobs.enterprise.BaseJobsEnterpriseBean;
import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
-import org.mxchange.jphone.model.phonenumbers.fax.FaxNumbers;
import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
-import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumbers;
import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
-import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumbers;
+import org.mxchange.jphone.model.utils.FaxNumberUtils;
+import org.mxchange.jphone.model.utils.LandLineNumberUtils;
+import org.mxchange.jphone.model.utils.MobileNumberUtils;
import org.mxchange.jusercore.exceptions.UserNotFoundException;
import org.mxchange.jusercore.exceptions.UserStatusConfirmedException;
import org.mxchange.jusercore.exceptions.UserStatusLockedException;
import org.mxchange.jusercore.model.user.password_history.PasswordHistory;
import org.mxchange.jusercore.model.user.password_history.UserPasswordHistory;
import org.mxchange.jusercore.model.user.status.UserAccountStatus;
-import org.mxchange.juserlogincore.model.user.register.UserRegistrationSessionBeanRemote;
+import org.mxchange.jusercore.model.utils.UserUtils;
/**
* A user EJB
*/
private static final long serialVersionUID = 542_145_347_916L;
- /**
- * Registration EJB
- */
- @EJB (lookup = "java:global/jjobs-ejb/userRegistration!org.mxchange.juserlogincore.model.user.register.UserRegistrationSessionBeanRemote")
- private UserRegistrationSessionBeanRemote registerBean;
-
/**
* Default constructor
*/
}
@Override
- public User confirmAccount (final User user, final String baseUrl) throws UserStatusConfirmedException, UserStatusLockedException {
+ public User confirmAccount (final User user, final String baseUrl) throws UserStatusConfirmedException, UserStatusLockedException, UserNotFoundException {
// Trace message
this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.confirmAccount: user={1},baseUrl={2} - CALLED!", this.getClass().getSimpleName(), user, baseUrl)); //NOI18N
// Throw it again
throw new NullPointerException("baseUrl is null"); //NOI18N
} else if (baseUrl.isEmpty()) {
- // Invalid parameter
+ // Throw IAE
throw new IllegalArgumentException("baseUrl is empty"); //NOI18N
}
// Update user status and remove confirmation key
managedUser.setUserAccountStatus(UserAccountStatus.CONFIRMED);
managedUser.setUserConfirmKey(null);
- managedUser.setUserUpdated(new Date());
+ managedUser.setUserEntryUpdated(new Date());
// Send out email
this.sendEmail("User account confirmed", "user_account_confirmed", managedUser, baseUrl, null); //NOI18N
// Fetch whole list
for (final User currentUser : this.fetchAllUsers()) {
- // Is found?
- if (Objects.equals(user, currentUser)) {
+ /*
+ * E.g. userAccountStatus can be fifferent because lockUserAccount
+ * is setting it BEFORE this method is invoked. So this is enough
+ * for us in this case. But otherwise e.g. when a new user is
+ * created with same data, then this method must return FALSE even
+ * when userId is currently NULL.
+ */
+ //* NOISY-DEBUG: */ this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.ifUserExists: currentUser={1},currentUser.userId={2}", this.getClass(), currentUser, currentUser.getUserId())); //NOI18N
+ if ((Objects.equals(user.getUserId(), currentUser.getUserId()) && user.getUserId() != null) || Objects.equals(user, currentUser)) {
// Yes, then set flag and exit iteration
isFound = true;
break;
}
@Override
- public User updateUserData (final User user) {
+ public User updateUserData (final User user) throws UserNotFoundException {
// Trace message
this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserData: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
throw new NullPointerException("user.userAccountStatus is null"); //NOI18N
} else if (!this.ifUserExists(user)) {
// User does not exist
- throw new EJBException(MessageFormat.format("User with id {0} does not exist.", user.getUserId())); //NOI18N
+ throw new UserNotFoundException(user.getUserId());
}
// Find the instance
assert (foundUser instanceof User) : MessageFormat.format("User with id {0} not found, but should be.", user.getUserId()); //NOI18N
// Copy all data
- Users.copyUserData(user, foundUser);
+ UserUtils.copyUserData(user, foundUser);
// Merge user
final User managedUser = this.getEntityManager().merge(foundUser);
assert (managedUser instanceof User) : MessageFormat.format("User with id {0} not found, but should be.", user.getUserId()); //NOI18N
// Set as updated
- managedUser.setUserUpdated(new Date());
+ managedUser.setUserEntryUpdated(new Date());
// Trace message
this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserData: managedUser={1} - EXIT!", this.getClass().getSimpleName(), managedUser)); //NOI18N
final User managedUser = this.updateUserData(user);
// Update user account
- managedUser.setUserUpdated(new Date());
+ managedUser.setUserEntryUpdated(new Date());
// Create history entry
- PasswordHistory entry = new UserPasswordHistory(user.getUserEncryptedPassword(), managedUser);
+ final PasswordHistory entry = new UserPasswordHistory(user.getUserEncryptedPassword(), managedUser);
// Set created timestamp
entry.setUserPasswordHistoryCreated(new Date());
assert (managedUser instanceof User) : MessageFormat.format("User with id {0} not found, but should be.", user.getUserId()); //NOI18N
// Copy all data
- Users.copyUserData(user, managedUser);
+ UserUtils.copyUserData(user, managedUser);
// Set as updated
- managedUser.setUserUpdated(new Date());
+ managedUser.setUserEntryUpdated(new Date());
// Update user data
final Contact managedContact = this.mergeContactData(managedUser.getUserContact());
assert (foundMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", foundMobile.getMobileId()); //NOI18N
// Copy all
- MobileNumbers.copyMobileNumberData(managedUser.getUserContact().getContactMobileNumber(), foundMobile);
+ MobileNumberUtils.copyMobileNumberData(managedUser.getUserContact().getContactMobileNumber(), foundMobile);
// Then merge it, too
final DialableMobileNumber managedMobile = this.getEntityManager().merge(foundMobile);
assert (foundFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", foundFax.getPhoneId()); //NOI18N
// Copy all
- FaxNumbers.copyFaxNumberData(managedUser.getUserContact().getContactFaxNumber(), foundFax);
+ FaxNumberUtils.copyFaxNumberData(managedUser.getUserContact().getContactFaxNumber(), foundFax);
// Then merge it, too
final DialableFaxNumber managedFax = this.getEntityManager().merge(foundFax);
assert (foundLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", foundLandLine.getPhoneId()); //NOI18N
// Copy all
- LandLineNumbers.copyLandLineNumberData(managedUser.getUserContact().getContactLandLineNumber(), foundLandLine);
+ LandLineNumberUtils.copyLandLineNumberData(managedUser.getUserContact().getContactLandLineNumber(), foundLandLine);
// Then merge it, too
final DialableLandLineNumber managedLandLine = this.getEntityManager().merge(foundLandLine);