Search in sources :

Example 36 with RosterItem

use of org.jivesoftware.openfire.roster.RosterItem 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);
        }
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) RosterItem(org.jivesoftware.openfire.roster.RosterItem) Group(org.jivesoftware.openfire.group.Group) Roster(org.jivesoftware.openfire.roster.Roster) ServiceException(org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException) UserAlreadyExistsException(org.jivesoftware.openfire.user.UserAlreadyExistsException) SharedGroupException(org.jivesoftware.openfire.SharedGroupException)

Example 37 with RosterItem

use of org.jivesoftware.openfire.roster.RosterItem 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);
}
Also used : RosterItem(org.jivesoftware.openfire.roster.RosterItem) Roster(org.jivesoftware.openfire.roster.Roster) JID(org.xmpp.packet.JID)

Aggregations

RosterItem (org.jivesoftware.openfire.roster.RosterItem)37 Roster (org.jivesoftware.openfire.roster.Roster)27 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)26 JID (org.xmpp.packet.JID)18 UserAlreadyExistsException (org.jivesoftware.openfire.user.UserAlreadyExistsException)11 ArrayList (java.util.ArrayList)10 Element (org.dom4j.Element)8 SharedGroupException (org.jivesoftware.openfire.SharedGroupException)6 User (org.jivesoftware.openfire.user.User)5 StringTokenizer (java.util.StringTokenizer)4 IQ (org.xmpp.packet.IQ)4 StringprepException (gnu.inet.encoding.StringprepException)3 ServiceException (org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException)3 ParseException (java.text.ParseException)2 Email (net.sf.jml.Email)2 DefaultElement (org.dom4j.tree.DefaultElement)2 XMPPServer (org.jivesoftware.openfire.XMPPServer)2 Group (org.jivesoftware.openfire.group.Group)2 PacketRejectedException (org.jivesoftware.openfire.interceptor.PacketRejectedException)2 UserManager (org.jivesoftware.openfire.user.UserManager)2