Search in sources :

Example 1 with IResultList

use of org.eclipse.ecf.presence.search.IResultList 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 IResultList

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

the class XMPPUserSearchManager method createResultList.

/**
 * Create a result list from ReportedData. Identify dynamically columns and
 * rows and create users adding it to a {@link IResultList}
 *
 * @param data
 *            ReportedData
 * @return {@link IResultList} a list of users
 * @throws
 */
protected IResultList createResultList(ReportedData data) {
    ResultList result = new ResultList();
    Iterator rows = data.getRows();
    while (rows.hasNext()) {
        Row row = (Row) rows.next();
        Iterator jids = row.getValues(JID);
        Iterator names = row.getValues(NAME);
        String jid = null;
        String name = null;
        // XMPP server returns the same length for both
        while (jids.hasNext() && names.hasNext()) {
            try {
                jid = (String) jids.next();
                name = (String) names.next();
                IUser user = new User(new XMPPID(connectNamespace, jid), name);
                result.add(new XMPPResultItem(user));
            } catch (URISyntaxException e) {
                throw new RuntimeException(// $NON-NLS-1$
                "cannot create connect id for client " + jid + " , name = " + name, // $NON-NLS-1$
                e);
            }
        }
    }
    return result;
}
Also used : IResultList(org.eclipse.ecf.presence.search.IResultList) ResultList(org.eclipse.ecf.presence.search.ResultList) User(org.eclipse.ecf.core.user.User) IUser(org.eclipse.ecf.core.user.IUser) Iterator(java.util.Iterator) IUser(org.eclipse.ecf.core.user.IUser) Row(org.jivesoftware.smackx.ReportedData.Row) URISyntaxException(java.net.URISyntaxException) XMPPID(org.eclipse.ecf.provider.xmpp.identity.XMPPID)

Example 3 with IResultList

use of org.eclipse.ecf.presence.search.IResultList 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);
    }
}
Also used : IResultList(org.eclipse.ecf.presence.search.IResultList) ResultList(org.eclipse.ecf.presence.search.ResultList) Form(org.jivesoftware.smackx.Form) IResultList(org.eclipse.ecf.presence.search.IResultList) ECFException(org.eclipse.ecf.core.util.ECFException) Iterator(java.util.Iterator) IResultList(org.eclipse.ecf.presence.search.IResultList) List(java.util.List) ResultList(org.eclipse.ecf.presence.search.ResultList) XMPPException(org.jivesoftware.smack.XMPPException) ICriterion(org.eclipse.ecf.presence.search.ICriterion) UserSearchException(org.eclipse.ecf.presence.search.UserSearchException) ReportedData(org.jivesoftware.smackx.ReportedData)

Example 4 with IResultList

use of org.eclipse.ecf.presence.search.IResultList 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 5 with IResultList

use of org.eclipse.ecf.presence.search.IResultList 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

IResultList (org.eclipse.ecf.presence.search.IResultList)5 ICriterion (org.eclipse.ecf.presence.search.ICriterion)4 UserSearchException (org.eclipse.ecf.presence.search.UserSearchException)4 Iterator (java.util.Iterator)3 ICriteria (org.eclipse.ecf.presence.search.ICriteria)3 IRestriction (org.eclipse.ecf.presence.search.IRestriction)3 ISearch (org.eclipse.ecf.presence.search.ISearch)3 ECFException (org.eclipse.ecf.core.util.ECFException)2 ResultList (org.eclipse.ecf.presence.search.ResultList)2 URISyntaxException (java.net.URISyntaxException)1 List (java.util.List)1 ContainerConnectException (org.eclipse.ecf.core.ContainerConnectException)1 IUser (org.eclipse.ecf.core.user.IUser)1 User (org.eclipse.ecf.core.user.User)1 IResult (org.eclipse.ecf.presence.search.IResult)1 XMPPID (org.eclipse.ecf.provider.xmpp.identity.XMPPID)1 XMPPException (org.jivesoftware.smack.XMPPException)1 Form (org.jivesoftware.smackx.Form)1 ReportedData (org.jivesoftware.smackx.ReportedData)1 Row (org.jivesoftware.smackx.ReportedData.Row)1