use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.
the class SearchPlugin method processSetPacket.
/**
* Processes an IQ stanza of type 'set', which in the context of 'Jabber Search' is a search request.
*
* @param packet
* An IQ stanza of type 'get'
* @return A result IQ stanza that contains the possbile search fields.
*/
private IQ processSetPacket(IQ packet) {
if (!packet.getType().equals(IQ.Type.set)) {
throw new IllegalArgumentException("This method only accepts 'set' typed IQ stanzas as an argument.");
}
JID fromJID = packet.getFrom();
final IQ resultIQ;
// check if the request complies to the XEP-0055 standards
if (!isValidSearchRequest(packet)) {
resultIQ = IQ.createResultIQ(packet);
resultIQ.setError(Condition.bad_request);
return resultIQ;
}
final Element incomingForm = packet.getChildElement();
final boolean isDataFormQuery = (incomingForm.element(QName.get("x", "jabber:x:data")) != null);
final Element rsmElement = incomingForm.element(QName.get("set", ResultSet.NAMESPACE_RESULT_SET_MANAGEMENT));
if (rsmElement != null) {
final Element maxElement = rsmElement.element("max");
final Element startIndexElement = rsmElement.element("index");
int startIndex = 0;
if (startIndexElement != null) {
startIndex = Integer.parseInt(startIndexElement.getTextTrim());
}
int max = -1;
if (maxElement != null) {
max = Integer.parseInt(maxElement.getTextTrim());
}
final Set<User> searchResults = performSearch(incomingForm, startIndex, max);
if (groupOnly) {
Collection<Group> groups = GroupManager.getInstance().getGroups(fromJID);
Set<User> allSearchResults = new HashSet<User>(searchResults);
searchResults.clear();
for (User user : allSearchResults) {
for (Group group : groups) {
if (group.isUser(user.getUID())) {
searchResults.add(user);
}
}
}
}
// apply RSM
final List<User> rsmResults;
final ResultSet<User> rs = new ResultSetImpl<User>(searchResults);
try {
rsmResults = rs.applyRSMDirectives(rsmElement);
} catch (NullPointerException e) {
final IQ itemNotFound = IQ.createResultIQ(packet);
itemNotFound.setError(Condition.item_not_found);
return itemNotFound;
}
if (isDataFormQuery) {
resultIQ = replyDataFormResult(rsmResults, packet);
} else {
resultIQ = replyNonDataFormResult(rsmResults, packet);
}
// add the additional 'set' element.
final Element set = rs.generateSetElementFromResults(rsmResults);
resultIQ.getChildElement().add(set);
} else {
final Set<User> searchResults = performSearch(incomingForm);
if (groupOnly) {
Collection<Group> groups = GroupManager.getInstance().getGroups(fromJID);
Set<User> allSearchResults = new HashSet<User>(searchResults);
searchResults.clear();
for (User user : allSearchResults) {
for (Group group : groups) {
if (group.isUser(user.getUID())) {
searchResults.add(user);
}
}
}
}
// don't apply RSM
if (isDataFormQuery) {
resultIQ = replyDataFormResult(searchResults, packet);
} else {
resultIQ = replyNonDataFormResult(searchResults, packet);
}
}
return resultIQ;
}
use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.
the class SearchPlugin method performSearch.
private Set<User> performSearch(Element incomingForm, int startIndex, int max) {
Set<User> users = new HashSet<User>();
Hashtable<String, String> searchList = extractSearchQuery(incomingForm);
for (Entry<String, String> entry : searchList.entrySet()) {
String field = entry.getKey();
String query = entry.getValue();
Collection<User> foundUsers = new ArrayList<User>();
if (userManager != null && query.length() > 0 && !query.equals(NAMESPACE_JABBER_IQ_SEARCH)) {
if (max >= 0) {
foundUsers.addAll(userManager.findUsers(new HashSet<String>(Arrays.asList(field)), query, startIndex, max));
} else {
foundUsers.addAll(userManager.findUsers(new HashSet<String>(Arrays.asList(field)), query));
}
}
// occasionally a null User is returned so filter them out
for (User user : foundUsers) {
if (user != null) {
users.add(user);
}
}
}
return users;
}
use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.
the class UserServiceController method addProperties.
/**
* Adds the properties.
*
* @param userEntity
* the user entity
* @throws ServiceException
* the service exception
*/
private void addProperties(String username, List<UserProperty> properties) throws ServiceException {
User user = getAndCheckUser(username);
user.getProperties().clear();
if (properties != null) {
for (UserProperty property : properties) {
user.getProperties().put(property.getKey(), property.getValue());
}
}
}
use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.
the class UserServiceController method deleteUser.
/**
* Delete user.
*
* @param username
* the username
* @throws ServiceException
* the service exception
*/
public void deleteUser(String username) throws ServiceException {
User user = getAndCheckUser(username);
userManager.deleteUser(user);
rosterManager.deleteRoster(server.createJID(username, null));
}
use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.
the class UserServiceController method updateUser.
/**
* Update user.
*
* @param username
* the username
* @param userEntity
* the user entity
* @throws ServiceException
* the service exception
*/
public void updateUser(String username, UserEntity userEntity) throws ServiceException {
if (userEntity != null && !username.isEmpty()) {
// parameter
if (userEntity.getUsername() != null) {
if (!userEntity.getUsername().equals(username)) {
JustMarriedController.changeName(username, userEntity.getUsername(), true, userEntity.getEmail(), userEntity.getName());
addProperties(userEntity.getUsername(), userEntity.getProperties());
return;
}
}
User user = getAndCheckUser(username);
if (userEntity.getPassword() != null) {
user.setPassword(userEntity.getPassword());
}
if (userEntity.getName() != null) {
user.setName(userEntity.getName());
}
if (userEntity.getEmail() != null) {
user.setEmail(userEntity.getEmail());
}
addProperties(username, userEntity.getProperties());
}
}
Aggregations