use of org.eclipse.ecf.presence.search.ICriterion in project ecf by eclipse.
the class XMPPSearchTest method testRetrieveBuddiesEmailFieldSync.
/**
* Try to locate buddies on the XMPP server in a call block way
*
* @throws ContainerConnectException
*/
public void testRetrieveBuddiesEmailFieldSync() throws Exception {
assertNotNull(searchManager);
IRestriction selection = searchManager.createRestriction();
assertNotNull(selection);
// search field for XMPP, criterion to match the search
// fields to consider on XMPP server side search
ICriterion email = selection.eq(EMAIL, "mayworm*");
// create a specific criteria
ICriteria criteria = searchManager.createCriteria();
assertNotNull(criteria);
criteria.add(email);
// call the block search
try {
ISearch search = searchManager.search(criteria);
// the collection of IResult
IResultList resultList = search.getResultList();
// check if there is at least one result
int resultListSize = resultList.getResults().size();
if (resultListSize == 0)
System.out.println("XMPPSearchTest.testRetrieveBuddiesEmailFieldSync...no email field retrieved");
else
assertTrue(1 == resultListSize);
} catch (UserSearchException e) {
e.printStackTrace();
}
}
use of org.eclipse.ecf.presence.search.ICriterion in project ecf by eclipse.
the class XMPPSearchTest method testRetrieveBuddiesAsync.
public void testRetrieveBuddiesAsync() throws Exception {
assertNotNull(searchManager);
IRestriction selection = searchManager.createRestriction();
assertNotNull(selection);
// fields to consider on XMPP server side search
// search field for XMPP, criterion to match the search
ICriterion name = selection.eq(NAME, "Marcelo*");
ICriterion email = selection.eq(EMAIL, "zx*");
ICriterion username = selection.eq(USERNAME, "sl*");
// create a specific criteria
final ICriteria criteria = searchManager.createCriteria();
assertNotNull(criteria);
criteria.add(name);
criteria.add(email);
criteria.add(username);
IUserSearchListener listenerCompleted = new IUserSearchListener() {
public void handleUserSearchEvent(IUserSearchEvent event) {
if (event instanceof IUserSearchCompleteEvent) {
searchResult = ((IUserSearchCompleteEvent) event).getSearch();
}
}
};
// call the non-block search
searchManager.search(criteria, listenerCompleted);
assertNull(searchResult);
Thread.sleep(5000);
// put the completion result on the search handle
if (searchResult == null)
return;
assertNotNull(searchResult);
// check if there is at least one result
assertTrue(0 != searchResult.getResultList().getResults().size());
}
use of org.eclipse.ecf.presence.search.ICriterion in project ecf by eclipse.
the class XMPPCriteria method toString.
public String toString() {
// $NON-NLS-1$
StringBuffer sb = new StringBuffer("XMPPCriteria[");
Iterator it = criteria.iterator();
while (it.hasNext()) {
// $NON-NLS-1$
sb.append("[");
ICriterion criterion = (ICriterion) it.next();
sb.append(criterion.toString());
// $NON-NLS-1$
sb.append("];");
}
// $NON-NLS-1$
sb.append("]");
return sb.toString();
}
use of org.eclipse.ecf.presence.search.ICriterion in project ecf by eclipse.
the class XMPPUserSearchManager method search.
/**
* Specific implementation for XMPP
*
* @see IUserSearchManager#search(ICriteria).
*/
public ISearch search(ICriteria criteria) throws UserSearchException {
ResultList resultList = new ResultList();
try {
// initialize the form by chance it is null
if (form == null)
form = manager.getSearchForm(ecfConnection.getXMPPConnection(), SERVICE_SEARCH + ecfConnection.getXMPPConnection().getServiceName());
/*
* For XMPP criterion is considered. The XMPP server will deal with
* the search.
*/
List criterions = criteria.getCriterions();
// add the fields for the search dynamically
// consider just the fields used on the search
// fields checked by user
String[] fields = getUserPropertiesFields();
for (int i = 0; i < fields.length; i++) {
Iterator criterionsIterator = criterions.iterator();
// the partial result is added to the result list
while (criterionsIterator.hasNext()) {
ICriterion criterion = (ICriterion) criterionsIterator.next();
if (criterion.equals(fields[i])) {
Form answerForm = form.createAnswerForm();
answerForm.setAnswer(fields[i], true);
answerForm.setAnswer(SEARCH_ACTION, criterion.toExpression());
ReportedData data = manager.sendSearchForm(ecfConnection.getXMPPConnection(), answerForm, SERVICE_SEARCH + ecfConnection.getXMPPConnection().getServiceName());
// create a result list from ReportedData
IResultList partialResultList = createResultList(data);
resultList.addAll(partialResultList.getResults());
}
}
}
return new XMPPSearch(resultList);
} catch (final XMPPException e) {
String message = null;
if (e.getXMPPError() != null && e.getXMPPError().getCode() == 404) {
message = Messages.XMPPContainer_UNRECOGONIZED_SEARCH_SERVICE;
} else {
message = e.getLocalizedMessage();
}
throw new UserSearchException(message, e, criteria);
} catch (ECFException e) {
throw new UserSearchException(e, criteria);
}
}
use of org.eclipse.ecf.presence.search.ICriterion in project ecf by eclipse.
the class XMPPSearchTest method testRetrieveBuddiesAllFieldsSync.
/**
* Try to locate buddies on the XMPP server in a call block way
*
* @throws ContainerConnectException
*/
public void testRetrieveBuddiesAllFieldsSync() throws ContainerConnectException {
try {
assertNotNull(searchManager);
IRestriction selection = searchManager.createRestriction();
assertNotNull(selection);
// fields to consider on XMPP server side search
// search field for XMPP, criterion to match the search
ICriterion name = selection.eq(NAME, "Marcelo*");
ICriterion email = selection.eq(EMAIL, "zx*");
ICriterion username = selection.eq(USERNAME, "sl*");
// create a specific criteria
ICriteria criteria = searchManager.createCriteria();
assertNotNull(criteria);
criteria.add(name);
criteria.add(email);
criteria.add(username);
// call the block search
ISearch search = searchManager.search(criteria);
// the collection of IResult
IResultList resultList = search.getResultList();
// check if there is at least one result
assertTrue(0 != resultList.getResults().size());
Iterator it = resultList.getResults().iterator();
while (it.hasNext()) {
IResult type = (IResult) it.next();
System.out.println(type.getUser().getName() + " : " + type.getUser().getID());
}
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations