]> git.mxchange.org Git - pizzaservice-war.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Sat, 5 Aug 2017 19:47:08 +0000 (21:47 +0200)
committerRoland Häder <roland@mxchange.org>
Sun, 6 Aug 2017 18:59:59 +0000 (20:59 +0200)
- opps, somehow by that big cherry-pick, these changes got lost, now fully fixed

Signed-off-by: Roland Häder <roland@mxchange.org>
12 files changed:
src/java/org/mxchange/jfinancials/beans/user/activity/FinancialsUserActivityWebApplicationBean.java [deleted file]
src/java/org/mxchange/jfinancials/beans/user/activity/FinancialsUserActivityWebApplicationController.java [deleted file]
src/java/org/mxchange/pizzaapplication/beans/contact/phone/PizzaAdminContactPhoneWebRequestBean.java
src/java/org/mxchange/pizzaapplication/beans/contact/phone/PizzaContactPhoneWebSessionBean.java
src/java/org/mxchange/pizzaapplication/beans/customer/PizzaAdminCustomerWebRequestBean.java
src/java/org/mxchange/pizzaapplication/beans/helper/PizzaWebRequestHelperBean.java
src/java/org/mxchange/pizzaapplication/beans/helper/PizzaWebRequestHelperController.java
src/java/org/mxchange/pizzaapplication/beans/receipt/PizzaReceiptWebSessionBean.java
src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestBean.java
src/java/org/mxchange/pizzaapplication/beans/user/activity/PizzaUserActivityWebApplicationBean.java [new file with mode: 0644]
src/java/org/mxchange/pizzaapplication/beans/user/activity/PizzaUserActivityWebApplicationController.java [new file with mode: 0644]
src/java/org/mxchange/pizzaapplication/beans/user/confirmlink/PizzaConfirmationLinkWebRequestBean.java

diff --git a/src/java/org/mxchange/jfinancials/beans/user/activity/FinancialsUserActivityWebApplicationBean.java b/src/java/org/mxchange/jfinancials/beans/user/activity/FinancialsUserActivityWebApplicationBean.java
deleted file mode 100644 (file)
index 7f14f25..0000000
+++ /dev/null
@@ -1,696 +0,0 @@
-/*
- * Copyright (C) 2016, 2017 Roland Häder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jfinancials.beans.user.activity;
-
-import java.text.MessageFormat;
-import java.util.Collections;
-import java.util.GregorianCalendar;
-import java.util.LinkedHashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import javax.annotation.PostConstruct;
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.event.Observes;
-import javax.faces.view.facelets.FaceletException;
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import org.mxchange.jfinancials.beans.BaseFinancialsController;
-import org.mxchange.jfinancials.beans.helper.FinancialsWebRequestHelperController;
-import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
-import org.mxchange.jusercore.events.user.created.ObservableCreatedUserEvent;
-import org.mxchange.jusercore.events.user.delete.ObservableAdminDeletedUserEvent;
-import org.mxchange.jusercore.events.user.linked.ObservableAdminLinkedUserEvent;
-import org.mxchange.jusercore.events.user.locked.ObservableAdminLockedUserEvent;
-import org.mxchange.jusercore.events.user.unlocked.ObservableAdminUnlockedUserEvent;
-import org.mxchange.jusercore.events.user.update.ObservableAdminUpdatedUserDataEvent;
-import org.mxchange.jusercore.events.user.update.ObservableUpdatedUserPersonalDataEvent;
-import org.mxchange.jusercore.model.user.User;
-import org.mxchange.jusercore.model.user.activity.LogableUserActivity;
-import org.mxchange.jusercore.model.user.activity.UserActivityLog;
-import org.mxchange.jusercore.model.user.activity.UserActivityLogSessionBeanRemote;
-import org.mxchange.jusercore.model.user.activity.comparator.UserActivityLogTimestampComparator;
-import org.mxchange.juserlogincore.events.confirmation.ObservableUserConfirmedAccountEvent;
-import org.mxchange.juserlogincore.events.login.ObservableUserLoggedInEvent;
-import org.mxchange.juserlogincore.events.logout.ObservableUserLogoutEvent;
-import org.mxchange.juserlogincore.events.registration.ObservableUserRegisteredEvent;
-import org.mxchange.juserlogincore.events.resendlink.ObservableUserResendLinkAccountEvent;
-import org.mxchange.juserlogincore.events.user.password_change.ObservableUpdatedUserPasswordEvent;
-
-/**
- * A controller (bean) for user activity log
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@Named ("userActivityController")
-@ApplicationScoped
-public class FinancialsUserActivityWebApplicationBean extends BaseFinancialsController implements FinancialsUserActivityWebApplicationController {
-
-       /**
-        * Serial number
-        */
-       private static final long serialVersionUID = 192_586_376_717_856_904L;
-
-       /**
-        * Bean helper
-        */
-       @Inject
-       private FinancialsWebRequestHelperController beanHelper;
-
-       /**
-        * User instance
-        */
-       private User user;
-
-       /**
-        * EJB for user activity log
-        */
-       private UserActivityLogSessionBeanRemote userActivityBean;
-
-       /**
-        * "Cache" for activity log per user
-        */
-       private final Map<User, List<LogableUserActivity>> usersActivity;
-
-       /**
-        * Default constructor
-        */
-       @SuppressWarnings ("CollectionWithoutInitialCapacity")
-       public FinancialsUserActivityWebApplicationBean () {
-               // Try to get EJB instance
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // Try to lookup
-                       this.userActivityBean = (UserActivityLogSessionBeanRemote) context.lookup("java:global/jfinancials-ejb/userActivity!org.mxchange.jusercore.model.user.activity.UserActivityLogSessionBeanRemote"); //NOI18N
-               } catch (final NamingException e) {
-                       // Throw again
-                       throw new FaceletException(e);
-               }
-
-               // Init cache
-               this.usersActivity = new LinkedHashMap<>();
-       }
-
-       /**
-        * Adds user activity entry with given type
-        * <p>
-        * @param user User instance
-        * @param activityType Activity type
-        */
-       private void addUserActivity (final User user, final String activityType) {
-               // Better re-validate
-               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
-               } else if (null == activityType) {
-                       // Throw NPE again
-                       throw new NullPointerException("activityType is null"); //NOI18N
-               } else if (activityType.isEmpty()) {
-                       // Is empty
-                       throw new IllegalArgumentException("activityType is empty"); //NOI18N
-               }
-
-               // Create new activity object
-               LogableUserActivity userActivity = new UserActivityLog(activityType, user, new GregorianCalendar(), this.determinePrincipalName());
-
-               // Call bean to add it
-               this.userActivityBean.addUserActivityLog(userActivity);
-
-               // Add to cache, too
-               this.addUserActivityToCache(userActivity);
-       }
-
-       /**
-        * Adds user activity log with type and message
-        * <p>
-        * @param user User instance
-        * @param activityType Activity type
-        * @param message Activity message
-        */
-       private void addUserActivity (final User user, final String activityType, final String message) {
-               // Better re-validate
-               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
-               } else if (null == activityType) {
-                       // Throw NPE again
-                       throw new NullPointerException("activityType is null"); //NOI18N
-               } else if (activityType.isEmpty()) {
-                       // Is empty
-                       throw new IllegalArgumentException("activityType is empty"); //NOI18N
-               } else if (null == message) {
-                       // Throw NPE again
-                       throw new NullPointerException("message is null"); //NOI18N
-               } else if (message.isEmpty()) {
-                       // Is empty
-                       throw new IllegalArgumentException("message is empty"); //NOI18N
-               }
-
-               // Create new activity object
-               LogableUserActivity userActivity = new UserActivityLog(message, activityType, user, new GregorianCalendar(), this.determinePrincipalName());
-
-               // Call bean to add it
-               this.userActivityBean.addUserActivityLog(userActivity);
-
-               // Add to cache, too
-               this.addUserActivityToCache(userActivity);
-       }
-
-       /**
-        * Event observer for newly added users by administrator
-        * <p>
-        * @param event Event being fired
-        */
-       public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) {
-               // event should not be null
-               if (null == event) {
-                       // Throw NPE
-                       throw new NullPointerException("event is null"); //NOI18N
-               } else if (event.getAddedUser() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("event.addedUser is null"); //NOI18N
-               } else if (event.getAddedUser().getUserId() == null) {
-                       // userId is null
-                       throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
-               } else if (event.getAddedUser().getUserId() < 1) {
-                       // Not avalid id
-                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
-               }
-
-               // Update user list
-               this.addUserActivity(event.getAddedUser(), "ADMIN_ADDED_USER_ACCOUNT"); //NOI18N
-       }
-
-       /**
-        * Event observer for deleted user accounts (by administrator)
-        * <p>
-        * @param event Event being fired
-        */
-       public void afterAdminDeletedUserEvent (@Observes final ObservableAdminDeletedUserEvent 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
-       }
-
-       /**
-        * Event observer for linked users with existing contact data
-        * <p>
-        * @param event Event being fired
-        */
-       public void afterAdminLinkedUserEvent (@Observes final ObservableAdminLinkedUserEvent event) {
-               // event should not be null
-               if (null == event) {
-                       // Throw NPE
-                       throw new NullPointerException("event is null"); //NOI18N
-               } else if (event.getLinkedUser() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("event.linkedUser is null"); //NOI18N
-               } else if (event.getLinkedUser().getUserId() == null) {
-                       // userId is null
-                       throw new NullPointerException("event.linkedUser.userId is null"); //NOI18N
-               } else if (event.getLinkedUser().getUserId() < 1) {
-                       // Not avalid id
-                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLinkedUser(), event.getLinkedUser().getUserId())); //NOI18N
-               }
-
-               // Update user list
-               this.addUserActivity(event.getLinkedUser(), "ADMIN_LINKED_USER_ACCOUNT"); //NOI18N
-       }
-
-       /**
-        * Event observer for locked users
-        * <p>
-        * @param event Event being fired
-        */
-       public void afterAdminLockedUserEvent (@Observes final ObservableAdminLockedUserEvent event) {
-               // event should not be null
-               if (null == event) {
-                       // Throw NPE
-                       throw new NullPointerException("event is null"); //NOI18N
-               } else if (event.getLockedUser() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("event.lockedUser is null"); //NOI18N
-               } else if (event.getLockedUser().getUserId() == null) {
-                       // userId is null
-                       throw new NullPointerException("event.lockedUser.userId is null"); //NOI18N
-               } else if (event.getLockedUser().getUserId() < 1) {
-                       // Not avalid id
-                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLockedUser(), event.getLockedUser().getUserId())); //NOI18N
-               }
-
-               // Update user list
-               this.addUserActivity(event.getLockedUser(), "ADMIN_LOCKED_USER_ACCOUNT", event.getLockedUser().getUserLastLockedReason()); //NOI18N
-       }
-
-       /**
-        * Event observer for unlocked users
-        * <p>
-        * @param event Event being fired
-        */
-       public void afterAdminUnlockedUserEvent (@Observes final ObservableAdminUnlockedUserEvent event) {
-               // event should not be null
-               if (null == event) {
-                       // Throw NPE
-                       throw new NullPointerException("event is null"); //NOI18N
-               } else if (event.getUnlockedUser() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("event.unlockedUser is null"); //NOI18N
-               } else if (event.getUnlockedUser().getUserId() == null) {
-                       // userId is null
-                       throw new NullPointerException("event.unlockedUser.userId is null"); //NOI18N
-               } else if (event.getUnlockedUser().getUserId() < 1) {
-                       // Not avalid id
-                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUnlockedUser(), event.getUnlockedUser().getUserId())); //NOI18N
-               }
-
-               // Update user list
-               this.addUserActivity(event.getUnlockedUser(), "ADMIN_UNLOCKED_USER_ACCOUNT"); //NOI18N
-       }
-
-       /**
-        * Event observer for updated user data by administrator
-        * <p>
-        * @param event Event being updated
-        */
-       public void afterAdminUpdatedUserDataEvent (@Observes final ObservableAdminUpdatedUserDataEvent event) {
-               // event should not be null
-               if (null == event) {
-                       // Throw NPE
-                       throw new NullPointerException("event is null"); //NOI18N
-               } else if (event.getUpdatedUser() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("event.updatedUser is null"); //NOI18N
-               } else if (event.getUpdatedUser().getUserId() == null) {
-                       // userId is null
-                       throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N
-               } else if (event.getUpdatedUser().getUserId() < 1) {
-                       // Not avalid id
-                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUpdatedUser(), event.getUpdatedUser().getUserId())); //NOI18N
-               }
-
-               // Update user list
-               this.addUserActivity(event.getUpdatedUser(), "ADMIN_UPDATED_USER_PERSONAL_DATA"); //NOI18N
-       }
-
-       /**
-        * Event observer for when a bean helper has successfully created a user
-        * instance, means the user exists. If the user does not exist, this event
-        * should not fire but instead a proper exception must be thrown.
-        * <p>
-        * @param event User created event
-        */
-       public void afterCreatedUserEvent (@Observes final ObservableCreatedUserEvent event) {
-               // Is the instance valid?
-               if (null == event) {
-                       // Throw NPE
-                       throw new NullPointerException("event is null"); //NOI18N
-               } else if (event.getCreatedUser() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("event.createdUser is null"); //NOI18N
-               } else if (event.getCreatedUser().getUserId() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("event.createdUser.userId is null"); //NOI18N
-               } else if (event.getCreatedUser().getUserId() < 1) {
-                       // Throw NPE again
-                       throw new NullPointerException(MessageFormat.format("event.createdUser.userId={0} is not valid", event.getCreatedUser().getUserId())); //NOI18N
-               }
-
-               // Set whole user
-               this.setUser(event.getCreatedUser());
-       }
-
-       /**
-        * Event observer when user confirmed account.
-        * <p>
-        * @param event Event being fired
-        */
-       public void afterUserConfirmedAccountEvent (@Observes final ObservableUserConfirmedAccountEvent event) {
-               // event should not be null
-               if (null == event) {
-                       // Throw NPE
-                       throw new NullPointerException("event is null"); //NOI18N
-               } else if (event.getConfirmedUser() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("event.confirmedUser is null"); //NOI18N
-               } else if (event.getConfirmedUser().getUserId() == null) {
-                       // userId is null
-                       throw new NullPointerException("event.confirmedUser.userId is null"); //NOI18N
-               } else if (event.getConfirmedUser().getUserId() < 1) {
-                       // Not avalid id
-                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getConfirmedUser(), event.getConfirmedUser().getUserId())); //NOI18N
-               }
-
-               // Update user list
-               this.addUserActivity(event.getConfirmedUser(), "USER_CONFIRMED_ACCOUNT"); //NOI18N
-       }
-
-       /**
-        * Event observer for logged-in user
-        * <p>
-        * @param event Event being fired
-        */
-       public void afterUserLoginEvent (@Observes final ObservableUserLoggedInEvent event) {
-               // event should not be null
-               if (null == event) {
-                       // Throw NPE
-                       throw new NullPointerException("event is null"); //NOI18N
-               } else if (event.getLoggedInUser() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("event.registeredUser is null"); //NOI18N
-               } else if (event.getLoggedInUser().getUserId() == null) {
-                       // userId is null
-                       throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
-               } else if (event.getLoggedInUser().getUserId() < 1) {
-                       // Not avalid id
-                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
-               }
-
-               // Copy all data to this bean
-               this.addUserActivity(event.getLoggedInUser(), "USER_LOGGED_IN"); //NOI18N
-       }
-
-       /**
-        * Event observer for logged-out user
-        * <p>
-        * @param event Event instance
-        */
-       public void afterUserLogoutEvent (@Observes final ObservableUserLogoutEvent event) {
-               // event should not be null
-               if (null == event) {
-                       // Throw NPE
-                       throw new NullPointerException("event is null"); //NOI18N
-               } else if (event.getLoggedOutUser() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("event.loggedOutUser is null"); //NOI18N
-               } else if (event.getLoggedOutUser().getUserId() == null) {
-                       // userId is null
-                       throw new NullPointerException("event.loggedOutUser.userId is null"); //NOI18N
-               } else if (event.getLoggedOutUser().getUserId() < 1) {
-                       // Not avalid id
-                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedOutUser(), event.getLoggedOutUser().getUserId())); //NOI18N
-               }
-
-               // Update user list
-               this.addUserActivity(event.getLoggedOutUser(), "USER_LOGGED_OUT"); //NOI18N
-       }
-
-       /**
-        * Event observer for new user registrations
-        * <p>
-        * @param event Event being fired
-        */
-       public void afterUserRegistrationEvent (@Observes final ObservableUserRegisteredEvent 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
-               }
-
-               // Update user list
-               this.addUserActivity(event.getRegisteredUser(), "USER_REGISTERED_NEW_ACCOUNT"); //NOI18N
-       }
-
-       /**
-        * Event observer for users resending their confirmation link
-        * <p>
-        * @param event Event being fired
-        */
-       public void afterUserResendConfirmationLinkEvent (@Observes final ObservableUserResendLinkAccountEvent event) {
-               // event should not be null
-               if (null == event) {
-                       // Throw NPE
-                       throw new NullPointerException("event is null"); //NOI18N
-               } else if (event.getResendLinkUser() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("event.resendLinkUser is null"); //NOI18N
-               } else if (event.getResendLinkUser().getUserId() == null) {
-                       // userId is null
-                       throw new NullPointerException("event.resendLinkUser.userId is null"); //NOI18N
-               } else if (event.getResendLinkUser().getUserId() < 1) {
-                       // Not avalid id
-                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getResendLinkUser(), event.getResendLinkUser().getUserId())); //NOI18N
-               }
-
-               // Copy all data to this bean
-               this.addUserActivity(event.getResendLinkUser(), "USER_RESEND_CONFIRMATION_LINK"); //NOI18N
-       }
-
-       /**
-        * Method being call after user's password has been updated (and history
-        * entry has been created).
-        * <p>
-        * @param event Event being observed
-        */
-       public void afterUserUpdatedPasswordEvent (@Observes final ObservableUpdatedUserPasswordEvent event) {
-               // Check parameter
-               if (null == event) {
-                       // Throw NPE
-                       throw new NullPointerException("event is null"); //NOI18N
-               } else if (event.getPasswordHistory() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("event.passwordHistory is null"); //NOI18N
-               } else if (event.getPasswordHistory().getUserPasswordHistoryId() == null) {
-                       // ... and again
-                       throw new NullPointerException("event.passwordHistory.userPasswordHistoryId is null"); //NOI18N
-               } else if (event.getPasswordHistory().getUserPasswordHistoryId() < 1) {
-                       // Invalid value
-                       throw new IllegalArgumentException(MessageFormat.format("event.passwordHistory.userPasswordHistoryId={0} is in valid", event.getPasswordHistory().getUserPasswordHistoryId())); //NOI18N
-               }
-
-               // Update user list
-               this.addUserActivity(event.getPasswordHistory().getUserPasswordHistoryUser(), "USER_UPDATED_PASSWORD"); //NOI18N
-       }
-
-       /**
-        * Listens to fired event when user updated personal data
-        * <p>
-        * @param event Event being fired
-        */
-       public void afterUserUpdatedPersonalDataEvent (@Observes final ObservableUpdatedUserPersonalDataEvent event) {
-               // Check parameter
-               if (null == event) {
-                       // Throw NPE
-                       throw new NullPointerException("event is null"); //NOI18N
-               } else if (event.getUpdatedUser() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("event.updatedUser is null"); //NOI18N
-               } else if (event.getUpdatedUser().getUserId() == null) {
-                       // ... and again
-                       throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N
-               } else if (event.getUpdatedUser().getUserId() < 1) {
-                       // Invalid value
-                       throw new IllegalArgumentException(MessageFormat.format("event.updatedUser.userId={0} is in valid", event.getUpdatedUser().getUserId())); //NOI18N
-               }
-
-               // Update user list
-               this.addUserActivity(event.getUpdatedUser(), "USER_UPDATED_PERSONAL_DATA"); //NOI18N
-       }
-
-       /**
-        * Expands given activity type into a i18n string for administrators
-        * <p>
-        * @param activityType Activity type
-        * <p>
-        * @return Expanded i18n string
-        */
-       public String expandAdminActivityType (final String activityType) {
-               // Is it valid?
-               if (null == activityType) {
-                       // Throw NPE
-                       throw new NullPointerException("activityType is null"); //NOI18N
-               } else if (activityType.isEmpty()) {
-                       // Is empty
-                       throw new IllegalArgumentException("activityType is empty"); //NOI18N
-               }
-
-               // Expand it
-               return "ADMIN_ACTIVITY_" + activityType; //NOI18N
-       }
-
-       /**
-        * Expands given activity type into a i18n string for users
-        * <p>
-        * @param activityType Activity type
-        * <p>
-        * @return Expanded i18n string
-        */
-       public String expandUserActivityType (final String activityType) {
-               // Is it valid?
-               if (null == activityType) {
-                       // Throw NPE
-                       throw new NullPointerException("activityType is null"); //NOI18N
-               } else if (activityType.isEmpty()) {
-                       // Is empty
-                       throw new IllegalArgumentException("activityType is empty"); //NOI18N
-               }
-
-               // Expand it
-               return "USER_ACTIVITY_" + activityType; //NOI18N
-       }
-
-       /**
-        * Returns a list of in beanHelper set user instance's activity log
-        * <p>
-        * @return List of user's activity log
-        */
-       public List<LogableUserActivity> fetchCurrentUsersActivityLog () {
-               // beanHelper.user should be set and valid
-               if (this.getUser() == null) {
-                       // Is not set
-                       throw new NullPointerException("this.beanHelper.user is null"); //NOI18N
-               } else if (this.getUser().getUserId() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("this.beanHelper.user.userId is null"); //NOI18N
-               } else if (this.getUser().getUserId() < 1) {
-                       // Invalid id number
-                       throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.user.userId={0} is not valid", this.getUser().getUserId())); //NOI18N
-               }
-
-               // Init list
-               List<LogableUserActivity> list = new LinkedList<>();
-
-               // Is the user set?
-               if (this.usersActivity.containsKey(this.getUser())) {
-                       // Return it
-                       list.addAll(this.usersActivity.get(this.getUser()));
-
-                       // Sort list and reverse it
-                       Collections.sort(list, new UserActivityLogTimestampComparator());
-                       Collections.reverse(list);
-               }
-
-               // Return it
-               return list;
-       }
-
-       /**
-        * Getter for user instance
-        * <p>
-        * @return User instance
-        */
-       public User getUser () {
-               return this.user;
-       }
-
-       /**
-        * Setter for user instance
-        * <p>
-        * @param user User instance
-        */
-       public void setUser (final User user) {
-               this.user = user;
-       }
-
-       /**
-        * Post-constructor method
-        */
-       @PostConstruct
-       public void init () {
-               // Get whole list
-               List<LogableUserActivity> list = this.userActivityBean.fetchAllUserActivityLog();
-
-               // Put all in map, per-user
-               for (final LogableUserActivity userActivity : list) {
-                       // Is the list there?
-                       if (!this.usersActivity.containsKey(userActivity.getActivityUser())) {
-                               // Init list
-                               this.usersActivity.put(userActivity.getActivityUser(), new LinkedList<LogableUserActivity>());
-                       }
-
-                       // Add by user instance
-                       boolean added = this.usersActivity.get(userActivity.getActivityUser()).add(userActivity);
-
-                       // Should be added
-                       assert (added) : "Activity log not added"; //NOI18N
-               }
-       }
-
-       /**
-        * Adds given user activity instance to "cache" (local map)
-        * <p>
-        * @param userActivity User activity instance
-        */
-       private void addUserActivityToCache (final LogableUserActivity userActivity) {
-               // Is the instance valid
-               if (null == userActivity) {
-                       // Throw NPE again
-                       throw new NullPointerException("userActivity is null");
-               } else if (userActivity.getActivityId() instanceof Long) {
-                       // Is not null
-                       throw new IllegalArgumentException("userActivity.activityId=" + userActivity.getActivityId() + " is not null");
-               } else if (userActivity.getActivityUser() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("userActivity.activityUser is null");
-               } else if (userActivity.getActivityUser().getUserId() == null) {
-                       // Throw it again
-                       throw new NullPointerException("userActivity.activityUser.userId is null");
-               } else if (userActivity.getActivityUser().getUserId() < 1) {
-                       // Invalid id number
-                       throw new IllegalArgumentException("userActivity.activityUser.userId=" + userActivity.getActivityUser().getUserId() + " is not valid");
-               }
-
-               // Is it there?
-               if (!this.usersActivity.containsKey(userActivity.getActivityUser())) {
-                       // Init it
-                       this.usersActivity.put(userActivity.getActivityUser(), new LinkedList<LogableUserActivity>());
-               }
-
-               // Add activity to log
-               this.usersActivity.get(userActivity.getActivityUser()).add(userActivity);
-       }
-
-}
diff --git a/src/java/org/mxchange/jfinancials/beans/user/activity/FinancialsUserActivityWebApplicationController.java b/src/java/org/mxchange/jfinancials/beans/user/activity/FinancialsUserActivityWebApplicationController.java
deleted file mode 100644 (file)
index 802c11a..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (C) 2016, 2017 Roland Häder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jfinancials.beans.user.activity;
-
-import java.io.Serializable;
-
-/**
- * A controller (bean) interface for user activity log
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public interface FinancialsUserActivityWebApplicationController extends Serializable {
-
-}
index 0cf671da912c10de06be85a06ff9f06d376ea548..66de22a1672c668446e9f753e7bebcd7d4b1dcab 100644 (file)
@@ -17,6 +17,7 @@
 package org.mxchange.pizzaapplication.beans.contact.phone;
 
 import java.text.MessageFormat;
+import java.util.Calendar;
 import javax.annotation.PostConstruct;
 import javax.enterprise.context.RequestScoped;
 import javax.enterprise.event.Event;
@@ -82,6 +83,11 @@ public class PizzaAdminContactPhoneWebRequestBean extends BasePizzaController im
         */
        private static final long serialVersionUID = 542_145_347_916L;
 
+       /**
+        * Administrative EJB for phone number
+        */
+       private AdminContactsPhoneSessionBeanRemote adminContactPhoneBean;
+
        /**
         * Event being fired when a fax number has been linked
         */
@@ -103,11 +109,6 @@ public class PizzaAdminContactPhoneWebRequestBean extends BasePizzaController im
        @Any
        private Event<ObservableAdminLinkedMobileNumberEvent> adminLinkedMobileNumberEvent;
 
-       /**
-        * Administrative EJB for phone number
-        */
-       private AdminContactsPhoneSessionBeanRemote adminPhoneBean;
-
        /**
         * Administrative phone controller
         */
@@ -121,25 +122,9 @@ public class PizzaAdminContactPhoneWebRequestBean extends BasePizzaController im
        private PizzaWebRequestHelperController beanHelper;
 
        /**
-        * Event being fired when a fax number has been unlinked
-        */
-       @Inject
-       @Any
-       private Event<ObservableAdminUnlinkedFaxNumberEvent> faxNumberUnlinkedEvent;
-
-       /**
-        * Event being fired when a land-line number has been unlinked
-        */
-       @Inject
-       @Any
-       private Event<ObservableAdminUnlinkedLandLineNumberEvent> landLineNumberUnlinkedEvent;
-
-       /**
-        * Event being fired when admin unlinks mobile from contact
+        * Contact instance
         */
-       @Inject
-       @Any
-       private Event<ObservableAdminUnlinkedMobileNumberEvent> mobileNumberUnlinkedEvent;
+       private Contact contact;
 
        /**
         * Area code (city dial prefix) for fax number
@@ -156,6 +141,13 @@ public class PizzaAdminContactPhoneWebRequestBean extends BasePizzaController im
         */
        private Long faxNumber;
 
+       /**
+        * Event being fired when a fax number has been unlinked
+        */
+       @Inject
+       @Any
+       private Event<ObservableAdminUnlinkedFaxNumberEvent> faxNumberUnlinkedEvent;
+
        /**
         * Area code (city dial prefix) for land-line number
         */
@@ -172,15 +164,44 @@ public class PizzaAdminContactPhoneWebRequestBean extends BasePizzaController im
        private Long landLineNumber;
 
        /**
-        * Mobile provider
+        * Event being fired when a land-line number has been unlinked
         */
-       private MobileProvider mobileProvider;
+       @Inject
+       @Any
+       private Event<ObservableAdminUnlinkedLandLineNumberEvent> landLineNumberUnlinkedEvent;
 
        /**
         * Mobile number
         */
        private Long mobileNumber;
 
+       /**
+        * Event being fired when admin unlinks mobile from contact
+        */
+       @Inject
+       @Any
+       private Event<ObservableAdminUnlinkedMobileNumberEvent> mobileNumberUnlinkedEvent;
+
+       /**
+        * Mobile provider
+        */
+       private MobileProvider mobileProvider;
+
+       /**
+        * When fax number has been created
+        */
+       private Calendar phoneEntryCreated;
+
+       /**
+        * When fax number has been updated
+        */
+       private Calendar phoneEntryUpdated;
+
+       /**
+        * Phone id (primary key)
+        */
+       private Long phoneId;
+
        /**
         * Default constructor
         */
@@ -405,18 +426,18 @@ public class PizzaAdminContactPhoneWebRequestBean extends BasePizzaController im
         */
        public String doLinkMainFaxNumber () {
                // Get contact from helper
-               Contact contact = this.beanHelper.getContact();
+               Contact targetContact = this.getContact();
 
                // Is all data properly set?
-               if (null == contact) {
+               if (null == targetContact) {
                        // Throw NPE
-                       throw new NullPointerException("contact is null"); //NOI18N
-               } else if (contact.getContactId() == null) {
+                       throw new NullPointerException("targetContact is null"); //NOI18N
+               } else if (targetContact.getContactId() == null) {
                        // Throw it again
-                       throw new NullPointerException("contact.contactId is null"); //NOI18N
-               } else if (contact.getContactId() < 1) {
+                       throw new NullPointerException("targetContact.contactId is null"); //NOI18N
+               } else if (targetContact.getContactId() < 1) {
                        // Is not valid
-                       throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
+                       throw new IllegalArgumentException(MessageFormat.format("targetContact.contactId={0} is not valid", targetContact.getContactId())); //NOI18N
                } else if (this.getFaxCountry() == null) {
                        // Throw NPE again
                        throw new NullPointerException("this.faxCountry is null"); //NOI18N
@@ -447,7 +468,7 @@ public class PizzaAdminContactPhoneWebRequestBean extends BasePizzaController im
                // Try it again
                try {
                        // Link it, too
-                       updatedContact = this.adminPhoneBean.linkNewFaxNumberWithContact(contact, number);
+                       updatedContact = this.adminContactPhoneBean.linkNewFaxNumberWithContact(targetContact, number);
                } catch (final PhoneNumberAlreadyLinkedException ex) {
                        // Throw again as cause
                        this.showFacesMessage("form_add_contact_fax:faxNumber", ex); //NOI18N
@@ -469,18 +490,18 @@ public class PizzaAdminContactPhoneWebRequestBean extends BasePizzaController im
         */
        public String doLinkMainLandLineNumber () {
                // Get contact from helper
-               Contact contact = this.beanHelper.getContact();
+               Contact targetContact = this.getContact();
 
                // Is all data properly set?
-               if (null == contact) {
+               if (null == targetContact) {
                        // Throw NPE
-                       throw new NullPointerException("contact is null"); //NOI18N
-               } else if (contact.getContactId() == null) {
+                       throw new NullPointerException("targetContact is null"); //NOI18N
+               } else if (targetContact.getContactId() == null) {
                        // Throw it again
-                       throw new NullPointerException("contact.contactId is null"); //NOI18N
-               } else if (contact.getContactId() < 1) {
+                       throw new NullPointerException("targetContact.contactId is null"); //NOI18N
+               } else if (targetContact.getContactId() < 1) {
                        // Is not valid
-                       throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
+                       throw new IllegalArgumentException(MessageFormat.format("targetContact.contactId={0} is not valid", targetContact.getContactId())); //NOI18N
                } else if (this.getLandLineCountry() == null) {
                        // Throw NPE again
                        throw new NullPointerException("this.landLineCountry is null"); //NOI18N
@@ -511,7 +532,7 @@ public class PizzaAdminContactPhoneWebRequestBean extends BasePizzaController im
                // Try it again
                try {
                        // Link it, too
-                       updatedContact = this.adminPhoneBean.linkNewLandLineNumberWithContact(contact, number);
+                       updatedContact = this.adminContactPhoneBean.linkNewLandLineNumberWithContact(targetContact, number);
                } catch (final PhoneNumberAlreadyLinkedException ex) {
                        // Throw again as cause
                        this.showFacesMessage("form_add_contact_landLine:landLineNumber", ex); //NOI18N
@@ -532,18 +553,18 @@ public class PizzaAdminContactPhoneWebRequestBean extends BasePizzaController im
         */
        public String doLinkMainMobileNumber () {
                // Get contact from helper
-               Contact contact = this.beanHelper.getContact();
+               Contact targetContact = this.getContact();
 
                // Is all data properly set?
-               if (null == contact) {
+               if (null == targetContact) {
                        // Throw NPE
-                       throw new NullPointerException("contact is null"); //NOI18N
-               } else if (contact.getContactId() == null) {
+                       throw new NullPointerException("targetContact is null"); //NOI18N
+               } else if (targetContact.getContactId() == null) {
                        // Throw it again
-                       throw new NullPointerException("contact.contactId is null"); //NOI18N
-               } else if (contact.getContactId() < 1) {
+                       throw new NullPointerException("targetContact.contactId is null"); //NOI18N
+               } else if (targetContact.getContactId() < 1) {
                        // Is not valid
-                       throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
+                       throw new IllegalArgumentException(MessageFormat.format("targetContact.contactId={0} is not valid", targetContact.getContactId())); //NOI18N
                } else if (this.getMobileProvider() == null) {
                        // Throw NPE
                        throw new NullPointerException("this.mobileProvider is null"); //NOI18N
@@ -568,7 +589,7 @@ public class PizzaAdminContactPhoneWebRequestBean extends BasePizzaController im
                // Try it again
                try {
                        // Link it, too
-                       updatedContact = this.adminPhoneBean.linkNewMobileNumberWithContact(contact, number);
+                       updatedContact = this.adminContactPhoneBean.linkNewMobileNumberWithContact(targetContact, number);
                } catch (final PhoneNumberAlreadyLinkedException ex) {
                        // Throw again as cause
                        this.showFacesMessage("form_add_contact_mobile:mobileNumber", ex); //NOI18N
@@ -582,6 +603,24 @@ public class PizzaAdminContactPhoneWebRequestBean extends BasePizzaController im
                return "admin_show_contact"; //NOI18N
        }
 
+       /**
+        * Getter for contact instance
+        * <p>
+        * @return Contact instance
+        */
+       public Contact getContact () {
+               return this.contact;
+       }
+
+       /**
+        * Setter for contact instance
+        * <p>
+        * @param contact Contact instance
+        */
+       public void setContact (final Contact contact) {
+               this.contact = contact;
+       }
+
        /**
         * Getter for fax area code
         * <p>
@@ -690,6 +729,24 @@ public class PizzaAdminContactPhoneWebRequestBean extends BasePizzaController im
                this.landLineNumber = landLineNumber;
        }
 
+       /**
+        * Getter for mobile number
+        * <p>
+        * @return Mobile number
+        */
+       public Long getMobileNumber () {
+               return this.mobileNumber;
+       }
+
+       /**
+        * Setter for mobile number
+        * <p>
+        * @param mobileNumber Mobile number
+        */
+       public void setMobileNumber (final Long mobileNumber) {
+               this.mobileNumber = mobileNumber;
+       }
+
        /**
         * Getter for mobile provider
         * <p>
@@ -709,21 +766,21 @@ public class PizzaAdminContactPhoneWebRequestBean extends BasePizzaController im
        }
 
        /**
-        * Getter for mobile number
+        * Setter for phone id
         * <p>
-        * @return Mobile number
+        * @return Phone id
         */
-       public Long getMobileNumber () {
-               return this.mobileNumber;
+       public Long getPhoneId () {
+               return this.phoneId;
        }
 
        /**
-        * Setter for mobile number
+        * Getter for phone id
         * <p>
-        * @param mobileNumber Mobile number
+        * @param phoneId Phone id
         */
-       public void setMobileNumber (final Long mobileNumber) {
-               this.mobileNumber = mobileNumber;
+       public void setPhoneId (final Long phoneId) {
+               this.phoneId = phoneId;
        }
 
        /**
@@ -737,7 +794,7 @@ public class PizzaAdminContactPhoneWebRequestBean extends BasePizzaController im
                        Context context = new InitialContext();
 
                        // Try to lookup the beans
-                       this.adminPhoneBean = (AdminContactsPhoneSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/adminContactPhone!org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote"); //NOI18N
+                       this.adminContactPhoneBean = (AdminContactsPhoneSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/adminContactPhone!org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote"); //NOI18N
                } catch (final NamingException e) {
                        // Throw again
                        throw new FaceletException(e);
@@ -750,31 +807,34 @@ public class PizzaAdminContactPhoneWebRequestBean extends BasePizzaController im
         * @return Redirect outcome
         */
        public String unlinkFaxContactData () {
+               // Create fax number instance
+               DialableFaxNumber number = this.createFaxNumber();
+
                // Is all data set
-               if (this.beanHelper.getFaxNumber() == null) {
+               if (number == null) {
                        // Not set, throw NPE
-                       throw new NullPointerException("this.beanHelper.faxNumber is null"); //NOI18N
-               } else if (this.beanHelper.getFaxNumber().getPhoneId() == null) {
+                       throw new NullPointerException("number is null"); //NOI18N
+               } else if (number.getPhoneId() == null) {
                        // Throw NPE again
-                       throw new NullPointerException("this.beanHelper.faxNumber.phoneId is null"); //NOI18N
-               } else if (this.beanHelper.getFaxNumber().getPhoneId() < 1) {
+                       throw new NullPointerException("number.phoneId is null"); //NOI18N
+               } else if (number.getPhoneId() < 1) {
                        // Invalid number
-                       throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.faxNumber.phoneId={0} is not valid", this.beanHelper.getFaxNumber().getPhoneId())); //NOI18N
-               } else if (this.beanHelper.getFaxNumber().getPhoneNumber() == null) {
+                       throw new IllegalArgumentException(MessageFormat.format("number.phoneId={0} is not valid", number.getPhoneId())); //NOI18N
+               } else if (number.getPhoneNumber() == null) {
                        // Throw NPE again
-                       throw new NullPointerException("this.beanHelper.faxNumber.phoneNumber is null"); //NOI18N
-               } else if (this.beanHelper.getFaxNumber().getPhoneNumber() < 1) {
+                       throw new NullPointerException("number.phoneNumber is null"); //NOI18N
+               } else if (number.getPhoneNumber() < 1) {
                        // Throw it again ...
-                       throw new NullPointerException(MessageFormat.format("this.beanHelper.faxNumber.phoneNumber={0} is not valid.", this.beanHelper.getFaxNumber().getPhoneNumber())); //NOI18N
-               } else if (this.beanHelper.getContact() == null) {
+                       throw new NullPointerException(MessageFormat.format("number.phoneNumber={0} is not valid.", number.getPhoneNumber())); //NOI18N
+               } else if (this.getContact() == null) {
                        // ... and throw again
-                       throw new NullPointerException("this.beanHelper.contact is null"); //NOI18N
-               } else if (this.beanHelper.getContact().getContactId() == null) {
+                       throw new NullPointerException("this.contact is null"); //NOI18N
+               } else if (this.getContact().getContactId() == null) {
                        // ... and again ...
-                       throw new NullPointerException("this.beanHelper.contact.contactId is null"); //NOI18N
-               } else if (this.beanHelper.getContact().getContactId() < 1) {
+                       throw new NullPointerException("this.contact.contactId is null"); //NOI18N
+               } else if (this.getContact().getContactId() < 1) {
                        // Invalid id number
-                       throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.contact.contactId={0} is invalid.", this.beanHelper.getContact().getContactId())); //NOI18N
+                       throw new IllegalArgumentException(MessageFormat.format("this.contact.contactId={0} is invalid.", this.getContact().getContactId())); //NOI18N
                }
 
                // Init contact instance
@@ -782,7 +842,7 @@ public class PizzaAdminContactPhoneWebRequestBean extends BasePizzaController im
 
                try {
                        // Unlink it and return contact without fax instance
-                       updatedContact = this.adminPhoneBean.unlinkFaxDataFromContact(this.beanHelper.getContact(), this.beanHelper.getFaxNumber());
+                       updatedContact = this.adminContactPhoneBean.unlinkFaxDataFromContact(this.getContact(), number);
                } catch (final PhoneNumberNotLinkedException ex) {
                        // Did not work
                        this.showFacesMessage("form_unlink_contact_fax:faxNumberId", ex); //NOI18N
@@ -790,7 +850,7 @@ public class PizzaAdminContactPhoneWebRequestBean extends BasePizzaController im
                }
 
                // Fire event
-               this.faxNumberUnlinkedEvent.fire(new AdminUnlinkedFaxNumberEvent(updatedContact, this.beanHelper.getFaxNumber()));
+               this.faxNumberUnlinkedEvent.fire(new AdminUnlinkedFaxNumberEvent(updatedContact, number));
 
                // All fine here
                return "admin_show_contact"; //NOI18N
@@ -802,31 +862,34 @@ public class PizzaAdminContactPhoneWebRequestBean extends BasePizzaController im
         * @return Redirect outcome
         */
        public String unlinkLandLineContactData () {
+               // Create fax number instance
+               DialableLandLineNumber number = this.createLandLineNumber();
+
                // Is all data set
-               if (this.beanHelper.getLandLineNumber() == null) {
+               if (number == null) {
                        // Not set, throw NPE
-                       throw new NullPointerException("this.beanHelper.landLineNumber is null"); //NOI18N
-               } else if (this.beanHelper.getLandLineNumber().getPhoneId() == null) {
+                       throw new NullPointerException("number is null"); //NOI18N
+               } else if (number.getPhoneId() == null) {
                        // Throw NPE again
-                       throw new NullPointerException("this.beanHelper.landLineNumber.phoneId is null"); //NOI18N
-               } else if (this.beanHelper.getLandLineNumber().getPhoneId() < 1) {
+                       throw new NullPointerException("number.phoneId is null"); //NOI18N
+               } else if (number.getPhoneId() < 1) {
                        // Invalid number
-                       throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.landLineNumber.phoneId={0} is not valid", this.beanHelper.getLandLineNumber().getPhoneId())); //NOI18N
-               } else if (this.beanHelper.getLandLineNumber().getPhoneNumber() == null) {
+                       throw new IllegalArgumentException(MessageFormat.format("number.phoneId={0} is not valid", number.getPhoneId())); //NOI18N
+               } else if (number.getPhoneNumber() == null) {
                        // Throw NPE again
-                       throw new NullPointerException("this.beanHelper.landLineNumber.phoneNumber is null"); //NOI18N
-               } else if (this.beanHelper.getLandLineNumber().getPhoneNumber() < 1) {
+                       throw new NullPointerException("number.phoneNumber is null"); //NOI18N
+               } else if (number.getPhoneNumber() < 1) {
                        // Throw it again ...
-                       throw new NullPointerException(MessageFormat.format("this.beanHelper.landLineNumber.phoneNumber={0} is not valid.", this.beanHelper.getLandLineNumber().getPhoneNumber())); //NOI18N
-               } else if (this.beanHelper.getContact() == null) {
+                       throw new NullPointerException(MessageFormat.format("number.phoneNumber={0} is not valid.", number.getPhoneNumber())); //NOI18N
+               } else if (this.getContact() == null) {
                        // ... and throw again
-                       throw new NullPointerException("this.beanHelper.contact is null"); //NOI18N
-               } else if (this.beanHelper.getContact().getContactId() == null) {
+                       throw new NullPointerException("this.contact is null"); //NOI18N
+               } else if (this.getContact().getContactId() == null) {
                        // ... and again ...
-                       throw new NullPointerException("this.beanHelper.contact.contactId is null"); //NOI18N
-               } else if (this.beanHelper.getContact().getContactId() < 1) {
+                       throw new NullPointerException("this.contact.contactId is null"); //NOI18N
+               } else if (this.getContact().getContactId() < 1) {
                        // Invalid id number
-                       throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.contact.contactId={0} is invalid.", this.beanHelper.getContact().getContactId())); //NOI18N
+                       throw new IllegalArgumentException(MessageFormat.format("this.contact.contactId={0} is invalid.", this.getContact().getContactId())); //NOI18N
                }
 
                // Init contact instance
@@ -834,7 +897,7 @@ public class PizzaAdminContactPhoneWebRequestBean extends BasePizzaController im
 
                try {
                        // Unlink it and return contact without landLine instance
-                       updatedContact = this.adminPhoneBean.unlinkLandLineDataFromContact(this.beanHelper.getContact(), this.beanHelper.getLandLineNumber());
+                       updatedContact = this.adminContactPhoneBean.unlinkLandLineDataFromContact(this.getContact(), number);
                } catch (final PhoneNumberNotLinkedException ex) {
                        // Did not work
                        this.showFacesMessage("form_unlink_contact_landLine:landLineNumberId", ex); //NOI18N
@@ -842,7 +905,7 @@ public class PizzaAdminContactPhoneWebRequestBean extends BasePizzaController im
                }
 
                // Fire event
-               this.landLineNumberUnlinkedEvent.fire(new AdminUnlinkedLandLineNumberEvent(updatedContact, this.beanHelper.getLandLineNumber()));
+               this.landLineNumberUnlinkedEvent.fire(new AdminUnlinkedLandLineNumberEvent(updatedContact, number));
 
                // All fine here
                return "admin_show_contact"; //NOI18N
@@ -854,40 +917,43 @@ public class PizzaAdminContactPhoneWebRequestBean extends BasePizzaController im
         * @return Redirect outcome
         */
        public String unlinkMobileContactData () {
+               // Create fax number instance
+               DialableMobileNumber number = this.createMobileNumber();
+
                // Is all data set
-               if (this.beanHelper.getMobileNumber() == null) {
+               if (number == null) {
                        // Not set, throw NPE
-                       throw new NullPointerException("this.beanHelper.mobileNumber is null"); //NOI18N
-               } else if (this.beanHelper.getMobileNumber().getPhoneId() == null) {
+                       throw new NullPointerException("number is null"); //NOI18N
+               } else if (number.getPhoneId() == null) {
                        // Throw NPE again
-                       throw new NullPointerException("this.beanHelper.mobileNumber.phoneId is null"); //NOI18N
-               } else if (this.beanHelper.getMobileNumber().getPhoneId() < 1) {
+                       throw new NullPointerException("number.phoneId is null"); //NOI18N
+               } else if (number.getPhoneId() < 1) {
                        // Invalid number
-                       throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.mobileNumber.phoneId={0} is not valid", this.beanHelper.getMobileNumber().getPhoneId())); //NOI18N
-               } else if (this.beanHelper.getMobileNumber().getMobileProvider() == null) {
+                       throw new IllegalArgumentException(MessageFormat.format("number.phoneId={0} is not valid", number.getPhoneId())); //NOI18N
+               } else if (number.getMobileProvider() == null) {
                        // Throw NPE
-                       throw new NullPointerException("this.beanHelper.mobileNumber.mobileProvider is null"); //NOI18N
-               } else if (this.beanHelper.getMobileNumber().getMobileProvider().getProviderId() == null) {
+                       throw new NullPointerException("number.mobileProvider is null"); //NOI18N
+               } else if (number.getMobileProvider().getProviderId() == null) {
                        // ... throw again
-                       throw new NullPointerException("this.beanHelper.mobileNumber.mobileProvider.providerId is null"); //NOI18N
-               } else if (this.beanHelper.getMobileNumber().getMobileProvider().getProviderId() < 1) {
+                       throw new NullPointerException("number.mobileProvider.providerId is null"); //NOI18N
+               } else if (number.getMobileProvider().getProviderId() < 1) {
                        // Id not valid
-                       throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.mobileNumber.mobileProvider.providerId={0} is not valid.", this.beanHelper.getMobileNumber().getMobileProvider().getProviderId())); //NOI18N
-               } else if (this.beanHelper.getMobileNumber().getPhoneNumber() == null) {
+                       throw new IllegalArgumentException(MessageFormat.format("number.mobileProvider.providerId={0} is not valid.", number.getMobileProvider().getProviderId())); //NOI18N
+               } else if (number.getPhoneNumber() == null) {
                        // Throw NPE again
-                       throw new NullPointerException("this.beanHelper.mobileNumber.phoneNumber is null"); //NOI18N
-               } else if (this.beanHelper.getMobileNumber().getPhoneNumber() < 1) {
+                       throw new NullPointerException("number.phoneNumber is null"); //NOI18N
+               } else if (number.getPhoneNumber() < 1) {
                        // Throw it again ...
-                       throw new NullPointerException(MessageFormat.format("this.beanHelper.mobileNumber.phoneNumber={0} is not valid.", this.beanHelper.getMobileNumber().getPhoneNumber())); //NOI18N
-               } else if (this.beanHelper.getContact() == null) {
+                       throw new NullPointerException(MessageFormat.format("number.phoneNumber={0} is not valid.", number.getPhoneNumber())); //NOI18N
+               } else if (this.getContact() == null) {
                        // ... and throw again
-                       throw new NullPointerException("this.beanHelper.contact is null"); //NOI18N
-               } else if (this.beanHelper.getContact().getContactId() == null) {
+                       throw new NullPointerException("this.contact is null"); //NOI18N
+               } else if (this.getContact().getContactId() == null) {
                        // ... and again ...
-                       throw new NullPointerException("this.beanHelper.contact.contactId is null"); //NOI18N
-               } else if (this.beanHelper.getContact().getContactId() < 1) {
+                       throw new NullPointerException("this.contact.contactId is null"); //NOI18N
+               } else if (this.getContact().getContactId() < 1) {
                        // Invalid id number
-                       throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.contact.contactId={0} is invalid.", this.beanHelper.getContact().getContactId())); //NOI18N
+                       throw new IllegalArgumentException(MessageFormat.format("this.contact.contactId={0} is invalid.", this.getContact().getContactId())); //NOI18N
                }
 
                // Init contact instance
@@ -895,7 +961,7 @@ public class PizzaAdminContactPhoneWebRequestBean extends BasePizzaController im
 
                try {
                        // Unlink it and return contact without mobile instance
-                       updatedContact = this.adminPhoneBean.unlinkMobileDataFromContact(this.beanHelper.getContact(), this.beanHelper.getMobileNumber());
+                       updatedContact = this.adminContactPhoneBean.unlinkMobileDataFromContact(this.getContact(), number);
                } catch (final PhoneNumberNotLinkedException ex) {
                        // Did not work
                        this.showFacesMessage("form_unlink_contact_mobile:mobileNumberId", ex); //NOI18N
@@ -903,7 +969,7 @@ public class PizzaAdminContactPhoneWebRequestBean extends BasePizzaController im
                }
 
                // Fire event
-               this.mobileNumberUnlinkedEvent.fire(new AdminUnlinkedMobileNumberEvent(updatedContact, this.beanHelper.getMobileNumber()));
+               this.mobileNumberUnlinkedEvent.fire(new AdminUnlinkedMobileNumberEvent(updatedContact, number));
 
                // All fine here
                return "admin_show_contact"; //NOI18N
@@ -916,4 +982,115 @@ public class PizzaAdminContactPhoneWebRequestBean extends BasePizzaController im
                // Clear all data
        }
 
+       /**
+        * Creates an instance of a DialableFaxNumber class
+        * <p>
+        * @return DialableFaxNumber class
+        */
+       private DialableFaxNumber createFaxNumber () {
+               // Instanciate it
+               DialableFaxNumber number = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
+
+               // Set all other fields
+               number.setPhoneEntryCreated(this.getPhoneEntryCreated());
+               number.setPhoneEntryUpdated(this.getPhoneEntryUpdated());
+
+               // Is id number there?
+               if (this.getPhoneId() instanceof Long) {
+                       // Set it
+                       number.setPhoneId(this.getPhoneId());
+               }
+
+               // Return it
+               return number;
+       }
+
+       /**
+        * Returns an instance of a DialableLandLineNumber from all fields stored in
+        * this bean.
+        * <p>
+        * @return An instance of a DialableLandLineNumber class
+        */
+       private DialableLandLineNumber createLandLineNumber () {
+               // Initialize it
+               DialableLandLineNumber number = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
+
+               // Add all other data
+               number.setPhoneEntryCreated(this.getPhoneEntryCreated());
+               number.setPhoneEntryUpdated(this.getPhoneEntryUpdated());
+
+               // Is id number set?
+               if (this.getPhoneId() instanceof Long) {
+                       // Set it
+                       number.setPhoneId(this.getPhoneId());
+               }
+
+               // Return it
+               return number;
+       }
+
+       /**
+        * Returns an instance of a DialableMobileNumber from all fields stored in
+        * this bean.
+        * <p>
+        * @return An instance of a DialableMobileNumber class
+        */
+       private DialableMobileNumber createMobileNumber () {
+               // Initialize it
+               DialableMobileNumber number = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
+
+               // Add all other data
+               number.setPhoneEntryCreated(this.getPhoneEntryCreated());
+               number.setPhoneEntryUpdated(this.getPhoneEntryUpdated());
+
+               // Is id number set?
+               if (this.getPhoneId() instanceof Long) {
+                       // Set it
+                       number.setPhoneId(this.getPhoneId());
+               }
+
+               // Return it
+               return number;
+       }
+
+       /**
+        * Getter for phone entry created
+        * <p>
+        * @param faxNumberEntryCreated Phone entry created
+        */
+       @SuppressWarnings ("ReturnOfDateField")
+       private Calendar getPhoneEntryCreated () {
+               return this.phoneEntryCreated;
+       }
+
+       /**
+        * Setter for phone entry created
+        * <p>
+        * @param phoneEntryCreated Phone entry created
+        */
+       @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+       private void setPhoneEntryCreated (final Calendar phoneEntryCreated) {
+               this.phoneEntryCreated = phoneEntryCreated;
+       }
+
+       /**
+        * Getter for phone entry updated
+        * <p>
+        * @return Phone entry updated
+        */
+       @SuppressWarnings ("ReturnOfDateField")
+       private Calendar getPhoneEntryUpdated () {
+               return this.phoneEntryUpdated;
+       }
+
+       /**
+        * Setter for phone entry updated
+        * <p>
+        * @param phoneEntryUpdated Phone entry updated
+        */
+       @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+       private void setPhoneEntryUpdated (final Calendar phoneEntryUpdated) {
+               this.phoneEntryUpdated = phoneEntryUpdated;
+       }
+
 }
index 62ac24e49cf62c4f261ab2a9afb0acaeb9f72366..a221b7372b53ce81580846e1aabd2b922cdfc202 100644 (file)
@@ -77,6 +77,21 @@ public class PizzaContactPhoneWebSessionBean extends BasePizzaController impleme
         */
        private final Map<DialableNumber, List<Contact>> contacts;
 
+       /**
+        * fax number
+        */
+       private DialableFaxNumber faxNumber;
+
+       /**
+        * land-line number
+        */
+       private DialableLandLineNumber landLineNumber;
+
+       /**
+        * Chosen mobile number
+        */
+       private DialableMobileNumber mobileNumber;
+
        /**
         * Default constructor
         */
@@ -333,12 +348,12 @@ public class PizzaContactPhoneWebSessionBean extends BasePizzaController impleme
         */
        public List<Contact> allCurrentFaxNumberContacts () {
                // Get id
-               DialableFaxNumber faxNumber = this.beanHelper.getFaxNumber();
+               DialableFaxNumber number = this.getFaxNumber();
 
                // Is cache there?
-               if (this.contacts.containsKey(faxNumber)) {
+               if (this.contacts.containsKey(number)) {
                        // Return cached version
-                       return this.contacts.get(faxNumber);
+                       return this.contacts.get(number);
                } else {
                        // Ask bean
                        List<Contact> list = new LinkedList<>();
@@ -346,14 +361,14 @@ public class PizzaContactPhoneWebSessionBean extends BasePizzaController impleme
                        // "Walk" through all contacts
                        for (final Contact contact : this.contactController.allContacts()) {
                                // Is mobile instance the same?
-                               if (Objects.equals(contact.getContactFaxNumber(), faxNumber)) {
+                               if (Objects.equals(contact.getContactFaxNumber(), number)) {
                                        // Found one
                                        list.add(contact);
                                }
                        }
 
                        // Store result in cache
-                       this.contacts.put(faxNumber, list);
+                       this.contacts.put(number, list);
 
                        // Return now-cached list
                        return list;
@@ -367,12 +382,12 @@ public class PizzaContactPhoneWebSessionBean extends BasePizzaController impleme
         */
        public List<Contact> allCurrentLandLineNumberContacts () {
                // Get id
-               DialableLandLineNumber landLineNumber = this.beanHelper.getLandLineNumber();
+               DialableLandLineNumber number = this.getLandLineNumber();
 
                // Is cache there?
-               if (this.contacts.containsKey(landLineNumber)) {
+               if (this.contacts.containsKey(number)) {
                        // Return cached version
-                       return this.contacts.get(landLineNumber);
+                       return this.contacts.get(number);
                } else {
                        // Ask bean
                        List<Contact> list = new LinkedList<>();
@@ -380,14 +395,14 @@ public class PizzaContactPhoneWebSessionBean extends BasePizzaController impleme
                        // "Walk" through all contacts
                        for (final Contact contact : this.contactController.allContacts()) {
                                // Is mobile instance the same?
-                               if (Objects.equals(contact.getContactLandLineNumber(), landLineNumber)) {
+                               if (Objects.equals(contact.getContactLandLineNumber(), number)) {
                                        // Found one
                                        list.add(contact);
                                }
                        }
 
                        // Store result in cache
-                       this.contacts.put(landLineNumber, list);
+                       this.contacts.put(number, list);
 
                        // Return now-cached list
                        return list;
@@ -401,12 +416,12 @@ public class PizzaContactPhoneWebSessionBean extends BasePizzaController impleme
         */
        public List<Contact> allCurrentMobileNumberContacts () {
                // Get id
-               DialableMobileNumber mobileNumber = this.beanHelper.getMobileNumber();
+               DialableMobileNumber number = this.getMobileNumber();
 
                // Is cache there?
-               if (this.contacts.containsKey(mobileNumber)) {
+               if (this.contacts.containsKey(number)) {
                        // Return cached version
-                       return this.contacts.get(mobileNumber);
+                       return this.contacts.get(number);
                } else {
                        // Ask bean
                        List<Contact> list = new LinkedList<>();
@@ -414,20 +429,74 @@ public class PizzaContactPhoneWebSessionBean extends BasePizzaController impleme
                        // "Walk" through all contacts
                        for (final Contact contact : this.contactController.allContacts()) {
                                // Is mobile instance the same?
-                               if (Objects.equals(contact.getContactMobileNumber(), mobileNumber)) {
+                               if (Objects.equals(contact.getContactMobileNumber(), number)) {
                                        // Found one
                                        list.add(contact);
                                }
                        }
 
                        // Store result in cache
-                       this.contacts.put(mobileNumber, list);
+                       this.contacts.put(number, list);
 
                        // Return now-cached list
                        return list;
                }
        }
 
+       /**
+        * Getter for chosen fax number
+        * <p>
+        * @return fax number
+        */
+       public DialableFaxNumber getFaxNumber () {
+               return this.faxNumber;
+       }
+
+       /**
+        * Setter for chosen fax number
+        * <p>
+        * @param faxNumber fax number
+        */
+       public void setFaxNumber (final DialableFaxNumber faxNumber) {
+               this.faxNumber = faxNumber;
+       }
+
+       /**
+        * Getter for chosen land-line number
+        * <p>
+        * @return land-line number
+        */
+       public DialableLandLineNumber getLandLineNumber () {
+               return this.landLineNumber;
+       }
+
+       /**
+        * Setter for chosen land-line number
+        * <p>
+        * @param landLineNumber land-line number
+        */
+       public void setLandLineNumber (final DialableLandLineNumber landLineNumber) {
+               this.landLineNumber = landLineNumber;
+       }
+
+       /**
+        * Getter for chosen mobile number
+        * <p>
+        * @return mobile number
+        */
+       public DialableMobileNumber getMobileNumber () {
+               return this.mobileNumber;
+       }
+
+       /**
+        * Setter for chosen mobile number
+        * <p>
+        * @param mobileNumber mobile number
+        */
+       public void setMobileNumber (final DialableMobileNumber mobileNumber) {
+               this.mobileNumber = mobileNumber;
+       }
+
        /**
         * Clears this bean
         */
index eda423acf58812cda6af1494839cb9c2c466deeb..6ab779f7297fdda42b8a3bb7e178138f12aca726 100644 (file)
@@ -189,7 +189,7 @@ public class PizzaAdminCustomerWebRequestBean extends BasePizzaController implem
        }
 
        /**
-        * Checks whether ther minimum customer data is set
+        * Checks whether the minimum customer data is set
         * <p>
         * @return Whether minimum data is set
         */
index 684adee9d1eceef55267359e27ab69d0798f13be..e9939cd2268eb67125bd265f385fbe8d8e1e431e 100644 (file)
@@ -25,19 +25,20 @@ import javax.inject.Named;
 import org.mxchange.jcontacts.contact.Contact;
 import org.mxchange.jcontacts.events.contact.created.CreatedContactEvent;
 import org.mxchange.jcontacts.events.contact.created.ObservableCreatedContactEvent;
+import org.mxchange.jcustomercore.events.customer.created.CreatedCustomerEvent;
+import org.mxchange.jcustomercore.events.customer.created.ObservableCreatedCustomerEvent;
 import org.mxchange.jcustomercore.model.customer.Customer;
-import org.mxchange.jphone.events.helper.fax.created.HelperCreatedFaxNumberEvent;
-import org.mxchange.jphone.events.helper.fax.created.ObservableHelperCreatedFaxNumberEvent;
-import org.mxchange.jphone.events.helper.landline.created.HelperCreatedLandLineNumberEvent;
-import org.mxchange.jphone.events.helper.landline.created.ObservableHelperCreatedLandLineNumberEvent;
-import org.mxchange.jphone.events.helper.mobile.created.ObservableHelperCreatedMobileNumberEvent;
+import org.mxchange.jphone.events.fax.created.CreatedFaxNumberEvent;
+import org.mxchange.jphone.events.fax.created.ObservableCreatedFaxNumberEvent;
+import org.mxchange.jphone.events.landline.created.CreatedLandLineNumberEvent;
+import org.mxchange.jphone.events.landline.created.ObservableCreatedLandLineNumberEvent;
 import org.mxchange.jphone.events.mobile.created.CreatedMobileNumberEvent;
 import org.mxchange.jphone.events.mobile.created.ObservableCreatedMobileNumberEvent;
 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
 import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
-import org.mxchange.jusercore.events.user.helper.created.HelperCreatedUserEvent;
-import org.mxchange.jusercore.events.user.helper.created.ObservableHelperCreatedUserEvent;
+import org.mxchange.jusercore.events.user.created.CreatedUserEvent;
+import org.mxchange.jusercore.events.user.created.ObservableCreatedUserEvent;
 import org.mxchange.jusercore.model.user.User;
 import org.mxchange.pizzaapplication.beans.contact.PizzaAdminContactWebRequestController;
 import org.mxchange.pizzaapplication.beans.customer.PizzaAdminCustomerWebRequestController;
@@ -95,17 +96,23 @@ public class PizzaWebRequestHelperBean implements PizzaWebRequestHelperControlle
        private Event<ObservableCreatedContactEvent> contactCreatedEvent;
 
        /**
-        * Fax number
+        * Customer instance
         */
        private Customer customer;
 
        /**
-<<<<<<< HEAD:src/java/org/mxchange/pizzaapplication/beans/helper/PizzaWebRequestHelperBean.java
-        * General user controller
+        * General customer controller
         */
        @Inject
        private PizzaCustomerWebSessionController customerController;
 
+       /**
+        * An event being fired when a customer has been created
+        */
+       @Any
+       @Inject
+       private Event<ObservableCreatedCustomerEvent> customerCreatedEvent;
+
        /**
         * Fax number
         */
@@ -116,7 +123,7 @@ public class PizzaWebRequestHelperBean implements PizzaWebRequestHelperControlle
         */
        @Any
        @Inject
-       private Event<ObservableHelperCreatedFaxNumberEvent> faxNumberCreatedEvent;
+       private Event<ObservableCreatedFaxNumberEvent> faxNumberCreatedEvent;
 
        /**
         * Land-line number
@@ -128,7 +135,7 @@ public class PizzaWebRequestHelperBean implements PizzaWebRequestHelperControlle
         */
        @Any
        @Inject
-       private Event<ObservableHelperCreatedLandLineNumberEvent> landLineNumberCreatedEvent;
+       private Event<ObservableCreatedLandLineNumberEvent> landLineNumberCreatedEvent;
 
        /**
         * Mobile number
@@ -154,55 +161,206 @@ public class PizzaWebRequestHelperBean implements PizzaWebRequestHelperControlle
        private PizzaUserWebSessionController userController;
 
        /**
-        * Event for when a fax number instance was created
+        * Event for when a user instance was created
         */
        @Any
        @Inject
-       private Event<ObservableHelperCreatedFaxNumberEvent> faxNumberCreatedEvent;
+       private Event<ObservableCreatedUserEvent> userCreatedEvent;
 
        /**
-        * Event for when a land-line number instance was created
+        * Default constructor
         */
-       @Any
-       @Inject
-       private Event<ObservableHelperCreatedLandLineNumberEvent> landLineNumberCreatedEvent;
+       public PizzaWebRequestHelperBean () {
+               // Call super constructor
+               super();
+
+               // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[3].getClassName(), Thread.currentThread().getStackTrace()[3].getMethodName());
+               // System.out.println(MessageFormat.format("{0}: Constructed, caller: {1}", this.getClass().getSimpleName(), caller));
+       }
 
        /**
-        * Event for when a mobile number instance was created
+        * Copies currently set customer instance's data to adminCustomerController
         */
-       @Any
-       @Inject
-       private Event<ObservableHelperCreatedMobileNumberEvent> mobileNumberCreatedEvent;
+       public void copyCustomerToController () {
+               // Validate customer instance
+               if (this.getCustomer() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("this.customer is null"); //NOI18N
+               } else if (this.getCustomer().getCustomerId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("this.customer.customerId is null"); //NOI18N
+               } else if (this.getContact().getContactId() < 1) {
+                       // Not valid
+                       throw new IllegalStateException(MessageFormat.format("this.customer.customerId={0} is not valid.", this.getContact().getContactId())); //NOI18N
+               }
+
+               // Set all phone instances
+               this.setPhoneInstances(this.getContact());
+
+               // Set all fields: user
+               this.customerCreatedEvent.fire(new CreatedCustomerEvent(this.getCustomer()));
+       }
 
        /**
-        * Regular user controller
+        * Getter for contact instance
+        * <p>
+        * @return Contact instance
         */
-       @Inject
-       private TrainingsUserWebSessionController userController;
+       public Contact getContact () {
+               return this.contact;
+       }
 
        /**
-        * Event for when a user instance was created
+        * Setter for contact instance
+        * <p>
+        * @param contact Contact instance
         */
-       @Any
-       @Inject
-       private Event<ObservableHelperCreatedUserEvent> userCreatedEvent;
+       public void setContact (final Contact contact) {
+               // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[THREAD_STACK].getClassName(), Thread.currentThread().getStackTrace()[THREAD_STACK].getMethodName());
+               // System.out.println(MessageFormat.format("{0}: Setting contact={1}, previous: {2}, caller: {3}", this.getClass().getSimpleName(), contact, this.contact, caller));
+               this.contact = contact;
+       }
 
        /**
-        * Default constructor
+        * Returns a message key depending on if this contact is a user and/or a
+        * contact. If this contact is unused, a default key is returned.
+        * <p>
+        * @param contact Contact instance to check
+        * <p>
+        * @return Message key
         */
-       public PizzaWebRequestHelperBean () {
-               // Call super constructor
-               super();
+       public String getContactUsageMessageKey (final Contact contact) {
+               // The contact must be valid
+               if (null == contact) {
+                       // Throw NPE
+                       throw new NullPointerException("contact is null"); //NOI18N
+               } else if (contact.getContactId() == null) {
+                       // Throw again ...
+                       throw new NullPointerException("contact.contactId is null"); //NOI18N
+               } else if (contact.getContactId() < 1) {
+                       // Not valid
+                       throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
+               }
 
-               // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[3].getClassName(), Thread.currentThread().getStackTrace()[3].getMethodName());
-               // System.out.println(MessageFormat.format("{0}: Constructed, caller: {1}", this.getClass().getSimpleName(), caller));
+               // Default key is "unused"
+               String messageKey = "CONTACT_IS_UNUSED"; //NOI18N
+
+               // Check user/customer contact
+               boolean isUserContact = this.userController.isContactFound(contact);
+               boolean isCustomerContact = this.customerController.isContactFound(contact);
+
+               // Check user first
+               if (isUserContact && isCustomerContact) {
+                       // Is both
+                       messageKey = "CONTACT_IS_CUSTOMER_USER"; //NOI18N
+               } else if (isUserContact) {
+                       // Only user
+                       messageKey = "CONTACT_IS_USER"; //NOI18N
+               } else if (isCustomerContact) {
+                       // Only customer
+                       messageKey = "CONTACT_IS_CUSTOMER"; //NOI18N
+               }
+
+               // Return message key
+               return messageKey;
        }
 
        /**
-        * Copies currently set contact instances data to adminContactController
+        * Getter for customer instance
+        * <p>
+        * @return Customer instance
         */
-       public void copyContactToController () {
-               // Validate user instance
+       public Customer getCustomer () {
+               return this.customer;
+       }
+
+       /**
+        * Setter for customer instance
+        * <p>
+        * @param customer Contact instance
+        */
+       public void setCustomer (final Customer customer) {
+               this.customer = customer;
+       }
+
+       /**
+        * Getter for dialable fax number
+        * <p>
+        * @return Dialable fax number
+        */
+       public DialableFaxNumber getFaxNumber () {
+               return this.faxNumber;
+       }
+
+       /**
+        * Setter for dialable fax number
+        * <p>
+        * @param faxNumber Dialable fax number
+        */
+       public void setFaxNumber (final DialableFaxNumber faxNumber) {
+               this.faxNumber = faxNumber;
+       }
+
+       /**
+        * Getter for dialable land-line number
+        * <p>
+        * @return Dialable land-line number
+        */
+       public DialableLandLineNumber getLandLineNumber () {
+               return this.landLineNumber;
+       }
+
+       /**
+        * Setter for dialable land-line number
+        * <p>
+        * @param landLineNumber Dialable land-line number
+        */
+       public void setLandLineNumber (final DialableLandLineNumber landLineNumber) {
+               this.landLineNumber = landLineNumber;
+       }
+
+       /**
+        * Getter for dialable mobile number
+        * <p>
+        * @return Dialable mobile number
+        */
+       public DialableMobileNumber getMobileNumber () {
+               return this.mobileNumber;
+       }
+
+       /**
+        * Setter for dialable mobile number
+        * <p>
+        * @param mobileNumber Dialable mobile number
+        */
+       public void setMobileNumber (final DialableMobileNumber mobileNumber) {
+               this.mobileNumber = mobileNumber;
+       }
+
+       /**
+        * Getter for user instance
+        * <p>
+        * @return User instance
+        */
+       public User getUser () {
+               return this.user;
+       }
+
+       /**
+        * Setter for user instance
+        * <p>
+        * @param user User instance
+        */
+       public void setUser (final User user) {
+               this.user = user;
+       }
+
+       /**
+        * Notifies other controllers (backing beans) if a contact id has been
+        * successfully converted to a Contact instance.
+        */
+       public void notifyControllerContactConverted () {
+               // Validate contact instance
                if (this.getContact() == null) {
                        // Throw NPE
                        throw new NullPointerException("this.contact is null"); //NOI18N
@@ -221,28 +379,11 @@ public class PizzaWebRequestHelperBean implements PizzaWebRequestHelperControlle
                this.contactCreatedEvent.fire(new CreatedContactEvent(this.getContact()));
        }
 
-       @Override
-       public void copyCustomerToController () {
-               // Validate user instance
-               if (this.getCustomer() == null) {
-                       // Throw NPE
-                       throw new NullPointerException("this.customer is null"); //NOI18N
-               } else if (this.getCustomer().getCustomerId() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("this.customer.customerId is null"); //NOI18N
-               } else if (this.getCustomer().getCustomerId() < 1) {
-                       // Not valid
-                       throw new IllegalStateException(MessageFormat.format("this.customer.customerId={0} is not valid.", this.getCustomer().getCustomerId())); //NOI18N
-               }
-
-               // Set all fields: user
-               this.adminCustomerController.copyCustomerToController(this.getCustomer());
-       }
-
        /**
-        * Copies currently set fax number's data to admin phone controller
+        * Notifies other controllers (backing beans) if a phone id has been
+        * successfully converted to a DialableFaxNumber instance.
         */
-       public void copyFaxNumberToController () {
+       public void notifyControllerFaxNumberConverted () {
                // Validate fax instance
                if (this.getFaxNumber() == null) {
                        // Throw NPE
@@ -277,13 +418,14 @@ public class PizzaWebRequestHelperBean implements PizzaWebRequestHelperControlle
                }
 
                // Fire event
-               this.faxNumberCreatedEvent.fire(new HelperCreatedFaxNumberEvent(this.getFaxNumber()));
+               this.faxNumberCreatedEvent.fire(new CreatedFaxNumberEvent(this.getFaxNumber()));
        }
 
        /**
-        * Copies currently set land-line number's data to admin phone controller
+        * Notifies other controllers (backing beans) if a phone id has been
+        * successfully converted to a DialableLandLineNumber instance.
         */
-       public void copyLandLineNumberToController () {
+       public void notifyControllerLandLineNumberConverted () {
                // Validate land-line instance
                if (this.getLandLineNumber() == null) {
                        // Throw NPE
@@ -318,13 +460,14 @@ public class PizzaWebRequestHelperBean implements PizzaWebRequestHelperControlle
                }
 
                // Fire event
-               this.landLineNumberCreatedEvent.fire(new HelperCreatedLandLineNumberEvent(this.getLandLineNumber()));
+               this.landLineNumberCreatedEvent.fire(new CreatedLandLineNumberEvent(this.getLandLineNumber()));
        }
 
        /**
-        * Copies currently set mobile number's data to admin phone controller
+        * Notifies other controllers (backing beans) if a phone id has been
+        * successfully converted to a DialableMobileNumber instance.
         */
-       public void copyMobileNumberToController () {
+       public void notifyControllerMobileNumberConverted () {
                // Validate mobile instance
                if (this.getMobileNumber() == null) {
                        // Throw NPE
@@ -357,9 +500,10 @@ public class PizzaWebRequestHelperBean implements PizzaWebRequestHelperControlle
        }
 
        /**
-        * Copies currently set user instances data to adminUserController
+        * Notifies other controllers (backing beans) if a user id has been
+        * successfully converted to a User instance.
         */
-       public void copyUserToController () {
+       public void notifyControllerUserConverted () {
                // Validate user instance
                if (this.getUser() == null) {
                        // Throw NPE
@@ -382,139 +526,12 @@ public class PizzaWebRequestHelperBean implements PizzaWebRequestHelperControlle
                this.setPhoneInstances(userContact);
 
                // Fire event
-               this.userCreatedEvent.fire(new HelperCreatedUserEvent(this.getUser()));
-       }
-
-       /**
-        * Getter for contact instance
-        * <p>
-        * @return Contact instance
-        */
-       public Contact getContact () {
-               return this.contact;
-       }
-
-       /**
-        * Setter for contact instance
-        * <p>
-        * @param contact Contact instance
-        */
-       public void setContact (final Contact contact) {
-               // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[THREAD_STACK].getClassName(), Thread.currentThread().getStackTrace()[THREAD_STACK].getMethodName());
-               // System.out.println(MessageFormat.format("{0}: Setting contact={1}, previous: {2}, caller: {3}", this.getClass().getSimpleName(), contact, this.contact, caller));
-               this.contact = contact;
-       }
-
-       /**
-        * Returns a message key depending on if this contact is a user and/or a
-        * contact. If this contact is unused, a default key is returned.
-        * <p>
-        * @param contact Contact instance to check
-        * <p>
-        * @return Message key
-        */
-       public String getContactUsageMessageKey (final Contact contact) {
-               // The contact must be valid
-               if (null == contact) {
-                       // Throw NPE
-                       throw new NullPointerException("contact is null"); //NOI18N
-               } else if (contact.getContactId() == null) {
-                       // Throw again ...
-                       throw new NullPointerException("contact.contactId is null"); //NOI18N
-               } else if (contact.getContactId() < 1) {
-                       // Not valid
-                       throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
-               }
-
-               // Default key is "unused"
-               String messageKey = "CONTACT_IS_UNUSED"; //NOI18N
-
-               // Check user/customer contact
-               boolean isUserContact = this.userController.isContactFound(contact);
-               boolean isCustomerContact = this.customerController.isContactFound(contact);
-
-               // Check user first
-               if (isUserContact && isCustomerContact) {
-                       // Is both
-                       messageKey = "CONTACT_IS_CUSTOMER_USER"; //NOI18N
-               } else if (isUserContact) {
-                       // Only user
-                       messageKey = "CONTACT_IS_USER"; //NOI18N
-               } else if (isCustomerContact) {
-                       // Only customer
-                       messageKey = "CONTACT_IS_CUSTOMER"; //NOI18N
-               }
-
-               // Return message key
-               return messageKey;
-       }
-
-       @Override
-       public Customer getCustomer () {
-               return this.customer;
-       }
-
-       @Override
-       public void setCustomer (final Customer customer) {
-               this.customer = customer;
-       }
-
-       /**
-        * Getter for dialable fax number
-        * <p>
-        * @return Dialable fax number
-        */
-       public DialableFaxNumber getFaxNumber () {
-               return this.faxNumber;
-       }
-
-       /**
-        * Setter for dialable fax number
-        * <p>
-        * @param faxNumber Dialable fax number
-        */
-       public void setFaxNumber (final DialableFaxNumber faxNumber) {
-               this.faxNumber = faxNumber;
-       }
-
-       /**
-        * Getter for dialable land-line number
-        * <p>
-        * @return Dialable land-line number
-        */
-       public DialableLandLineNumber getLandLineNumber () {
-               return this.landLineNumber;
-       }
-
-       /**
-        * Setter for dialable land-line number
-        * <p>
-        * @param landLineNumber Dialable land-line number
-        */
-       public void setLandLineNumber (final DialableLandLineNumber landLineNumber) {
-               this.landLineNumber = landLineNumber;
-       }
-
-       /**
-        * Getter for dialable mobile number
-        * <p>
-        * @return Dialable mobile number
-        */
-       public DialableMobileNumber getMobileNumber () {
-               return this.mobileNumber;
-       }
-
-       /**
-        * Setter for dialable mobile number
-        * <p>
-        * @param mobileNumber Dialable mobile number
-        */
-       public void setMobileNumber (final DialableMobileNumber mobileNumber) {
-               this.mobileNumber = mobileNumber;
+               this.userCreatedEvent.fire(new CreatedUserEvent(this.getUser()));
        }
 
        /**
-        * Set's all given contact's phone instances: land-line, cellphone and fax
+        * Set's all given contact's phone instances: land-line, mobile and
+        * faxNumber
         * <p>
         * @param contact Contact to set phone instances for
         */
@@ -531,22 +548,22 @@ public class PizzaWebRequestHelperBean implements PizzaWebRequestHelperControlle
                        throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
                }
 
-               // Is cellphone set?
+               // Is mobile set?
                if (contact.getContactMobileNumber() instanceof DialableMobileNumber) {
                        // Yes, then set it in admin controller
-                       this.adminPhoneController.setMobileNumber(contact.getContactMobileNumber());
+                       this.setMobileNumber(contact.getContactMobileNumber());
                }
 
                // Is land-line set?
                if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
                        // Yes, then set it in admin controller
-                       this.adminPhoneController.setLandLineNumber(contact.getContactLandLineNumber());
+                       this.setLandLineNumber(contact.getContactLandLineNumber());
                }
 
-               // Is fax set?
+               // Is faxNumber set?
                if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
                        // Yes, then set it in admin controller
-                       this.adminPhoneController.setFaxNumber(contact.getContactFaxNumber());
+                       this.setFaxNumber(contact.getContactFaxNumber());
                }
        }
 
index 4c265a43cfa958995984c63852ff240d2bcbb981..31577fce995574f75ac2a31ac00cc7d60b1ea685 100644 (file)
@@ -17,7 +17,6 @@
 package org.mxchange.pizzaapplication.beans.helper;
 
 import java.io.Serializable;
-import org.mxchange.jcustomercore.model.customer.Customer;
 
 /**
  * An interface for general bean helper
@@ -26,23 +25,4 @@ import org.mxchange.jcustomercore.model.customer.Customer;
  */
 public interface PizzaWebRequestHelperController extends Serializable {
 
-       /**
-        * Getter for customer instance
-        * <p>
-        * @return Customer instance
-        */
-       Customer getCustomer ();
-
-       /**
-        * Setter for customer instance
-        * <p>
-        * @param customer Contact instance
-        */
-       void setCustomer (final Customer customer);
-
-       /**
-        * Copies currently set customer instance's data to adminCustomerController
-        */
-       void copyCustomerToController ();
-
 }
index 2318775ba6afbf452d3c4be7791bbe62705bd785..fdc1185b70a4fe598619416d1f01e37f79189a78 100644 (file)
@@ -16,6 +16,7 @@
  */
 package org.mxchange.pizzaapplication.beans.receipt;
 
+import javax.annotation.PostConstruct;
 import javax.enterprise.context.SessionScoped;
 import javax.faces.FacesException;
 import javax.inject.Inject;
@@ -56,21 +57,27 @@ public class PizzaReceiptWebSessionBean extends BasePizzaController implements P
         * Default constructor
         */
        public PizzaReceiptWebSessionBean () {
+       }
+
+       @Override
+       public String fetchAccessKey () {
+               return this.receiptBean.fetchAccessKey(this.beanHelper.getCustomer());
+       }
+
+       /**
+        * Post-construction method
+        */
+       @PostConstruct
+       public void init () {
                try {
                        // Get initial context
                        Context context = new InitialContext();
 
                        // Get factory from JMS resource
-                       this.receiptBean = (ReceiptBeanRemote) context.lookup("java:global/jshop-ejb/pdf!org.mxchange.jshopcore.model.receipt.ReceiptBeanRemote");
+                       this.receiptBean = (ReceiptBeanRemote) context.lookup("java:global/pizzaservice-ejb/pdf!org.mxchange.jshopcore.model.receipt.ReceiptBeanRemote");
                } catch (final NamingException e) {
                        // Continued to throw
                        throw new FacesException(e);
                }
        }
-
-       @Override
-       public String fetchAccessKey () {
-               return this.receiptBean.fetchAccessKey(this.beanHelper.getCustomer());
-       }
-
 }
index e4bc9d287c0e067428be912c06f28c0bb5e1ebbd..5cab0b5b39fcb41311b6fd8b1f21315ca4763c10 100644 (file)
@@ -105,6 +105,11 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements
        @Inject
        private PizzaWebRequestHelperController beanHelper;
 
+       /**
+        * Contact instance
+        */
+       private Contact contact;
+
        /**
         * Regular contact controller
         */
@@ -112,7 +117,7 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements
        private PizzaContactWebSessionController contactController;
 
        /**
-        * Event being fired when admin has deleted user
+        * Event being fired when administrator has deleted user
         */
        @Inject
        @Any
@@ -131,6 +136,11 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements
        @Any
        private Event<ObservableAdminUpdatedUserDataEvent> updatedUserDataEvent;
 
+       /**
+        * User instance
+        */
+       private User user;
+
        /**
         * General user EJB
         */
@@ -210,9 +220,6 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements
         * @return Redirect outcome
         */
        public String addUser () {
-               // Get contact from bean helper to "cache" it locally
-               Contact contact = this.beanHelper.getContact();
-
                // As the form cannot validate the data (required="true"), check it here
                if (this.getUserName() == null) {
                        // Throw NPE
@@ -220,47 +227,47 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements
                } else if (this.getUserName().isEmpty()) {
                        // Is empty
                        throw new IllegalArgumentException("userName is null"); //NOI18N
-               } else if (contact == null) {
+               } else if (this.getContact() == null) {
                        // No contact instance set, so test required fields: gender, first name and family name
                        this.adminContactController.validateContactData();
                }
 
                // Create new user instance
-               User user = new LoginUser();
+               User newUser = new LoginUser();
 
                // Set user name, CONFIRMED and INVISIBLE
-               user.setUserName(this.getUserName());
-               user.setUserMustChangePassword(this.getUserMustChangePassword());
-               user.setUserAccountStatus(UserAccountStatus.CONFIRMED);
-               user.setUserProfileMode(ProfileMode.INVISIBLE);
+               newUser.setUserName(this.getUserName());
+               newUser.setUserMustChangePassword(this.getUserMustChangePassword());
+               newUser.setUserAccountStatus(UserAccountStatus.CONFIRMED);
+               newUser.setUserProfileMode(ProfileMode.INVISIBLE);
 
                // Copy user locale
-               user.setUserLocale(this.localizationController.getLocale());
+               newUser.setUserLocale(this.localizationController.getLocale());
 
                // Init instance
                Contact userContact;
 
                // Is a contact instance in helper set?
-               if (contact instanceof Contact) {
+               if (this.getContact() instanceof Contact) {
                        // Then use it for contact linking
-                       userContact = contact;
+                       userContact = this.getContact();
                } else {
                        // Create contact instance
                        userContact = this.contactController.createContactInstance();
                }
 
                // Set contact in user
-               user.setUserContact(userContact);
+               newUser.setUserContact(userContact);
 
                // Init variable for password
                String password = null;
 
                // Is the user name or email address used already?
                // @TODO Add password length check
-               if (this.userController.isUserNameRegistered(user)) {
+               if (this.userController.isUserNameRegistered(newUser)) {
                        // User name is already used
-                       throw new FaceletException(new UserNameAlreadyRegisteredException(user));
-               } else if ((contact == null) && (this.contactController.isEmailAddressRegistered(user.getUserContact()))) {
+                       throw new FaceletException(new UserNameAlreadyRegisteredException(newUser));
+               } else if ((this.getContact() == null) && (this.contactController.isEmailAddressRegistered(newUser.getUserContact()))) {
                        // Email address is already used
                        this.showFacesMessage("admin_add_user:emailAddress", "ERROR_EMAIL_ADDRESS_ALREADY_USED"); //NOI18N
 
@@ -275,7 +282,7 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements
                        password = UserLoginUtils.createRandomPassword(PizzaUserWebSessionController.MINIMUM_PASSWORD_LENGTH);
                } else if (!this.isSamePasswordEntered()) {
                        // Both passwords don't match
-                       throw new FaceletException(new UserPasswordRepeatMismatchException(user));
+                       throw new FaceletException(new UserPasswordRepeatMismatchException(newUser));
                } else {
                        // Both match, so get it from this bean
                        password = this.getUserPassword();
@@ -286,19 +293,19 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements
                assert (password.length() >= PizzaUserWebSessionController.MINIMUM_PASSWORD_LENGTH) : "Password is not long enough."; //NOI18N
 
                // Encrypt password and set it
-               user.setUserEncryptedPassword(UserLoginUtils.encryptPassword(password));
+               newUser.setUserEncryptedPassword(UserLoginUtils.encryptPassword(password));
 
                try {
                        // Now, that all is set, call EJB
-                       if (contact instanceof Contact) {
+                       if (this.getContact() instanceof Contact) {
                                // Link contact with this user
-                               User updatedUser = this.adminUserBean.linkUser(user);
+                               User updatedUser = this.adminUserBean.linkUser(newUser);
 
                                // Fire event
                                this.userLinkedEvent.fire(new AdminLinkedUserEvent(updatedUser));
                        } else {
                                // Add new contact
-                               User updatedUser = this.adminUserBean.addUser(user);
+                               User updatedUser = this.adminUserBean.addUser(newUser);
 
                                // Fire event
                                this.addedUserEvent.fire(new AdminAddedUserEvent(updatedUser));
@@ -309,7 +316,7 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements
                }
 
                // Clear helper
-               this.beanHelper.setContact(null);
+               this.setContact(null);
 
                // Clear this bean
                this.clear();
@@ -341,12 +348,8 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements
                        throw new NullPointerException(MessageFormat.format("event.createdUser.userId={0} is not valid", event.getCreatedUser().getUserId())); //NOI18N
                }
 
-               // Get user instance
-               User user = event.getCreatedUser();
-
-               // Set all fields here
-               this.setUserName(user.getUserName());
-               this.setUserLockReason(user.getUserLastLockedReason());
+               // Set whole user
+               this.setUser(event.getCreatedUser());
        }
 
        /**
@@ -384,31 +387,28 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements
         * @return Redirect outcome
         */
        public String deleteUserData () {
-               // Get user instance into local variable
-               User user = this.beanHelper.getUser();
-
                // Is the user instance valid and CONFIRMED?
-               if (null == user) {
+               if (this.getUser() == null) {
                        // Throw NPE
                        throw new NullPointerException("user is null"); //NOI18N
-               } else if (user.getUserId() == null) {
+               } else if (this.getUser().getUserId() == null) {
                        // Throw again
                        throw new NullPointerException("user.userId is null"); //NOI18N
-               } else if (user.getUserId() < 1) {
+               } else if (this.getUser().getUserId() < 1) {
                        // Invalid id number
-                       throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", user.getUserId())); //NOI18N
+                       throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", this.getUser().getUserId())); //NOI18N
                }
 
                try {
                        // All fine, delete it
-                       this.adminUserBean.deleteUser(user, this.getUserDeleteReason());
+                       this.adminUserBean.deleteUser(this.getUser(), this.getUserDeleteReason());
                } catch (final UserNotFoundException ex) {
                        // Should not happen, so throw again
                        throw new FaceletException(ex);
                }
 
                // Fire event
-               this.deleteUserEvent.fire(new AdminDeletedUserEvent(user, this.getUserDeleteReason()));
+               this.deleteUserEvent.fire(new AdminDeletedUserEvent(this.getUser(), this.getUserDeleteReason()));
 
                // Redirect
                return "admin_list_user"; //NOI18N
@@ -420,22 +420,19 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements
         * @return Redirect outcome
         */
        public String editUserData () {
-               // Get user instance
-               User user = this.beanHelper.getUser();
-
                // Null password means not setting it
                String encryptedPassword = null;
 
                // Check if user instance is in helper and valid
-               if (null == user) {
+               if (this.getUser() == null) {
                        // Throw NPE
                        throw new NullPointerException("beanHelper.user is null"); //NOI18N
-               } else if (user.getUserId() == null) {
+               } else if (this.getUser().getUserId() == null) {
                        // Throw NPE again
                        throw new NullPointerException("beanHelper.user.userId is null"); //NOI18N
-               } else if (user.getUserId() < 1) {
+               } else if (this.getUser().getUserId() < 1) {
                        // Invalid id
-                       throw new IllegalStateException(MessageFormat.format("beanHelper.user.userId={0} is invalid", user.getUserId())); //NOI18N
+                       throw new IllegalStateException(MessageFormat.format("beanHelper.user.userId={0} is invalid", this.getUser().getUserId())); //NOI18N
                } else if (this.getUserName() == null) {
                        // Not all required fields are set
                        throw new NullPointerException("this.userName is null"); //NOI18N
@@ -450,7 +447,7 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements
                        // Not same password entered
                        this.showFacesMessage("form_edit_user:userPassword", "ADMIN_USER_PASSWORD_REPEAT_DIFFERENT"); //NOI18N
                        return ""; //NOI18N
-               } else if ((!Objects.equals(user.getUserName(), this.getUserName())) && (this.userBean.ifUserNameExists(this.getUserName()))) {
+               } else if ((!Objects.equals(this.getUser().getUserName(), this.getUserName())) && (this.userBean.ifUserNameExists(this.getUserName()))) {
                        // Clear all fields
                        this.clear();
 
@@ -459,7 +456,7 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements
                        return ""; //NOI18N
                } else if (this.isSamePasswordEntered()) {
                        // Same password entered, create container
-                       if ((Objects.equals(user.getUserMustChangePassword(), this.getUserMustChangePassword())) && (UserLoginUtils.ifPasswordMatches(new UserLoginContainer(user, this.getUserPassword())))) {
+                       if ((Objects.equals(this.getUser().getUserMustChangePassword(), this.getUserMustChangePassword())) && (UserLoginUtils.ifPasswordMatches(new UserLoginContainer(this.getUser(), this.getUserPassword())))) {
                                // Clear password fields
                                this.setUserPassword(null);
                                this.setUserPasswordRepeat(null);
@@ -474,17 +471,17 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements
                }
 
                // Set user name and flag
-               user.setUserName(this.getUserName());
-               user.setUserMustChangePassword(this.getUserMustChangePassword());
+               this.getUser().setUserName(this.getUserName());
+               this.getUser().setUserMustChangePassword(this.getUserMustChangePassword());
 
                // Is a password set?
                if (encryptedPassword != null) {
                        // Set it as well
-                       user.setUserEncryptedPassword(encryptedPassword);
+                       this.getUser().setUserEncryptedPassword(encryptedPassword);
                }
 
                // Call EJB for updating user data
-               User updatedUser = this.userBean.updateUserData(user);
+               User updatedUser = this.userBean.updateUserData(this.getUser());
 
                // Fire event
                this.updatedUserDataEvent.fire(new AdminUpdatedUserDataEvent(updatedUser));
@@ -493,6 +490,42 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements
                return "admin_list_user"; //NOI18N
        }
 
+       /**
+        * Getter for contact instance
+        * <p>
+        * @return Contact instance
+        */
+       public Contact getContact () {
+               return this.contact;
+       }
+
+       /**
+        * Setter for contact instance
+        * <p>
+        * @param contact Contact instance
+        */
+       public void setContact (final Contact contact) {
+               this.contact = contact;
+       }
+
+       /**
+        * Getter for user instance
+        * <p>
+        * @return User instance
+        */
+       public User getUser () {
+               return this.user;
+       }
+
+       /**
+        * Setter for user instance
+        * <p>
+        * @param user User instance
+        */
+       public void setUser (final User user) {
+               this.user = user;
+       }
+
        /**
         * Getter for user delete reason
         * <p>
@@ -627,25 +660,22 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements
         * @return Redirect outcome
         */
        public String lockUserAccount () {
-               // Get user instance
-               User user = this.beanHelper.getUser();
-
                // Is the user instance valid and CONFIRMED?
-               if (null == user) {
+               if (this.getUser() == null) {
                        // Throw NPE
-                       throw new NullPointerException("user is null"); //NOI18N
-               } else if (user.getUserId() == null) {
+                       throw new NullPointerException("this.user is null"); //NOI18N
+               } else if (this.getUser().getUserId() == null) {
                        // Throw again
-                       throw new NullPointerException("user.userId is null"); //NOI18N
-               } else if (user.getUserId() < 1) {
+                       throw new NullPointerException("this.user.userId is null"); //NOI18N
+               } else if (this.getUser().getUserId() < 1) {
                        // Invalid id number
-                       throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", user.getUserId())); //NOI18N
-               } else if (user.getUserAccountStatus() == UserAccountStatus.LOCKED) {
+                       throw new IllegalArgumentException(MessageFormat.format("this.user.userId={0} is not valid", this.getUser().getUserId())); //NOI18N
+               } else if (this.getUser().getUserAccountStatus() == UserAccountStatus.LOCKED) {
                        // User account is locked
-                       throw new FacesException(new UserStatusLockedException(user));
-               } else if (user.getUserAccountStatus() == UserAccountStatus.UNCONFIRMED) {
+                       throw new FacesException(new UserStatusLockedException(this.getUser()));
+               } else if (this.getUser().getUserAccountStatus() == UserAccountStatus.UNCONFIRMED) {
                        // User account is locked
-                       throw new FaceletException(new UserStatusUnconfirmedException(user));
+                       throw new FaceletException(new UserStatusUnconfirmedException(this.getUser()));
                } else if (this.getUserLockReason() == null) {
                        // Throw NPE again
                        throw new NullPointerException("this.userLockReason is null"); //NOI18N
@@ -662,7 +692,7 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements
                        String baseUrl = FacesUtils.generateBaseUrl();
 
                        // Call EJB to lock account
-                       updatedUser = this.adminUserBean.lockUserAccount(user, this.getUserLockReason(), baseUrl);
+                       updatedUser = this.adminUserBean.lockUserAccount(this.getUser(), this.getUserLockReason(), baseUrl);
                } catch (final UserStatusLockedException | UserStatusUnconfirmedException | UserNotFoundException ex) {
                        // Throw again
                        throw new FaceletException(ex);
@@ -685,25 +715,22 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements
         * @return Redirect outcome
         */
        public String unlockUserAccount () {
-               // Get user instance
-               User user = this.beanHelper.getUser();
-
                // Is the user instance valid and CONFIRMED?
-               if (null == user) {
+               if (this.getUser() == null) {
                        // Throw NPE
-                       throw new NullPointerException("user is null"); //NOI18N
-               } else if (user.getUserId() == null) {
+                       throw new NullPointerException("this.user is null"); //NOI18N
+               } else if (this.getUser().getUserId() == null) {
                        // Throw again
-                       throw new NullPointerException("user.userId is null"); //NOI18N
-               } else if (user.getUserId() < 1) {
+                       throw new NullPointerException("this.user.userId is null"); //NOI18N
+               } else if (this.getUser().getUserId() < 1) {
                        // Invalid id number
-                       throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", user.getUserId())); //NOI18N
-               } else if (user.getUserAccountStatus() == UserAccountStatus.CONFIRMED) {
+                       throw new IllegalArgumentException(MessageFormat.format("this.user.userId={0} is not valid", this.getUser().getUserId())); //NOI18N
+               } else if (this.getUser().getUserAccountStatus() == UserAccountStatus.CONFIRMED) {
                        // User account is locked
-                       throw new FacesException(new UserStatusConfirmedException(user));
-               } else if (user.getUserAccountStatus() == UserAccountStatus.UNCONFIRMED) {
+                       throw new FacesException(new UserStatusConfirmedException(this.getUser()));
+               } else if (this.getUser().getUserAccountStatus() == UserAccountStatus.UNCONFIRMED) {
                        // User account is locked
-                       throw new FaceletException(new UserStatusUnconfirmedException(user));
+                       throw new FaceletException(new UserStatusUnconfirmedException(this.getUser()));
                }
 
                // Init updated user instance
@@ -714,7 +741,7 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements
                        String baseUrl = FacesUtils.generateBaseUrl();
 
                        // Call EJB to unlock account
-                       updatedUser = this.adminUserBean.unlockUserAccount(user, baseUrl);
+                       updatedUser = this.adminUserBean.unlockUserAccount(this.getUser(), baseUrl);
                } catch (final UserStatusConfirmedException | UserStatusUnconfirmedException | UserNotFoundException ex) {
                        // Throw again
                        throw new FaceletException(ex);
@@ -735,11 +762,10 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements
         */
        private void clear () {
                // Clear all data
-               // - other data
-               this.setUserName(null);
-               this.setUserPassword(null);
-               this.setUserPasswordRepeat(null);
+               this.setContact(null);
+               this.setUserLockReason(null);
                this.setUserMustChangePassword(null);
+               this.setUserName(null);
        }
 
        /**
diff --git a/src/java/org/mxchange/pizzaapplication/beans/user/activity/PizzaUserActivityWebApplicationBean.java b/src/java/org/mxchange/pizzaapplication/beans/user/activity/PizzaUserActivityWebApplicationBean.java
new file mode 100644 (file)
index 0000000..e3ba84a
--- /dev/null
@@ -0,0 +1,696 @@
+/*
+ * Copyright (C) 2016, 2017 Roland Häder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.pizzaapplication.beans.user.activity;
+
+import java.text.MessageFormat;
+import java.util.Collections;
+import java.util.GregorianCalendar;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import javax.annotation.PostConstruct;
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.event.Observes;
+import javax.faces.view.facelets.FaceletException;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
+import org.mxchange.jusercore.events.user.created.ObservableCreatedUserEvent;
+import org.mxchange.jusercore.events.user.delete.ObservableAdminDeletedUserEvent;
+import org.mxchange.jusercore.events.user.linked.ObservableAdminLinkedUserEvent;
+import org.mxchange.jusercore.events.user.locked.ObservableAdminLockedUserEvent;
+import org.mxchange.jusercore.events.user.unlocked.ObservableAdminUnlockedUserEvent;
+import org.mxchange.jusercore.events.user.update.ObservableAdminUpdatedUserDataEvent;
+import org.mxchange.jusercore.events.user.update.ObservableUpdatedUserPersonalDataEvent;
+import org.mxchange.jusercore.model.user.User;
+import org.mxchange.jusercore.model.user.activity.LogableUserActivity;
+import org.mxchange.jusercore.model.user.activity.UserActivityLog;
+import org.mxchange.jusercore.model.user.activity.UserActivityLogSessionBeanRemote;
+import org.mxchange.jusercore.model.user.activity.comparator.UserActivityLogTimestampComparator;
+import org.mxchange.juserlogincore.events.confirmation.ObservableUserConfirmedAccountEvent;
+import org.mxchange.juserlogincore.events.login.ObservableUserLoggedInEvent;
+import org.mxchange.juserlogincore.events.logout.ObservableUserLogoutEvent;
+import org.mxchange.juserlogincore.events.registration.ObservableUserRegisteredEvent;
+import org.mxchange.juserlogincore.events.resendlink.ObservableUserResendLinkAccountEvent;
+import org.mxchange.juserlogincore.events.user.password_change.ObservableUpdatedUserPasswordEvent;
+import org.mxchange.pizzaapplication.beans.BasePizzaController;
+import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestHelperController;
+
+/**
+ * A controller (bean) for user activity log
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("userActivityController")
+@ApplicationScoped
+public class PizzaUserActivityWebApplicationBean extends BasePizzaController implements PizzaUserActivityWebApplicationController {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 192_586_376_717_856_904L;
+
+       /**
+        * Bean helper
+        */
+       @Inject
+       private PizzaWebRequestHelperController beanHelper;
+
+       /**
+        * User instance
+        */
+       private User user;
+
+       /**
+        * EJB for user activity log
+        */
+       private UserActivityLogSessionBeanRemote userActivityBean;
+
+       /**
+        * "Cache" for activity log per user
+        */
+       private final Map<User, List<LogableUserActivity>> usersActivity;
+
+       /**
+        * Default constructor
+        */
+       @SuppressWarnings ("CollectionWithoutInitialCapacity")
+       public PizzaUserActivityWebApplicationBean () {
+               // Try to get EJB instance
+               try {
+                       // Get initial context
+                       Context context = new InitialContext();
+
+                       // Try to lookup
+                       this.userActivityBean = (UserActivityLogSessionBeanRemote) context.lookup("java:global/jfinancials-ejb/userActivity!org.mxchange.jusercore.model.user.activity.UserActivityLogSessionBeanRemote"); //NOI18N
+               } catch (final NamingException e) {
+                       // Throw again
+                       throw new FaceletException(e);
+               }
+
+               // Init cache
+               this.usersActivity = new LinkedHashMap<>();
+       }
+
+       /**
+        * Adds user activity entry with given type
+        * <p>
+        * @param user User instance
+        * @param activityType Activity type
+        */
+       private void addUserActivity (final User user, final String activityType) {
+               // Better re-validate
+               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
+               } else if (null == activityType) {
+                       // Throw NPE again
+                       throw new NullPointerException("activityType is null"); //NOI18N
+               } else if (activityType.isEmpty()) {
+                       // Is empty
+                       throw new IllegalArgumentException("activityType is empty"); //NOI18N
+               }
+
+               // Create new activity object
+               LogableUserActivity userActivity = new UserActivityLog(activityType, user, new GregorianCalendar(), this.determinePrincipalName());
+
+               // Call bean to add it
+               this.userActivityBean.addUserActivityLog(userActivity);
+
+               // Add to cache, too
+               this.addUserActivityToCache(userActivity);
+       }
+
+       /**
+        * Adds user activity log with type and message
+        * <p>
+        * @param user User instance
+        * @param activityType Activity type
+        * @param message Activity message
+        */
+       private void addUserActivity (final User user, final String activityType, final String message) {
+               // Better re-validate
+               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
+               } else if (null == activityType) {
+                       // Throw NPE again
+                       throw new NullPointerException("activityType is null"); //NOI18N
+               } else if (activityType.isEmpty()) {
+                       // Is empty
+                       throw new IllegalArgumentException("activityType is empty"); //NOI18N
+               } else if (null == message) {
+                       // Throw NPE again
+                       throw new NullPointerException("message is null"); //NOI18N
+               } else if (message.isEmpty()) {
+                       // Is empty
+                       throw new IllegalArgumentException("message is empty"); //NOI18N
+               }
+
+               // Create new activity object
+               LogableUserActivity userActivity = new UserActivityLog(message, activityType, user, new GregorianCalendar(), this.determinePrincipalName());
+
+               // Call bean to add it
+               this.userActivityBean.addUserActivityLog(userActivity);
+
+               // Add to cache, too
+               this.addUserActivityToCache(userActivity);
+       }
+
+       /**
+        * Event observer for newly added users by administrator
+        * <p>
+        * @param event Event being fired
+        */
+       public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getAddedUser() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.addedUser is null"); //NOI18N
+               } else if (event.getAddedUser().getUserId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
+               } else if (event.getAddedUser().getUserId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
+               }
+
+               // Update user list
+               this.addUserActivity(event.getAddedUser(), "ADMIN_ADDED_USER_ACCOUNT"); //NOI18N
+       }
+
+       /**
+        * Event observer for deleted user accounts (by administrator)
+        * <p>
+        * @param event Event being fired
+        */
+       public void afterAdminDeletedUserEvent (@Observes final ObservableAdminDeletedUserEvent 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
+       }
+
+       /**
+        * Event observer for linked users with existing contact data
+        * <p>
+        * @param event Event being fired
+        */
+       public void afterAdminLinkedUserEvent (@Observes final ObservableAdminLinkedUserEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getLinkedUser() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.linkedUser is null"); //NOI18N
+               } else if (event.getLinkedUser().getUserId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.linkedUser.userId is null"); //NOI18N
+               } else if (event.getLinkedUser().getUserId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLinkedUser(), event.getLinkedUser().getUserId())); //NOI18N
+               }
+
+               // Update user list
+               this.addUserActivity(event.getLinkedUser(), "ADMIN_LINKED_USER_ACCOUNT"); //NOI18N
+       }
+
+       /**
+        * Event observer for locked users
+        * <p>
+        * @param event Event being fired
+        */
+       public void afterAdminLockedUserEvent (@Observes final ObservableAdminLockedUserEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getLockedUser() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.lockedUser is null"); //NOI18N
+               } else if (event.getLockedUser().getUserId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.lockedUser.userId is null"); //NOI18N
+               } else if (event.getLockedUser().getUserId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLockedUser(), event.getLockedUser().getUserId())); //NOI18N
+               }
+
+               // Update user list
+               this.addUserActivity(event.getLockedUser(), "ADMIN_LOCKED_USER_ACCOUNT", event.getLockedUser().getUserLastLockedReason()); //NOI18N
+       }
+
+       /**
+        * Event observer for unlocked users
+        * <p>
+        * @param event Event being fired
+        */
+       public void afterAdminUnlockedUserEvent (@Observes final ObservableAdminUnlockedUserEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getUnlockedUser() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.unlockedUser is null"); //NOI18N
+               } else if (event.getUnlockedUser().getUserId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.unlockedUser.userId is null"); //NOI18N
+               } else if (event.getUnlockedUser().getUserId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUnlockedUser(), event.getUnlockedUser().getUserId())); //NOI18N
+               }
+
+               // Update user list
+               this.addUserActivity(event.getUnlockedUser(), "ADMIN_UNLOCKED_USER_ACCOUNT"); //NOI18N
+       }
+
+       /**
+        * Event observer for updated user data by administrator
+        * <p>
+        * @param event Event being updated
+        */
+       public void afterAdminUpdatedUserDataEvent (@Observes final ObservableAdminUpdatedUserDataEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getUpdatedUser() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.updatedUser is null"); //NOI18N
+               } else if (event.getUpdatedUser().getUserId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N
+               } else if (event.getUpdatedUser().getUserId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUpdatedUser(), event.getUpdatedUser().getUserId())); //NOI18N
+               }
+
+               // Update user list
+               this.addUserActivity(event.getUpdatedUser(), "ADMIN_UPDATED_USER_PERSONAL_DATA"); //NOI18N
+       }
+
+       /**
+        * Event observer for when a bean helper has successfully created a user
+        * instance, means the user exists. If the user does not exist, this event
+        * should not fire but instead a proper exception must be thrown.
+        * <p>
+        * @param event User created event
+        */
+       public void afterCreatedUserEvent (@Observes final ObservableCreatedUserEvent event) {
+               // Is the instance valid?
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getCreatedUser() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.createdUser is null"); //NOI18N
+               } else if (event.getCreatedUser().getUserId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.createdUser.userId is null"); //NOI18N
+               } else if (event.getCreatedUser().getUserId() < 1) {
+                       // Throw NPE again
+                       throw new NullPointerException(MessageFormat.format("event.createdUser.userId={0} is not valid", event.getCreatedUser().getUserId())); //NOI18N
+               }
+
+               // Set whole user
+               this.setUser(event.getCreatedUser());
+       }
+
+       /**
+        * Event observer when user confirmed account.
+        * <p>
+        * @param event Event being fired
+        */
+       public void afterUserConfirmedAccountEvent (@Observes final ObservableUserConfirmedAccountEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getConfirmedUser() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.confirmedUser is null"); //NOI18N
+               } else if (event.getConfirmedUser().getUserId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.confirmedUser.userId is null"); //NOI18N
+               } else if (event.getConfirmedUser().getUserId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getConfirmedUser(), event.getConfirmedUser().getUserId())); //NOI18N
+               }
+
+               // Update user list
+               this.addUserActivity(event.getConfirmedUser(), "USER_CONFIRMED_ACCOUNT"); //NOI18N
+       }
+
+       /**
+        * Event observer for logged-in user
+        * <p>
+        * @param event Event being fired
+        */
+       public void afterUserLoginEvent (@Observes final ObservableUserLoggedInEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getLoggedInUser() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.registeredUser is null"); //NOI18N
+               } else if (event.getLoggedInUser().getUserId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
+               } else if (event.getLoggedInUser().getUserId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
+               }
+
+               // Copy all data to this bean
+               this.addUserActivity(event.getLoggedInUser(), "USER_LOGGED_IN"); //NOI18N
+       }
+
+       /**
+        * Event observer for logged-out user
+        * <p>
+        * @param event Event instance
+        */
+       public void afterUserLogoutEvent (@Observes final ObservableUserLogoutEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getLoggedOutUser() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.loggedOutUser is null"); //NOI18N
+               } else if (event.getLoggedOutUser().getUserId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.loggedOutUser.userId is null"); //NOI18N
+               } else if (event.getLoggedOutUser().getUserId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedOutUser(), event.getLoggedOutUser().getUserId())); //NOI18N
+               }
+
+               // Update user list
+               this.addUserActivity(event.getLoggedOutUser(), "USER_LOGGED_OUT"); //NOI18N
+       }
+
+       /**
+        * Event observer for new user registrations
+        * <p>
+        * @param event Event being fired
+        */
+       public void afterUserRegistrationEvent (@Observes final ObservableUserRegisteredEvent 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
+               }
+
+               // Update user list
+               this.addUserActivity(event.getRegisteredUser(), "USER_REGISTERED_NEW_ACCOUNT"); //NOI18N
+       }
+
+       /**
+        * Event observer for users resending their confirmation link
+        * <p>
+        * @param event Event being fired
+        */
+       public void afterUserResendConfirmationLinkEvent (@Observes final ObservableUserResendLinkAccountEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getResendLinkUser() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.resendLinkUser is null"); //NOI18N
+               } else if (event.getResendLinkUser().getUserId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.resendLinkUser.userId is null"); //NOI18N
+               } else if (event.getResendLinkUser().getUserId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getResendLinkUser(), event.getResendLinkUser().getUserId())); //NOI18N
+               }
+
+               // Copy all data to this bean
+               this.addUserActivity(event.getResendLinkUser(), "USER_RESEND_CONFIRMATION_LINK"); //NOI18N
+       }
+
+       /**
+        * Method being call after user's password has been updated (and history
+        * entry has been created).
+        * <p>
+        * @param event Event being observed
+        */
+       public void afterUserUpdatedPasswordEvent (@Observes final ObservableUpdatedUserPasswordEvent event) {
+               // Check parameter
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getPasswordHistory() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.passwordHistory is null"); //NOI18N
+               } else if (event.getPasswordHistory().getUserPasswordHistoryId() == null) {
+                       // ... and again
+                       throw new NullPointerException("event.passwordHistory.userPasswordHistoryId is null"); //NOI18N
+               } else if (event.getPasswordHistory().getUserPasswordHistoryId() < 1) {
+                       // Invalid value
+                       throw new IllegalArgumentException(MessageFormat.format("event.passwordHistory.userPasswordHistoryId={0} is in valid", event.getPasswordHistory().getUserPasswordHistoryId())); //NOI18N
+               }
+
+               // Update user list
+               this.addUserActivity(event.getPasswordHistory().getUserPasswordHistoryUser(), "USER_UPDATED_PASSWORD"); //NOI18N
+       }
+
+       /**
+        * Listens to fired event when user updated personal data
+        * <p>
+        * @param event Event being fired
+        */
+       public void afterUserUpdatedPersonalDataEvent (@Observes final ObservableUpdatedUserPersonalDataEvent event) {
+               // Check parameter
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getUpdatedUser() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.updatedUser is null"); //NOI18N
+               } else if (event.getUpdatedUser().getUserId() == null) {
+                       // ... and again
+                       throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N
+               } else if (event.getUpdatedUser().getUserId() < 1) {
+                       // Invalid value
+                       throw new IllegalArgumentException(MessageFormat.format("event.updatedUser.userId={0} is in valid", event.getUpdatedUser().getUserId())); //NOI18N
+               }
+
+               // Update user list
+               this.addUserActivity(event.getUpdatedUser(), "USER_UPDATED_PERSONAL_DATA"); //NOI18N
+       }
+
+       /**
+        * Expands given activity type into a i18n string for administrators
+        * <p>
+        * @param activityType Activity type
+        * <p>
+        * @return Expanded i18n string
+        */
+       public String expandAdminActivityType (final String activityType) {
+               // Is it valid?
+               if (null == activityType) {
+                       // Throw NPE
+                       throw new NullPointerException("activityType is null"); //NOI18N
+               } else if (activityType.isEmpty()) {
+                       // Is empty
+                       throw new IllegalArgumentException("activityType is empty"); //NOI18N
+               }
+
+               // Expand it
+               return "ADMIN_ACTIVITY_" + activityType; //NOI18N
+       }
+
+       /**
+        * Expands given activity type into a i18n string for users
+        * <p>
+        * @param activityType Activity type
+        * <p>
+        * @return Expanded i18n string
+        */
+       public String expandUserActivityType (final String activityType) {
+               // Is it valid?
+               if (null == activityType) {
+                       // Throw NPE
+                       throw new NullPointerException("activityType is null"); //NOI18N
+               } else if (activityType.isEmpty()) {
+                       // Is empty
+                       throw new IllegalArgumentException("activityType is empty"); //NOI18N
+               }
+
+               // Expand it
+               return "USER_ACTIVITY_" + activityType; //NOI18N
+       }
+
+       /**
+        * Returns a list of in beanHelper set user instance's activity log
+        * <p>
+        * @return List of user's activity log
+        */
+       public List<LogableUserActivity> fetchCurrentUsersActivityLog () {
+               // beanHelper.user should be set and valid
+               if (this.getUser() == null) {
+                       // Is not set
+                       throw new NullPointerException("this.beanHelper.user is null"); //NOI18N
+               } else if (this.getUser().getUserId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("this.beanHelper.user.userId is null"); //NOI18N
+               } else if (this.getUser().getUserId() < 1) {
+                       // Invalid id number
+                       throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.user.userId={0} is not valid", this.getUser().getUserId())); //NOI18N
+               }
+
+               // Init list
+               List<LogableUserActivity> list = new LinkedList<>();
+
+               // Is the user set?
+               if (this.usersActivity.containsKey(this.getUser())) {
+                       // Return it
+                       list.addAll(this.usersActivity.get(this.getUser()));
+
+                       // Sort list and reverse it
+                       Collections.sort(list, new UserActivityLogTimestampComparator());
+                       Collections.reverse(list);
+               }
+
+               // Return it
+               return list;
+       }
+
+       /**
+        * Getter for user instance
+        * <p>
+        * @return User instance
+        */
+       public User getUser () {
+               return this.user;
+       }
+
+       /**
+        * Setter for user instance
+        * <p>
+        * @param user User instance
+        */
+       public void setUser (final User user) {
+               this.user = user;
+       }
+
+       /**
+        * Post-constructor method
+        */
+       @PostConstruct
+       public void init () {
+               // Get whole list
+               List<LogableUserActivity> list = this.userActivityBean.fetchAllUserActivityLog();
+
+               // Put all in map, per-user
+               for (final LogableUserActivity userActivity : list) {
+                       // Is the list there?
+                       if (!this.usersActivity.containsKey(userActivity.getActivityUser())) {
+                               // Init list
+                               this.usersActivity.put(userActivity.getActivityUser(), new LinkedList<LogableUserActivity>());
+                       }
+
+                       // Add by user instance
+                       boolean added = this.usersActivity.get(userActivity.getActivityUser()).add(userActivity);
+
+                       // Should be added
+                       assert (added) : "Activity log not added"; //NOI18N
+               }
+       }
+
+       /**
+        * Adds given user activity instance to "cache" (local map)
+        * <p>
+        * @param userActivity User activity instance
+        */
+       private void addUserActivityToCache (final LogableUserActivity userActivity) {
+               // Is the instance valid
+               if (null == userActivity) {
+                       // Throw NPE again
+                       throw new NullPointerException("userActivity is null");
+               } else if (userActivity.getActivityId() instanceof Long) {
+                       // Is not null
+                       throw new IllegalArgumentException("userActivity.activityId=" + userActivity.getActivityId() + " is not null");
+               } else if (userActivity.getActivityUser() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("userActivity.activityUser is null");
+               } else if (userActivity.getActivityUser().getUserId() == null) {
+                       // Throw it again
+                       throw new NullPointerException("userActivity.activityUser.userId is null");
+               } else if (userActivity.getActivityUser().getUserId() < 1) {
+                       // Invalid id number
+                       throw new IllegalArgumentException("userActivity.activityUser.userId=" + userActivity.getActivityUser().getUserId() + " is not valid");
+               }
+
+               // Is it there?
+               if (!this.usersActivity.containsKey(userActivity.getActivityUser())) {
+                       // Init it
+                       this.usersActivity.put(userActivity.getActivityUser(), new LinkedList<LogableUserActivity>());
+               }
+
+               // Add activity to log
+               this.usersActivity.get(userActivity.getActivityUser()).add(userActivity);
+       }
+
+}
diff --git a/src/java/org/mxchange/pizzaapplication/beans/user/activity/PizzaUserActivityWebApplicationController.java b/src/java/org/mxchange/pizzaapplication/beans/user/activity/PizzaUserActivityWebApplicationController.java
new file mode 100644 (file)
index 0000000..d03b07b
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2016, 2017 Roland Häder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.pizzaapplication.beans.user.activity;
+
+import java.io.Serializable;
+
+/**
+ * A controller (bean) interface for user activity log
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface PizzaUserActivityWebApplicationController extends Serializable {
+
+}
index 0fba828b28d108c695b63c0b12f544d23abfb327..ad0a09e37ac17a5c5d975c10f51e8208c420bc79 100644 (file)
@@ -33,6 +33,8 @@ import javax.naming.NamingException;
 import org.mxchange.jcoreee.events.helper.clear.HelperCleanupEvent;
 import org.mxchange.jcoreee.events.helper.clear.ObservableHelperCleanupEvent;
 import org.mxchange.jcoreee.utils.FacesUtils;
+import org.mxchange.jusercore.events.user.created.CreatedUserEvent;
+import org.mxchange.jusercore.events.user.created.ObservableCreatedUserEvent;
 import org.mxchange.jusercore.exceptions.UserStatusConfirmedException;
 import org.mxchange.jusercore.exceptions.UserStatusLockedException;
 import org.mxchange.jusercore.model.user.User;
@@ -94,6 +96,13 @@ public class PizzaConfirmationLinkWebRequestBean extends BasePizzaController imp
        @Inject
        private PizzaUserWebSessionController userController;
 
+       /**
+        * Event for when a user instance was created
+        */
+       @Any
+       @Inject
+       private Event<ObservableCreatedUserEvent> userCreatedEvent;
+
        /**
         * Default constructor
         */
@@ -250,11 +259,8 @@ public class PizzaConfirmationLinkWebRequestBean extends BasePizzaController imp
                // Debug message
                System.out.println(MessageFormat.format("{0}.confirmUserAccount: updatedUser={1}", this.getClass().getSimpleName(), updatedUser)); //NOI18N
 
-               // Set it again in helper
-               this.beanHelper.setUser(updatedUser);
-
-               // ... and copy it to the controller
-               this.beanHelper.copyUserToController();
+               // Fire event
+               this.userCreatedEvent.fire(new CreatedUserEvent(updatedUser));
 
                // Trace message
                System.out.println(MessageFormat.format("{0}.confirmUserAccount: EXIT!", this.getClass().getSimpleName())); //NOI18N