]> git.mxchange.org Git - addressbook-war.git/blobdiff - src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebBean.java
seperated user init and method invocation
[addressbook-war.git] / src / java / org / mxchange / addressbook / beans / addressbook / AddressbookWebBean.java
index 5593aa0af5598c2c03533f612c595c7ed1b89891..411449fcbc688688a9d14f0689ab9575b7f8be2d 100644 (file)
@@ -421,11 +421,47 @@ 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
         */
        private void initAddressbookList () {
+               // Get user instance
+               User user = this.loginController.getLoggedInUser();
+
                // Fill list with entries
-               this.usersAddressbooks = this.addressbookBean.getUsersAddressbookList(this.loginController.getLoggedInUser());
+               this.usersAddressbooks = this.addressbookBean.getUsersAddressbookList(user);
        }
 }