]> git.mxchange.org Git - juser-core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sun, 19 Nov 2017 00:35:58 +0000 (01:35 +0100)
committerRoland Häder <roland@mxchange.org>
Sun, 19 Nov 2017 01:22:19 +0000 (02:22 +0100)
- userMustChangePassword is no longer optional, please do make a choice here
- remember that userContact.contactId could be NULL when it has been created
  while the user's account has been created
- added constructor with all required fields and validated them in it

Signed-off-by: Roland Häder <roland@mxchange.org>
src/org/mxchange/jusercore/model/user/LoginUser.java

index 25ba50a7ba4d44a8a8459300f63dfcf5015e23ca..0ba0fa14055946ab25aa3ca1c316999e352c47cf 100644 (file)
@@ -140,7 +140,8 @@ public class LoginUser implements User {
        /**
         * Whether the user must change password after login
         */
-       @Column (name = "user_must_change_password")
+       @Basic (optional = false)
+       @Column (name = "user_must_change_password", nullable = false)
        private Boolean userMustChangePassword;
 
        /**
@@ -173,6 +174,56 @@ public class LoginUser implements User {
                this.userProfileMode = ProfileMode.INVISIBLE;
        }
 
+       /**
+        * Constructor with all required fields
+        * <p>
+        * @param userName               Username
+        * @param userProfileMode        Profile mode
+        * @param userMustChangePassword Whether user must change password
+        * @param userEncryptedPassword  Encrypted password
+        * @param userAccountStatus      Account status
+        * @param userContact User's contact data
+        */
+       public LoginUser (final String userName, final ProfileMode userProfileMode, final Boolean userMustChangePassword, final String userEncryptedPassword, final UserAccountStatus userAccountStatus, final Contact userContact) {
+               // Call other constructor first
+               this();
+
+               // Validate all parameter
+               if (null == userName) {
+                       // Throw NPE
+                       throw new NullPointerException("userName is null"); //NOI18N
+               } else if (userName.isEmpty()) {
+                       // Throw IAE
+                       throw new IllegalArgumentException("userName is empty"); //NOI18N
+               } else if (null == userProfileMode) {
+                       // Throw NPE
+                       throw new NullPointerException("userProfileMode is null"); //NOI18N
+               } else if (null == userMustChangePassword) {
+                       // Throw it again
+                       throw new NullPointerException("userMustChangePassword is null"); //NOI18N
+               } else if (null == userEncryptedPassword) {
+                       // Throw it again
+                       throw new NullPointerException("userEncryptedPassword is null"); //NOI18N
+               } else if (userEncryptedPassword.isEmpty()) {
+                       // Throw IAE
+                       throw new IllegalArgumentException("userEncryptedPassword is empty"); //NOI18N
+               } else if (null == userAccountStatus) {
+                       // Throw NPE
+                       throw new NullPointerException("userAccountStatus is null"); //NOI18N
+               } else if (null == userContact) {
+                       // Throw it again
+                       throw new NullPointerException("userContact is null"); //NOI18N
+               }
+
+               // Set all fields
+               this.userAccountStatus = userAccountStatus;
+               this.userEncryptedPassword = userEncryptedPassword;
+               this.userMustChangePassword = userMustChangePassword;
+               this.userName = userName;
+               this.userProfileMode = userProfileMode;
+               this.userContact = userContact;
+       }
+
        @Override
        public boolean equals (final Object object) {
                if (null == object) {