]> git.mxchange.org Git - jjobs-war.git/commitdiff
Continued with deleting user accounts: (please cherry-pick)
authorRoland Häder <roland@mxchange.org>
Mon, 29 Aug 2016 10:03:43 +0000 (12:03 +0200)
committerRoland Haeder <roland@mxchange.org>
Mon, 29 Aug 2016 17:30:53 +0000 (19:30 +0200)
- added form with delete reason
- added method in controller (managed bean) which fires an event after the EJB deleted the user
- added activity log for deleting users (based on fired event)
- added missing i18n strings

Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/jjobs/beans/user/JobsAdminUserWebRequestBean.java
src/java/org/mxchange/jjobs/beans/user/JobsAdminUserWebRequestController.java
src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java
src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionController.java
src/java/org/mxchange/jjobs/beans/user/activity/JobsUserActivityWebApplicationBean.java
src/java/org/mxchange/jjobs/beans/user/activity/JobsUserActivityWebApplicationController.java
src/java/org/mxchange/localization/bundle_de_DE.properties
src/java/org/mxchange/localization/bundle_en_US.properties
web/admin/user/admin_user_delete.xhtml

index f8158ea5452fa9381bb880fa1c89dd9989064212..0bcf903ec200499b5d5f79b5afecd57c5621f9a7 100644 (file)
@@ -35,10 +35,13 @@ import org.mxchange.jjobs.beans.BaseJobsController;
 import org.mxchange.jjobs.beans.contact.JobsAdminContactWebRequestController;
 import org.mxchange.jjobs.beans.contact.JobsContactWebSessionController;
 import org.mxchange.jjobs.beans.helper.JobsWebViewHelperController;
+import org.mxchange.jjobs.beans.localization.JobsLocalizationSessionController;
 import org.mxchange.jusercore.container.login.UserLoginContainer;
 import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
 import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
 import org.mxchange.jusercore.events.user.add.AdminUserAddedEvent;
+import org.mxchange.jusercore.events.user.delete.AdminDeletedUserEvent;
+import org.mxchange.jusercore.events.user.delete.AdminUserDeletedEvent;
 import org.mxchange.jusercore.events.user.linked.AdminLinkedUserEvent;
 import org.mxchange.jusercore.events.user.linked.AdminUserLinkedEvent;
 import org.mxchange.jusercore.events.user.locked.AdminLockedUserEvent;
@@ -106,6 +109,19 @@ public class JobsAdminUserWebRequestBean extends BaseJobsController implements J
        @Inject
        private JobsContactWebSessionController contactController;
 
+       /**
+        * Event being fired when admin has deleted user
+        */
+       @Inject
+       @Any
+       private Event<AdminDeletedUserEvent> deleteUserEvent;
+
+       /**
+        * Localization controller
+        */
+       @Inject
+       private JobsLocalizationSessionController localizationController;
+
        /**
         * An event fired when the administrator has updated a new user
         */
@@ -124,6 +140,11 @@ public class JobsAdminUserWebRequestBean extends BaseJobsController implements J
        @Inject
        private JobsUserWebSessionController userController;
 
+       /**
+        * Delete reason
+        */
+       private String userDeleteReason;
+
        /**
         * An event fired when the administrator has linked a user with existing
         * contact data.
@@ -338,6 +359,35 @@ public class JobsAdminUserWebRequestBean extends BaseJobsController implements J
                //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterRegistration: EXIT!"); //NOI18N
        }
 
+       @Override
+       public String deleteUserData (final User user) {
+               // Is the user instance valid and CONFIRMED?
+               if (null == user) {
+                       // Throw NPE
+                       throw new NullPointerException("user is null"); //NOI18N
+               } else if (user.getUserId() == null) {
+                       // Throw again
+                       throw new NullPointerException("user.userId is null"); //NOI18N
+               } else if (user.getUserId() < 1) {
+                       // Invalid id number
+                       throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", user.getUserId())); //NOI18N
+               }
+
+               try {
+                       // All fine, delete it
+                       this.adminUserBean.deleteUser(user, this.getUserDeleteReason());
+               } catch (final UserNotFoundException ex) {
+                       // Should not happen, so throw again
+                       throw new FaceletException(ex);
+               }
+
+               // Fire event
+               this.deleteUserEvent.fire(new AdminUserDeletedEvent(user, this.getUserDeleteReason()));
+
+               // Redirect
+               return "admin_list_user"; //NOI18N
+       }
+
        @Override
        public String editUserData () {
                // Get user instance
@@ -403,6 +453,16 @@ public class JobsAdminUserWebRequestBean extends BaseJobsController implements J
                return "admin_list_user"; //NOI18N
        }
 
+       @Override
+       public String getUserDeleteReason () {
+               return this.userDeleteReason;
+       }
+
+       @Override
+       public void setUserDeleteReason (final String userDeleteReason) {
+               this.userDeleteReason = userDeleteReason;
+       }
+
        @Override
        public String getUserLockReason () {
                return this.userLockReason;
index 2a99cf3258be5b734a3f418a1dbea069193323b6..69598ed43ea63f06eb2267875fc7116cd9d2e086 100644 (file)
@@ -43,6 +43,15 @@ public interface JobsAdminUserWebRequestController extends Serializable {
         */
        String addUser ();
 
+       /**
+        * Deletes given user account
+        * <p>
+        * @param user User instance to delete
+        * <p>
+        * @return Redirect outcome
+        */
+       String deleteUserData (final User user);
+
        /**
         * Edits cuirrently loaded user's data in database.
         * <p>
@@ -140,4 +149,18 @@ public interface JobsAdminUserWebRequestController extends Serializable {
         */
        void setUserLockReason (final String userLockReason);
 
+       /**
+        * Getter for user delete reason
+        * <p>
+        * @return User delete reason
+        */
+       String getUserDeleteReason ();
+
+       /**
+        * Setter for user delete reason
+        * <p>
+        * @param userDeleteReason User delete reason
+        */
+       void setUserDeleteReason (final String userDeleteReason);
+
 }
index ee16e15b9066fcbbdf338a43da2a1648ed617918..87295f817fc66d8c5cff928d6dc6f79012586cc6 100644 (file)
@@ -42,6 +42,7 @@ import org.mxchange.jusercore.events.confirmation.UserConfirmedAccountEvent;
 import org.mxchange.jusercore.events.login.UserLoggedInEvent;
 import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
 import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
+import org.mxchange.jusercore.events.user.delete.AdminDeletedUserEvent;
 import org.mxchange.jusercore.events.user.linked.AdminLinkedUserEvent;
 import org.mxchange.jusercore.events.user.locked.AdminLockedUserEvent;
 import org.mxchange.jusercore.events.user.password_change.UpdatedUserPasswordEvent;
@@ -195,6 +196,30 @@ public class JobsUserWebSessionBean extends BaseJobsController implements JobsUs
                this.setUserId(event.getAddedUser().getUserId());
        }
 
+       @Override
+       public void afterAdminDeletedUserEvent (final AdminDeletedUserEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getDeletedUser() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.deletedUser is null"); //NOI18N
+               } else if (event.getDeletedUser().getUserId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.deletedUser.userId is null"); //NOI18N
+               } else if (event.getDeletedUser().getUserId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getDeletedUser(), event.getDeletedUser().getUserId())); //NOI18N
+               }
+
+               // Update user list
+               this.removeFromList(event.getDeletedUser());
+
+               // Clear all data
+               this.clear();
+       }
+
        @Override
        public void afterAdminLinkedUserEvent (@Observes final AdminLinkedUserEvent event) {
                // event should not be null
@@ -288,48 +313,6 @@ public class JobsUserWebSessionBean extends BaseJobsController implements JobsUs
                this.clear();
        }
 
-       @Override
-       public void afterUserRegistrationEvent (@Observes final UserRegisteredEvent event) {
-               // event should not be null
-               if (null == event) {
-                       // Throw NPE
-                       throw new NullPointerException("event is null"); //NOI18N
-               } else if (event.getRegisteredUser() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("event.registeredUser is null"); //NOI18N
-               } else if (event.getRegisteredUser().getUserId() == null) {
-                       // userId is null
-                       throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
-               } else if (event.getRegisteredUser().getUserId() < 1) {
-                       // Not avalid id
-                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
-               }
-
-               // Get user instance
-               User registeredUser = event.getRegisteredUser();
-
-               // Copy all data from registered->user
-               this.copyUser(registeredUser);
-
-               // Clear all data
-               this.clear();
-
-               // Update user list
-               this.updateList(registeredUser);
-
-               // Add user name
-               this.addUserName(registeredUser);
-
-               // Is the account public?
-               if (Objects.equals(registeredUser.getUserProfileMode(), ProfileMode.PUBLIC)) {
-                       // Also add it to this list
-                       this.visibleUserList.add(registeredUser);
-               }
-
-               // Set user id again
-               this.setUserId(registeredUser.getUserId());
-       }
-
        @Override
        public void afterUserConfirmedAccountEvent (@Observes final UserConfirmedAccountEvent event) {
                // event should not be null
@@ -381,6 +364,48 @@ public class JobsUserWebSessionBean extends BaseJobsController implements JobsUs
                }
        }
 
+       @Override
+       public void afterUserRegistrationEvent (@Observes final UserRegisteredEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getRegisteredUser() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.registeredUser is null"); //NOI18N
+               } else if (event.getRegisteredUser().getUserId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
+               } else if (event.getRegisteredUser().getUserId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
+               }
+
+               // Get user instance
+               User registeredUser = event.getRegisteredUser();
+
+               // Copy all data from registered->user
+               this.copyUser(registeredUser);
+
+               // Clear all data
+               this.clear();
+
+               // Update user list
+               this.updateList(registeredUser);
+
+               // Add user name
+               this.addUserName(registeredUser);
+
+               // Is the account public?
+               if (Objects.equals(registeredUser.getUserProfileMode(), ProfileMode.PUBLIC)) {
+                       // Also add it to this list
+                       this.visibleUserList.add(registeredUser);
+               }
+
+               // Set user id again
+               this.setUserId(registeredUser.getUserId());
+       }
+
        @Override
        public void afterUserUpdatedPasswordEvent (@Observes final UpdatedUserPasswordEvent event) {
                // Check parameter
@@ -861,6 +886,32 @@ public class JobsUserWebSessionBean extends BaseJobsController implements JobsUs
                this.setUserProfileMode(user.getUserProfileMode());
        }
 
+       /**
+        * Removes user from all lists
+        * <p>
+        * @param user User to remove
+        */
+       private void removeFromList (final User user) {
+               // The user should be valid
+               if (null == user) {
+                       // Throw NPE
+                       throw new NullPointerException("user is null"); //NOI18N
+               } else if (user.getUserId() == null) {
+                       // ... again NPE
+                       throw new NullPointerException("user.userId is null"); //NOI18N
+               } else if (user.getUserId() < 1) {
+                       // Invalid id
+                       throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); //NOI18N
+               }
+
+               // Remove it from lists
+               this.userList.remove(user);
+               this.visibleUserList.remove(user);
+
+               // Remove name from list
+               this.userNameList.remove(user.getUserName());
+       }
+
        /**
         * Updates list with given user instance
         * <p>
index e1c241827c7f3a45f55a404c2c3c93ecf2e3f169..d8c45f6ee57d0b5810f513e9c403311d5d29f6a1 100644 (file)
@@ -23,6 +23,7 @@ import org.mxchange.jusercore.events.confirmation.UserConfirmedAccountEvent;
 import org.mxchange.jusercore.events.login.UserLoggedInEvent;
 import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
 import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
+import org.mxchange.jusercore.events.user.delete.AdminDeletedUserEvent;
 import org.mxchange.jusercore.events.user.linked.AdminLinkedUserEvent;
 import org.mxchange.jusercore.events.user.locked.AdminLockedUserEvent;
 import org.mxchange.jusercore.events.user.password_change.UpdatedUserPasswordEvent;
@@ -53,6 +54,13 @@ public interface JobsUserWebSessionController extends Serializable {
         */
        void afterAdminAddedUserEvent (final AdminAddedUserEvent event);
 
+       /**
+        * Event observer for deleted user accounts (by administrator)
+        * <p>
+        * @param event Event being fired
+        */
+       void afterAdminDeletedUserEvent (final AdminDeletedUserEvent event);
+
        /**
         * Event observer for linked users with existing contact data
         * <p>
index c6cc8c0b98b82c828c553c3bf37f8849c66ed6de..104f3cf36b10ceaf37f5abdd20d42dbe96c0565a 100644 (file)
@@ -40,6 +40,7 @@ import org.mxchange.jusercore.events.logout.ObserveableUserLogoutEvent;
 import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
 import org.mxchange.jusercore.events.resendlink.UserResendLinkAccountEvent;
 import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
+import org.mxchange.jusercore.events.user.delete.AdminDeletedUserEvent;
 import org.mxchange.jusercore.events.user.linked.AdminLinkedUserEvent;
 import org.mxchange.jusercore.events.user.locked.AdminLockedUserEvent;
 import org.mxchange.jusercore.events.user.password_change.UpdatedUserPasswordEvent;
@@ -190,6 +191,27 @@ public class JobsUserActivityWebApplicationBean extends BaseJobsController imple
                this.addUserActivity(event.getAddedUser(), "ADMIN_ADDED_USER_ACCOUNT"); //NOI18N
        }
 
+       @Override
+       public void afterAdminDeletedUserEvent (@Observes final AdminDeletedUserEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getDeletedUser() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.deletedUser is null"); //NOI18N
+               } else if (event.getDeletedUser().getUserId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.deletedUser.userId is null"); //NOI18N
+               } else if (event.getDeletedUser().getUserId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getDeletedUser(), event.getDeletedUser().getUserId())); //NOI18N
+               }
+
+               // Add acitivity
+               this.addUserActivity(event.getDeletedUser(), "ADMIN_DELETED_USER_ACCOUNT", event.getUserDeleteReason()); //NOI18N
+       }
+
        @Override
        public void afterAdminLinkedUserEvent (@Observes final AdminLinkedUserEvent event) {
                // event should not be null
index 4bc30ada88b2c1f412ff7556b8cbb4d5f00fa029..86db26907ee07d0b0ac3ba7b90057ae76f0ecbef 100644 (file)
@@ -25,6 +25,7 @@ import org.mxchange.jusercore.events.logout.ObserveableUserLogoutEvent;
 import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
 import org.mxchange.jusercore.events.resendlink.UserResendLinkAccountEvent;
 import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
+import org.mxchange.jusercore.events.user.delete.AdminDeletedUserEvent;
 import org.mxchange.jusercore.events.user.linked.AdminLinkedUserEvent;
 import org.mxchange.jusercore.events.user.locked.AdminLockedUserEvent;
 import org.mxchange.jusercore.events.user.password_change.UpdatedUserPasswordEvent;
@@ -49,6 +50,13 @@ public interface JobsUserActivityWebApplicationController extends Serializable {
         */
        void afterAdminAddedUserEvent (final AdminAddedUserEvent event);
 
+       /**
+        * Event observer for deleted user accounts (by administrator)
+        * <p>
+        * @param event Event being fired
+        */
+       void afterAdminDeletedUserEvent (final AdminDeletedUserEvent event);
+
        /**
         * Event observer for linked users with existing contact data
         * <p>
index dacc22aab1f809f6ccfd9b016d59f8f1a7986255..090a1afaf62af45e0794218484c4c800f4e6b099 100644 (file)
@@ -769,3 +769,9 @@ ADMIN_ACTIVITY_USER_LOGGED_OUT=Benutzer hat sich ausgeloggt.
 USER_ACTIVITY_USER_LOGGED_OUT=Sie haben sich ausgeloggt.
 ERROR_GUEST_USER_NAME_REQUIRED_DISABLED=Fehler: Die Anwendung verwendet keine Benutzernamen, dennoch wurde dieses Template geladen.
 ADMIN_SHOW_PRINCIPAL_NAME=Admin-Login:
+ADMIN_LINK_SHOW_USER_ACTIVITY_LOG_TITLE=Listet Aktivit\u00e4tslogbuch des Benutzers auf.
+ADMIN_DELETE_USER_TITLE=Wollen Sie den Benutzer {0} (Id-Nummer {1}) wirklich l\u00f6schen?
+BUTTON_ADMIN_DELETE_USER=Benutzeraccount l\u00f6schen
+ADMIN_DELETE_USER_NOTICE=Durch das L\u00f6schen des Benutzeraccounts werden nur die Benutzerdaten, jedoch nicht Kontaktdaten.
+ADMIN_ACTIVITY_ADMIN_DELETED_USER_ACCOUNT=Benutzeraccount gel\u00f6scht vom Administrator.
+USER_ACTIVITY_ADMIN_DELETED_USER_ACCOUNT=Ihr Benutzeraccount wurde von einem Administrator gel\u00f6scht.
index 1f38285f29884f432a7669ca0d7d3fdb6a4164bc..8b9f10c12a66e650807ba056142fcfadd214e618 100644 (file)
@@ -770,3 +770,9 @@ ADMIN_ACTIVITY_USER_LOGGED_OUT=User has logged out.
 USER_ACTIVITY_USER_LOGGED_OUT=You have logged out.
 ERROR_GUEST_USER_NAME_REQUIRED_DISABLED=Error: This application requires no user name, still this template has been loaded.
 ADMIN_SHOW_PRINCIPAL_NAME=Admin-Login:
+ADMIN_LINK_SHOW_USER_ACTIVITY_LOG_TITLE=Lists all user's activity.
+ADMIN_DELETE_USER_TITLE=Do you really want to delete user account {0} (id number {1})?
+BUTTON_ADMIN_DELETE_USER=Delete user account
+ADMIN_DELETE_USER_NOTICE=By deleting the user's account, only user data is deleted but not contact data.
+ADMIN_ACTIVITY_ADMIN_DELETED_USER_ACCOUNT=User account has been deleted by administrator.
+USER_ACTIVITY_ADMIN_DELETED_USER_ACCOUNT=Your account has been deleted by an administrator.
index b2e157aabebb3966be1deac41addfaf64fb75d91..6a2931c5d127ac02bfd3e10cf4bb0da4d482e14d 100644 (file)
                                </ui:include>
                        </ui:fragment>
 
-                       Here goes your content.
+                       <h:form id="form_admin_delete_user" rendered="#{not empty beanHelper.user}">
+                               <h:panelGroup styleClass="table" layout="block">
+                                       <div class="table_header">
+                                               <h:outputFormat value="#{msg.ADMIN_DELETE_USER_TITLE}">
+                                                       <f:param value="#{beanHelper.user.userName}" />
+                                                       <f:param value="#{beanHelper.user.userId}" />
+                                               </h:outputFormat>
+                                       </div>
+
+                                       <div class="para notice">
+                                               <h:outputFormat value="#{msg.ADMIN_DELETE_USER_NOTICE}" />
+                                       </div>
+
+                                       <ui:include src="/WEB-INF/templates/admin/user/admin_show_user_data_mini.tpl" />
+
+                                       <div class="table_row">
+                                               <div class="table_left_medium">
+                                                       <h:outputLabel for="userDeleteReason" value="#{msg.ADMIN_USER_DELETE_REASON}" />
+                                               </div>
+
+                                               <div class="table_right_medium">
+                                                       <h:inputTextarea id="userDeleteReason" styleClass="input" value="#{adminUserController.userDeleteReason}" rows="7" cols="25" />
+                                               </div>
+
+                                               <div class="clear"></div>
+                                       </div>
+
+                                       <div class="table_footer">
+                                               <h:commandButton styleClass="reset right_space" type="reset" value="#{msg.BUTTON_RESET_FORM}" />
+                                               <h:commandButton styleClass="delete_button" type="submit" id="delete_user" value="#{msg.BUTTON_ADMIN_DELETE_USER}" action="#{adminUserController.deleteUserData(beanHelper.user)}" />
+                                       </div>
+                               </h:panelGroup>
+                       </h:form>
                </ui:define>
        </ui:composition>
 </html>