]> git.mxchange.org Git - juser-core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sun, 23 Oct 2022 16:03:35 +0000 (18:03 +0200)
committerRoland Häder <roland@mxchange.org>
Sun, 23 Oct 2022 16:19:09 +0000 (18:19 +0200)
- added a long description, why you should invoke a simplier constructor
- added checks on arguments/parameter in some constructors
- sorted enum members, thanks to EnumType.STRING you don't have to touch your
  data

src/org/mxchange/jusercore/model/user/password_history/UserPasswordHistory.java
src/org/mxchange/jusercore/model/user/profilemodes/ProfileMode.java
src/org/mxchange/jusercore/model/user/status/UserAccountStatus.java

index 83c73fd4b1bc79722d0adb2194444ebf4cf9cacc..16a64d6d33a76fb73ccf0f7a3f1917fed2af68f1 100644 (file)
@@ -16,6 +16,7 @@
  */
 package org.mxchange.jusercore.model.user.password_history;
 
+import java.text.MessageFormat;
 import java.util.Date;
 import java.util.Objects;
 import javax.persistence.Basic;
@@ -102,6 +103,37 @@ public class UserPasswordHistory implements PasswordHistory {
         * @param userPasswordHistoryUser         User instance
         */
        public UserPasswordHistory (final String userPasswordHistoryPasswordHash, final User userPasswordHistoryUser) {
+               /*
+                * Invoke default constructor. This one here (above this constructor)
+                * might do nothing useful, that's true. It is an empty method for the
+                * JPA to invoke, that's true, too. The thing here is, that you might
+                * become lazy and forget it somewhere else where you really have to
+                * invoke it or otherwise your object isn't fully/correctly initialized.
+                * This has leaded already to funny side-effects such as "suddenly it
+                * doesn't work, then it works again" and also to NPEs in the
+                * history.Thumb of a rule: If there is a simplier constructor, DO
+                * INVOKE it.
+                */
+               this();
+
+               // Validate all parameter
+               if (null == userPasswordHistoryPasswordHash) {
+                       // Throw NPE
+                       throw new NullPointerException("userPasswordHistoryPasswordHash is null"); //NOI18N
+               } else if (userPasswordHistoryPasswordHash.isEmpty()) {
+                       // Throw IAE
+                       throw new IllegalArgumentException("userPasswordHistoryPasswordHash is empty"); //NOI18N
+               } else if (null == userPasswordHistoryUser) {
+                       // Throw NPE
+                       throw new NullPointerException("userPasswordHistoryUser is null"); //NOI18N
+               } else if (userPasswordHistoryUser.getUserId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("userPasswordHistoryUser.userId is null"); //NOI18N
+               } else if (userPasswordHistoryUser.getUserId() < 1) {
+                       // Throw IAE
+                       throw new IllegalArgumentException(MessageFormat.format("userPasswordHistoryUser.userId={0} is not valid", userPasswordHistoryUser.getUserId())); //NOI18N
+               }
+
                // Set all
                this.userPasswordHistoryPasswordHash = userPasswordHistoryPasswordHash;
                this.userPasswordHistoryUser = userPasswordHistoryUser;
index 3e3c56295c67e3aeda6d25a75e5e9898b05bf512..abab3acc38368d9f05b71ff5ca254ea8775c95a9 100644 (file)
@@ -26,7 +26,7 @@ import java.io.Serializable;
 public enum ProfileMode implements Serializable {
 
        /**
-        * Invisible to guests and members (not administrators)
+        * Invisible to guests and members (but visible to administrators)
         */
        INVISIBLE("PROFILE_MODE_INVISIBLE"), //NOI18N
 
@@ -51,6 +51,16 @@ public enum ProfileMode implements Serializable {
         * @param messageKey Message key
         */
        private ProfileMode (final String messageKey) {
+               // Validate all parameter
+               if (null == messageKey) {
+                       // Throw NPE
+                       throw new NullPointerException("messageKey is null"); //NOI18N
+               } else if (messageKey.isEmpty()) {
+                       // Throw IAE
+                       throw new IllegalArgumentException("messageKey is empty"); //NOI18N
+               }
+
+               // Set all enum fields
                this.messageKey = messageKey;
        }
 
index 584ec894f9863cd8310d12e1195765ce78c1139a..6da2179c34678ffd28e95edad50b0f13cf4ca601 100644 (file)
@@ -25,11 +25,6 @@ import java.io.Serializable;
  */
 public enum UserAccountStatus implements Serializable {
 
-       /**
-        * Unconfirmed (default)
-        */
-       UNCONFIRMED("USER_ACCOUNT_STATUS_UNCONFIRMED", "user-status-unconfirmed"), //NOI18N
-
        /**
         * Confirmed (email address validated)
         */
@@ -38,7 +33,12 @@ public enum UserAccountStatus implements Serializable {
        /**
         * Locked (maybe violated T&C)
         */
-       LOCKED("USER_ACCOUNT_STATUS_LOCKED", "user-status-locked"); //NOI18N
+       LOCKED("USER_ACCOUNT_STATUS_LOCKED", "user-status-locked"), //NOI18N
+
+       /**
+        * Unconfirmed (default)
+        */
+       UNCONFIRMED("DEPRECATED", "user-status-unconfirmed"); //NOI18N
 
        /**
         * Message key