use of org.jivesoftware.openfire.roster.Roster in project Openfire by igniterealtime.
the class MSNSession method completedPendingContactAdd.
/**
* Completes the addition of groups to a new contact after the contact has been created.
*
* @param msnContact Contact that was added.
*/
public void completedPendingContactAdd(MsnContact msnContact) {
try {
Roster roster = getTransport().getRosterManager().getRoster(getJID().getNode());
Email contact = msnContact.getEmail();
JID contactJID = getTransport().convertIDToJID(contact.toString());
RosterItem item = roster.getRosterItem(contactJID);
getBuddyManager().storeBuddy(new MSNBuddy(getBuddyManager(), msnContact));
syncContactGroups(contact, item.getGroups());
} catch (UserNotFoundException e) {
Log.debug("MSN: Unable to find roster when adding pendingcontact for " + getJID());
}
}
use of org.jivesoftware.openfire.roster.Roster in project Openfire by igniterealtime.
the class MSNSession method completedPendingGroupAdd.
/**
* Completes the addition of a contact to a new group after the group has been created.
*
* @param msnGroup Group that was added.
*/
public void completedPendingGroupAdd(MsnGroup msnGroup) {
if (!msnPendingGroups.containsKey(msnGroup.getGroupName())) {
// Nothing to do, no pending.
return;
}
try {
Roster roster = getTransport().getRosterManager().getRoster(getJID().getNode());
for (Email contact : msnPendingGroups.get(msnGroup.getGroupName())) {
JID contactJID = getTransport().convertIDToJID(contact.toString());
RosterItem item = roster.getRosterItem(contactJID);
syncContactGroups(contact, item.getGroups());
}
} catch (UserNotFoundException e) {
Log.debug("MSN: Unable to find roster when adding pending group contacts for " + getJID());
}
}
use of org.jivesoftware.openfire.roster.Roster in project Openfire by igniterealtime.
the class IQRosterPayloadProcessor method handleIQset.
private void handleIQset(IQ myPacket, final String subdomain, final String username) throws PacketRejectedException {
IQ response = IQ.createResultIQ(myPacket);
List<Node> nodes = findNodesInDocument(myPacket.getElement().getDocument(), "//roster:item");
for (Node n : nodes) {
Roster roster;
String jid = n.valueOf("@jid");
String name = n.valueOf("@name");
String subvalue = n.valueOf("@subscription");
// causing trouble on register:remove
if (JiveGlobals.getBooleanProperty("plugin.remoteroster.ignoreSubdomains", true) && jid.equals(subdomain) && subvalue.equals("both"))
throw new PacketRejectedException();
if (subvalue.equals("both")) {
try {
roster = _rosterManager.getRoster(username);
List<String> grouplist = new ArrayList<String>();
List<Node> groupnodes = findNodesInDocument(n.getDocument(), "//roster:group");
for (Node ne : groupnodes) {
String groupName = ne.getText();
grouplist.add(groupName);
}
boolean rosterPersistent = JiveGlobals.getBooleanProperty("plugin.remoteroster.persistent", true);
Log.debug("Adding/Updating Contact " + jid + " to roster of " + username);
try {
RosterItem item = roster.getRosterItem(new JID(jid));
item.setGroups(grouplist);
roster.updateRosterItem(item);
// dont send iq-result if just updating user
continue;
} catch (UserNotFoundException exc) {
// Then we should add him!
}
RosterItem item = roster.createRosterItem(new JID(jid), name, grouplist, false, rosterPersistent);
item.setSubStatus(RosterItem.SUB_BOTH);
roster.updateRosterItem(item);
} catch (Exception e) {
Log.info("Could not add user to Roster although no entry should exist..." + username, e);
}
dispatchPacket(response);
} else if (subvalue.equals("remove")) {
// we dont need to do this when persistent = false because they will get deleted as soon as gateway is unavailable
if (JiveGlobals.getBooleanProperty("plugin.remoteroster.persistent", false) && jid.equals(subdomain)) {
deleteSubdomainItemsFromRoster(username, subdomain);
}
// to handle it
throw new PacketRejectedException();
}
}
}
use of org.jivesoftware.openfire.roster.Roster in project Openfire by igniterealtime.
the class IQRosterPayloadProcessor method deleteSubdomainItemsFromRoster.
/**
* Searches the users roster for a specific subdomain and deletes all contacts that contain subdomain
*
* @param username
* @param subdomain
*/
private void deleteSubdomainItemsFromRoster(String username, String subdomain) {
try {
Roster roster = _rosterManager.getRoster(username);
Collection<RosterItem> items = roster.getRosterItems();
for (RosterItem item : items) {
String itemName = item.getJid().toString();
if (itemName.contains(subdomain)) {
Log.debug("Removing contact " + item.getJid().toString() + " from contact list because of Unregister.");
roster.deleteRosterItem(item.getJid(), false);
}
}
} catch (UserNotFoundException e) {
Log.debug("Couldnt find User!" + e.toString());
} catch (SharedGroupException e) {
e.printStackTrace();
}
}
use of org.jivesoftware.openfire.roster.Roster in project Openfire by igniterealtime.
the class IQRosterPayloadProcessor method handleIQget.
private void handleIQget(IQ myPacket, String subdomain, String username) {
if (JiveGlobals.getBooleanProperty("plugin.remoteroster.persistent", false)) {
Roster roster;
try {
roster = _rosterManager.getRoster(username);
Collection<RosterItem> items = roster.getRosterItems();
Log.debug("Sending contacts with subdomain " + subdomain + " from user " + username + " to external Component");
sendRosterToComponent(myPacket, items, subdomain);
} catch (UserNotFoundException e) {
e.printStackTrace();
}
} else {
Log.debug("Sending nonpersistant-RemoteRosterResponse to external Component for User: " + username);
sendEmptyRoster(myPacket, subdomain);
}
}
Aggregations