diff --git a/cave/com.raytheon.uf.viz.collaboration.comm/src/com/raytheon/uf/viz/collaboration/comm/identity/roster/ISubscriptionResponder.java b/cave/com.raytheon.uf.viz.collaboration.comm/src/com/raytheon/uf/viz/collaboration/comm/identity/roster/ISubscriptionResponder.java index 5eb83929ef..ea08dcf06e 100644 --- a/cave/com.raytheon.uf.viz.collaboration.comm/src/com/raytheon/uf/viz/collaboration/comm/identity/roster/ISubscriptionResponder.java +++ b/cave/com.raytheon.uf.viz.collaboration.comm/src/com/raytheon/uf/viz/collaboration/comm/identity/roster/ISubscriptionResponder.java @@ -33,6 +33,7 @@ import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId; * Mar 16, 2012 jkorman Initial creation * Jan 27, 2014 2700 bclement handle subscribe request returns a boolean * all methods take user id instead of qualified id + * Feb 13, 2014 2755 bclement handleSubscribeRequest now returns SubscriptionResponse * * * @@ -48,7 +49,7 @@ public interface ISubscriptionResponder { * @param fromID * @return true if the subscribe request is accepted. */ - public boolean handleSubscribeRequest(UserId fromID); + public SubscriptionResponse handleSubscribeRequest(UserId fromID); /** * Triggered when a contact subscribes to user diff --git a/cave/com.raytheon.uf.viz.collaboration.comm/src/com/raytheon/uf/viz/collaboration/comm/identity/roster/SubscriptionResponse.java b/cave/com.raytheon.uf.viz.collaboration.comm/src/com/raytheon/uf/viz/collaboration/comm/identity/roster/SubscriptionResponse.java new file mode 100644 index 0000000000..4cb02c3e8e --- /dev/null +++ b/cave/com.raytheon.uf.viz.collaboration.comm/src/com/raytheon/uf/viz/collaboration/comm/identity/roster/SubscriptionResponse.java @@ -0,0 +1,106 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.uf.viz.collaboration.comm.identity.roster; + +import org.apache.commons.lang.StringUtils; + +/** + * Response to subscription (contacts) request. Includes user input from prompt + * dialog. + * + *
+ * + * SOFTWARE HISTORY + * + * Date Ticket# Engineer Description + * ------------ ---------- ----------- -------------------------- + * Feb 13, 2014 2755 bclement Initial creation + * + *+ * + * @author bclement + * @version 1.0 + */ +public class SubscriptionResponse { + + private String group; + + private boolean accepted; + + public SubscriptionResponse() { + } + + /** + * @param accepted + * true if contact request was accepted + * @param group + * optional group to add user to + */ + public SubscriptionResponse(boolean accepted, String group) { + this.accepted = accepted; + this.group = group; + } + + /** + * @param accepted + * true if contact request was accepted + */ + public SubscriptionResponse(boolean accepted) { + this(accepted, null); + } + + /** + * @return true if user should be added to group + */ + public boolean addToGroup() { + return !StringUtils.isBlank(group); + } + + /** + * @return the group + */ + public String getGroup() { + return group; + } + + /** + * @return the accepted + */ + public boolean isAccepted() { + return accepted; + } + + /** + * @param group + * the group to set + */ + public void setGroup(String group) { + this.group = group; + } + + /** + * @param accepted + * the accepted to set + */ + public void setAccepted(boolean accepted) { + this.accepted = accepted; + } + +} diff --git a/cave/com.raytheon.uf.viz.collaboration.comm/src/com/raytheon/uf/viz/collaboration/comm/provider/session/AccountManager.java b/cave/com.raytheon.uf.viz.collaboration.comm/src/com/raytheon/uf/viz/collaboration/comm/provider/session/AccountManager.java index 32a5b3d700..7c3507c385 100644 --- a/cave/com.raytheon.uf.viz.collaboration.comm/src/com/raytheon/uf/viz/collaboration/comm/provider/session/AccountManager.java +++ b/cave/com.raytheon.uf.viz.collaboration.comm/src/com/raytheon/uf/viz/collaboration/comm/provider/session/AccountManager.java @@ -41,6 +41,7 @@ import com.raytheon.uf.viz.collaboration.comm.identity.IVenueSession; import com.raytheon.uf.viz.collaboration.comm.identity.event.IRosterChangeEvent; import com.raytheon.uf.viz.collaboration.comm.identity.event.RosterChangeType; import com.raytheon.uf.viz.collaboration.comm.identity.roster.ISubscriptionResponder; +import com.raytheon.uf.viz.collaboration.comm.identity.roster.SubscriptionResponse; import com.raytheon.uf.viz.collaboration.comm.provider.Tools; import com.raytheon.uf.viz.collaboration.comm.provider.event.RosterChangeEvent; import com.raytheon.uf.viz.collaboration.comm.provider.event.UserPresenceChangedEvent; @@ -69,6 +70,7 @@ import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId; * Jan 27, 2014 2700 bclement changes to subscription request responders * Jan 31, 2014 2700 bclement fixed subscribe back after accepting subscription * Feb 12, 2014 2797 bclement added protective copy to sendPresence + * Feb 13, 2014 2755 bclement added user input for which group to add contact to * * * @@ -98,11 +100,13 @@ public class AccountManager implements IAccountManager { UserId fromId = IDConverter.convertFrom(pres.getFrom()); switch (type) { case subscribe: - boolean accept = true; + SubscriptionResponse response; if (responder != null) { - accept = responder.handleSubscribeRequest(fromId); + response = responder.handleSubscribeRequest(fromId); + } else { + response = new SubscriptionResponse(true); } - handleSubRequest(fromId, accept); + handleSubRequest(fromId, response); break; case subscribed: if (responder != null) { @@ -157,11 +161,12 @@ public class AccountManager implements IAccountManager { * * @param fromId */ - private void handleSubRequest(UserId fromId, boolean accept) { + private void handleSubRequest(UserId fromId, + SubscriptionResponse response) { Presence.Type subscribedType; ContactsManager cm = sessionManager.getContactsManager(); boolean addToRoster = false; - if (accept) { + if (response.isAccepted()) { subscribedType = Presence.Type.subscribed; RosterEntry entry = cm.getRosterEntry(fromId); if (entry == null) { @@ -175,7 +180,12 @@ public class AccountManager implements IAccountManager { try { sendPresence(fromId, presence); if (addToRoster) { - cm.addToRoster(fromId); + if (response.addToGroup()) { + cm.addToGroup(response.getGroup(), fromId); + } else { + cm.addToRoster(fromId); + } + } } catch (CollaborationException e) { AccountManager.this.log.error("Unable to send presence", e); diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/SubRequestDialog.java b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/SubRequestDialog.java index 7037db7570..ef9fdbd13d 100644 --- a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/SubRequestDialog.java +++ b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/SubRequestDialog.java @@ -37,7 +37,6 @@ import org.eclipse.swt.widgets.Shell; import org.jivesoftware.smack.RosterGroup; import com.raytheon.uf.viz.collaboration.comm.provider.session.CollaborationConnection; -import com.raytheon.uf.viz.collaboration.comm.provider.user.ContactsManager; import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId; /** @@ -51,6 +50,7 @@ import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId; * ------------ ---------- ----------- -------------------------- * Jan 27, 2014 2700 bclement Initial creation * Jan 31, 2014 2700 bclement don't prompt for group if user is already in one + * Feb 13, 2014 2755 bclement roster addition now done in account manager, user input passed back * * * @@ -67,6 +67,8 @@ public class SubRequestDialog extends Dialog { private Combo groupCombo; + private String group; + /** * @param parentShell */ @@ -97,7 +99,6 @@ public class SubRequestDialog extends Dialog { if (buttonId == IDialogConstants.OK_ID) { int count = groupCombo.getItemCount(); int index = groupCombo.getSelectionIndex(); - String group = null; if ( index == count - 1){ // new group CreateGroupDialog dialog = new CreateGroupDialog(Display @@ -107,11 +108,6 @@ public class SubRequestDialog extends Dialog { } else if ( index >= 0){ group = groupCombo.getItem(index); } - CollaborationConnection connection = CollaborationConnection.getConnection(); - if ( group != null && connection != null){ - ContactsManager cm = connection.getContactsManager(); - cm.addToGroup(group, userid); - } } super.buttonPressed(buttonId); } @@ -188,4 +184,11 @@ public class SubRequestDialog extends Dialog { createButton(parent, IDialogConstants.CANCEL_ID, "Deny", false); } + /** + * @return the group + */ + public String getGroup() { + return group; + } + } diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/prefs/AutoSubscribePropertyListener.java b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/prefs/AutoSubscribePropertyListener.java index bb50b6b196..832c379b3e 100644 --- a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/prefs/AutoSubscribePropertyListener.java +++ b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/prefs/AutoSubscribePropertyListener.java @@ -31,6 +31,7 @@ import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.viz.collaboration.comm.identity.IAccountManager; import com.raytheon.uf.viz.collaboration.comm.identity.roster.ISubscriptionResponder; +import com.raytheon.uf.viz.collaboration.comm.identity.roster.SubscriptionResponse; import com.raytheon.uf.viz.collaboration.comm.provider.session.CollaborationConnection; import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId; import com.raytheon.uf.viz.collaboration.comm.provider.user.UserSearch; @@ -50,6 +51,7 @@ import com.raytheon.uf.viz.core.VizApp; * ------------ ---------- ----------- -------------------------- * Jan 24, 2014 2700 bclement Initial creation * Feb 3, 2014 2699 bclement fixed assumption that username search was exact + * Feb 13, 2014 2755 bclement added user input for which group to add contact to * * * @@ -163,7 +165,8 @@ public class AutoSubscribePropertyListener implements IPropertyChangeListener { } @Override - public boolean handleSubscribeRequest(final UserId fromID) { + public SubscriptionResponse handleSubscribeRequest( + final UserId fromID) { String displayName = getDisplayName(fromID); StringBuilder builder = new StringBuilder(); builder.append(fromID.getFQName()); @@ -172,7 +175,7 @@ public class AutoSubscribePropertyListener implements IPropertyChangeListener { } builder.append(" wants to add you to his or her contacts list."); final String msg = builder.toString(); - final boolean[] rval = new boolean[1]; + final SubscriptionResponse rval = new SubscriptionResponse(); VizApp.runSync(new Runnable() { @Override @@ -181,11 +184,13 @@ public class AutoSubscribePropertyListener implements IPropertyChangeListener { SubRequestDialog dlg = new SubRequestDialog(shell, "Authorize Collaboration Contact", msg, fromID); int index = dlg.open(); - rval[0] = index == Window.OK; + + rval.setAccepted(index == Window.OK); + rval.setGroup(dlg.getGroup()); } }); - return rval[0]; + return rval; } /**