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;
}
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;
}
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);
}
}
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);
}
}
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));
}
}
}
Aggregations