From: Roland Haeder Date: Fri, 16 Oct 2015 09:30:22 +0000 (+0200) Subject: sorted members X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=0944deaaf45d3eff44670406c470c7eb9dd633bd;p=addressbook-war.git sorted members Signed-off-by:Roland Häder --- diff --git a/src/java/org/mxchange/addressbook/beans/shares/SharesWebBean.java b/src/java/org/mxchange/addressbook/beans/shares/SharesWebBean.java index 809c4392..c98cbfcb 100644 --- a/src/java/org/mxchange/addressbook/beans/shares/SharesWebBean.java +++ b/src/java/org/mxchange/addressbook/beans/shares/SharesWebBean.java @@ -72,14 +72,14 @@ public class SharesWebBean implements SharesWebController { private ShareableAddressbook share; /** - * A list of all user's shared (with others) address books + * Remote bean for sharing address books */ - private List sharedAddressbooks; + private SharedAddressbooksSessionBeanRemote shareBean; /** - * Remote bean for sharing address books + * A list of all user's shared (with others) address books */ - private SharedAddressbooksSessionBeanRemote shareBean; + private List sharedAddressbooks; /** * User id of sharee @@ -110,10 +110,61 @@ public class SharesWebBean implements SharesWebController { } } - @PostConstruct - public void init () { - // Init share list - this.sharedAddressbooks = this.shareBean.allSharedAddressbooks(this.loginController.getLoggedInUser()); + @Override + public void afterAdressbookShareEnded (final @Observes AddressbookSharingEvent event) { + // Validate parameter + if (null == event) { + // Throw NPE + throw new NullPointerException("event 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 (final @Observes AddressbookSharingEvent event) { + // Validate parameter + if (null == event) { + // Throw NPE + throw new NullPointerException("event 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 List 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 + public ShareableAddressbook getShare () { + return this.share; + } + + @Override + public void setShare (final ShareableAddressbook share) { + this.share = share; } @Override @@ -126,9 +177,10 @@ public class SharesWebBean implements SharesWebController { this.shareeUserId = shareeUserId; } - @Override - public boolean isShareeUserIdSet () { - return ((this.getShareeUserId() instanceof Long) && (this.getShareeUserId() > 0)); + @PostConstruct + public void init () { + // Init share list + this.sharedAddressbooks = this.shareBean.allSharedAddressbooks(this.loginController.getLoggedInUser()); } @Override @@ -136,6 +188,11 @@ public class SharesWebBean implements SharesWebController { 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 @@ -204,63 +261,6 @@ public class SharesWebBean implements SharesWebController { return null; } - @Override - public List 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 - public ShareableAddressbook getShare () { - return this.share; - } - - @Override - public void setShare (final ShareableAddressbook share) { - this.share = share; - } - - @Override - public void afterAdressbookShareStarted (final @Observes AddressbookSharingEvent event) { - // Validate parameter - if (null == event) { - // Throw NPE - throw new NullPointerException("event 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 afterAdressbookShareEnded (final @Observes AddressbookSharingEvent event) { - // Validate parameter - if (null == event) { - // Throw NPE - throw new NullPointerException("event 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()); - } - /** * Validates given event for all values and throws exceptions *

diff --git a/src/java/org/mxchange/addressbook/beans/shares/SharesWebController.java b/src/java/org/mxchange/addressbook/beans/shares/SharesWebController.java index 3a4196bf..650e27f9 100644 --- a/src/java/org/mxchange/addressbook/beans/shares/SharesWebController.java +++ b/src/java/org/mxchange/addressbook/beans/shares/SharesWebController.java @@ -31,25 +31,25 @@ import org.mxchange.jusercore.model.user.User; public interface SharesWebController extends Serializable { /** - * Checks wether the current user is sharing address books with others + * Observer method for ended sharing events *

- * @return Whether the current user is sharing address books + * @param event Event instance */ - boolean isSharingAddressbooks (); + void afterAdressbookShareEnded (final AddressbookSharingEvent event); /** - * Getter for sharee's user id + * Observer method for started sharing events *

- * @return Sharee's user id + * @param event Event instance */ - Long getShareeUserId (); + void afterAdressbookShareStarted (final AddressbookSharingEvent event); /** - * Setter for sharee's user id + * Returns a list of all address books the user is sharing with others. *

- * @param shareeUserId Sharee's user id + * @return List of all shared address books */ - void setShareeUserId (final Long shareeUserId); + List allShares (); /** * Getter for share instance @@ -66,47 +66,47 @@ public interface SharesWebController extends Serializable { void setShare (final ShareableAddressbook share); /** - * Checks whether the sharee's user id is set + * Getter for sharee's user id *

- * @return Whether the sharee's user id is set + * @return Sharee's user id */ - boolean isShareeUserIdSet (); + Long getShareeUserId (); /** - * Checks if the sharee's user id is empty. + * Setter for sharee's user id *

- * @return Whether the sharee's user id is empty. + * @param shareeUserId Sharee's user id */ - boolean isShareeUserIdEmpty (); + void setShareeUserId (final Long shareeUserId); /** - * Starts an address book share between currently logged-in user and - * assigned user for current address book. + * Checks if the sharee's user id is empty. *

- * @param user User instance - * @param addressbook Address book instance - * @return Redirect target + * @return Whether the sharee's user id is empty. */ - String startSharing (final User user, final Addressbook addressbook); + boolean isShareeUserIdEmpty (); /** - * Returns a list of all address books the user is sharing with others. + * Checks whether the sharee's user id is set *

- * @return List of all shared address books + * @return Whether the sharee's user id is set */ - List allShares (); + boolean isShareeUserIdSet (); /** - * Observer method for started sharing events + * Checks wether the current user is sharing address books with others *

- * @param event Event instance + * @return Whether the current user is sharing address books */ - void afterAdressbookShareStarted (final AddressbookSharingEvent event); + boolean isSharingAddressbooks (); /** - * Observer method for ended sharing events + * Starts an address book share between currently logged-in user and + * assigned user for current address book. *

- * @param event Event instance + * @param user User instance + * @param addressbook Address book instance + * @return Redirect target */ - void afterAdressbookShareEnded (final AddressbookSharingEvent event); + String startSharing (final User user, final Addressbook addressbook); }