Search in sources :

Example 11 with Roster

use of org.jivesoftware.openfire.roster.Roster in project Openfire by igniterealtime.

the class NonPersistantRosterProcessor method process.

@Override
public void process(Packet packet, String subdomain, String to, String from) throws PacketRejectedException {
    Presence myPacket = (Presence) packet;
    if (myPacket.getType() != null && myPacket.getType().equals(Presence.Type.unavailable) && !myPacket.getElement().getStringValue().equals("Connecting")) {
        String username = getUsernameFromJid(to);
        Log.debug("Processing packet in NonPersistantRosterProcessor for " + subdomain + "and user " + username + " Packet: " + packet.toString());
        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.");
                    roster.deleteRosterItem(item.getJid(), false);
                }
            }
        } catch (Exception e) {
            Log.debug("Execption occured when cleaning up the Roster.", e);
            e.printStackTrace();
        }
    }
}
Also used : RosterItem(org.jivesoftware.openfire.roster.RosterItem) Roster(org.jivesoftware.openfire.roster.Roster) Presence(org.xmpp.packet.Presence) PacketRejectedException(org.jivesoftware.openfire.interceptor.PacketRejectedException)

Example 12 with Roster

use of org.jivesoftware.openfire.roster.Roster in project Openfire by igniterealtime.

the class UserServicePlugin method addRosterItem.

/**
	 * Add new roster item for specified user
	 *
	 * @param username
	 *            the username of the local user to add roster item to.
	 * @param itemJID
	 *            the JID of the roster item to be added.
	 * @param itemName
	 *            the nickname of the roster item.
	 * @param subscription
	 *            the type of subscription of the roster item. Possible values
	 *            are: -1(remove), 0(none), 1(to), 2(from), 3(both).
	 * @param groupNames
	 *            the name of a group to place contact into.
	 * @throws UserNotFoundException
	 *             if the user does not exist in the local server.
	 * @throws UserAlreadyExistsException
	 *             if roster item with the same JID already exists.
	 * @throws SharedGroupException
	 *             if roster item cannot be added to a shared group.
	 */
public void addRosterItem(String username, String itemJID, String itemName, String subscription, String groupNames) throws UserNotFoundException, UserAlreadyExistsException, SharedGroupException {
    getUser(username);
    Roster r = rosterManager.getRoster(username);
    JID j = new JID(itemJID);
    try {
        r.getRosterItem(j);
        throw new UserAlreadyExistsException(j.toBareJID());
    } catch (UserNotFoundException e) {
    // Roster item does not exist. Try to add it.
    }
    if (r != null) {
        List<String> groups = new ArrayList<String>();
        if (groupNames != null) {
            StringTokenizer tkn = new StringTokenizer(groupNames, ",");
            while (tkn.hasMoreTokens()) {
                groups.add(tkn.nextToken());
            }
        }
        RosterItem ri = r.createRosterItem(j, itemName, groups, false, true);
        if (subscription == null) {
            subscription = "0";
        }
        ri.setSubStatus(RosterItem.SubType.getTypeFromInt(Integer.parseInt(subscription)));
        r.updateRosterItem(ri);
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) RosterItem(org.jivesoftware.openfire.roster.RosterItem) StringTokenizer(java.util.StringTokenizer) Roster(org.jivesoftware.openfire.roster.Roster) JID(org.xmpp.packet.JID) ArrayList(java.util.ArrayList) UserAlreadyExistsException(org.jivesoftware.openfire.user.UserAlreadyExistsException)

Example 13 with Roster

use of org.jivesoftware.openfire.roster.Roster in project Openfire by igniterealtime.

the class UserServicePlugin method deleteRosterItem.

/**
	 * Delete roster item for specified user. No error returns if nothing to
	 * delete.
	 *
	 * @param username
	 *            the username of the local user to add roster item to.
	 * @param itemJID
	 *            the JID of the roster item to be deleted.
	 * @throws UserNotFoundException
	 *             if the user does not exist in the local server.
	 * @throws SharedGroupException
	 *             if roster item cannot be deleted from a shared group.
	 */
public void deleteRosterItem(String username, String itemJID) throws UserNotFoundException, SharedGroupException {
    getUser(username);
    Roster r = rosterManager.getRoster(username);
    JID j = new JID(itemJID);
    // No roster item is found. Uncomment the following line to throw
    // UserNotFoundException.
    // r.getRosterItem(j);
    r.deleteRosterItem(j, true);
}
Also used : Roster(org.jivesoftware.openfire.roster.Roster) JID(org.xmpp.packet.JID)

Example 14 with Roster

use of org.jivesoftware.openfire.roster.Roster in project Openfire by igniterealtime.

the class UserServicePluginNG 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);
    }
}
Also used : Roster(org.jivesoftware.openfire.roster.Roster) JID(org.xmpp.packet.JID) ServiceException(org.jivesoftware.openfire.exceptions.ServiceException)

Example 15 with Roster

use of org.jivesoftware.openfire.roster.Roster in project Openfire by igniterealtime.

the class UserServicePluginNG method getRosterEntities.

/**
	 * Gets the roster entities.
	 *
	 * @param username
	 *            the username
	 * @return the roster entities
	 * @throws ServiceException
	 *             the service exception
	 */
public RosterEntities getRosterEntities(String username) throws ServiceException {
    Roster roster = getUserRoster(username);
    List<RosterItemEntity> rosterEntities = new ArrayList<RosterItemEntity>();
    for (RosterItem rosterItem : roster.getRosterItems()) {
        RosterItemEntity rosterItemEntity = new RosterItemEntity(rosterItem.getJid().toBareJID(), rosterItem.getNickname(), rosterItem.getSubStatus().getValue());
        rosterItemEntity.setGroups(rosterItem.getGroups());
        rosterEntities.add(rosterItemEntity);
    }
    return new RosterEntities(rosterEntities);
}
Also used : RosterItem(org.jivesoftware.openfire.roster.RosterItem) Roster(org.jivesoftware.openfire.roster.Roster) RosterEntities(org.jivesoftware.openfire.entity.RosterEntities) ArrayList(java.util.ArrayList) RosterItemEntity(org.jivesoftware.openfire.entity.RosterItemEntity)

Aggregations

Roster (org.jivesoftware.openfire.roster.Roster)42 RosterItem (org.jivesoftware.openfire.roster.RosterItem)29 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)27 JID (org.xmpp.packet.JID)20 UserAlreadyExistsException (org.jivesoftware.openfire.user.UserAlreadyExistsException)13 SharedGroupException (org.jivesoftware.openfire.SharedGroupException)9 ArrayList (java.util.ArrayList)7 StringTokenizer (java.util.StringTokenizer)4 PacketException (org.jivesoftware.openfire.PacketException)4 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)4 ServiceException (org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException)4 Presence (org.xmpp.packet.Presence)4 NotFoundException (org.jivesoftware.util.NotFoundException)3 IQ (org.xmpp.packet.IQ)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 Email (net.sf.jml.Email)2 XMPPServer (org.jivesoftware.openfire.XMPPServer)2 ServiceException (org.jivesoftware.openfire.exceptions.ServiceException)2 Group (org.jivesoftware.openfire.group.Group)2 PacketRejectedException (org.jivesoftware.openfire.interceptor.PacketRejectedException)2