use of org.jivesoftware.openfire.roster.Roster in project Openfire by igniterealtime.
the class PresenceSubscribeHandler method getRoster.
/**
* <p>Obtain the roster for the given address or null if the address doesn't have a roster.</p>
*
* @param address The address to check
* @return The roster or null if the address is not managed on the server
*/
private Roster getRoster(JID address) {
String username;
Roster roster = null;
if (userManager.isRegisteredUser(address, false)) {
username = address.getNode();
try {
roster = rosterManager.getRoster(username);
} catch (UserNotFoundException e) {
// Do nothing
}
}
return roster;
}
use of org.jivesoftware.openfire.roster.Roster in project Openfire by igniterealtime.
the class JustMarriedController method addNewUserToOthersRoster.
/**
* Adds the new user to others roster.
*
* @param newUser
* the new user
* @param otherItem
* the other item
* @param currentUser
* the current user
* @throws ServiceException
* the service exception
*/
private static void addNewUserToOthersRoster(User newUser, RosterItem otherItem, String currentUser) throws ServiceException {
otherItem.getJid();
UserManager userManager = UserManager.getInstance();
// Is this user registered with our OF server?
String username = otherItem.getJid().getNode();
if (username != null && username.length() > 0 && userManager.isRegisteredUser(username) && XMPPServer.getInstance().isLocal(XMPPServer.getInstance().createJID(currentUser, null))) {
try {
User otherUser = userManager.getUser(username);
Roster otherRoster = otherUser.getRoster();
RosterItem oldUserOnOthersRoster = otherRoster.getRosterItem(XMPPServer.getInstance().createJID(currentUser, null));
try {
if (!oldUserOnOthersRoster.isOnlyShared()) {
RosterItem justCreated = otherRoster.createRosterItem(XMPPServer.getInstance().createJID(newUser.getUsername(), null), oldUserOnOthersRoster.getNickname(), oldUserOnOthersRoster.getGroups(), true, true);
justCreated.setAskStatus(oldUserOnOthersRoster.getAskStatus());
justCreated.setRecvStatus(oldUserOnOthersRoster.getRecvStatus());
justCreated.setSubStatus(oldUserOnOthersRoster.getSubStatus());
otherRoster.updateRosterItem(justCreated);
}
} catch (UserAlreadyExistsException e) {
throw new ServiceException("Could not create roster item for user ", newUser.getUsername(), ExceptionType.USER_ALREADY_EXISTS_EXCEPTION, Response.Status.CONFLICT, e);
} catch (SharedGroupException e) {
throw new ServiceException("Could not create roster item, because it is a contact from a shared group", newUser.getUsername(), ExceptionType.USER_ALREADY_EXISTS_EXCEPTION, Response.Status.BAD_REQUEST, e);
}
} catch (UserNotFoundException e) {
throw new ServiceException("Could not create roster item for user " + newUser.getUsername() + " because it is a contact from a shared group.", newUser.getUsername(), ExceptionType.USER_NOT_FOUND_EXCEPTION, Response.Status.NOT_FOUND, e);
}
}
}
use of org.jivesoftware.openfire.roster.Roster in project Openfire by igniterealtime.
the class JustMarriedController method copyRoster.
/**
* Copy roster.
*
* @param currentUser
* the current user
* @param newUser
* the new user
* @param currentUserName
* the current user name
* @throws ServiceException
* the service exception
*/
private static void copyRoster(User currentUser, User newUser, String currentUserName) throws ServiceException {
Roster newRoster = newUser.getRoster();
Roster currentRoster = currentUser.getRoster();
for (RosterItem item : currentRoster.getRosterItems()) {
try {
List<String> groups = item.getGroups();
RosterItem justCreated = newRoster.createRosterItem(item.getJid(), item.getNickname(), groups, true, true);
justCreated.setAskStatus(item.getAskStatus());
justCreated.setRecvStatus(item.getRecvStatus());
justCreated.setSubStatus(item.getSubStatus());
for (Group gr : item.getSharedGroups()) {
justCreated.addSharedGroup(gr);
}
for (Group gr : item.getInvisibleSharedGroups()) {
justCreated.addInvisibleSharedGroup(gr);
}
newRoster.updateRosterItem(justCreated);
addNewUserToOthersRoster(newUser, item, currentUserName);
} catch (UserAlreadyExistsException e) {
throw new ServiceException("Could not create roster item for user ", newUser.getUsername(), ExceptionType.USER_ALREADY_EXISTS_EXCEPTION, Response.Status.CONFLICT, e);
} catch (SharedGroupException e) {
throw new ServiceException("Could not create roster item, because it is a contact from a shared group", newUser.getUsername(), ExceptionType.USER_ALREADY_EXISTS_EXCEPTION, Response.Status.BAD_REQUEST, e);
} catch (UserNotFoundException e) {
throw new ServiceException("Could not update roster item for user " + newUser.getUsername() + " because it was not properly created.", newUser.getUsername(), ExceptionType.USER_NOT_FOUND_EXCEPTION, Response.Status.NOT_FOUND, e);
}
}
}
use of org.jivesoftware.openfire.roster.Roster in project Openfire by igniterealtime.
the class UserServiceController method updateRosterItem.
/**
* Update roster item.
*
* @param username
* the username
* @param rosterJid
* the roster jid
* @param rosterItemEntity
* the roster item entity
* @throws ServiceException
* the service exception
* @throws UserNotFoundException
* the user not found exception
* @throws UserAlreadyExistsException
* the user already exists exception
* @throws SharedGroupException
* the shared group exception
*/
public void updateRosterItem(String username, String rosterJid, RosterItemEntity rosterItemEntity) throws ServiceException, UserNotFoundException, UserAlreadyExistsException, SharedGroupException {
getAndCheckUser(username);
Roster roster = getUserRoster(username);
JID jid = new JID(rosterJid);
RosterItem rosterItem = roster.getRosterItem(jid);
if (rosterItemEntity.getNickname() != null) {
rosterItem.setNickname(rosterItemEntity.getNickname());
}
if (rosterItemEntity.getGroups() != null) {
rosterItem.setGroups(rosterItemEntity.getGroups());
}
UserUtils.checkSubType(rosterItemEntity.getSubscriptionType());
rosterItem.setSubStatus(RosterItem.SubType.getTypeFromInt(rosterItemEntity.getSubscriptionType()));
roster.updateRosterItem(rosterItem);
}
use of org.jivesoftware.openfire.roster.Roster in project Openfire by igniterealtime.
the class UserServiceController method deleteRosterItem.
/**
* Delete roster item.
*
* @param username
* the username
* @param rosterJid
* the roster jid
* @throws SharedGroupException
* the shared group exception
* @throws ServiceException
* the service exception
*/
public void deleteRosterItem(String username, String rosterJid) throws SharedGroupException, ServiceException {
getAndCheckUser(username);
Roster roster = getUserRoster(username);
JID jid = new JID(rosterJid);
if (roster.deleteRosterItem(jid, true) == null) {
throw new ServiceException("Roster Item could not deleted", jid.toBareJID(), "RosterItemNotFound", Response.Status.NOT_FOUND);
}
}
Aggregations