Search in sources :

Example 1 with ServiceException

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

the class PropertyDAO method getUsernameByProperty.

/**
	 * Gets the username by property key and or value.
	 *
	 * @param propertyName
	 *            the property name
	 * @param propertyValue
	 *            the property value (can be null)
	 * @return the username by property
	 * @throws ServiceException
	 *             the service exception
	 */
public static List<String> getUsernameByProperty(String propertyName, String propertyValue) throws ServiceException {
    List<String> usernames = new ArrayList<String>();
    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        con = DbConnectionManager.getConnection();
        // Load property by key and value
        if (propertyValue != null) {
            pstmt = con.prepareStatement(LOAD_PROPERTY);
            pstmt.setString(1, propertyName);
            pstmt.setString(2, propertyValue);
        } else {
            // Load property by key
            pstmt = con.prepareStatement(LOAD_PROPERTY_BY_KEY);
            pstmt.setString(1, propertyName);
        }
        rs = pstmt.executeQuery();
        while (rs.next()) {
            usernames.add(rs.getString(1));
        }
    } catch (SQLException sqle) {
        throw new ServiceException("Could not get username by property", propertyName, ExceptionType.PROPERTY_NOT_FOUND, Response.Status.NOT_FOUND, sqle);
    } finally {
        DbConnectionManager.closeConnection(rs, pstmt, con);
    }
    return usernames;
}
Also used : ServiceException(org.jivesoftware.openfire.exceptions.ServiceException) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 2 with ServiceException

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

the class UserServicePluginNG method createGroup.

/**
	 * Creates the group.
	 *
	 * @param groupName
	 *            the group name
	 * @return the group
	 * @throws ServiceException
	 * @throws GroupAlreadyExistsException
	 *             the group already exists exception
	 */
private Group createGroup(String groupName) throws ServiceException {
    Group group = null;
    try {
        group = GroupManager.getInstance().createGroup(groupName);
        group.getProperties().put("sharedRoster.showInRoster", "onlyGroup");
        group.getProperties().put("sharedRoster.displayName", groupName);
        group.getProperties().put("sharedRoster.groupList", "");
    } catch (GroupAlreadyExistsException e) {
        throw new ServiceException("Could not create group", groupName, ExceptionType.GROUP_ALREADY_EXISTS, Response.Status.BAD_REQUEST, e);
    }
    return group;
}
Also used : Group(org.jivesoftware.openfire.group.Group) ServiceException(org.jivesoftware.openfire.exceptions.ServiceException) GroupAlreadyExistsException(org.jivesoftware.openfire.group.GroupAlreadyExistsException)

Example 3 with ServiceException

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

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

the class UserServicePluginNG method addRosterItem.

/**
	 * Adds the roster item.
	 *
	 * @param username
	 *            the username
	 * @param rosterItemEntity
	 *            the roster item entity
	 * @throws ServiceException
	 *             the service exception
	 * @throws UserAlreadyExistsException
	 *             the user already exists exception
	 * @throws SharedGroupException
	 *             the shared group exception
	 * @throws UserNotFoundException
	 *             the user not found exception
	 */
public void addRosterItem(String username, RosterItemEntity rosterItemEntity) throws ServiceException, UserAlreadyExistsException, SharedGroupException, UserNotFoundException {
    Roster roster = getUserRoster(username);
    if (rosterItemEntity.getJid() == null) {
        throw new ServiceException("JID is null", "JID", "IllegalArgumentException", Response.Status.BAD_REQUEST);
    }
    JID jid = new JID(rosterItemEntity.getJid());
    try {
        roster.getRosterItem(jid);
        throw new UserAlreadyExistsException(jid.toBareJID());
    } catch (UserNotFoundException e) {
    // Roster item does not exist. Try to add it.
    }
    if (roster != null) {
        RosterItem rosterItem = roster.createRosterItem(jid, rosterItemEntity.getNickname(), rosterItemEntity.getGroups(), false, true);
        UserUtils.checkSubType(rosterItemEntity.getSubscriptionType());
        rosterItem.setSubStatus(RosterItem.SubType.getTypeFromInt(rosterItemEntity.getSubscriptionType()));
        roster.updateRosterItem(rosterItem);
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) RosterItem(org.jivesoftware.openfire.roster.RosterItem) Roster(org.jivesoftware.openfire.roster.Roster) ServiceException(org.jivesoftware.openfire.exceptions.ServiceException) JID(org.xmpp.packet.JID) UserAlreadyExistsException(org.jivesoftware.openfire.user.UserAlreadyExistsException)

Example 5 with ServiceException

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

the class UserServicePluginNG method deleteUserFromGroups.

/**
	 * Delete user from groups.
	 *
	 * @param username
	 *            the username
	 * @param userGroupsEntity
	 *            the user groups entity
	 * @throws ServiceException
	 *             the service exception
	 */
public void deleteUserFromGroups(String username, UserGroupsEntity userGroupsEntity) throws ServiceException {
    if (userGroupsEntity != null) {
        for (String groupName : userGroupsEntity.getGroupNames()) {
            Group group = null;
            try {
                group = GroupManager.getInstance().getGroup(groupName);
            } catch (GroupNotFoundException e) {
                throw new ServiceException("Could not find group", groupName, ExceptionType.GROUP_NOT_FOUND, Response.Status.NOT_FOUND, e);
            }
            group.getMembers().remove(server.createJID(username, null));
        }
    }
}
Also used : Group(org.jivesoftware.openfire.group.Group) ServiceException(org.jivesoftware.openfire.exceptions.ServiceException) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException)

Aggregations

ServiceException (org.jivesoftware.openfire.exceptions.ServiceException)5 Group (org.jivesoftware.openfire.group.Group)2 Roster (org.jivesoftware.openfire.roster.Roster)2 JID (org.xmpp.packet.JID)2 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 GroupAlreadyExistsException (org.jivesoftware.openfire.group.GroupAlreadyExistsException)1 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)1 RosterItem (org.jivesoftware.openfire.roster.RosterItem)1 UserAlreadyExistsException (org.jivesoftware.openfire.user.UserAlreadyExistsException)1 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)1