]> git.mxchange.org Git - juser-activity-core.git/commitdiff
Continued a bit:
authorRoland Häder <roland@mxchange.org>
Thu, 25 Aug 2016 09:18:48 +0000 (11:18 +0200)
committerRoland Häder <roland@mxchange.org>
Thu, 25 Aug 2016 09:18:48 +0000 (11:18 +0200)
- added more user/contact fields being logged in activity log (e.g. when user changes name)
- added initial checks on parameters

src/org/mxchange/jusercore/model/user/activity/LogableUserActivity.java
src/org/mxchange/jusercore/model/user/activity/UserActivityLog.java

index d62ab2f168fff8368f008f7bca9bcb1e79097987..252676ccfeba0d4d2a38b82d7016064a4a9737d0 100644 (file)
@@ -18,6 +18,7 @@ package org.mxchange.jusercore.model.user.activity;
 
 import java.io.Serializable;
 import java.util.Calendar;
+import org.mxchange.jcontacts.contact.gender.Gender;
 import org.mxchange.jusercore.model.user.User;
 
 /**
@@ -97,6 +98,62 @@ public interface LogableUserActivity extends Serializable {
         */
        void setActivityUser (final User activityUser);
 
+       /**
+        * Getter for user name
+        * <p>
+        * @return User name
+        */
+       String getActivityUserName ();
+
+       /**
+        * Setter for user name
+        * <p>
+        * @param activityUserName User name
+        */
+       void setActivityUserName (final String activityUserName);
+
+       /**
+        * Getter for contact family name
+        * <p>
+        * @return Contact family name
+        */
+       String getActivityContactFamilyName ();
+
+       /**
+        * Setter for contact family name
+        * <p>
+        * @param activityContactFamilyName Contact family name
+        */
+       void setActivityContactFamilyName (final String activityContactFamilyName);
+
+       /**
+        * Getter for contact first name
+        * <p>
+        * @return Contact first name
+        */
+       String getActivityContactFirstName ();
+
+       /**
+        * Setter for contact first name
+        * <p>
+        * @param activityContactFirstName Contact first name
+        */
+       void setActivityContactFirstName (final String activityContactFirstName);
+
+       /**
+        * Getter for contact gender
+        * <p>
+        * @return Contact gender
+        */
+       Gender getActivityContactGender ();
+
+       /**
+        * Setter for contact gender
+        * <p>
+        * @param activityContactGender Contact gender
+        */
+       void setActivityContactGender (final Gender activityContactGender);
+
        @Override
        boolean equals (final Object object);
 
index 6012d8c59f8c0c59ac355c1872f6f67f7ada0cd6..a1178e9e898c29736482c50343c447a287c35767 100644 (file)
  */
 package org.mxchange.jusercore.model.user.activity;
 
+import java.text.MessageFormat;
 import java.util.Calendar;
 import java.util.Objects;
 import javax.persistence.Basic;
 import javax.persistence.CascadeType;
 import javax.persistence.Column;
 import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
 import javax.persistence.GeneratedValue;
 import javax.persistence.GenerationType;
 import javax.persistence.Id;
@@ -34,6 +37,7 @@ import javax.persistence.Table;
 import javax.persistence.Temporal;
 import javax.persistence.TemporalType;
 import javax.persistence.Transient;
+import org.mxchange.jcontacts.contact.gender.Gender;
 import org.mxchange.jusercore.model.user.LoginUser;
 import org.mxchange.jusercore.model.user.User;
 
@@ -62,6 +66,28 @@ public class UserActivityLog implements LogableUserActivity {
        @Transient
        private static final long serialVersionUID = 12_945_967_867_290_601L;
 
+       /**
+        * Family name
+        */
+       @Basic (optional = false)
+       @Column (name = "activity_contact_family_name", nullable = false, updatable = false)
+       private String activityContactFamilyName;
+
+       /**
+        * First name
+        */
+       @Basic (optional = false)
+       @Column (name = "activity_contact_first_name", nullable = false, updatable = false)
+       private String activityContactFirstName;
+
+       /**
+        * Gender instance
+        */
+       @Basic (optional = false)
+       @Column (name = "activity_contact_gender", nullable = false, updatable = false)
+       @Enumerated (EnumType.STRING)
+       private Gender activityContactGender;
+
        /**
         * Primary key
         */
@@ -95,10 +121,17 @@ public class UserActivityLog implements LogableUserActivity {
        /**
         * User instance
         */
-       @JoinColumn (name = "activity_user_id", referencedColumnName = "user_id", nullable = false, updatable = false)
-       @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.ALL, optional = false)
+       @JoinColumn (name = "activity_user_id", referencedColumnName = "user_id")
+       @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.ALL)
        private User activityUser;
 
+       /**
+        * User name
+        */
+       @Basic (optional = false)
+       @Column (name = "activity_user_name", nullable = false, updatable = false)
+       private String activityUserName;
+
        /**
         * Default constructor
         */
@@ -117,6 +150,15 @@ public class UserActivityLog implements LogableUserActivity {
                // Call other constructor
                this(activityType, activityUser, activityTimestamp);
 
+               // Is a message given?
+               if (null == activityMessage) {
+                       // Throw NPE
+                       throw new NullPointerException("activityMessage is null"); //NOI18N
+               } else if (activityMessage.isEmpty()) {
+                       // Empty string
+                       throw new IllegalArgumentException("activityMessage is empty"); //NOI18N
+               }
+
                // Set message
                this.activityMessage = activityMessage;
        }
@@ -129,10 +171,46 @@ public class UserActivityLog implements LogableUserActivity {
         * @param activityTimestamp imestamp
         */
        public UserActivityLog (final String activityType, final User activityUser, final Calendar activityTimestamp) {
+               // Make sure all is set
+               if (null == activityType) {
+                       // Throw NPE
+                       throw new NullPointerException("activityType is null"); //NOI18N
+               } else if (activityType.isEmpty()) {
+                       // Empty string
+                       throw new IllegalArgumentException("activityType is empty"); //NOI18N
+               } else if (null == activityUser) {
+                       // Throw NPE
+                       throw new NullPointerException("activityUser is null"); //NOI18N
+               } else if (activityUser.getUserId() == null) {
+                       // Throw it again
+                       throw new NullPointerException("activityUser.userId is null"); //NOI18N
+               } else if (activityUser.getUserId() < 1) {
+                       // Invalid id number
+                       throw new IllegalArgumentException(MessageFormat.format("activityUser.userId={0} is not valid", activityUser.getUserId())); //NOI18N
+               } else if (null == activityUser.getUserContact()) {
+                       // Throw NPE
+                       throw new NullPointerException("activityUser.userContact is null"); //NOI18N
+               } else if (null == activityUser.getUserContact().getContactId()) {
+                       // Throw NPE
+                       throw new NullPointerException("activityUser.userContact.contactId is null"); //NOI18N
+               } else if (activityUser.getUserContact().getContactId() < 1) {
+                       // Invalid id number
+                       throw new IllegalArgumentException(MessageFormat.format("activityUser.userContact.contactId={0} is not valid", activityUser.getUserContact().getContactId())); //NOI18N
+               } else if (null == activityTimestamp) {
+                       // Throw NPE again
+                       throw new NullPointerException("activityTimestamp is null"); //NOI18N
+               }
+
                // Set all values
                this.activityType = activityType;
                this.activityUser = activityUser;
                this.activityTimestamp = activityTimestamp;
+
+               // Set all user/contact fields
+               this.activityUserName = activityUser.getUserName();
+               this.activityContactGender = activityUser.getUserContact().getContactGender();
+               this.activityContactFirstName = activityUser.getUserContact().getContactFirstName();
+               this.activityContactFamilyName = activityUser.getUserContact().getContactFamilyName();
        }
 
        @Override
@@ -162,6 +240,36 @@ public class UserActivityLog implements LogableUserActivity {
                return true;
        }
 
+       @Override
+       public String getActivityContactFamilyName () {
+               return this.activityContactFamilyName;
+       }
+
+       @Override
+       public void setActivityContactFamilyName (final String activityContactFamilyName) {
+               this.activityContactFamilyName = activityContactFamilyName;
+       }
+
+       @Override
+       public String getActivityContactFirstName () {
+               return this.activityContactFirstName;
+       }
+
+       @Override
+       public void setActivityContactFirstName (final String activityContactFirstName) {
+               this.activityContactFirstName = activityContactFirstName;
+       }
+
+       @Override
+       public Gender getActivityContactGender () {
+               return this.activityContactGender;
+       }
+
+       @Override
+       public void setActivityContactGender (final Gender activityContactGender) {
+               this.activityContactGender = activityContactGender;
+       }
+
        @Override
        public Long getActivityId () {
                return this.activityId;
@@ -214,6 +322,16 @@ public class UserActivityLog implements LogableUserActivity {
                this.activityUser = activityUser;
        }
 
+       @Override
+       public String getActivityUserName () {
+               return this.activityUserName;
+       }
+
+       @Override
+       public void setActivityUserName (final String activityUserName) {
+               this.activityUserName = activityUserName;
+       }
+
        @Override
        public int hashCode () {
                int hash = 7;