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
*/
*/
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;
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
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;
+ }
}
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
* @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);
}