Search in sources :

Example 16 with ServiceException

use of org.jivesoftware.openfire.plugin.rest.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.plugin.rest.exceptions.ServiceException) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

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