]> git.mxchange.org Git - jjobs-ejb.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Mon, 29 Aug 2016 10:22:00 +0000 (12:22 +0200)
committerRoland Haeder <roland@mxchange.org>
Mon, 29 Aug 2016 17:28:31 +0000 (19:28 +0200)
- implemented business method for deleting user accounts

src/java/org/mxchange/jusercore/model/user/JobsAdminUserSessionBean.java

index d55610f7cbf621858574db7c1ddd7977318ee925..5b7eb69104a99660d5d8f41c6be71d0389c9f591 100644 (file)
@@ -109,6 +109,48 @@ public class JobsAdminUserSessionBean extends BaseJobsDatabaseBean implements Ad
                return user;
        }
 
+       @Override
+       public void deleteUser (final User user, final String userDeleteReason) throws UserNotFoundException {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteUser: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
+
+               // user should not be null
+               if (null == user) {
+                       // Abort here
+                       throw new NullPointerException("user is null"); //NOI18N
+               } else if (user.getUserId() instanceof Long) {
+                       // Id is set
+                       throw new IllegalArgumentException("user.userId is not null"); //NOI18N
+               } else if (user.getUserContact() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("user.userContact is null"); //NOI18N
+               } else if (user.getUserContact().getContactId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("user.userContact.contactId is null"); //NOI18N
+               } else if (user.getUserContact().getContactId() < 1) {
+                       // Not valid id number
+                       throw new IllegalArgumentException(MessageFormat.format("user.userContact.contactId={0} is not valid", user.getUserContact().getContactId())); //NOI18N
+               } else if (user.getUserAccountStatus() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("user.userAccountStatus is null"); //NOI18N
+               } else if (!this.userBean.ifUserExists(user)) {
+                       // Name already found
+                       throw new UserNotFoundException(user);
+               }
+
+               // Get a managed instance
+               User managedUser = this.getManagedUser(user);
+
+               // Should be found!
+               assert (managedUser instanceof User) : MessageFormat.format("User with id {0} not found, but should be.", user.getUserId()); //NOI18N
+
+               // Delete it
+               this.getEntityManager().refresh(managedUser);
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteUser: EXIT!", this.getClass().getSimpleName())); //NOI18N
+       }
+
        @Override
        public User linkUser (final User user) throws UserNameAlreadyRegisteredException, EmailAddressAlreadyRegisteredException {
                // Trace message
@@ -142,7 +184,7 @@ public class JobsAdminUserSessionBean extends BaseJobsDatabaseBean implements Ad
                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.", managedContact.getContactId()); //NOI18N
+               assert (managedContact instanceof Contact) : MessageFormat.format("Contact with id {0} not found, but should be.", user.getUserContact().getContactId()); //NOI18N
 
                // Set detached object in rexcruiter instance
                user.setUserContact(managedContact);