Package org.apache.directory.api.ldap.model.cursor

Examples of org.apache.directory.api.ldap.model.cursor.SearchCursor


        req.setTimeLimit(config.getSearchTimeout());
        req.setBase(new Dn(idConfig.getBaseDN()));
        req.setFilter(searchFilter);

        // Process the request
        SearchCursor searchCursor = connection.search(req);
        while (searchCursor.next()) {
            Response response = searchCursor.get();

            // process the SearchResultEntry
            if (response instanceof SearchResultEntry) {
                Entry resultEntry = ((SearchResultEntry) response).getEntry();
                if (searchCursor.next()) {
                    log.warn("search for {} returned more than one entry. discarding additional ones.", searchFilter);
                }
                if (log.isDebugEnabled()) {
                    log.debug("search below {} with {} found {}",
                            new Object[]{idConfig.getBaseDN(), searchFilter, resultEntry.getDn()});
View Full Code Here


            Map<String, ExternalIdentityRef> groups = new HashMap<String, ExternalIdentityRef>();
            DebugTimer timer = new DebugTimer();
            connection = connect();
            timer.mark("connect");

            SearchCursor searchCursor = connection.search(req);
            timer.mark("search");
            while (searchCursor.next()) {
                Response response = searchCursor.get();
                if (response instanceof SearchResultEntry) {
                    Entry resultEntry = ((SearchResultEntry) response).getEntry();
                    ExternalIdentityRef groupRef = new ExternalIdentityRef(resultEntry.getDn().toString(), this.getName());
                    groups.put(groupRef.getId(), groupRef);
                }
View Full Code Here

    public void testWithInvalidAttributeAndCriticality() throws Exception
    {
        sk.setAttributeTypeDesc( "Non-existing-At" );
        ctrl.setCritical( true );

        SearchCursor cursor = con.search( req );
        assertFalse( cursor.next() );

        SearchResultDone sd = cursor.getSearchResultDone();

        cursor.close();

        SortResponse resp = ( SortResponse ) sd.getControl( SortResponse.OID );
        assertNotNull( resp );

        assertEquals( SortResultCode.NOSUCHATTRIBUTE, resp.getSortResult() );
View Full Code Here

    public void testWithInvalidAttributeAndNoCriticality() throws Exception
    {
        sk.setAttributeTypeDesc( "Non-existing-At" );
        ctrl.setCritical( false );

        SearchCursor cursor = con.search( req );

        int count = 0;

        while ( cursor.next() )
        {
            cursor.get();
            count++;
        }

        cursor.close();

        assertEquals( 14, count );

        SearchResultDone sd = cursor.getSearchResultDone();

        SortResponse resp = ( SortResponse ) sd.getControl( SortResponse.OID );
        assertNotNull( resp );

        assertEquals( SortResultCode.NOSUCHATTRIBUTE, resp.getSortResult() );
View Full Code Here

    @Test
    public void testWithInvalidFilter() throws Exception
    {
        req.setFilter( new PresenceNode( "mail" ) );

        SearchCursor cursor = con.search( req );

        assertFalse( cursor.next() );

        cursor.close();

        SearchResultDone sd = cursor.getSearchResultDone();

        SortResponse resp = ( SortResponse ) sd.getControl( SortResponse.OID );
        assertNull( resp );

        assertEquals( ResultCodeEnum.SUCCESS, sd.getLdapResult().getResultCode() );
View Full Code Here

    @Test
    public void testSortBySn() throws Exception
    {
        sk.setAttributeTypeDesc( "sn" );
        SearchCursor cursor = con.search( req );

        List<String> expectedOrder = new ArrayList<String>();
        expectedOrder.add( "uid=person1,ou=parent,ou=system" );
        expectedOrder.add( "uid=person2,ou=parent,ou=system" );
        expectedOrder.add( "uid=person3,ou=parent,ou=system" );
        expectedOrder.add( "uid=user0,ou=parent,ou=system" );
        expectedOrder.add( "uid=user1,ou=parent,ou=system" );
        expectedOrder.add( "uid=user2,ou=children,ou=parent,ou=system" );
        expectedOrder.add( "uid=user3,ou=children,ou=parent,ou=system" );
        expectedOrder.add( "uid=user4,ou=grandchildren,ou=children,ou=parent,ou=system" );
        expectedOrder.add( "uid=user5,ou=grandchildren,ou=children,ou=parent,ou=system" );
        expectedOrder.add( "uid=user6,ou=parent,ou=system" );
        expectedOrder.add( "uid=user7,ou=parent,ou=system" );

        int expectedCount = expectedOrder.size();

        List<String> actualOrder = new ArrayList<String>();

        while ( cursor.next() )
        {
            SearchResultEntry se = ( SearchResultEntry ) cursor.get();
            Entry entry = se.getEntry();
            actualOrder.add( entry.getDn().getName() );
        }

        cursor.close();

        // remove the LAST 3 entries present in the actualOrder list, they exist on top cause they don't have "sn" attribute
        // NOTE: there is no guaranteed order for these LAST 3 entries
        actualOrder.remove( actualOrder.size() - 1 );
        actualOrder.remove( actualOrder.size() - 1 );
        actualOrder.remove( actualOrder.size() - 1 );

        assertEquals( expectedCount, actualOrder.size() );

        for ( int i = 0; i < expectedOrder.size(); i++ )
        {
            assertEquals( expectedOrder.get( i ), actualOrder.get( i ) );
        }

        // check reverse order
        actualOrder.clear();

        sk.setReverseOrder( true );
        cursor = con.search( req );

        while ( cursor.next() )
        {
            SearchResultEntry se = ( SearchResultEntry ) cursor.get();
            Entry entry = se.getEntry();
            actualOrder.add( entry.getDn().getName() );
        }

        cursor.close();

        // remove the FIRST 3 entries present in the actualOrder list, they exist on top cause they don't have "sn" attribute
        // NOTE: there is no guaranteed order for these FIRST 3 entries
        actualOrder.remove( 0 );
        actualOrder.remove( 0 );
View Full Code Here

    // so using "cn" for this test
    @Test
    public void testSortByMultiValuedAttribute() throws Exception
    {
        sk.setAttributeTypeDesc( "cn" );
        SearchCursor cursor = con.search( req );

        List<String> expectedOrder = new ArrayList<String>();
        expectedOrder.add( "uid=user6,ou=parent,ou=system" );
        expectedOrder.add( "uid=user0,ou=parent,ou=system" );
        expectedOrder.add( "uid=user1,ou=parent,ou=system" );
        expectedOrder.add( "uid=person3,ou=parent,ou=system" );
        expectedOrder.add( "uid=user2,ou=children,ou=parent,ou=system" );
        expectedOrder.add( "uid=user3,ou=children,ou=parent,ou=system" );
        expectedOrder.add( "uid=user4,ou=grandchildren,ou=children,ou=parent,ou=system" );
        expectedOrder.add( "uid=user5,ou=grandchildren,ou=children,ou=parent,ou=system" );
        expectedOrder.add( "uid=user7,ou=parent,ou=system" );
        expectedOrder.add( "uid=person1,ou=parent,ou=system" );
        expectedOrder.add( "uid=person2,ou=parent,ou=system" );

        int expectedCount = expectedOrder.size();

        List<String> actualOrder = new ArrayList<String>();

        while ( cursor.next() )
        {
            SearchResultEntry se = ( SearchResultEntry ) cursor.get();
            Entry entry = se.getEntry();
            actualOrder.add( entry.getDn().getName() );
        }

        cursor.close();

        // remove the LAST 3 entries present in the actualOrder list, they exist on top cause they don't have "sn" attribute
        // NOTE: there is no guaranteed order for these LAST 3 entries
        actualOrder.remove( actualOrder.size() - 1 );
        actualOrder.remove( actualOrder.size() - 1 );
        actualOrder.remove( actualOrder.size() - 1 );

        assertEquals( expectedCount, actualOrder.size() );

        for ( int i = 0; i < expectedOrder.size(); i++ )
        {
            assertEquals( expectedOrder.get( i ), actualOrder.get( i ) );
        }

        // check reverse order
        actualOrder.clear();

        sk.setReverseOrder( true );
        cursor = con.search( req );

        while ( cursor.next() )
        {
            SearchResultEntry se = ( SearchResultEntry ) cursor.get();
            Entry entry = se.getEntry();
            actualOrder.add( entry.getDn().getName() );
        }

        cursor.close();

        // remove the FIRST 3 entries present in the actualOrder list, they exist on top cause they don't have "sn" attribute
        // NOTE: there is no guaranteed order for these FIRST 3 entries
        actualOrder.remove( 0 );
        actualOrder.remove( 0 );
View Full Code Here

    @Test
    public void testSortByDn() throws Exception
    {
        sk.setAttributeTypeDesc( "entryDn" );
        sk.setMatchingRuleId( "2.5.13.1" );
        SearchCursor cursor = con.search( req );

        List<Entry> actualOrder = new ArrayList<Entry>();

        while ( cursor.next() )
        {
            SearchResultEntry se = ( SearchResultEntry ) cursor.get();
            Entry entry = se.getEntry();
            actualOrder.add( entry );
        }

        cursor.close();
       
        // start deleting from the first entry
        // SHOULD succeeded if the order is as expected
        for( int i = 0; i < actualOrder.size(); i++ )
        {
            con.delete( actualOrder.get( i ).getDn() );
        }
       
        // now insert from the last entry, SHOULD succeed
        for( int i = actualOrder.size() - 1; i >= 0; i-- )
        {
            con.add( actualOrder.get( i ) );
        }
       
        actualOrder.clear();

        sk.setReverseOrder( true );
        cursor = con.search( req );
       
        while ( cursor.next() )
        {
            SearchResultEntry se = ( SearchResultEntry ) cursor.get();
            Entry entry = se.getEntry();
            actualOrder.add( entry );
        }

        // now delete again, this time from the end, SHOULD succeed
View Full Code Here

                t00 = System.currentTimeMillis();
            }

            searchRequest.setFilter( "(cn=user" + random.nextInt( 100000 ) + ")" );

            SearchCursor cursor = connection.search( searchRequest );

            while ( cursor.next() )
            {
                count++;
                cursor.getEntry();
            }

            cursor.close();
        }

        long t1 = System.currentTimeMillis();

        Long deltaWarmed = ( t1 - t00 );
View Full Code Here

    public void testSimpleSearchWithControl() throws Exception
    {
        SearchRequest searchRequest = new SearchRequestImpl().setBase( new Dn( "ou=system" ) )
            .setFilter( "(objectclass=*)" )
            .setScope( SearchScope.ONELEVEL ).addControl( new ManageDsaITImpl() );
        SearchCursor cursor = connection.search( searchRequest );
        int count = 0;
   
        while ( cursor.next() )
        {
            Response response = cursor.get();
            assertNotNull( response );
   
            if ( response instanceof SearchResultEntry )
            {
                Entry entry = ( ( SearchResultEntry ) response ).getEntry();
                assertNotNull( entry );
            }
   
            count++;
        }
   
        SearchResultDone done = cursor.getSearchResultDone();
   
        assertNotNull( done );
        assertEquals( ResultCodeEnum.SUCCESS, done.getLdapResult().getResultCode() );
        assertEquals( 5, count );
        cursor.close();
    }
View Full Code Here

TOP

Related Classes of org.apache.directory.api.ldap.model.cursor.SearchCursor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.