From b64fbb4ecf782cc1f234364395d840e28e01f9f8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 25 Aug 2016 11:18:48 +0200 Subject: [PATCH] Continued a bit: - added more user/contact fields being logged in activity log (e.g. when user changes name) - added initial checks on parameters --- .../user/activity/LogableUserActivity.java | 57 ++++++++ .../model/user/activity/UserActivityLog.java | 122 +++++++++++++++++- 2 files changed, 177 insertions(+), 2 deletions(-) diff --git a/src/org/mxchange/jusercore/model/user/activity/LogableUserActivity.java b/src/org/mxchange/jusercore/model/user/activity/LogableUserActivity.java index d62ab2f..252676c 100644 --- a/src/org/mxchange/jusercore/model/user/activity/LogableUserActivity.java +++ b/src/org/mxchange/jusercore/model/user/activity/LogableUserActivity.java @@ -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 + *

+ * @return User name + */ + String getActivityUserName (); + + /** + * Setter for user name + *

+ * @param activityUserName User name + */ + void setActivityUserName (final String activityUserName); + + /** + * Getter for contact family name + *

+ * @return Contact family name + */ + String getActivityContactFamilyName (); + + /** + * Setter for contact family name + *

+ * @param activityContactFamilyName Contact family name + */ + void setActivityContactFamilyName (final String activityContactFamilyName); + + /** + * Getter for contact first name + *

+ * @return Contact first name + */ + String getActivityContactFirstName (); + + /** + * Setter for contact first name + *

+ * @param activityContactFirstName Contact first name + */ + void setActivityContactFirstName (final String activityContactFirstName); + + /** + * Getter for contact gender + *

+ * @return Contact gender + */ + Gender getActivityContactGender (); + + /** + * Setter for contact gender + *

+ * @param activityContactGender Contact gender + */ + void setActivityContactGender (final Gender activityContactGender); + @Override boolean equals (final Object object); diff --git a/src/org/mxchange/jusercore/model/user/activity/UserActivityLog.java b/src/org/mxchange/jusercore/model/user/activity/UserActivityLog.java index 6012d8c..a1178e9 100644 --- a/src/org/mxchange/jusercore/model/user/activity/UserActivityLog.java +++ b/src/org/mxchange/jusercore/model/user/activity/UserActivityLog.java @@ -16,12 +16,15 @@ */ 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; -- 2.39.5