From 3850db85781e4c998d9e57047dfed2821b627f7e Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 16 Oct 2015 18:23:09 +0200 Subject: [PATCH] Added ProfileMode instead of boolean public/private flag. This is way more flexible but requires rewrite --- .../jusercore/model/user/LoginUser.java | 26 ++++---- .../mxchange/jusercore/model/user/User.java | 5 +- .../model/user/profilemodes/ProfileMode.java | 62 +++++++++++++++++++ 3 files changed, 78 insertions(+), 15 deletions(-) create mode 100644 src/org/mxchange/jusercore/model/user/profilemodes/ProfileMode.java diff --git a/src/org/mxchange/jusercore/model/user/LoginUser.java b/src/org/mxchange/jusercore/model/user/LoginUser.java index 9f3f14f..aa99a5e 100644 --- a/src/org/mxchange/jusercore/model/user/LoginUser.java +++ b/src/org/mxchange/jusercore/model/user/LoginUser.java @@ -37,6 +37,7 @@ import javax.persistence.Temporal; import javax.persistence.TemporalType; import org.mxchange.jcontacts.contact.Contact; import org.mxchange.jcontacts.contact.UserContact; +import org.mxchange.jusercore.model.user.profilemodes.ProfileMode; import org.mxchange.jusercore.model.user.status.UserAccountStatus; /** @@ -135,20 +136,19 @@ public class LoginUser implements User { private String userName; /** - * Whether the user wants a public profile. This means that it can be viewed - * from the Internet by everyone (only profile, no personal data, this needs - * explicit agreement) and it can be found for sharing addresses with. + * Profile mode of this user */ @Basic (optional = false) - @Column (name = "user_public_profile_flag", nullable = false) - private Boolean userPublicProfile; + @Enumerated (EnumType.STRING) + @Column (name = "user_profile_mode", nullable = false) + private ProfileMode userProfileMode; /** * Default constructor */ public LoginUser () { - // Default is not public - this.userPublicProfile = Boolean.FALSE; + // Default is invisible + this.userProfileMode = ProfileMode.INVISIBLE; } @Override @@ -176,8 +176,8 @@ public class LoginUser implements User { final User other = (User) object; - return ((Objects.equals(this.getUserName(), other.getUserName())) - && (Objects.equals(this.getUserId(), other.getUserId()))); + return ((Objects.equals(this.getUserName(), other.getUserName())) && + (Objects.equals(this.getUserId(), other.getUserId()))); } @Override @@ -261,13 +261,13 @@ public class LoginUser implements User { } @Override - public Boolean getUserPublicProfile () { - return this.userPublicProfile; + public ProfileMode getUserProfileMode () { + return this.userProfileMode; } @Override - public void setUserPublicProfile (final Boolean userPublicProfile) { - this.userPublicProfile = userPublicProfile; + public void setUserProfileMode (final ProfileMode userProfileMode) { + this.userProfileMode = userProfileMode; } @Override diff --git a/src/org/mxchange/jusercore/model/user/User.java b/src/org/mxchange/jusercore/model/user/User.java index 1cc63cf..9bc1e8f 100644 --- a/src/org/mxchange/jusercore/model/user/User.java +++ b/src/org/mxchange/jusercore/model/user/User.java @@ -19,6 +19,7 @@ package org.mxchange.jusercore.model.user; import java.io.Serializable; import java.util.Calendar; import org.mxchange.jcontacts.contact.Contact; +import org.mxchange.jusercore.model.user.profilemodes.ProfileMode; import org.mxchange.jusercore.model.user.status.UserAccountStatus; /** @@ -152,14 +153,14 @@ public interface User extends Serializable { *

* @return Whether the user has a public profile */ - Boolean getUserPublicProfile (); + ProfileMode getUserProfileMode (); /** * Setter for public user profile flag *

* @param userPublicProfile Whether the user has a public profile */ - void setUserPublicProfile (final Boolean userPublicProfile); + void setUserProfileMode (final ProfileMode userPublicProfile); /** * Checks if object is a User instance and whether it matches with this diff --git a/src/org/mxchange/jusercore/model/user/profilemodes/ProfileMode.java b/src/org/mxchange/jusercore/model/user/profilemodes/ProfileMode.java new file mode 100644 index 0000000..1a09646 --- /dev/null +++ b/src/org/mxchange/jusercore/model/user/profilemodes/ProfileMode.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.jusercore.model.user.profilemodes; + +import java.io.Serializable; + +/** + * User profile modes + *

+ * @author Roland Haeder + */ +public enum ProfileMode implements Serializable { + + /** + * Invisible to guests and members (not administrators) + */ + INVISIBLE("USER_PROFILE_MODE_PRIVATE"), + /** + * Only visible to members (and administrators) + */ + MEMBERS("USER_PROFILE_MODE_PRIVATE"), + /** + * Visible to all (public in Internet) + */ + PUBLIC("USER_PROFILE_MODE_PRIVATE"); + + /** + * Message key (i18n) + */ + private final String messageKey; + + /** + * Constructor with message key + *

+ * @param messageKey Message key + */ + private ProfileMode (final String messageKey) { + this.messageKey = messageKey; + } + + /** + * Getter for message key (i18n) + * @return Message key + */ + public String getMessageKey () { + return this.messageKey; + } +} -- 2.39.5