From aa489f89cf2c8eb473522e1850e7d654fb2890d0 Mon Sep 17 00:00:00 2001
From: Roland Haeder <roland@mxchange.org>
Date: Mon, 19 Oct 2015 11:06:02 +0200
Subject: [PATCH] =?utf8?q?Continued:=20-=20isAddressbookLoaded()=20also=20?=
 =?utf8?q?checks=20User=20instance=20+=20name=20-=20added=20check=20before?=
 =?utf8?q?=20start=20of=20sharing=20address=20books=20if=20the=20owner=20a?=
 =?utf8?q?nd=20sharee=20are=20both=20not=20invisible=20-=20added=20isUserN?=
 =?utf8?q?otInvisible().=20EL=20code=20seems=20not=20handle=20negative=20c?=
 =?utf8?q?heck=3F=20:-(=20-=20fixed=20check=20on=20user=20instance=20in=20?=
 =?utf8?q?template=20user=5Fprofile=5Flink.tpl=20-=20removed=20one=20ui:fr?=
 =?utf8?q?agment=20as=20it=20can=20be=20attached=20to=20h:panelGrid,=20too?=
 =?utf8?q?=20Signed-off-by:Roland=20H=C3=A4der=20<roland@mxchange.org>?=
MIME-Version: 1.0
Content-Type: text/plain; charset=utf8
Content-Transfer-Encoding: 8bit

---
 nbproject/faces-config.NavData                | 62 ++++++++---------
 .../AddressbookWebSessionBean.java            |  5 +-
 .../beans/login/UserLoginWebSessionBean.java  |  8 +++
 .../login/UserLoginWebSessionController.java  |  7 ++
 .../beans/shares/SharesWebSessionBean.java    |  7 ++
 .../templates/generic/user_profile_link.tpl   |  2 +-
 .../login_start_sharing_addressbook.xhtml     |  4 +-
 web/user/show_addressbook.xhtml               | 68 +++++++++----------
 8 files changed, 93 insertions(+), 70 deletions(-)

diff --git a/nbproject/faces-config.NavData b/nbproject/faces-config.NavData
index 4ef739c7..9d6df15b 100644
--- a/nbproject/faces-config.NavData
+++ b/nbproject/faces-config.NavData
@@ -1,60 +1,60 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <Scene Scope="Project" version="2">
     <Scope Scope="Faces Configuration Only">
+        <Node id="admin/admin_logout.xhtml" x="650" y="150" zoom="true"/>
+        <Node id="user/login.xhtml" x="150" y="300" zoom="true"/>
+        <Node id="admin/index.xhtml" x="400" y="300" zoom="true"/>
+        <Node id="user/lost_passwd.xhtml" x="400" y="450" zoom="true"/>
+        <Node id="*" x="1150" y="150" zoom="true"/>
+        <Node id="terms.xhtml" x="400" y="150" zoom="true"/>
         <Node id="bye.xhtml" x="150" y="450" zoom="true"/>
-        <Node id="index.xhtml" x="900" y="150" zoom="true"/>
         <Node id="privacy.xhtml" x="650" y="300" zoom="true"/>
-        <Node id="*" x="1150" y="150" zoom="true"/>
+        <Node id="index.xhtml" x="900" y="150" zoom="true"/>
         <Node id="imprint.xhtml" x="150" y="600" zoom="true"/>
         <Node id="admin/category.xhtml" x="650" y="450" zoom="true"/>
-        <Node id="admin/index.xhtml" x="400" y="300" zoom="true"/>
         <Node id="user/register.xhtml" x="150" y="150" zoom="true"/>
-        <Node id="admin/admin_logout.xhtml" x="650" y="150" zoom="true"/>
-        <Node id="terms.xhtml" x="400" y="150" zoom="true"/>
         <Node id="admin/product.xhtml" x="900" y="300" zoom="true"/>
-        <Node id="user/lost_passwd.xhtml" x="400" y="450" zoom="true"/>
-        <Node id="user/login.xhtml" x="150" y="300" zoom="true"/>
     </Scope>
     <Scope Scope="Project">
-        <Node id="login/login_shared_addressbooks.xhtml" x="400" y="150" zoom="true"/>
-        <Node id="login/login_edit_address.xhtml" x="1400" y="300" zoom="true"/>
+        <Node id="user/user_list.xhtml" x="900" y="450" zoom="true"/>
+        <Node id="user/login.xhtml" x="900" y="600" zoom="true"/>
+        <Node id="login/login_other_addressbooks.xhtml" x="1150" y="300" zoom="true"/>
+        <Node id="user/login_error.xhtml" x="150" y="450" zoom="true"/>
         <Node id="privacy.xhtml" x="1400" y="150" zoom="true"/>
+        <Node id="admin/admin_index.xhtml" x="400" y="300" zoom="true"/>
         <Node id="login/login_start_sharing_addressbook.xhtml" x="400" y="450" zoom="true"/>
-        <Node id="user/register.xhtml" x="900" y="300" zoom="true"/>
-        <Node id="login/login_index.xhtml" x="150" y="150" zoom="true"/>
+        <Node id="user/user_profile.xhtml" x="150" y="900" zoom="true"/>
+        <Node id="login/login_list_sharing_addressbooks.xhtml" x="150" y="600" zoom="true"/>
+        <Node id="admin/admin_logout.xhtml" x="400" y="750" zoom="true"/>
         <Node id="login/login_add_addressbook.xhtml" x="1150" y="150" zoom="true"/>
-        <Node id="user/resend_link.xhtml" x="1150" y="450" zoom="true"/>
+        <Node id="login/login_edit_address.xhtml" x="1400" y="300" zoom="true"/>
+        <Node id="login/login_edit_user_data.xhtml" x="1650" y="150" zoom="true"/>
+        <Node id="user/lost_passwd.xhtml" x="400" y="900" zoom="true"/>
+        <Node id="*" x="900" y="150" zoom="true"/>
         <Node id="login/login_own_addressbooks.xhtml" x="650" y="450" zoom="true"/>
-        <Node id="admin/admin_logout.xhtml" x="400" y="750" zoom="true"/>
         <Node id="terms.xhtml" x="400" y="600" zoom="true"/>
-        <Node id="user/user_list.xhtml" x="900" y="450" zoom="true"/>
+        <Node id="user/register_done.xhtml" x="150" y="300" zoom="true"/>
+        <Node id="login/login_shared_addressbooks.xhtml" x="400" y="150" zoom="true"/>
         <Node id="bye.xhtml" x="650" y="600" zoom="true"/>
         <Node id="index.xhtml" x="650" y="150" zoom="true"/>
-        <Node id="user/register_done.xhtml" x="150" y="300" zoom="true"/>
-        <Node id="user/user_profile.xhtml" x="150" y="900" zoom="true"/>
         <Node id="imprint.xhtml" x="650" y="750" zoom="true"/>
-        <Node id="*" x="900" y="150" zoom="true"/>
-        <Node id="user/login_error.xhtml" x="150" y="450" zoom="true"/>
-        <Node id="login/login_other_addressbooks.xhtml" x="1150" y="300" zoom="true"/>
-        <Node id="admin/admin_index.xhtml" x="400" y="300" zoom="true"/>
-        <Node id="user/lost_passwd.xhtml" x="400" y="900" zoom="true"/>
-        <Node id="user/login.xhtml" x="900" y="600" zoom="true"/>
-        <Node id="login/login_list_sharing_addressbooks.xhtml" x="150" y="600" zoom="true"/>
-        <Node id="login/login_edit_user_data.xhtml" x="1650" y="150" zoom="true"/>
+        <Node id="login/login_index.xhtml" x="150" y="150" zoom="true"/>
+        <Node id="user/register.xhtml" x="900" y="300" zoom="true"/>
+        <Node id="user/resend_link.xhtml" x="1150" y="450" zoom="true"/>
     </Scope>
     <Scope Scope="All Faces Configurations">
+        <Node id="admin/admin_logout.xhtml" x="650" y="150" zoom="true"/>
+        <Node id="user/login.xhtml" x="150" y="300" zoom="true"/>
+        <Node id="admin/index.xhtml" x="400" y="300" zoom="true"/>
+        <Node id="user/lost_passwd.xhtml" x="400" y="450" zoom="true"/>
+        <Node id="*" x="1150" y="150" zoom="true"/>
+        <Node id="terms.xhtml" x="400" y="150" zoom="true"/>
         <Node id="bye.xhtml" x="150" y="450" zoom="true"/>
-        <Node id="index.xhtml" x="900" y="150" zoom="true"/>
         <Node id="privacy.xhtml" x="650" y="300" zoom="true"/>
-        <Node id="*" x="1150" y="150" zoom="true"/>
+        <Node id="index.xhtml" x="900" y="150" zoom="true"/>
         <Node id="imprint.xhtml" x="150" y="600" zoom="true"/>
         <Node id="admin/category.xhtml" x="650" y="450" zoom="true"/>
-        <Node id="admin/index.xhtml" x="400" y="300" zoom="true"/>
         <Node id="user/register.xhtml" x="150" y="150" zoom="true"/>
-        <Node id="admin/admin_logout.xhtml" x="650" y="150" zoom="true"/>
-        <Node id="terms.xhtml" x="400" y="150" zoom="true"/>
         <Node id="admin/product.xhtml" x="900" y="300" zoom="true"/>
-        <Node id="user/lost_passwd.xhtml" x="400" y="450" zoom="true"/>
-        <Node id="user/login.xhtml" x="150" y="300" zoom="true"/>
     </Scope>
 </Scene>
diff --git a/src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebSessionBean.java b/src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebSessionBean.java
index 18334615..cfc167dd 100644
--- a/src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebSessionBean.java
+++ b/src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebSessionBean.java
@@ -406,7 +406,10 @@ public class AddressbookWebSessionBean implements AddressbookWebSessionControlle
 
 	@Override
 	public boolean isAddressbookLoaded () {
-		return (this.getAddressbookId() instanceof Long);
+		return ((this.getAddressbookId() instanceof Long)
+				&& (this.getAddressbookName() instanceof String)
+				&& (!this.getAddressbookName().isEmpty())
+				&& (this.getAddressbookUser() instanceof User));
 	}
 
 	/**
diff --git a/src/java/org/mxchange/addressbook/beans/login/UserLoginWebSessionBean.java b/src/java/org/mxchange/addressbook/beans/login/UserLoginWebSessionBean.java
index 564184c0..8854311a 100644
--- a/src/java/org/mxchange/addressbook/beans/login/UserLoginWebSessionBean.java
+++ b/src/java/org/mxchange/addressbook/beans/login/UserLoginWebSessionBean.java
@@ -37,6 +37,7 @@ import org.mxchange.jusercore.exceptions.UserStatusLockedException;
 import org.mxchange.jusercore.exceptions.UserStatusUnconfirmedException;
 import org.mxchange.jusercore.model.login.UserLoginSessionBeanRemote;
 import org.mxchange.jusercore.model.user.User;
+import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
 import org.mxchange.jusercore.model.user.status.UserAccountStatus;
 
 /**
@@ -167,7 +168,14 @@ public class UserLoginWebSessionBean implements UserLoginWebSessionController {
 
 		// Trace message
 		// NOISY: System.out.println(MessageFormat.format("UserLoginWebSessionBean:isUserLoggedIn: this.userLoggedIn={0} - EXIT!", this.userLoggedIn));
+
 		// Return it
 		return this.userLoggedIn;
 	}
+
+	@Override
+	public boolean isNotInvisible () {
+		// Check logged-in first, then invisibility
+		return ((this.isUserLoggedIn()) && (!Objects.equals(this.getLoggedInUser().getUserProfileMode(), ProfileMode.INVISIBLE)));
+	}
 }
diff --git a/src/java/org/mxchange/addressbook/beans/login/UserLoginWebSessionController.java b/src/java/org/mxchange/addressbook/beans/login/UserLoginWebSessionController.java
index a0641a10..680cdf2e 100644
--- a/src/java/org/mxchange/addressbook/beans/login/UserLoginWebSessionController.java
+++ b/src/java/org/mxchange/addressbook/beans/login/UserLoginWebSessionController.java
@@ -74,4 +74,11 @@ public interface UserLoginWebSessionController extends Serializable {
 	 * @return Whether the user is truly a guest
 	 */
 	boolean isGuest ();
+
+	/**
+	 * Whether the currently logged-in user is not invisible
+	 * <p>
+	 * @return Whether the currently logged-in user is not invisible
+	 */
+	boolean isNotInvisible ();
 }
diff --git a/src/java/org/mxchange/addressbook/beans/shares/SharesWebSessionBean.java b/src/java/org/mxchange/addressbook/beans/shares/SharesWebSessionBean.java
index b493921a..e14d89e5 100644
--- a/src/java/org/mxchange/addressbook/beans/shares/SharesWebSessionBean.java
+++ b/src/java/org/mxchange/addressbook/beans/shares/SharesWebSessionBean.java
@@ -40,6 +40,7 @@ import org.mxchange.addressbook.model.addressbook.Addressbook;
 import org.mxchange.addressbook.model.addressbook.shared.ShareableAddressbook;
 import org.mxchange.addressbook.model.shared.SharedAddressbooksSessionBeanRemote;
 import org.mxchange.jusercore.model.user.User;
+import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
 
 /**
  * A bean for sharing address books with other users
@@ -253,6 +254,12 @@ public class SharesWebSessionBean implements SharesWebSessionController {
 		} else if (!Objects.equals(addressbook.getAddressbookUser(), this.loginController.getLoggedInUser())) {
 			// Not the same user!
 			throw new IllegalStateException(MessageFormat.format("Address book id {0} owner id {1} mismatching logged-in user id {2}", addressbook.getAddressbookId(), addressbook.getAddressbookUser().getUserId(), this.loginController.getLoggedInUser().getUserId())); //NOI18N
+		} else if (this.loginController.getLoggedInUser().getUserProfileMode() == ProfileMode.INVISIBLE) {
+			// User is invisible
+			throw new FaceletException(MessageFormat.format("user {0} is invisible and cannot start sharing address books.", this.loginController.getLoggedInUser().getUserId())); //NOI18N
+		} else if (user.getUserProfileMode() == ProfileMode.INVISIBLE) {
+			// User is invisible
+			throw new FaceletException(MessageFormat.format("user {0} is invisible and cannot be selected for sharing.", user.getUserId())); //NOI18N
 		}
 
 		try {
diff --git a/web/WEB-INF/templates/generic/user_profile_link.tpl b/web/WEB-INF/templates/generic/user_profile_link.tpl
index 0bbe58a5..617a0496 100644
--- a/web/WEB-INF/templates/generic/user_profile_link.tpl
+++ b/web/WEB-INF/templates/generic/user_profile_link.tpl
@@ -7,7 +7,7 @@
 	xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">
 
 	<c:choose>
-		<c:when test="#{profileController.isProfileLinkVisible(user)}">
+		<c:when test="#{user != null and profileController.isProfileLinkVisible(user)}">
 			<h:link id="userProfileLink" outcome="user_profile" title="#{msg.LINK_USER_PROFILE_TITLE}">
 				<h:outputText id="userName" value="#{user.userName}" />
 				<f:param name="userId" value="#{user.userId}" />
diff --git a/web/login/login_start_sharing_addressbook.xhtml b/web/login/login_start_sharing_addressbook.xhtml
index 38660fcb..c25adf43 100644
--- a/web/login/login_start_sharing_addressbook.xhtml
+++ b/web/login/login_start_sharing_addressbook.xhtml
@@ -21,7 +21,7 @@
 				</div>
 
 				<div class="para">
-					<h:dataTable id="userList" headerClass="table_header_column" var="user" value="#{addressbookController.allUsersNotSharing()}">
+					<h:dataTable id="userList" headerClass="table_header_column" var="user" value="#{addressbookController.allUsersNotSharing()}" rendered="#{loginController.isNotInvisible()}">
 						<h:column>
 							<f:facet name="header">#{msg.USER_ID}</f:facet>
 							<h:outputText value="#{user.userId}" />
@@ -36,7 +36,7 @@
 
 						<h:column>
 							<f:facet name="header">#{msg.LOGIN_START_SHARING_TITLE}</f:facet>
-							<h:form acceptcharset="utf-8" id="startSharing">
+							<h:form acceptcharset="utf-8" id="startSharing" rendered="#{profileController.isProfileLinkVisible(user)}">
 								<h:commandButton class="submit" id="submit" value="#{msg.LOGIN_START_SHARING_BUTTON}" action="#{shareController.startSharing(user, addressbookController.addressbook)}" title="#{msg.LOGIN_START_SHARING_BUTTON_TITLE}" />
 							</h:form>
 						</h:column>
diff --git a/web/user/show_addressbook.xhtml b/web/user/show_addressbook.xhtml
index 0a73b4ad..8c2115fe 100644
--- a/web/user/show_addressbook.xhtml
+++ b/web/user/show_addressbook.xhtml
@@ -22,42 +22,40 @@
 		</ui:define>
 
 		<ui:define name="content">
-			<ui:fragment rendered="#{addressbookController.isAddressbookLoaded()}">
-				<h:panelGrid headerClass="table_header" styleClass="table" columns="2">
-					<f:facet name="header">#{msg.TABLE_HEADER_SHOW_ADDRESSBOOK}</f:facet>
-
-					<h:outputLabel for="addressbookId" class="table_label">#{msg.ADDRESSBOOK_ID}</h:outputLabel>
-					<h:outputText id="addressbookId" value="#{addressbookController.addressbookId}" />
-
-					<h:outputLabel for="addressbookName" class="table_label">#{msg.ADDRESSBOOK_NAME}</h:outputLabel>
-					<h:outputText id="addressbookName" value="#{addressbookController.addressbookName}" />
-
-					<h:outputLabel for="userProfileLink" class="table_label">#{msg.ADDRESSBOOK_OWNER}</h:outputLabel>
-					<ui:include src="/WEB-INF/templates/generic/user_profile_link.tpl">
-						<ui:param name="user" value="#{addressbookController.addressbookUser}" />
-					</ui:include>
-
-					<h:outputLabel for="addressbookCreated" class="table_label">#{msg.ADDRESSBOOK_CREATED}</h:outputLabel>
-					<h:outputFormat id="addressbookCreated" value="#{addressbookController.addressbook.addressbookCreated.time}" title="#{msg.ADDRESSBOOK_CREATED_TITLE}">
-						<f:convertDateTime for="addressbookCreated" type="both" timeStyle="short" dateStyle="medium" />
-					</h:outputFormat>
-
-					<h:outputLabel for="addressbookStatus" class="table_label">#{msg.ADDRESSBOOK_STATUS}</h:outputLabel>
-					<h:outputText id="addressbookStatus" value="#{msg[addressbookController.addressbook.addressbookStatus.messageKey]}" title="#{msg.ADDRESSBOOK_STATUS_TITLE}" />
-
-					<f:facet name="footer">
-						<ui:fragment rendered="#{loginController.isUserLoggedIn()}">
-							<ui:fragment rendered="#{addressbookController.isOwnAddressbook()}">
-								<h:link id="startSharing" outcome="login_start_sharing_addressbook" value="#{msg.LINK_LOGIN_START_SHARING_ADDRESSBOOK}" title="#{msg.LINK_LOGIN_START_SHARING_ADDRESSBOOK_TITLE}" />
-							</ui:fragment>
-
-							<ui:fragment rendered="#{addressbookController.isOtherAddressbook()}">
-								Bla bla
-							</ui:fragment>
+			<h:panelGrid headerClass="table_header" styleClass="table" columns="2" rendered="#{addressbookController.isAddressbookLoaded()}">
+				<f:facet name="header">#{msg.TABLE_HEADER_SHOW_ADDRESSBOOK}</f:facet>
+
+				<h:outputLabel for="addressbookId" class="table_label">#{msg.ADDRESSBOOK_ID}</h:outputLabel>
+				<h:outputText id="addressbookId" value="#{addressbookController.addressbookId}" />
+
+				<h:outputLabel for="addressbookName" class="table_label">#{msg.ADDRESSBOOK_NAME}</h:outputLabel>
+				<h:outputText id="addressbookName" value="#{addressbookController.addressbookName}" />
+
+				<h:outputLabel for="userProfileLink" class="table_label">#{msg.ADDRESSBOOK_OWNER}</h:outputLabel>
+				<ui:include src="/WEB-INF/templates/generic/user_profile_link.tpl">
+					<ui:param name="user" value="#{addressbookController.addressbookUser}" />
+				</ui:include>
+
+				<h:outputLabel for="addressbookCreated" class="table_label">#{msg.ADDRESSBOOK_CREATED}</h:outputLabel>
+				<h:outputFormat id="addressbookCreated" value="#{addressbookController.addressbook.addressbookCreated.time}" title="#{msg.ADDRESSBOOK_CREATED_TITLE}">
+					<f:convertDateTime for="addressbookCreated" type="both" timeStyle="short" dateStyle="medium" />
+				</h:outputFormat>
+
+				<h:outputLabel for="addressbookStatus" class="table_label">#{msg.ADDRESSBOOK_STATUS}</h:outputLabel>
+				<h:outputText id="addressbookStatus" value="#{msg[addressbookController.addressbook.addressbookStatus.messageKey]}" title="#{msg.ADDRESSBOOK_STATUS_TITLE}" />
+
+				<f:facet name="footer">
+					<ui:fragment rendered="#{loginController.isUserLoggedIn()}">
+						<ui:fragment rendered="#{addressbookController.isOwnAddressbook()}">
+							<h:link id="startSharing" outcome="login_start_sharing_addressbook" value="#{msg.LINK_LOGIN_START_SHARING_ADDRESSBOOK}" title="#{msg.LINK_LOGIN_START_SHARING_ADDRESSBOOK_TITLE}" />
+						</ui:fragment>
+
+						<ui:fragment rendered="#{addressbookController.isOtherAddressbook()}">
+							Bla bla
 						</ui:fragment>
-					</f:facet>
-				</h:panelGrid>
-			</ui:fragment>
+					</ui:fragment>
+				</f:facet>
+			</h:panelGrid>
 		</ui:define>
 	</ui:composition>
 </html>
-- 
2.39.5