Search in sources :

Example 11 with ServiceException

use of org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException in project Openfire by igniterealtime.

the class JustMarriedController method copyVCard.

/**
	 * Copy v card.
	 *
	 * @param currentUserName
	 *            the current user name
	 * @param newUserName
	 *            the new user name
	 * @throws ServiceException
	 *             the service exception
	 */
private static void copyVCard(String currentUserName, String newUserName) throws ServiceException {
    VCardManager vcardManager = VCardManager.getInstance();
    Element vcard = vcardManager.getVCard(currentUserName);
    if (vcard != null) {
        try {
            vcardManager.setVCard(newUserName, vcard);
        } catch (Exception e) {
            throw new ServiceException("Could not copy vcard to new user", newUserName, ExceptionType.ILLEGAL_ARGUMENT_EXCEPTION, Response.Status.BAD_REQUEST, e);
        }
    }
}
Also used : ServiceException(org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException) Element(org.dom4j.Element) VCardManager(org.jivesoftware.openfire.vcard.VCardManager) ServiceException(org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException) UserAlreadyExistsException(org.jivesoftware.openfire.user.UserAlreadyExistsException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) SharedGroupException(org.jivesoftware.openfire.SharedGroupException)

Example 12 with ServiceException

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

Example 13 with ServiceException

use of org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException 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 14 with ServiceException

use of org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException in project Openfire by igniterealtime.

the class MUCRoomController method deleteAffiliation.

/**
	 * Delete affiliation.
	 *
	 * @param serviceName
	 *            the service name
	 * @param roomName
	 *            the room name
	 * @param jid
	 *            the jid
	 * @throws ServiceException
	 *             the service exception
	 */
public void deleteAffiliation(String serviceName, String roomName, String jid) throws ServiceException {
    MUCRoom room = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName).getChatRoom(roomName.toLowerCase());
    try {
        JID userJid = UserUtils.checkAndGetJID(jid);
        // Send a presence to other room members
        List<Presence> addNonePresence = room.addNone(userJid, room.getRole());
        for (Presence presence : addNonePresence) {
            room.send(presence);
        }
    } catch (ForbiddenException e) {
        throw new ServiceException("Could not delete affiliation", jid, ExceptionType.NOT_ALLOWED, Response.Status.FORBIDDEN, e);
    } catch (ConflictException e) {
        throw new ServiceException("Could not delete affiliation", jid, ExceptionType.NOT_ALLOWED, Response.Status.CONFLICT, e);
    }
}
Also used : ForbiddenException(org.jivesoftware.openfire.muc.ForbiddenException) LocalMUCRoom(org.jivesoftware.openfire.muc.spi.LocalMUCRoom) MUCRoom(org.jivesoftware.openfire.muc.MUCRoom) JID(org.xmpp.packet.JID) ServiceException(org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException) ConflictException(org.jivesoftware.openfire.muc.ConflictException) Presence(org.xmpp.packet.Presence)

Example 15 with ServiceException

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

Aggregations

ServiceException (org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException)16 Group (org.jivesoftware.openfire.group.Group)7 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)6 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)5 UserAlreadyExistsException (org.jivesoftware.openfire.user.UserAlreadyExistsException)5 Roster (org.jivesoftware.openfire.roster.Roster)4 SharedGroupException (org.jivesoftware.openfire.SharedGroupException)3 RosterItem (org.jivesoftware.openfire.roster.RosterItem)3 JID (org.xmpp.packet.JID)3 ArrayList (java.util.ArrayList)2 MUCRoom (org.jivesoftware.openfire.muc.MUCRoom)2 LocalMUCRoom (org.jivesoftware.openfire.muc.spi.LocalMUCRoom)2 User (org.jivesoftware.openfire.user.User)2 UserManager (org.jivesoftware.openfire.user.UserManager)2 Presence (org.xmpp.packet.Presence)2 UnknownHostException (java.net.UnknownHostException)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1