]> git.mxchange.org Git - jjobs-ejb.git/blobdiff - src/java/org/mxchange/jusercore/model/user/JobsAdminUserSessionBean.java
Updated copyright year
[jjobs-ejb.git] / src / java / org / mxchange / jusercore / model / user / JobsAdminUserSessionBean.java
index 768e233964822261163a803aac0035ed2d10e208..f1c95218c98713a9448ec422b25cdb6aa2be0d1d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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;
@@ -29,7 +29,6 @@ import org.mxchange.jusercore.exceptions.UserStatusConfirmedException;
 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
@@ -37,23 +36,17 @@ import org.mxchange.juserlogincore.model.user.register.UserRegistrationSessionBe
  * @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;
 
        /**
@@ -69,37 +62,40 @@ public class JobsAdminUserSessionBean extends BaseJobsDatabaseBean implements Ad
                // 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);
 
-               // 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
 
@@ -112,7 +108,7 @@ public class JobsAdminUserSessionBean extends BaseJobsDatabaseBean implements Ad
                // 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
@@ -140,7 +136,7 @@ public class JobsAdminUserSessionBean extends BaseJobsDatabaseBean implements Ad
                }
 
                // Get a managed instance
-               final 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
@@ -188,14 +184,11 @@ public class JobsAdminUserSessionBean extends BaseJobsDatabaseBean implements Ad
                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
 
@@ -245,6 +238,12 @@ public class JobsAdminUserSessionBean extends BaseJobsDatabaseBean implements Ad
                } 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
@@ -252,7 +251,7 @@ public class JobsAdminUserSessionBean extends BaseJobsDatabaseBean implements Ad
 
                // 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
@@ -306,6 +305,12 @@ public class JobsAdminUserSessionBean extends BaseJobsDatabaseBean implements Ad
                } 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