import org.mxchange.addressbook.model.addressbook.AddressbookSessionBeanRemote;
import org.mxchange.addressbook.model.addressbook.UserAddressbook;
import org.mxchange.addressbook.model.addressbook.entry.AddressbookEntry;
+import org.mxchange.addressbook.model.addressbook.shared.ShareableAddressbook;
import org.mxchange.addressbook.model.addressbook.status.AddressbokStatus;
/**
/**
* A list of all user's address books
*/
- private List<Addressbook> addressbookList;
+ private List<Addressbook> usersAddressbooks;
+
+ /**
+ * A list of all user's shared (with others) address books
+ */
+ private List<ShareableAddressbook> sharedAddressbooks;
/**
* Name of the address book
this.setAddressbookName(null);
// Add address book entry to list
- this.addressbookList.add(updatedAddressbook);
+ this.usersAddressbooks.add(updatedAddressbook);
// All fine
return "login_own_addressbooks"; //NOI18N
throw new FaceletException("This method can only be called as logged-in user."); //NOI18N
}
- return Collections.unmodifiableList(this.addressbookList);
+ return Collections.unmodifiableList(this.usersAddressbooks);
+ }
+
+ @Override
+ public List<ShareableAddressbook> allShares () {
+ // Is the user logged in?
+ if (!this.loginController.isUserLoggedIn()) {
+ // Not logged in
+ throw new FaceletException("This method can only be called as logged-in user."); //NOI18N
+ }
+
+ return Collections.unmodifiableList(this.sharedAddressbooks);
}
@Override
}
// Check if the list is filled
- return (!this.addressbookList.isEmpty());
+ return (!this.usersAddressbooks.isEmpty());
}
@PostConstruct
public void init () {
// Init list
- this.addressbookList = new ArrayList<>(0);
+ this.usersAddressbooks = new ArrayList<>(0);
// Is the user logged-in?
if (this.loginController.isUserLoggedIn()) {
// Fill list with entries
- this.addressbookList = this.addressbookBean.getUsersList(this.loginController.getLoggedInUser());
+ this.usersAddressbooks = this.addressbookBean.getUsersList(this.loginController.getLoggedInUser());
}
}
if (null == addressbookName) {
// Is null
throw new NullPointerException("addressbookName is null"); //NOI18N
- } else if (this.addressbookList.isEmpty()) {
+ } else if (this.usersAddressbooks.isEmpty()) {
// Not found!
return false;
}
boolean isFound = false;
// Check all entries
- for (final Addressbook addressbook : this.addressbookList) {
+ for (final Addressbook addressbook : this.usersAddressbooks) {
// Is the name same?
if (addressbook.getAddressbookName().equals(addressbookName)) {
// Found a match
import java.util.List;
import org.mxchange.addressbook.model.addressbook.Addressbook;
import org.mxchange.addressbook.model.addressbook.entry.AddressbookEntry;
+import org.mxchange.addressbook.model.addressbook.shared.ShareableAddressbook;
/**
* An interface for user beans
*/
public List<AddressbookEntry> allEntries (final Addressbook addressbook);
+ /**
+ * Returns a list of all address books the user is sharing with others.
+ * <p>
+ * @return List of all shared address books
+ */
+ public List<ShareableAddressbook> allShares ();
+
/**
* Size of all entries in given address book
* <p>
--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.shares;
+
+import javax.enterprise.context.SessionScoped;
+import javax.faces.view.facelets.FaceletException;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import org.mxchange.addressbook.beans.login.UserLoginWebController;
+import org.mxchange.addressbook.model.shared.SharedAddressbooksSessionBeanRemote;
+
+/**
+ * A bean for sharing address books with other users
+ * <p>
+ * @author Roland Haeder
+ */
+@Named (value = "shareController")
+@SessionScoped
+public class SharesWebBean implements SharesWebController {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 19_868_976_871_976_780L;
+
+ /**
+ * Login controller injection
+ */
+ @Inject
+ private UserLoginWebController loginController;
+
+ /**
+ * Remote bean for sharing address books
+ */
+ private SharedAddressbooksSessionBeanRemote shareBean;
+
+ /**
+ * Default constructor
+ */
+ public SharesWebBean () {
+ // Try it
+ try {
+ // Get initial context
+ Context context = new InitialContext();
+
+ // Look up bean
+ this.shareBean = (SharedAddressbooksSessionBeanRemote) context.lookup("ejb/stateless-share");
+ } catch (final NamingException ex) {
+ // Continue to throw
+ throw new FaceletException(ex);
+ }
+ }
+
+ @Override
+ public boolean isSharingAddressbooks () {
+ // Only to be called for logged-in users
+ if (!this.loginController.isUserLoggedIn()) {
+ // Not logged in
+ throw new FaceletException("This method can only be called as logged-in user."); //NOI18N
+ }
+
+ // Call the proper bean
+ return this.shareBean.isUserSharingAddressbooks(this.loginController.getLoggedInUser());
+ }
+
+}
--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.shares;
+
+import java.io.Serializable;
+
+/**
+ * Controller interface sharing address books
+ * <p>
+ * @author Roland Haeder
+ */
+public interface SharesWebController extends Serializable {
+
+ /**
+ * Checks wether the current user is sharing address books with others
+ * <p>
+ * @return Whether the current user is sharing address books
+ */
+ public boolean isSharingAddressbooks ();
+}
contact.setContactEmailAddress(this.getEmailAddress());
// Don't set null or wrong references
- if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getPhoneAreaCode() != null) && (this.getPhoneNumber() != null) && (this.getPhoneAreaCode() > 0) &&(this.getPhoneNumber() > 0)) {
+ if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getPhoneAreaCode() != null) && (this.getPhoneNumber() != null) && (this.getPhoneAreaCode() > 0) && (this.getPhoneNumber() > 0)) {
// Now the number must be given
if (phone.getPhoneAreaCode() == null) {
// Is null
ENTERED_HOUSE_NUMBER_INVALID=Die eingegebene Hausnummer ist ung\u00fcltig.
ENTERED_ZIP_CODE_INVALID=Die eingegebene Postleitzahl ist ung\u00fcltig.
PARAMETER_ADDRESSBOOK_ID_NOT_FOUND=Der angeklickte Link ist nicht mehr g\u00fcltig: Adressbuch mit der Id-Nummer nicht gefunden.
+LINK_LOGIN_SHARED_ADDRESS_BOOKS=Mit anderen geteilt
+LINK_LOGIN_SHARED_ADDRESS_BOOKS_TITLE=Mit anderen Benutzern geteilte Adressb\u00fccher
+PAGE_TITLE_LOGIN_SHARED_ADDRESSBOOKS=Mit anderen geteilte Adressb\u00fccher
+CONTENT_TITLE_LOGIN_SHARED_ADDRESSBOOKS=Meine mit anderen Benutzern geteilte Adressb\u00fccher:
ENTERED_HOUSE_NUMBER_INVALID=The entered house number is invalid.
ENTERED_ZIP_CODE_INVALID=The entered ZIP code is invalid.
PARAMETER_ADDRESSBOOK_ID_NOT_FOUND=The clicked link is no longer valid: Address book with entered id number does not exist (anymore).
+LINK_LOGIN_SHARED_ADDRESS_BOOKS=Shared with others
+LINK_LOGIN_SHARED_ADDRESS_BOOKS_TITLE=With other users shared address books
+PAGE_TITLE_LOGIN_SHARED_ADDRESSBOOKS=With others shared address books
+CONTENT_TITLE_LOGIN_SHARED_ADDRESSBOOKS=Mine with other users shared address books:
<li>
<h:link title="#{msg.LINK_LOGIN_OTHER_ADDRESSBOOKS_TITLE}" outcome="login_other_addressbooks" value="#{msg.LINK_LOGIN_OTHER_ADDRESSBOOKS}" />
</li>
+ <li>
+ <h:link title="#{msg.LINK_LOGIN_SHARED_ADDRESS_BOOKS_TITLE}" outcome="login_shared_addressbooks" value="#{msg.LINK_LOGIN_SHARED_ADDRESS_BOOKS}" />
+ </li>
</ul>
<div class="menu_header">
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:ui="http://java.sun.com/jsf/facelets"
+ xmlns:h="http://xmlns.jcp.org/jsf/html"
+ xmlns:f="http://xmlns.jcp.org/jsf/core"
+ >
+
+ <ui:composition template="/WEB-INF/templates/login/login_base.tpl">
+ <ui:define name="login_title">#{msg.PAGE_TITLE_LOGIN_SHARED_ADDRESSBOOKS}</ui:define>
+
+ <ui:define name="content_header">
+ #{msg.CONTENT_TITLE_LOGIN_SHARED_ADDRESSBOOKS}
+ </ui:define>
+
+ <ui:define name="content">
+ <div class="table">
+ <div class="table_header">
+ <h:dataTable id="sharedAddressbooks" summary="#{msg.TABLE_SUMMARY_SHARED_ADDRESSBOOKS}" var="shares" value="#{addressbookController.allShares()}" rendered="#{shareController.isSharingAddressbooks()}">
+ </h:dataTable>
+ </div>
+ </div>
+ </ui:define>
+ </ui:composition>
+</html>