From: Roland Haeder Date: Thu, 15 Oct 2015 19:08:38 +0000 (+0200) Subject: added bean method startSharing() with unfinished part X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=a5b15b7db23f20c4b88c9dbca87f5fc0132cccca;p=jfinancials-war.git added bean method startSharing() with unfinished part --- diff --git a/src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebBean.java b/src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebBean.java index 5593aa0a..ff12c1b6 100644 --- a/src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebBean.java +++ b/src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebBean.java @@ -421,6 +421,39 @@ public class AddressbookWebBean implements AddressbookWebController { return Objects.equals(this.getAddressbookUser(), this.loginController.getLoggedInUser()); } + @Override + public String startSharing () { + // Check conditions + if (!this.loginController.isUserLoggedIn()) { + // No, then throw exception + throw new FaceletException("This method can only be called as logged-in user."); //NOI18N + } else if (this.getAddressbookUser() == null) { + // Throw NPE + throw new NullPointerException("this.addressbookUser is null"); //NOI18N + } else if (this.getAddressbookUser().getUserId() == null) { + // Throw NPE again + throw new NullPointerException("this.addressbookUser.userId is null"); //NOI18N + } else if (this.getAddressbookUser().getUserId() < 1) { + // Invalid id number + throw new IllegalStateException(MessageFormat.format("this.addressbookUser.userId={0} is invalid", this.getAddressbookUser().getUserId())); //NOI18N + } else if (Objects.equals(this.getAddressbookUser(), this.loginController.getLoggedInUser())) { + // Sharing with yourself! + throw new IllegalStateException("User tries to share with himself."); //NOI18N + } else if (this.getAddressbook() == null) { + // Throw NPE again + throw new NullPointerException("this.addressbook is null"); //NOI18N + } else if (this.getAddressbook().getAddressbookId() == null) { + // Throw NPE again + throw new NullPointerException("this.addressbook.addressbookId is null"); //NOI18N + } else if (this.getAddressbook().getAddressbookId() < 1) { + // Invalid id number + throw new IllegalArgumentException(MessageFormat.format("this.addressbook.addressbookId={0} is invalid.", this.getAddressbook().getAddressbookId())); //NOI18N + } + + // TODO Unfinished + return null; + } + /** * Initializes the user user's address book list */ diff --git a/src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebController.java b/src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebController.java index 97995957..5cc2ffb7 100644 --- a/src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebController.java +++ b/src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebController.java @@ -209,4 +209,12 @@ public interface AddressbookWebController extends Serializable { * @return List of not sharing users */ List allUsersNotSharing (); + + /** + * Starts an address book share between currently logged-in user and + * assigned user for current address book. + *

+ * @return Redirect target + */ + String startSharing (); }