Search in sources :

Example 1 with IRestriction

use of org.eclipse.ecf.presence.search.IRestriction 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();
    }
}
Also used : IRestriction(org.eclipse.ecf.presence.search.IRestriction) ISearch(org.eclipse.ecf.presence.search.ISearch) IResultList(org.eclipse.ecf.presence.search.IResultList) ICriterion(org.eclipse.ecf.presence.search.ICriterion) UserSearchException(org.eclipse.ecf.presence.search.UserSearchException) ICriteria(org.eclipse.ecf.presence.search.ICriteria)

Example 2 with IRestriction

use of org.eclipse.ecf.presence.search.IRestriction 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());
}
Also used : IUserSearchListener(org.eclipse.ecf.presence.search.IUserSearchListener) IUserSearchCompleteEvent(org.eclipse.ecf.presence.search.IUserSearchCompleteEvent) IRestriction(org.eclipse.ecf.presence.search.IRestriction) IUserSearchEvent(org.eclipse.ecf.presence.search.IUserSearchEvent) ICriterion(org.eclipse.ecf.presence.search.ICriterion) ICriteria(org.eclipse.ecf.presence.search.ICriteria)

Example 3 with IRestriction

use of org.eclipse.ecf.presence.search.IRestriction 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();
    }
}
Also used : IRestriction(org.eclipse.ecf.presence.search.IRestriction) ISearch(org.eclipse.ecf.presence.search.ISearch) Iterator(java.util.Iterator) IResultList(org.eclipse.ecf.presence.search.IResultList) ICriterion(org.eclipse.ecf.presence.search.ICriterion) ECFException(org.eclipse.ecf.core.util.ECFException) UserSearchException(org.eclipse.ecf.presence.search.UserSearchException) ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) ICriteria(org.eclipse.ecf.presence.search.ICriteria) IResult(org.eclipse.ecf.presence.search.IResult)

Example 4 with IRestriction

use of org.eclipse.ecf.presence.search.IRestriction in project ecf by eclipse.

the class XMPPSearchTest method testRetrieveBuddiesNameFieldSync.

/**
 * Try to locate buddies on the XMPP server in a call block way
 *
 * @throws ContainerConnectException
 */
public void testRetrieveBuddiesNameFieldSync() 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*");
    // create a specific criteria
    try {
        ICriteria criteria = searchManager.createCriteria();
        assertNotNull(criteria);
        // criteria.add(searchCriterion);
        criteria.add(name);
        // call the block search
        ISearch search = searchManager.search(criteria);
        // the collection of IResult
        IResultList resultList = search.getResultList();
        int resultListSize = resultList.getResults().size();
        if (resultListSize == 0)
            System.out.println("XMPPSearchTest.testRetrieveBuddiesNameFieldSync...no email field retrieved");
        else
            assertTrue(1 == resultListSize);
    } catch (UserSearchException e) {
        e.printStackTrace();
    }
}
Also used : IRestriction(org.eclipse.ecf.presence.search.IRestriction) ISearch(org.eclipse.ecf.presence.search.ISearch) IResultList(org.eclipse.ecf.presence.search.IResultList) ICriterion(org.eclipse.ecf.presence.search.ICriterion) UserSearchException(org.eclipse.ecf.presence.search.UserSearchException) ICriteria(org.eclipse.ecf.presence.search.ICriteria)

Aggregations

ICriteria (org.eclipse.ecf.presence.search.ICriteria)4 ICriterion (org.eclipse.ecf.presence.search.ICriterion)4 IRestriction (org.eclipse.ecf.presence.search.IRestriction)4 IResultList (org.eclipse.ecf.presence.search.IResultList)3 ISearch (org.eclipse.ecf.presence.search.ISearch)3 UserSearchException (org.eclipse.ecf.presence.search.UserSearchException)3 Iterator (java.util.Iterator)1 ContainerConnectException (org.eclipse.ecf.core.ContainerConnectException)1 ECFException (org.eclipse.ecf.core.util.ECFException)1 IResult (org.eclipse.ecf.presence.search.IResult)1 IUserSearchCompleteEvent (org.eclipse.ecf.presence.search.IUserSearchCompleteEvent)1 IUserSearchEvent (org.eclipse.ecf.presence.search.IUserSearchEvent)1 IUserSearchListener (org.eclipse.ecf.presence.search.IUserSearchListener)1