From afbc3efe57c0bd7749d55ba6af3c5a09e808d6f9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 17 Apr 2020 00:01:03 +0200 Subject: [PATCH] Continued: - moved post events in own package - created first pre event - removed clear events - removed no longer used constructor - "validate" all parameter in constructor MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../password/ClearUserPasswordEvent.java | 37 ----------- .../clear/username/ClearUserNameEvent.java | 37 ----------- .../ObservableClearUserNameEvent.java | 28 -------- .../AdminPostUserDataUpdatedEvent.java} | 8 +-- ...ervableAdminPostUserDataUpdatedEvent.java} | 6 +- ...ablePostUserPersonalDataUpdatedEvent.java} | 14 +++- .../PostUserPersonalDataUpdatedEvent.java} | 8 +-- ...vablePreUserPersonalDataUpdatedEvent.java} | 6 +- .../pre/PreUserPersonalDataUpdatedEvent.java | 66 +++++++++++++++++++ .../email_address/ChangeableEmailAddress.java | 1 + .../email_address/EmailAddressChange.java | 48 ++++++-------- .../mxchange/jusercore/model/user/Users.java | 6 +- 12 files changed, 116 insertions(+), 149 deletions(-) delete mode 100644 src/org/mxchange/jusercore/events/user/clear/password/ClearUserPasswordEvent.java delete mode 100644 src/org/mxchange/jusercore/events/user/clear/username/ClearUserNameEvent.java delete mode 100644 src/org/mxchange/jusercore/events/user/clear/username/ObservableClearUserNameEvent.java rename src/org/mxchange/jusercore/events/user/update/{AdminUpdatedUserDataEvent.java => post/AdminPostUserDataUpdatedEvent.java} (85%) rename src/org/mxchange/jusercore/events/user/update/{ObservableAdminUpdatedUserDataEvent.java => post/ObservableAdminPostUserDataUpdatedEvent.java} (81%) rename src/org/mxchange/jusercore/events/user/{clear/password/ObservableClearUserPasswordEvent.java => update/post/ObservablePostUserPersonalDataUpdatedEvent.java} (68%) rename src/org/mxchange/jusercore/events/user/update/{UpdatedUserPersonalDataEvent.java => post/PostUserPersonalDataUpdatedEvent.java} (85%) rename src/org/mxchange/jusercore/events/user/update/{ObservableUpdatedUserPersonalDataEvent.java => pre/ObservablePreUserPersonalDataUpdatedEvent.java} (81%) create mode 100644 src/org/mxchange/jusercore/events/user/update/pre/PreUserPersonalDataUpdatedEvent.java diff --git a/src/org/mxchange/jusercore/events/user/clear/password/ClearUserPasswordEvent.java b/src/org/mxchange/jusercore/events/user/clear/password/ClearUserPasswordEvent.java deleted file mode 100644 index fdb153c..0000000 --- a/src/org/mxchange/jusercore/events/user/clear/password/ClearUserPasswordEvent.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2016 - 2020 Free Software Foundation - * - * 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.clear.password; - -/** - * An event being fired when a user password should be cleared - *

- * @author Roland Häder - */ -public class ClearUserPasswordEvent implements ObservableClearUserPasswordEvent { - - /** - * Serial number - */ - private static final long serialVersionUID = 14_785_787_174_676_291L; - - /** - * Default constructor - */ - public ClearUserPasswordEvent () { - } - -} diff --git a/src/org/mxchange/jusercore/events/user/clear/username/ClearUserNameEvent.java b/src/org/mxchange/jusercore/events/user/clear/username/ClearUserNameEvent.java deleted file mode 100644 index a3573c5..0000000 --- a/src/org/mxchange/jusercore/events/user/clear/username/ClearUserNameEvent.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2016 - 2020 Free Software Foundation - * - * 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.clear.username; - -/** - * An event being fired when a user name should be cleared. - *

- * @author Roland Häder - */ -public class ClearUserNameEvent implements ObservableClearUserNameEvent { - - /** - * Serial number - */ - private static final long serialVersionUID = 14_785_787_174_676_291L; - - /** - * Default constructor - */ - public ClearUserNameEvent () { - } - -} diff --git a/src/org/mxchange/jusercore/events/user/clear/username/ObservableClearUserNameEvent.java b/src/org/mxchange/jusercore/events/user/clear/username/ObservableClearUserNameEvent.java deleted file mode 100644 index 00f9273..0000000 --- a/src/org/mxchange/jusercore/events/user/clear/username/ObservableClearUserNameEvent.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) 2016 - 2020 Free Software Foundation - * - * 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.clear.username; - -import java.io.Serializable; - -/** - * An interface for events being fired when a user name should be cleared. - *

- * @author Roland Häder - */ -public interface ObservableClearUserNameEvent extends Serializable { - -} diff --git a/src/org/mxchange/jusercore/events/user/update/AdminUpdatedUserDataEvent.java b/src/org/mxchange/jusercore/events/user/update/post/AdminPostUserDataUpdatedEvent.java similarity index 85% rename from src/org/mxchange/jusercore/events/user/update/AdminUpdatedUserDataEvent.java rename to src/org/mxchange/jusercore/events/user/update/post/AdminPostUserDataUpdatedEvent.java index 51187b6..9d8bc18 100644 --- a/src/org/mxchange/jusercore/events/user/update/AdminUpdatedUserDataEvent.java +++ b/src/org/mxchange/jusercore/events/user/update/post/AdminPostUserDataUpdatedEvent.java @@ -14,17 +14,17 @@ * 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.update; +package org.mxchange.jusercore.events.user.update.post; import java.text.MessageFormat; import org.mxchange.jusercore.model.user.User; /** - * An event being fired when the administrator has updated user data + * An event being fired after the administrator has updated user data *

* @author Roland Häder */ -public class AdminUpdatedUserDataEvent implements ObservableAdminUpdatedUserDataEvent { +public class AdminPostUserDataUpdatedEvent implements ObservableAdminPostUserDataUpdatedEvent { /** * Serial number @@ -41,7 +41,7 @@ public class AdminUpdatedUserDataEvent implements ObservableAdminUpdatedUserData *

* @param updatedUser Updated user instance */ - public AdminUpdatedUserDataEvent (final User updatedUser) { + public AdminPostUserDataUpdatedEvent (final User updatedUser) { // Is the user instance valid? if (null == updatedUser) { // Throw NPE diff --git a/src/org/mxchange/jusercore/events/user/update/ObservableAdminUpdatedUserDataEvent.java b/src/org/mxchange/jusercore/events/user/update/post/ObservableAdminPostUserDataUpdatedEvent.java similarity index 81% rename from src/org/mxchange/jusercore/events/user/update/ObservableAdminUpdatedUserDataEvent.java rename to src/org/mxchange/jusercore/events/user/update/post/ObservableAdminPostUserDataUpdatedEvent.java index 0c88735..99e1668 100644 --- a/src/org/mxchange/jusercore/events/user/update/ObservableAdminUpdatedUserDataEvent.java +++ b/src/org/mxchange/jusercore/events/user/update/post/ObservableAdminPostUserDataUpdatedEvent.java @@ -14,17 +14,17 @@ * 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.update; +package org.mxchange.jusercore.events.user.update.post; import java.io.Serializable; import org.mxchange.jusercore.model.user.User; /** - * An interface for events being fired when an administrator updated user data. + * An interface for events being fired after an administrator updated user data. *

* @author Roland Häder */ -public interface ObservableAdminUpdatedUserDataEvent extends Serializable { +public interface ObservableAdminPostUserDataUpdatedEvent extends Serializable { /** * Getter for updated user instance diff --git a/src/org/mxchange/jusercore/events/user/clear/password/ObservableClearUserPasswordEvent.java b/src/org/mxchange/jusercore/events/user/update/post/ObservablePostUserPersonalDataUpdatedEvent.java similarity index 68% rename from src/org/mxchange/jusercore/events/user/clear/password/ObservableClearUserPasswordEvent.java rename to src/org/mxchange/jusercore/events/user/update/post/ObservablePostUserPersonalDataUpdatedEvent.java index 1ff084e..c882ed5 100644 --- a/src/org/mxchange/jusercore/events/user/clear/password/ObservableClearUserPasswordEvent.java +++ b/src/org/mxchange/jusercore/events/user/update/post/ObservablePostUserPersonalDataUpdatedEvent.java @@ -14,15 +14,23 @@ * 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.clear.password; +package org.mxchange.jusercore.events.user.update.post; import java.io.Serializable; +import org.mxchange.jusercore.model.user.User; /** - * An interface for events being fired when user password should be cleared. + * An interface for events being fired after a user updates personal data. *

* @author Roland Häder */ -public interface ObservableClearUserPasswordEvent extends Serializable { +public interface ObservablePostUserPersonalDataUpdatedEvent extends Serializable { + + /** + * Getter for updated user instance + *

+ * @return Updated user instance + */ + User getUpdatedUser (); } diff --git a/src/org/mxchange/jusercore/events/user/update/UpdatedUserPersonalDataEvent.java b/src/org/mxchange/jusercore/events/user/update/post/PostUserPersonalDataUpdatedEvent.java similarity index 85% rename from src/org/mxchange/jusercore/events/user/update/UpdatedUserPersonalDataEvent.java rename to src/org/mxchange/jusercore/events/user/update/post/PostUserPersonalDataUpdatedEvent.java index 4e12633..bfb3b53 100644 --- a/src/org/mxchange/jusercore/events/user/update/UpdatedUserPersonalDataEvent.java +++ b/src/org/mxchange/jusercore/events/user/update/post/PostUserPersonalDataUpdatedEvent.java @@ -14,17 +14,17 @@ * 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.update; +package org.mxchange.jusercore.events.user.update.post; import java.text.MessageFormat; import org.mxchange.jusercore.model.user.User; /** - * An event being fired when the user has updated personal data + * An event being fired after the user has updated personal data *

* @author Roland Häder */ -public class UpdatedUserPersonalDataEvent implements ObservableUpdatedUserPersonalDataEvent { +public class PostUserPersonalDataUpdatedEvent implements ObservablePostUserPersonalDataUpdatedEvent { /** * Serial number @@ -41,7 +41,7 @@ public class UpdatedUserPersonalDataEvent implements ObservableUpdatedUserPerson *

* @param updatedUser Updated user instance */ - public UpdatedUserPersonalDataEvent (final User updatedUser) { + public PostUserPersonalDataUpdatedEvent (final User updatedUser) { // Is the user instance valid? if (null == updatedUser) { // Throw NPE diff --git a/src/org/mxchange/jusercore/events/user/update/ObservableUpdatedUserPersonalDataEvent.java b/src/org/mxchange/jusercore/events/user/update/pre/ObservablePreUserPersonalDataUpdatedEvent.java similarity index 81% rename from src/org/mxchange/jusercore/events/user/update/ObservableUpdatedUserPersonalDataEvent.java rename to src/org/mxchange/jusercore/events/user/update/pre/ObservablePreUserPersonalDataUpdatedEvent.java index f473729..990d697 100644 --- a/src/org/mxchange/jusercore/events/user/update/ObservableUpdatedUserPersonalDataEvent.java +++ b/src/org/mxchange/jusercore/events/user/update/pre/ObservablePreUserPersonalDataUpdatedEvent.java @@ -14,17 +14,17 @@ * 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.update; +package org.mxchange.jusercore.events.user.update.pre; import java.io.Serializable; import org.mxchange.jusercore.model.user.User; /** - * An interface for events being fired when a user updates personal data. + * An interface for events being fired before a user updates personal data. *

* @author Roland Häder */ -public interface ObservableUpdatedUserPersonalDataEvent extends Serializable { +public interface ObservablePreUserPersonalDataUpdatedEvent extends Serializable { /** * Getter for updated user instance diff --git a/src/org/mxchange/jusercore/events/user/update/pre/PreUserPersonalDataUpdatedEvent.java b/src/org/mxchange/jusercore/events/user/update/pre/PreUserPersonalDataUpdatedEvent.java new file mode 100644 index 0000000..3273a78 --- /dev/null +++ b/src/org/mxchange/jusercore/events/user/update/pre/PreUserPersonalDataUpdatedEvent.java @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2016 - 2020 Free Software Foundation + * + * 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.update.pre; + +import java.text.MessageFormat; +import org.mxchange.jusercore.model.user.User; + +/** + * An event being fired after the user has updated personal data + *

+ * @author Roland Häder + */ +public class PreUserPersonalDataUpdatedEvent implements ObservablePreUserPersonalDataUpdatedEvent { + + /** + * Serial number + */ + private static final long serialVersionUID = 14_785_787_174_676_291L; + + /** + * Updated user instance + */ + private final User updatedUser; + + /** + * Constructor with updated user instance + *

+ * @param updatedUser Updated user instance + */ + public PreUserPersonalDataUpdatedEvent (final User updatedUser) { + // Is the user instance valid? + if (null == updatedUser) { + // Throw NPE + throw new NullPointerException("updatedUser is null"); //NOI18N + } else if (updatedUser.getUserId() == null) { + // Throw NPE again + throw new NullPointerException("updatedUser.userId is null"); //NOI18N + } else if (updatedUser.getUserId() < 1) { + // Invalid id number + throw new IllegalArgumentException(MessageFormat.format("updatedUser.userId={0} is invalid.", updatedUser.getUserId())); //NOI18N + } + + // Set it here + this.updatedUser = updatedUser; + } + + @Override + public User getUpdatedUser () { + return this.updatedUser; + } + +} diff --git a/src/org/mxchange/jusercore/model/email_address/ChangeableEmailAddress.java b/src/org/mxchange/jusercore/model/email_address/ChangeableEmailAddress.java index eaf5be0..8f9c6f2 100644 --- a/src/org/mxchange/jusercore/model/email_address/ChangeableEmailAddress.java +++ b/src/org/mxchange/jusercore/model/email_address/ChangeableEmailAddress.java @@ -132,4 +132,5 @@ public interface ChangeableEmailAddress extends Serializable { @Override int hashCode (); + } diff --git a/src/org/mxchange/jusercore/model/email_address/EmailAddressChange.java b/src/org/mxchange/jusercore/model/email_address/EmailAddressChange.java index abc1562..58c1cfb 100644 --- a/src/org/mxchange/jusercore/model/email_address/EmailAddressChange.java +++ b/src/org/mxchange/jusercore/model/email_address/EmailAddressChange.java @@ -16,6 +16,7 @@ */ package org.mxchange.jusercore.model.email_address; +import java.text.MessageFormat; import java.util.Date; import java.util.Objects; import javax.persistence.Basic; @@ -48,9 +49,7 @@ import org.mxchange.jusercore.model.user.User; @Table (name = "email_changes") @NamedQueries ( value = { - @NamedQuery (name = "SearchEmailChangeByEmail", query = "SELECT e FROM email_changes AS e WHERE LOWER(e.emailAddress) LIKE LOWER(:email)"), - @NamedQuery (name = "AllEmailAddressChanges", query = "SELECT e.emailAddress FROM email_changes AS e ORDER BY e.emailChangeId ASC"), - @NamedQuery (name = "SearchEmailChangeByHash", query = "SELECT e FROM email_changes AS e WHERE e.emailChangeHash = :hash") + @NamedQuery (name = "AllEmailAddressChanges", query = "SELECT e FROM email_changes AS e ORDER BY e.emailChangeId ASC") } ) @SuppressWarnings ("PersistenceUnitPresent") @@ -123,39 +122,34 @@ public class EmailAddressChange implements ChangeableEmailAddress { this.emailChangeStatus = EmailChangeStatus.NEW; } - /** - * Constructor with all fields to set - *

- * @param emailChangeId Email change id - * @param user User instance - * @param emailAddress Email address - * @param emailChangeCreated Timestamp for creation - * @param emailChangeStatus Email change status - * @param emailChangeDone When this entry has been done - * @param emailChangeHash Email change hash - */ - public EmailAddressChange (final Long emailChangeId, final User user, final String emailAddress, final Date emailChangeCreated, final EmailChangeStatus emailChangeStatus, final Date emailChangeDone, final String emailChangeHash) { - // Call other constructor - this(user, emailAddress); - - // Set remaining - this.emailChangeId = emailChangeId; - this.emailChangeCreated = emailChangeCreated; - this.emailChangeStatus = emailChangeStatus; - this.emailChangeDone = emailChangeDone; - this.emailChangeHash = emailChangeHash; - } - /** * Constructor with user and email address *

- * @param user User instance + * @param user User instance * @param emailAddress Email address */ public EmailAddressChange (final User user, final String emailAddress) { // Call other constructor this(); + // Validate parameter + if (null == user) { + // Throw NPE + throw new NullPointerException("user is null"); //NOI18N + } else if (user.getUserId() == null) { + // Throw NPE again + throw new NullPointerException("user.userId is null"); //NOI18N + } else if (user.getUserId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", user.getUserId())); //NOI18N + } else if (null == emailAddress) { + // Throw NPE + throw new NullPointerException("emailAddress is null"); //NOI18N + } else if (emailAddress.isEmpty()) { + // Throw IAE + throw new IllegalArgumentException("emailAddress is empty"); //NOI18N + } + // Set all this.emailChangeUser = user; this.emailAddress = emailAddress; diff --git a/src/org/mxchange/jusercore/model/user/Users.java b/src/org/mxchange/jusercore/model/user/Users.java index 79cdc30..97ede17 100644 --- a/src/org/mxchange/jusercore/model/user/Users.java +++ b/src/org/mxchange/jusercore/model/user/Users.java @@ -262,9 +262,9 @@ public class Users implements Serializable { if (user.getUserContact().getContactEmailAddress() != null) { properties.setProperty("contactEmailAddress", user.getUserContact().getContactEmailAddress()); //NOI18N } - properties.setProperty("contactCreated", user.getUserContact().getContactCreated().toString()); //NOI18N - if (user.getUserContact().getContactUpdated() != null) { - properties.setProperty("contactUpdated", user.getUserContact().getContactUpdated().toString()); //NOI18N + properties.setProperty("contactCreated", user.getUserContact().getContactEntryCreated().toString()); //NOI18N + if (user.getUserContact().getContactEntryUpdated() != null) { + properties.setProperty("contactUpdated", user.getUserContact().getContactEntryUpdated().toString()); //NOI18N } // Return it -- 2.39.5