From: Roland Häder Date: Mon, 18 Apr 2016 16:05:13 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=8b8a576191bdcc3c4f6624a8d1da3491b3e7a516;p=juser-core.git Continued: - added event for administrators adding user accounts - added detailed checks on given user instances - Renamed fields for better naming convention --- diff --git a/src/org/mxchange/jusercore/events/login/UserLoggedInEvent.java b/src/org/mxchange/jusercore/events/login/UserLoggedInEvent.java index 960ca57..1846490 100644 --- a/src/org/mxchange/jusercore/events/login/UserLoggedInEvent.java +++ b/src/org/mxchange/jusercore/events/login/UserLoggedInEvent.java @@ -31,5 +31,6 @@ public interface UserLoggedInEvent extends Serializable { *

* @return User instance */ - User getUser (); + User getLoggedInUser (); + } diff --git a/src/org/mxchange/jusercore/events/login/UserLoginEvent.java b/src/org/mxchange/jusercore/events/login/UserLoginEvent.java index 3973a41..2ad452b 100644 --- a/src/org/mxchange/jusercore/events/login/UserLoginEvent.java +++ b/src/org/mxchange/jusercore/events/login/UserLoginEvent.java @@ -16,10 +16,11 @@ */ package org.mxchange.jusercore.events.login; +import java.text.MessageFormat; import org.mxchange.jusercore.model.user.User; /** - * This event is fired when the user has logged in + * This event is fired when the loggedInUser has logged in *

* @author Roland Haeder */ @@ -33,20 +34,33 @@ public class UserLoginEvent implements UserLoggedInEvent { /** * User instance */ - private final User user; + private final User loggedInUser; /** - * Constructor with updated user instance + * Constructor with updated loggedInUser instance *

- * @param user Updated user instance + * @param loggedInUser Updated loggedInUser instance */ - public UserLoginEvent (final User user) { - // Set user - this.user = user; + public UserLoginEvent (final User loggedInUser) { + // Is the logged-in user instance valid? + if (null == loggedInUser) { + // Throw NPE + throw new NullPointerException("loggedInUser is null"); //NOI18N + } else if (loggedInUser.getUserId() == null) { + // Throw NPE again + throw new NullPointerException("loggedInUser.userId is null"); //NOI18N + } else if (loggedInUser.getUserId() < 1) { + // Invalid id number + throw new IllegalArgumentException(MessageFormat.format("loggedInUser.userId={0} is invalid.", loggedInUser.getUserId())); //NOI18N + } + + // Set loggedInUser + this.loggedInUser = loggedInUser; } @Override - public User getUser () { - return this.user; + public User getLoggedInUser () { + return this.loggedInUser; } + } diff --git a/src/org/mxchange/jusercore/events/registration/RegisteredUserEvent.java b/src/org/mxchange/jusercore/events/registration/RegisteredUserEvent.java index 420c03f..85ae473 100644 --- a/src/org/mxchange/jusercore/events/registration/RegisteredUserEvent.java +++ b/src/org/mxchange/jusercore/events/registration/RegisteredUserEvent.java @@ -16,10 +16,11 @@ */ package org.mxchange.jusercore.events.registration; +import java.text.MessageFormat; import org.mxchange.jusercore.model.user.User; /** - * An event, fireed if a new user has registered + * An event, fireed if a new registeredUser has registered *

* @author Roland Haeder */ @@ -31,26 +32,40 @@ public class RegisteredUserEvent implements UserRegisteredEvent { private static final long serialVersionUID = 186_956_974_127_691L; /** - * Newly registered user; + * Newly registered registeredUser; */ - private final User user; + private final User registeredUser; /** - * Constructor with newly registered user + * Constructor with newly registered registeredUser *

- * @param user Newly registered user + * @param registeredUser Newly registered registeredUser */ - public RegisteredUserEvent (final User user) { - this.user = user; + public RegisteredUserEvent (final User registeredUser) { + // Is the registered user instance valid? + if (null == registeredUser) { + // Throw NPE + throw new NullPointerException("registeredUser is null"); //NOI18N + } else if (registeredUser.getUserId() == null) { + // Throw NPE again + throw new NullPointerException("registeredUser.userId is null"); //NOI18N + } else if (registeredUser.getUserId() < 1) { + // Invalid id number + throw new IllegalArgumentException(MessageFormat.format("registeredUser.userId={0} is invalid.", registeredUser.getUserId())); //NOI18N + } + + // Set it here + this.registeredUser = registeredUser; } /** - * Getter for user instance + * Getter for registeredUser instance *

* @return User instance */ @Override - public User getUser () { - return this.user; + public User getRegisteredUser () { + return this.registeredUser; } + } diff --git a/src/org/mxchange/jusercore/events/registration/UserRegisteredEvent.java b/src/org/mxchange/jusercore/events/registration/UserRegisteredEvent.java index 7755f64..ee1ecbe 100644 --- a/src/org/mxchange/jusercore/events/registration/UserRegisteredEvent.java +++ b/src/org/mxchange/jusercore/events/registration/UserRegisteredEvent.java @@ -31,5 +31,6 @@ public interface UserRegisteredEvent extends Serializable { *

* @return User instance */ - User getUser (); + User getRegisteredUser (); + } diff --git a/src/org/mxchange/jusercore/events/user/AdminAddedUserEvent.java b/src/org/mxchange/jusercore/events/user/AdminAddedUserEvent.java new file mode 100644 index 0000000..0238103 --- /dev/null +++ b/src/org/mxchange/jusercore/events/user/AdminAddedUserEvent.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2016 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.jusercore.events.user; + +import java.io.Serializable; +import org.mxchange.jusercore.model.user.User; + +/** + * An interface for events being fired when an administrator added a new user + * account. + *

+ * @author Roland Haeder + */ +public interface AdminAddedUserEvent extends Serializable { + + /** + * Getter for added user instance + *

+ * @return Added user instance + */ + User getAddedUser (); + +} diff --git a/src/org/mxchange/jusercore/events/user/AdminUserAddedEvent.java b/src/org/mxchange/jusercore/events/user/AdminUserAddedEvent.java new file mode 100644 index 0000000..e6b035b --- /dev/null +++ b/src/org/mxchange/jusercore/events/user/AdminUserAddedEvent.java @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2016 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.jusercore.events.user; + +import java.text.MessageFormat; +import org.mxchange.jusercore.model.user.User; + +/** + * An event being fired when the administrator has added a new user account + *

+ * @author Roland Haeder + */ +public class AdminUserAddedEvent implements AdminAddedUserEvent { + + /** + * Serial number + */ + private static final long serialVersionUID = 14_785_787_174_676_290L; + + /** + * Added user instance + */ + private final User addedUser; + + /** + * Constructor with added user instance + * @param addedUser Added user instance + */ + public AdminUserAddedEvent (final User addedUser) { + // Is the user instance valid? + if (null == addedUser) { + // Throw NPE + throw new NullPointerException("addedUser is null"); //NOI18N + } else if (addedUser.getUserId() == null) { + // Throw NPE again + throw new NullPointerException("addedUser.userId is null"); //NOI18N + } else if (addedUser.getUserId() < 1) { + // Invalid id number + throw new IllegalArgumentException(MessageFormat.format("addedUser.userId={0} is invalid.", addedUser.getUserId())); //NOI18N + } + + // Set it here + this.addedUser = addedUser; + } + + @Override + public User getAddedUser () { + return this.addedUser; + } + +}