]> git.mxchange.org Git - addressbook-war.git/commitdiff
Continued:
authorRoland Haeder <roland@mxchange.org>
Fri, 16 Oct 2015 07:50:22 +0000 (09:50 +0200)
committerRoland Haeder <roland@mxchange.org>
Fri, 16 Oct 2015 08:02:37 +0000 (10:02 +0200)
- moved bean (controller) method startSharing() with some open TODOs to proper bean
- updated template accordingly
Signed-off-by:Roland Häder <roland@mxchange.org>

src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebBean.java
src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebController.java
src/java/org/mxchange/addressbook/beans/shares/SharesWebBean.java
src/java/org/mxchange/addressbook/beans/shares/SharesWebController.java
web/login/login_start_sharing_addressbook.xhtml

index 411449fcbc688688a9d14f0689ab9575b7f8be2d..bfa9288cf21a6f33cc586a5918e818d11c7c0f25 100644 (file)
@@ -421,39 +421,6 @@ 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
         */
index 5cc2ffb7ed839eef296f54db2cadb7fd657df515..97995957b3d63e3700634261e178e6858b214c26 100644 (file)
@@ -209,12 +209,4 @@ public interface AddressbookWebController extends Serializable {
         * @return List of not sharing users
         */
        List<User> allUsersNotSharing ();
-
-       /**
-        * Starts an address book share between currently logged-in user and
-        * assigned user for current address book.
-        * <p>
-        * @return Redirect target
-        */
-       String startSharing ();
 }
index 9041da43c8d75344dd64a4eee7c6427d261d3478..1c34a583ce229690e5a501017313086c31a6fc5f 100644 (file)
@@ -16,6 +16,8 @@
  */
 package org.mxchange.addressbook.beans.shares;
 
+import java.text.MessageFormat;
+import java.util.Objects;
 import javax.enterprise.context.SessionScoped;
 import javax.faces.view.facelets.FaceletException;
 import javax.inject.Inject;
@@ -24,7 +26,11 @@ import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 import org.mxchange.addressbook.beans.login.UserLoginWebController;
+import org.mxchange.addressbook.exceptions.UserAlreadySharingAddressbookException;
+import org.mxchange.addressbook.model.addressbook.Addressbook;
+import org.mxchange.addressbook.model.addressbook.shared.ShareableAddressbook;
 import org.mxchange.addressbook.model.shared.SharedAddressbooksSessionBeanRemote;
+import org.mxchange.jusercore.model.user.User;
 
 /**
  * A bean for sharing address books with other users
@@ -116,4 +122,49 @@ public class SharesWebBean implements SharesWebController {
                return this.isUserSharing;
        }
 
+       @Override
+       public String startSharing (final User user, final Addressbook addressbook) {
+               // 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 (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.loginController.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.loginController.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.loginController.getLoggedInUser().getUserId()));
+               }
+
+               try {
+                       // Init sharing
+                       ShareableAddressbook share = this.shareBean.startSharing(user, addressbook);
+
+                       // TODO Set it here
+               } catch (final UserAlreadySharingAddressbookException ex) {
+                       // Throw again
+                       throw new FaceletException(ex);
+               }
+
+               // TODO Unfinished
+               return null;
+       }
 }
index b1480f032440b99288355cb641854b0bb5cfc147..bc70057bb305ead5af84983ce89251c21b432d84 100644 (file)
@@ -17,6 +17,8 @@
 package org.mxchange.addressbook.beans.shares;
 
 import java.io.Serializable;
+import org.mxchange.addressbook.model.addressbook.Addressbook;
+import org.mxchange.jusercore.model.user.User;
 
 /**
  * Controller interface sharing address books
@@ -59,4 +61,14 @@ public interface SharesWebController extends Serializable {
         * @return Whether the sharee's user id is empty.
         */
        boolean isShareeUserIdEmpty ();
+
+       /**
+        * 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
+        * @return Redirect target
+        */
+       String startSharing (final User user, final Addressbook addressbook);
 }
index 1eee227e674005f7c133768a216bf796d058323f..aca87c517106b81321568e70275dcd1240b4104c 100644 (file)
@@ -44,7 +44,7 @@
                                                <h:column>
                                                        <f:facet name="header">#{msg.LOGIN_START_SHARING_TITLE}</f:facet>
                                                        <h:form acceptcharset="utf-8" id="startSharing">
-                                                               <h:commandButton class="submit" id="submit" value="#{msg.LOGIN_START_SHARING_BUTTON}" action="#{addressbookController.startSharing()}" title="#{msg.LOGIN_START_SHARING_BUTTON_TITLE}" />
+                                                               <h:commandButton class="submit" id="submit" value="#{msg.LOGIN_START_SHARING_BUTTON}" action="#{shareController.startSharing(user, addressbookController.addressbook)}" title="#{msg.LOGIN_START_SHARING_BUTTON_TITLE}" />
                                                        </h:form>
                                                </h:column>
                                        </h:dataTable>