</target>
<target depends="init,compile,compile-jsps,-pre-dist,-do-dist-with-manifest,-do-dist-without-manifest" name="do-dist"/>
<target depends="init" if="dist.ear.dir" name="library-inclusion-in-manifest">
- <copyfiles files="${reference.addressbook-core.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
<mkdir dir="${build.web.dir}/META-INF"/>
<manifest file="${build.web.dir}/META-INF/MANIFEST.MF" mode="update"/>
</target>
- <target depends="init" name="library-inclusion-in-archive" unless="dist.ear.dir">
- <copyfiles files="${reference.addressbook-core.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
- </target>
+ <target depends="init" name="library-inclusion-in-archive" unless="dist.ear.dir"/>
<target depends="init" if="dist.ear.dir" name="-clean-webinf-lib">
<delete dir="${build.web.dir}/WEB-INF/lib"/>
</target>
build.xml.stylesheet.CRC32=651128d4@1.68.1.1
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
-nbproject/build-impl.xml.data.CRC32=f07494a8
-nbproject/build-impl.xml.script.CRC32=8dc59c00
+nbproject/build-impl.xml.data.CRC32=25847443
+nbproject/build-impl.xml.script.CRC32=b9d55450
nbproject/build-impl.xml.stylesheet.CRC32=99ea4b56@1.75.1.1
file.reference.gf-client.jar=lib/gf-client.jar
file.reference.jaddressbook-core.jar=lib/jaddressbook-core.jar
file.reference.jaddressbook-lib.jar=lib/jaddressbook-lib.jar
+file.reference.jaddressbook-share-core.jar=lib/jaddressbook-share-core.jar
+file.reference.jaddressbook-share-lib.jar=lib/jaddressbook-share-lib.jar
file.reference.jcontacts-business-core.jar=lib/jcontacts-business-core.jar
file.reference.jcontacts-core.jar=lib/jcontacts-core.jar
file.reference.jcontacts-lib.jar=lib/jcontacts-lib.jar
${file.reference.juser-lib.jar}:\
${file.reference.jaddressbook-core.jar}:\
${file.reference.jaddressbook-lib.jar}:\
+ ${file.reference.jaddressbook-share-core.jar}:\
+ ${file.reference.jaddressbook-share-lib.jar}:\
${reference.addressbook-core.jar}:\
${reference.addressbook-lib.jar}:\
${reference.addressbook-mailer.jar}:\
source.encoding=UTF-8
source.reference.jaddressbook-core.jar=../jaddressbook-core/src/
source.reference.jaddressbook-lib.jar=../jaddressbook-lib/src/
+source.reference.jaddressbook-share-core.jar=../jaddressbook-share-core/src
+source.reference.jaddressbook-share-lib.jar=../jaddressbook-share-lib/src
source.reference.jcontacts-business-core.jar=../jcontacts-business-core/src/
source.reference.jcontacts-core.jar=../jcontacts-core/src/
source.reference.jcontacts-lib.jar=../jcontacts-lib/src/
<library dirs="200">
<file>${file.reference.jaddressbook-lib.jar}</file>
</library>
+ <library dirs="200">
+ <file>${file.reference.jaddressbook-share-core.jar}</file>
+ </library>
+ <library dirs="200">
+ <file>${file.reference.jaddressbook-share-lib.jar}</file>
+ </library>
<library dirs="200">
<file>${reference.addressbook-core.jar}</file>
- <path-in-war>WEB-INF/lib</path-in-war>
</library>
<library dirs="200">
<file>${reference.addressbook-lib.jar}</file>
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import javax.enterprise.event.Event;
import org.mxchange.addressbook.beans.BaseAddressbookController;
import org.mxchange.addressbook.beans.login.user.AddressbookUserLoginWebSessionController;
import org.mxchange.addressbook.model.addressbook.AddressbookSessionBeanRemote;
-import org.mxchange.jaddressbookcore.events.addressbook.AddressbookLoadedEvent;
-import org.mxchange.jaddressbookcore.events.addressbook.ObservableAddressbookLoadedEvent;
-import org.mxchange.jaddressbookcore.exceptions.AddressbookNameAlreadyUsedException;
-import org.mxchange.jaddressbookcore.exceptions.AddressbookNotFoundException;
-import org.mxchange.jaddressbookcore.model.addressbook.Addressbook;
-import org.mxchange.jaddressbookcore.model.addressbook.UserAddressbook;
-import org.mxchange.jaddressbookcore.model.addressbook.entry.AddressbookEntry;
+import org.mxchange.jaddressbook.events.addressbook.AddressbookLoadedEvent;
+import org.mxchange.jaddressbook.events.addressbook.ObservableAddressbookLoadedEvent;
+import org.mxchange.jaddressbook.exceptions.AddressbookNameAlreadyUsedException;
+import org.mxchange.jaddressbook.exceptions.AddressbookNotFoundException;
+import org.mxchange.jaddressbook.model.addressbook.Addressbook;
+import org.mxchange.jaddressbook.model.addressbook.UserAddressbook;
+import org.mxchange.jaddressbook.model.addressbook.entry.AddressbookEntry;
import org.mxchange.jusercore.events.login.ObservableUserLoggedInEvent;
import org.mxchange.jusercore.model.user.User;
@SessionScoped
public class AddressbookWebSessionBean extends BaseAddressbookController implements AddressbookWebSessionController {
- /**
- * Map for count of user's shared addresses
- */
- private static ConcurrentMap<User, Integer> countSharesList;
-
/**
* Serial number
*/
public AddressbookWebSessionBean () {
// Call super constructor
super();
-
- // Init list
- AddressbookWebSessionBean.countSharesList = new ConcurrentHashMap<>(0);
}
@Override
}
}
- @Override
+ /**
+ * Event being fired after an address book has been loaded
+ * <p>
+ * @param event Event being fired
+ */
public void afterAddressbookLoadedEvent (@Observes final ObservableAddressbookLoadedEvent event) {
// event should not be null
if (null == event) {
this.setAddressbook(book);
}
- @Override
+ /**
+ * Event being fired after user has logged-in
+ * <p>
+ * @param event Event being fired
+ */
public void afterLoginEvent (@Observes final ObservableUserLoggedInEvent event) {
// Is the user logged in?
if (null == event) {
return this.allEntries(addressbook).size();
}
- @Override
- public List<User> allUsersNotSharing () {
- // Is the user logged in?
- if (!this.userLoginController.isUserLoggedIn()) {
- // Not logged in
- throw new FaceletException("This method can only be called as logged-in user."); //NOI18N
- }
-
- // Call EJB
- return this.addressbookBean.allUsersNotSharing(this.userLoginController.getLoggedInUser(), this.getAddressbook());
- }
-
- @Override
- public Integer countAllUserSharedAddressbooks (final User user) {
- // Is there cache?
- if (AddressbookWebSessionBean.countSharesList.containsKey(user)) {
- // Return it instead
- return AddressbookWebSessionBean.countSharesList.get(user);
- }
-
- // Call EJB ("expensive")
- Integer count = this.addressbookBean.countAllUserSharedAddressbooks(user);
-
- // Add to list
- AddressbookWebSessionBean.countSharesList.put(user, count);
-
- // Return it
- return count;
- }
-
@Override
public Addressbook getAddressbook () {
return this.addressbook;
import java.io.Serializable;
import java.util.Calendar;
import java.util.List;
-import org.mxchange.jaddressbookcore.model.addressbook.Addressbook;
-import org.mxchange.jaddressbookcore.model.addressbook.entry.AddressbookEntry;
+import org.mxchange.jaddressbook.model.addressbook.Addressbook;
+import org.mxchange.jaddressbook.model.addressbook.entry.AddressbookEntry;
import org.mxchange.jusercore.model.user.User;
-import org.mxchange.jaddressbookcore.events.addressbook.ObservableAddressbookLoadedEvent;
-import org.mxchange.jusercore.events.login.ObservableUserLoggedInEvent;
/**
* An interface for address book beans
*/
void setAddressbookCreated (final Calendar addressbookCreated);
- /**
- * This method is called when an address book has been successfully loaded
- * from JPA.
- * <p>
- * @param event Event with address book instance
- */
- void afterAddressbookLoadedEvent (final ObservableAddressbookLoadedEvent event);
-
- /**
- * Count all shared address books by given user id
- * <p>
- * @param user User instance to look for
- * <p>
- * @return Count of user's shared address books
- */
- Integer countAllUserSharedAddressbooks (final User user);
-
- /**
- * This method is called when a user has successfully logged in his/her
- * account.
- * <p>
- * @param event
- */
- void afterLoginEvent (final ObservableUserLoggedInEvent event);
-
/**
* Checks if the user is logged in and if so if it matches the current
* address book owner.
*/
void setAddressbook (final Addressbook addressbook);
- /**
- * Retrieves a list of all users this user is not sharing this address book
- * with.
- * <p>
- * @return List of not sharing users
- */
- List<User> allUsersNotSharing ();
-
/**
* Checks wether an address book has been loaded by checking the id number.
* <p>
--- /dev/null
+/*
+ * Copyright (C) 2016 Roland Häder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.addressbook.share;
+
+import java.text.MessageFormat;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import javax.annotation.PostConstruct;
+import javax.enterprise.context.SessionScoped;
+import javax.enterprise.event.Event;
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.Any;
+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.BaseAddressbookController;
+import org.mxchange.addressbook.beans.addressbook.AddressbookWebSessionController;
+import org.mxchange.addressbook.beans.login.user.AddressbookUserLoginWebSessionController;
+import org.mxchange.addressbook.model.shared.AddressbookShareSessionBeanRemote;
+import org.mxchange.jaddressbook.model.addressbook.Addressbook;
+import org.mxchange.jaddressbookshare.events.sharing.ObservableAddressbookSharingEvent;
+import org.mxchange.jaddressbookshare.events.sharing.StartedAddressbookSharingEvent;
+import org.mxchange.jaddressbookshare.events.sharing.type.SharingType;
+import org.mxchange.jaddressbookshare.exceptions.UserAlreadySharingAddressbookException;
+import org.mxchange.jaddressbookshare.model.addressbook.shared.ShareableAddressbook;
+import org.mxchange.jusercore.events.login.ObservableUserLoggedInEvent;
+import org.mxchange.jusercore.model.user.User;
+import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
+
+/**
+ * A bean for sharing address books with other users
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named (value = "shareController")
+@SessionScoped
+public class AddressbookSharesWebSessionBean extends BaseAddressbookController implements AddressbookSharesWebSessionController {
+
+ /**
+ * Map for count of user's shared addresses
+ */
+ private static ConcurrentMap<User, Integer> countSharesList;
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 19_868_976_871_976_780L;
+
+ /**
+ * Address book controller
+ */
+ @Inject
+ private AddressbookWebSessionController addressbookBean;
+
+ /**
+ * Remote bean for sharing address books
+ */
+ private AddressbookShareSessionBeanRemote addressbookShareBean;
+
+ /**
+ * Cached flag whether the user is sharing address books
+ */
+ private Boolean isUserSharing = null;
+
+ /**
+ * Share instance
+ */
+ private ShareableAddressbook share;
+
+ /**
+ * A list of all user's shared (with others) address books
+ */
+ private List<ShareableAddressbook> sharedAddressbooks;
+
+ /**
+ * User id of sharee
+ */
+ private Long shareeUserId;
+
+ /**
+ * An event triggered when address book sharing starts or ends
+ */
+ @Inject
+ @Any
+ private Event<ObservableAddressbookSharingEvent> sharingEvent;
+
+ /**
+ * Login controller injection
+ */
+ @Inject
+ private AddressbookUserLoginWebSessionController userLoginController;
+
+ /**
+ * Default constructor
+ */
+ public AddressbookSharesWebSessionBean () {
+ // Init list
+ countSharesList = new ConcurrentHashMap<>(0);
+ }
+
+ /**
+ * Observer method for ended sharing events
+ * <p>
+ * @param event Event instance
+ */
+ public void afterAdressbookShareEndedEvent (@Observes final ObservableAddressbookSharingEvent event) {
+ // Validate parameter
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getSharingType() == null) {
+ // Throw NPE
+ throw new NullPointerException("event.sharingType is null"); //NOI18N
+ } else if (event.getSharingType() != SharingType.ENDED) {
+ // Wrong event
+ return;
+ }
+
+ // Validate event
+ this.validateEvent(event);
+
+ // Add it to list
+ this.sharedAddressbooks.remove(event.getShareableAddressbook());
+ }
+
+ /**
+ * Observer method for started sharing events
+ * <p>
+ * @param event Event instance
+ */
+ public void afterAdressbookShareStartedEvent (@Observes final ObservableAddressbookSharingEvent event) {
+ // Validate parameter
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getSharingType() == null) {
+ // Throw NPE
+ throw new NullPointerException("event.sharingType is null"); //NOI18N
+ } else if (event.getSharingType() != SharingType.STARTED) {
+ // Wrong event
+ return;
+ }
+
+ // Validate event
+ this.validateEvent(event);
+
+ // Add it to list
+ this.sharedAddressbooks.add(event.getShareableAddressbook());
+ }
+
+ /**
+ * This method is called when a user has successfully logged in his/her
+ * account.
+ * <p>
+ * @param event Event instance
+ */
+ public void afterLoginEvent (@Observes final ObservableUserLoggedInEvent event) {
+ // Is the user logged in?
+ if (null == event) {
+ // Is null
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getLoggedInUser() == null) {
+ // user is null
+ throw new NullPointerException("event.user is null"); //NOI18N
+ }
+
+ // Init share list
+ this.sharedAddressbooks = this.addressbookShareBean.allSharedAddressbooks(event.getLoggedInUser());
+ }
+
+ @Override
+ public List<ShareableAddressbook> allShares () {
+ // Is the user logged in?
+ if (!this.userLoginController.isUserLoggedIn()) {
+ // Not logged in
+ throw new FaceletException("This method can only be called as logged-in user."); //NOI18N
+ }
+
+ return Collections.unmodifiableList(this.sharedAddressbooks);
+ }
+
+ @Override
+ public List<User> allUsersNotSharing () {
+ // Is the user logged in?
+ if (!this.userLoginController.isUserLoggedIn()) {
+ // Not logged in
+ throw new FaceletException("This method can only be called as logged-in user."); //NOI18N
+ }
+
+ // Call EJB
+ return this.addressbookShareBean.allUsersNotSharing(this.userLoginController.getLoggedInUser(), this.addressbookBean.getAddressbook());
+ }
+
+ @Override
+ public Integer countAllUserSharedAddressbooks (final User user) {
+ // Is there cache?
+ if (countSharesList.containsKey(user)) {
+ // Return it instead
+ return countSharesList.get(user);
+ }
+
+ // Call EJB ("expensive")
+ Integer count = this.addressbookShareBean.countAllUserSharedAddressbooks(user);
+
+ // Add to list
+ countSharesList.put(user, count);
+
+ // Return it
+ return count;
+ }
+
+ @Override
+ public ShareableAddressbook getShare () {
+ return this.share;
+ }
+
+ @Override
+ public void setShare (final ShareableAddressbook share) {
+ this.share = share;
+ }
+
+ @Override
+ public Long getShareeUserId () {
+ return this.shareeUserId;
+ }
+
+ @Override
+ public void setShareeUserId (final Long shareeUserId) {
+ this.shareeUserId = shareeUserId;
+ }
+
+ /**
+ * Post-initialization of this class
+ */
+ @PostConstruct
+ public void init () {
+ // Try it
+ try {
+ // Get initial context
+ Context context = new InitialContext();
+
+ // Look up bean
+ this.addressbookShareBean = (AddressbookShareSessionBeanRemote) context.lookup("ejb/stateless-addressbook-share"); //NOI18N
+ } catch (final NamingException ex) {
+ // Continue to throw
+ throw new FaceletException(ex);
+ }
+
+ }
+
+ @Override
+ public boolean isShareeUserIdEmpty () {
+ return (!this.isShareeUserIdSet());
+ }
+
+ @Override
+ public boolean isShareeUserIdSet () {
+ return ((this.getShareeUserId() instanceof Long) && (this.getShareeUserId() > 0));
+ }
+
+ @Override
+ public boolean isSharingAddressbooks () {
+ // Only to be called for logged-in users
+ if (!this.userLoginController.isUserLoggedIn()) {
+ // Not logged in
+ throw new FaceletException("This method can only be called as logged-in user."); //NOI18N
+ } else if (this.isUserSharing instanceof Boolean) {
+ // Return cached value
+ return this.isUserSharing;
+ }
+
+ // Call the proper bean
+ this.isUserSharing = this.addressbookShareBean.isUserSharingAddressbooks(this.userLoginController.getLoggedInUser());
+
+ // Return it
+ return this.isUserSharing;
+ }
+
+ @Override
+ public String startSharing (final User user, final Addressbook addressbook) {
+ // Check conditions
+ if (!this.userLoginController.isUserLoggedIn()) {
+ // No, then throw exception
+ throw new FaceletException("This method can only be called as logged-in user."); //NOI18N
+ } else if (null == user) {
+ // Throw NPE
+ throw new NullPointerException("user is null"); //NOI18N
+ } else if (user.getUserId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("user.userId is null"); //NOI18N
+ } else if (user.getUserId() < 1) {
+ // Invalid id number
+ throw new IllegalStateException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); //NOI18N
+ } else if (Objects.equals(user, this.userLoginController.getLoggedInUser())) {
+ // Sharing with yourself!
+ throw new IllegalStateException("User tries to share with himself."); //NOI18N
+ } else if (null == addressbook) {
+ // Throw NPE again
+ throw new NullPointerException("addressbook is null"); //NOI18N
+ } else if (addressbook.getAddressbookId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("addressbook.addressbookId is null"); //NOI18N
+ } else if (addressbook.getAddressbookId() < 1) {
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("addressbook.addressbookId={0} is invalid.", addressbook.getAddressbookId())); //NOI18N
+ } else if (!Objects.equals(addressbook.getAddressbookUser(), this.userLoginController.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.userLoginController.getLoggedInUser().getUserId())); //NOI18N
+ } else if (this.userLoginController.getLoggedInUser().getUserProfileMode() == ProfileMode.INVISIBLE) {
+ // User is invisible
+ throw new FaceletException(MessageFormat.format("user {0} is invisible and cannot start sharing address books.", this.userLoginController.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 {
+ // Init sharing
+ ShareableAddressbook shared = this.addressbookShareBean.startSharing(user, addressbook);
+
+ // TODO Set it here
+ this.setShare(shared);
+
+ /// Trigger event
+ this.sharingEvent.fire(new StartedAddressbookSharingEvent(shared));
+ } catch (final UserAlreadySharingAddressbookException ex) {
+ // Throw again
+ throw new FaceletException(ex);
+ }
+
+ // TODO Unfinished
+ return null;
+ }
+
+ /**
+ * Validates given event for all values and throws exceptions
+ * <p>
+ * @param event Event to validate
+ */
+ private void validateEvent (final ObservableAddressbookSharingEvent event) {
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getSharingType() == null) {
+ // Throw NPE
+ throw new NullPointerException("event.sharingType is null"); //NOI18N
+ } else if (event.getShareableAddressbook() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.shareableAddressbook is null"); //NOI18N
+ } else if (event.getShareableAddressbook().getShareId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.shareableAddressbook.shareId is null"); //NOI18N
+ } else if (event.getShareableAddressbook().getShareId() < 1) {
+ // Throw NPE again
+ throw new IllegalArgumentException(MessageFormat.format("event.shareableAddressbook.shareId={0} is invalid", event.getShareableAddressbook().getShareId())); //NOI18N
+ } else if (event.getShareableAddressbook().getShareAddressbook() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.shareableAddressbook.shareAddressbook is null"); //NOI18N
+ } else if (event.getShareableAddressbook().getShareAddressbook().getAddressbookId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.shareableAddressbook.shareAddressbook.addressbookId is null"); //NOI18N
+ } else if (event.getShareableAddressbook().getShareAddressbook().getAddressbookId() < 1) {
+ // Throw NPE again
+ throw new IllegalArgumentException(MessageFormat.format("event.shareableAddressbook.shareAddressbook.addressbookId={0} is invalid", event.getShareableAddressbook().getShareAddressbook().getAddressbookId())); //NOI18N
+ } else if (event.getShareableAddressbook().getShareUserOwner() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.shareableAddressbook.shareUserOwner is null"); //NOI18N
+ } else if (event.getShareableAddressbook().getShareUserOwner().getUserId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.shareableAddressbook.shareUserOwner.userId is null"); //NOI18N
+ } else if (event.getShareableAddressbook().getShareUserOwner().getUserId() < 1) {
+ // Throw NPE again
+ throw new IllegalArgumentException(MessageFormat.format("event.shareableAddressbook.shareUserOwner.userId={0} is invalid", event.getShareableAddressbook().getShareUserOwner().getUserId())); //NOI18N
+ } else if (event.getShareableAddressbook().getShareUserSharee() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.shareableAddressbook.shareUserSharee is null"); //NOI18N
+ } else if (event.getShareableAddressbook().getShareUserSharee().getUserId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.shareableAddressbook.shareUserSharee.userId is null"); //NOI18N
+ } else if (event.getShareableAddressbook().getShareUserSharee().getUserId() < 1) {
+ // Throw NPE again
+ throw new IllegalArgumentException(MessageFormat.format("event.shareableAddressbook.shareUserSharee.userId={0} is invalid", event.getShareableAddressbook().getShareUserOwner().getUserId())); //NOI18N
+ }
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2016 Roland Häder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.addressbook.share;
+
+import java.io.Serializable;
+import java.util.List;
+import org.mxchange.jaddressbook.model.addressbook.Addressbook;
+import org.mxchange.jaddressbookshare.model.addressbook.shared.ShareableAddressbook;
+import org.mxchange.jusercore.model.user.User;
+
+/**
+ * Controller interface sharing address books
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface AddressbookSharesWebSessionController extends Serializable {
+
+ /**
+ * Returns a list of all address books the user is sharing with others.
+ * <p>
+ * @return List of all shared address books
+ */
+ List<ShareableAddressbook> allShares ();
+
+ /**
+ * Getter for share instance
+ * <p>
+ * @return Share instance
+ */
+ ShareableAddressbook getShare ();
+
+ /**
+ * Setter for share instance
+ * <p>
+ * @param share Share instance
+ */
+ void setShare (final ShareableAddressbook share);
+
+ /**
+ * Getter for sharee's user id
+ * <p>
+ * @return Sharee's user id
+ */
+ Long getShareeUserId ();
+
+ /**
+ * Setter for sharee's user id
+ * <p>
+ * @param shareeUserId Sharee's user id
+ */
+ void setShareeUserId (final Long shareeUserId);
+
+ /**
+ * Checks if the sharee's user id is empty.
+ * <p>
+ * @return Whether the sharee's user id is empty.
+ */
+ boolean isShareeUserIdEmpty ();
+
+ /**
+ * Checks whether the sharee's user id is set
+ * <p>
+ * @return Whether the sharee's user id is set
+ */
+ boolean isShareeUserIdSet ();
+
+ /**
+ * Checks wether the current user is sharing address books with others
+ * <p>
+ * @return Whether the current user is sharing address books
+ */
+ boolean isSharingAddressbooks ();
+
+ /**
+ * Starts an address book share between currently logged-in user and
+ * assigned user for current address book.
+ * <p>
+ * @param user User instance
+ * @param addressbook Address book instance
+ * <p>
+ * @return Redirect target
+ */
+ String startSharing (final User user, final Addressbook addressbook);
+
+ /**
+ * Count all shared address books by given user id
+ * <p>
+ * @param user User instance to look for
+ * <p>
+ * @return Count of user's shared address books
+ */
+ Integer countAllUserSharedAddressbooks (final User user);
+
+ /**
+ * Retrieves a list of all users this user is not sharing this address book
+ * with.
+ * <p>
+ * @return List of not sharing users
+ */
+ List<User> allUsersNotSharing ();
+
+}
+++ /dev/null
-/*
- * Copyright (C) 2016 Roland Häder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.addressbook.beans.shares;
-
-import java.text.MessageFormat;
-import java.util.Collections;
-import java.util.List;
-import java.util.Objects;
-import javax.annotation.PostConstruct;
-import javax.enterprise.context.SessionScoped;
-import javax.enterprise.event.Event;
-import javax.enterprise.event.Observes;
-import javax.enterprise.inject.Any;
-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.BaseAddressbookController;
-import org.mxchange.addressbook.beans.login.user.AddressbookUserLoginWebSessionController;
-import org.mxchange.addressbook.model.shared.SharedAddressbooksSessionBeanRemote;
-import org.mxchange.jaddressbookcore.events.sharing.StartedAddressbookSharingEvent;
-import org.mxchange.jaddressbookcore.events.sharing.type.SharingType;
-import org.mxchange.jaddressbookcore.exceptions.UserAlreadySharingAddressbookException;
-import org.mxchange.jaddressbookcore.model.addressbook.Addressbook;
-import org.mxchange.jaddressbookcore.model.addressbook.shared.ShareableAddressbook;
-import org.mxchange.jusercore.model.user.User;
-import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
-import org.mxchange.jaddressbookcore.events.sharing.ObservableAddressbookSharingEvent;
-import org.mxchange.jusercore.events.login.ObservableUserLoggedInEvent;
-
-/**
- * A bean for sharing address books with other users
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@Named (value = "shareController")
-@SessionScoped
-public class AddressbookSharesWebSessionBean extends BaseAddressbookController implements AddressbookSharesWebSessionController {
-
- /**
- * Serial number
- */
- private static final long serialVersionUID = 19_868_976_871_976_780L;
-
- /**
- * Cached flag whether the user is sharing address books
- */
- private Boolean isUserSharing = null;
-
- /**
- * Login controller injection
- */
- @Inject
- private AddressbookUserLoginWebSessionController userLoginController;
-
- /**
- * Share instance
- */
- private ShareableAddressbook share;
-
- /**
- * Remote bean for sharing address books
- */
- private SharedAddressbooksSessionBeanRemote shareBean;
-
- /**
- * A list of all user's shared (with others) address books
- */
- private List<ShareableAddressbook> sharedAddressbooks;
-
- /**
- * User id of sharee
- */
- private Long shareeUserId;
-
- /**
- * An event triggered when address book sharing starts or ends
- */
- @Inject
- @Any
- private Event<ObservableAddressbookSharingEvent> sharingEvent;
-
- /**
- * Default constructor
- */
- public AddressbookSharesWebSessionBean () {
- // Try it
- try {
- // Get initial context
- Context context = new InitialContext();
-
- // Look up bean
- this.shareBean = (SharedAddressbooksSessionBeanRemote) context.lookup("ejb/stateless-addressbook-share"); //NOI18N
- } catch (final NamingException ex) {
- // Continue to throw
- throw new FaceletException(ex);
- }
- }
-
- @Override
- public void afterAdressbookShareEnded (@Observes final ObservableAddressbookSharingEvent event) {
- // Validate parameter
- if (null == event) {
- // Throw NPE
- throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getSharingType() == null) {
- // Throw NPE
- throw new NullPointerException("event.sharingType is null"); //NOI18N
- } else if (event.getSharingType() != SharingType.ENDED) {
- // Wrong event
- return;
- }
-
- // Validate event
- this.validateEvent(event);
-
- // Add it to list
- this.sharedAddressbooks.remove(event.getShareableAddressbook());
- }
-
- @Override
- public void afterAdressbookShareStarted (@Observes final ObservableAddressbookSharingEvent event) {
- // Validate parameter
- if (null == event) {
- // Throw NPE
- throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getSharingType() == null) {
- // Throw NPE
- throw new NullPointerException("event.sharingType is null"); //NOI18N
- } else if (event.getSharingType() != SharingType.STARTED) {
- // Wrong event
- return;
- }
-
- // Validate event
- this.validateEvent(event);
-
- // Add it to list
- this.sharedAddressbooks.add(event.getShareableAddressbook());
- }
-
- @Override
- public void afterLoginEvent (@Observes final ObservableUserLoggedInEvent event) {
- // Is the user logged in?
- if (null == event) {
- // Is null
- throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getLoggedInUser() == null) {
- // user is null
- throw new NullPointerException("event.user is null"); //NOI18N
- }
-
- // Init share list
- this.sharedAddressbooks = this.shareBean.allSharedAddressbooks(event.getLoggedInUser());
- }
-
- @Override
- public List<ShareableAddressbook> allShares () {
- // Is the user logged in?
- if (!this.userLoginController.isUserLoggedIn()) {
- // Not logged in
- throw new FaceletException("This method can only be called as logged-in user."); //NOI18N
- }
-
- return Collections.unmodifiableList(this.sharedAddressbooks);
- }
-
- @Override
- public ShareableAddressbook getShare () {
- return this.share;
- }
-
- @Override
- public void setShare (final ShareableAddressbook share) {
- this.share = share;
- }
-
- @Override
- public Long getShareeUserId () {
- return this.shareeUserId;
- }
-
- @Override
- public void setShareeUserId (final Long shareeUserId) {
- this.shareeUserId = shareeUserId;
- }
-
- /**
- * Post-initialization of this class
- */
- @PostConstruct
- public void init () {
- }
-
- @Override
- public boolean isShareeUserIdEmpty () {
- return (!this.isShareeUserIdSet());
- }
-
- @Override
- public boolean isShareeUserIdSet () {
- return ((this.getShareeUserId() instanceof Long) && (this.getShareeUserId() > 0));
- }
-
- @Override
- public boolean isSharingAddressbooks () {
- // Only to be called for logged-in users
- if (!this.userLoginController.isUserLoggedIn()) {
- // Not logged in
- throw new FaceletException("This method can only be called as logged-in user."); //NOI18N
- } else if (this.isUserSharing instanceof Boolean) {
- // Return cached value
- return this.isUserSharing;
- }
-
- // Call the proper bean
- this.isUserSharing = this.shareBean.isUserSharingAddressbooks(this.userLoginController.getLoggedInUser());
-
- // Return it
- return this.isUserSharing;
- }
-
- @Override
- public String startSharing (final User user, final Addressbook addressbook) {
- // Check conditions
- if (!this.userLoginController.isUserLoggedIn()) {
- // No, then throw exception
- throw new FaceletException("This method can only be called as logged-in user."); //NOI18N
- } else if (null == user) {
- // Throw NPE
- throw new NullPointerException("user is null"); //NOI18N
- } else if (user.getUserId() == null) {
- // Throw NPE again
- throw new NullPointerException("user.userId is null"); //NOI18N
- } else if (user.getUserId() < 1) {
- // Invalid id number
- throw new IllegalStateException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); //NOI18N
- } else if (Objects.equals(user, this.userLoginController.getLoggedInUser())) {
- // Sharing with yourself!
- throw new IllegalStateException("User tries to share with himself."); //NOI18N
- } else if (null == addressbook) {
- // Throw NPE again
- throw new NullPointerException("addressbook is null"); //NOI18N
- } else if (addressbook.getAddressbookId() == null) {
- // Throw NPE again
- throw new NullPointerException("addressbook.addressbookId is null"); //NOI18N
- } else if (addressbook.getAddressbookId() < 1) {
- // Invalid id number
- throw new IllegalArgumentException(MessageFormat.format("addressbook.addressbookId={0} is invalid.", addressbook.getAddressbookId())); //NOI18N
- } else if (!Objects.equals(addressbook.getAddressbookUser(), this.userLoginController.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.userLoginController.getLoggedInUser().getUserId())); //NOI18N
- } else if (this.userLoginController.getLoggedInUser().getUserProfileMode() == ProfileMode.INVISIBLE) {
- // User is invisible
- throw new FaceletException(MessageFormat.format("user {0} is invisible and cannot start sharing address books.", this.userLoginController.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 {
- // Init sharing
- ShareableAddressbook shared = this.shareBean.startSharing(user, addressbook);
-
- // TODO Set it here
- this.setShare(shared);
-
- /// Trigger event
- this.sharingEvent.fire(new StartedAddressbookSharingEvent(shared));
- } catch (final UserAlreadySharingAddressbookException ex) {
- // Throw again
- throw new FaceletException(ex);
- }
-
- // TODO Unfinished
- return null;
- }
-
- /**
- * Validates given event for all values and throws exceptions
- * <p>
- * @param event Event to validate
- */
- private void validateEvent (final ObservableAddressbookSharingEvent event) {
- if (null == event) {
- // Throw NPE
- throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getSharingType() == null) {
- // Throw NPE
- throw new NullPointerException("event.sharingType is null"); //NOI18N
- } else if (event.getShareableAddressbook() == null) {
- // Throw NPE again
- throw new NullPointerException("event.shareableAddressbook is null"); //NOI18N
- } else if (event.getShareableAddressbook().getShareId() == null) {
- // Throw NPE again
- throw new NullPointerException("event.shareableAddressbook.shareId is null"); //NOI18N
- } else if (event.getShareableAddressbook().getShareId() < 1) {
- // Throw NPE again
- throw new IllegalArgumentException(MessageFormat.format("event.shareableAddressbook.shareId={0} is invalid", event.getShareableAddressbook().getShareId())); //NOI18N
- } else if (event.getShareableAddressbook().getShareAddressbook() == null) {
- // Throw NPE again
- throw new NullPointerException("event.shareableAddressbook.shareAddressbook is null"); //NOI18N
- } else if (event.getShareableAddressbook().getShareAddressbook().getAddressbookId() == null) {
- // Throw NPE again
- throw new NullPointerException("event.shareableAddressbook.shareAddressbook.addressbookId is null"); //NOI18N
- } else if (event.getShareableAddressbook().getShareAddressbook().getAddressbookId() < 1) {
- // Throw NPE again
- throw new IllegalArgumentException(MessageFormat.format("event.shareableAddressbook.shareAddressbook.addressbookId={0} is invalid", event.getShareableAddressbook().getShareAddressbook().getAddressbookId())); //NOI18N
- } else if (event.getShareableAddressbook().getShareUserOwner() == null) {
- // Throw NPE again
- throw new NullPointerException("event.shareableAddressbook.shareUserOwner is null"); //NOI18N
- } else if (event.getShareableAddressbook().getShareUserOwner().getUserId() == null) {
- // Throw NPE again
- throw new NullPointerException("event.shareableAddressbook.shareUserOwner.userId is null"); //NOI18N
- } else if (event.getShareableAddressbook().getShareUserOwner().getUserId() < 1) {
- // Throw NPE again
- throw new IllegalArgumentException(MessageFormat.format("event.shareableAddressbook.shareUserOwner.userId={0} is invalid", event.getShareableAddressbook().getShareUserOwner().getUserId())); //NOI18N
- } else if (event.getShareableAddressbook().getShareUserSharee() == null) {
- // Throw NPE again
- throw new NullPointerException("event.shareableAddressbook.shareUserSharee is null"); //NOI18N
- } else if (event.getShareableAddressbook().getShareUserSharee().getUserId() == null) {
- // Throw NPE again
- throw new NullPointerException("event.shareableAddressbook.shareUserSharee.userId is null"); //NOI18N
- } else if (event.getShareableAddressbook().getShareUserSharee().getUserId() < 1) {
- // Throw NPE again
- throw new IllegalArgumentException(MessageFormat.format("event.shareableAddressbook.shareUserSharee.userId={0} is invalid", event.getShareableAddressbook().getShareUserOwner().getUserId())); //NOI18N
- }
- }
-}
+++ /dev/null
-/*
- * Copyright (C) 2016 Roland Häder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero 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;
-import java.util.List;
-import org.mxchange.jaddressbookcore.model.addressbook.Addressbook;
-import org.mxchange.jaddressbookcore.model.addressbook.shared.ShareableAddressbook;
-import org.mxchange.jusercore.model.user.User;
-import org.mxchange.jaddressbookcore.events.sharing.ObservableAddressbookSharingEvent;
-import org.mxchange.jusercore.events.login.ObservableUserLoggedInEvent;
-
-/**
- * Controller interface sharing address books
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public interface AddressbookSharesWebSessionController extends Serializable {
-
- /**
- * Observer method for ended sharing events
- * <p>
- * @param event Event instance
- */
- void afterAdressbookShareEnded (final ObservableAddressbookSharingEvent event);
-
- /**
- * Observer method for started sharing events
- * <p>
- * @param event Event instance
- */
- void afterAdressbookShareStarted (final ObservableAddressbookSharingEvent event);
-
- /**
- * This method is called when a user has successfully logged in his/her
- * account.
- * <p>
- * @param event
- */
- void afterLoginEvent (final ObservableUserLoggedInEvent event);
-
- /**
- * Returns a list of all address books the user is sharing with others.
- * <p>
- * @return List of all shared address books
- */
- List<ShareableAddressbook> allShares ();
-
- /**
- * Getter for share instance
- * <p>
- * @return Share instance
- */
- ShareableAddressbook getShare ();
-
- /**
- * Setter for share instance
- * <p>
- * @param share Share instance
- */
- void setShare (final ShareableAddressbook share);
-
- /**
- * Getter for sharee's user id
- * <p>
- * @return Sharee's user id
- */
- Long getShareeUserId ();
-
- /**
- * Setter for sharee's user id
- * <p>
- * @param shareeUserId Sharee's user id
- */
- void setShareeUserId (final Long shareeUserId);
-
- /**
- * Checks if the sharee's user id is empty.
- * <p>
- * @return Whether the sharee's user id is empty.
- */
- boolean isShareeUserIdEmpty ();
-
- /**
- * Checks whether the sharee's user id is set
- * <p>
- * @return Whether the sharee's user id is set
- */
- boolean isShareeUserIdSet ();
-
- /**
- * Checks wether the current user is sharing address books with others
- * <p>
- * @return Whether the current user is sharing address books
- */
- boolean isSharingAddressbooks ();
-
- /**
- * Starts an address book share between currently logged-in user and
- * assigned user for current address book.
- * <p>
- * @param user User instance
- * @param addressbook Address book instance
- * <p>
- * @return Redirect target
- */
- String startSharing (final User user, final Addressbook addressbook);
-}
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.mxchange.addressbook.model.addressbook.AddressbookSessionBeanRemote;
-import org.mxchange.jaddressbookcore.exceptions.AddressbookNotFoundException;
-import org.mxchange.jaddressbookcore.model.addressbook.Addressbook;
+import org.mxchange.jaddressbook.exceptions.AddressbookNotFoundException;
+import org.mxchange.jaddressbook.model.addressbook.Addressbook;
import org.mxchange.jcoreee.validator.number.BaseLongValidator;
import org.mxchange.jcoreeelogger.beans.local.logger.Log;
import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal;
</f:viewParam>
</f:metadata>
- <ui:composition template="/WEB-INF/templates/#{userLoginController.templateType}/#{userLoginController.templateType}_base.tpl">
+ <ui:composition template="/WEB-INF/templates/#{userLoginController.baseTemplatePathName}/#{userLoginController.baseTemplatePathName}_base.tpl">
<ui:define name="login_title">
<h:outputText value="#{msg.PAGE_TITLE_USER_SHOW_ADDRESSBOOK}" />
</ui:define>
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
- xmlns:f="http://xmlns.jcp.org/jsf/core"
- xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">
+ xmlns:f="http://xmlns.jcp.org/jsf/core">
- <ui:composition template="/WEB-INF/templates/#{userLoginController.templateType}/#{userLoginController.templateType}_base.tpl">
+ <ui:composition template="/WEB-INF/templates/#{userLoginController.baseTemplatePathName}/#{userLoginController.baseTemplatePathName}_base.tpl">
<ui:define name="login_title">
<h:outputText value="#{msg.PAGE_TITLE_LOGIN_START_SHARING_ADDRESSBOOK}" />
</ui:define>
<div class="para">
<h:outputText id="userNotLoggedIn" class="notice" value="#{msg.USER_NOT_LOGGED_IN}" rendered="#{not userLoginController.isUserLoggedIn()}" />
- <h:dataTable id="userList" headerClass="table_header_column" var="user" value="#{addressbookController.allUsersNotSharing()}" rendered="#{userLoginController.isUserLoggedIn() and not empty addressbookController.addressbook and not userLoginController.isInvisible()}">
+ <h:dataTable id="userList" headerClass="table_header_column" var="user" value="#{addressbookShareController.allUsersNotSharing()}" rendered="#{userLoginController.isUserLoggedIn() and not empty addressbookController.addressbook and not userLoginController.isInvisible()}">
<h:column>
<f:facet name="header">