]> git.mxchange.org Git - pizzaservice-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:22 +0000 (19:28 +0200)
- implemented business method for deleting user accounts

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

index b6c0397175b80baa7a63ba80ed5a97afdff77c8d..debec5738d34b564897044fdaae9c15722cced1b 100644 (file)
@@ -109,6 +109,48 @@ public class PizzaAdminUserSessionBean extends BasePizzaDatabaseBean implements
                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 PizzaAdminUserSessionBean extends BasePizzaDatabaseBean implements
                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);