]> git.mxchange.org Git - juser-core.git/commitdiff
Continued a bit:
authorRoland Häder <roland@mxchange.org>
Wed, 18 May 2016 08:14:55 +0000 (10:14 +0200)
committerRoland Häder <roland@mxchange.org>
Wed, 18 May 2016 08:27:19 +0000 (10:27 +0200)
- some fields are not always set and may cause a NPE
- added created/updated timestamps for user
- added some more initial checks on POJO properties/fields

src/org/mxchange/jusercore/model/user/UserUtils.java

index 18b1b332d896fe756b7c413f695d399ec1024a9c..2d663ab105214cf98be150acca7ee43e05398cac 100644 (file)
@@ -203,33 +203,86 @@ public class UserUtils implements Serializable {
                // Parameter should be valid
                if (null == user) {
                        // Throw NPE
-                       throw new NullPointerException("user is null");
+                       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) {
+                       // Not valid number
+                       throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid.", user.getUserId())); //NOI18N
+               } else if (user.getUserName() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("user.userName is null"); //NOI18N
+               } else if (user.getUserName().isEmpty()) {
+                       // Empty string
+                       throw new IllegalArgumentException("user.userName is empty"); //NOI18N
+               } else if (user.getUserAccountStatus() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("user.userAccountStatus is null"); //NOI18N
                }
 
                // Init properties list
                Properties properties = new Properties();
 
+               // Init some vbalues with empty strings
+               properties.setProperty("userConfirmKey", ""); //NOI18N
+               properties.setProperty("userUpdated", ""); //NOI18N
+               properties.setProperty("userLastLockedReason", ""); //NOI18N
+               properties.setProperty("contactTitle", ""); //NOI18N
+               properties.setProperty("contactStreet", ""); //NOI18N
+               properties.setProperty("contactHouseNumber", ""); //NOI18N
+               properties.setProperty("contacCity", ""); //NOI18N
+               properties.setProperty("contacCity", ""); //NOI18N
+               properties.setProperty("contactZipCode", ""); //NOI18N
+               properties.setProperty("contactBirthday", ""); //NOI18N
+               properties.setProperty("contactEmailAddress", ""); //NOI18N
+               properties.setProperty("contactUpdated", ""); //NOI18N
+
                // Set all:
                // - User data
-               properties.setProperty("userId", Long.toString(user.getUserId()));
-               properties.setProperty("userName", user.getUserName());
-               properties.setProperty("userConfirmKey", user.getUserConfirmKey());
-               properties.setProperty("userLastLockedReason", user.getUserLastLockedReason());
-               properties.setProperty("userAccountStatus", user.getUserAccountStatus().toString());
+               properties.setProperty("userId", Long.toString(user.getUserId())); //NOI18N
+               properties.setProperty("userName", user.getUserName()); //NOI18N
+               properties.setProperty("userCreated", user.getUserCreated().toString()); //NOI18N
+               if (user.getUserUpdated() != null) {
+                       properties.setProperty("contactUpdated", user.getUserUpdated().toString()); //NOI18N
+               }
+               if (user.getUserConfirmKey() != null) {
+                       properties.setProperty("userConfirmKey", user.getUserConfirmKey()); //NOI18N
+               }
+               if (user.getUserLastLockedReason() != null) {
+                       properties.setProperty("userLastLockedReason", user.getUserLastLockedReason()); //NOI18N
+               }
+               properties.setProperty("userAccountStatus", user.getUserAccountStatus().toString()); //NOI18N
 
                // - Contact data
-               properties.setProperty("contactGender", user.getUserContact().getContactGender().toString());
-               properties.setProperty("contactTitle", user.getUserContact().getContactTitle());
-               properties.setProperty("contactFirstName", user.getUserContact().getContactFirstName());
-               properties.setProperty("contactFamilyName", user.getUserContact().getContactFamilyName());
-               properties.setProperty("contactStreet", user.getUserContact().getContactStreet());
-               properties.setProperty("contactHouseNumber", Short.toString(user.getUserContact().getContactHouseNumber()));
-               properties.setProperty("contacCity", user.getUserContact().getContactCity());
-               properties.setProperty("contactZipCode", Integer.toString(user.getUserContact().getContactZipCode()));
-               properties.setProperty("contactBirthday", user.getUserContact().getContactBirthday().toString());
-               properties.setProperty("contactEmailAddress", user.getUserContact().getContactEmailAddress());
-               properties.setProperty("contactCreated", user.getUserContact().getContactCreated().toString());
-               properties.setProperty("contactUpdated", user.getUserContact().getContactUpdated().toString());
+               properties.setProperty("contactGender", user.getUserContact().getContactGender().toString()); //NOI18N
+               if (user.getUserContact().getContactTitle() != null) {
+                       properties.setProperty("contactTitle", user.getUserContact().getContactTitle()); //NOI18N
+               }
+               properties.setProperty("contactFirstName", user.getUserContact().getContactFirstName()); //NOI18N
+               properties.setProperty("contactFamilyName", user.getUserContact().getContactFamilyName()); //NOI18N
+               if (user.getUserContact().getContactStreet() != null) {
+                       properties.setProperty("contactStreet", user.getUserContact().getContactStreet()); //NOI18N
+               }
+               if (user.getUserContact().getContactHouseNumber() != null) {
+                       properties.setProperty("contactHouseNumber", Short.toString(user.getUserContact().getContactHouseNumber())); //NOI18N
+               }
+               if (user.getUserContact().getContactCity() != null) {
+                       properties.setProperty("contacCity", user.getUserContact().getContactCity()); //NOI18N
+               }
+               if (user.getUserContact().getContactZipCode() != null) {
+                       properties.setProperty("contactZipCode", Integer.toString(user.getUserContact().getContactZipCode())); //NOI18N
+               }
+               if (user.getUserContact().getContactBirthday() != null) {
+                       properties.setProperty("contactBirthday", user.getUserContact().getContactBirthday().toString()); //NOI18N
+               }
+               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
+               }
 
                // Return it
                return properties;