Package org.apache.directory.server.core.api.filtering

Examples of org.apache.directory.server.core.api.filtering.EntryFilteringCursor


        searchRequest.setBase( REPL_CONSUMER_DN );
        searchRequest.setScope( SearchScope.ONELEVEL );
        searchRequest.setFilter( filter );
        searchRequest.addAttributes( SchemaConstants.ALL_ATTRIBUTES_ARRAY );

        EntryFilteringCursor cursor = adminSession.search( searchRequest );

        // Now loop on each consumer configuration
        while ( cursor.next() )
        {
            Entry entry = cursor.get();
            ReplicaEventLog replica = convertEntryToReplica( entry );
            replicas.add( replica );
        }

        cursor.close();

        // Now, we can return the list of replicas
        return replicas;
    }
View Full Code Here


            searchRequest.setScope( SearchScope.ONELEVEL );

            SearchOperationContext searchContext = new SearchOperationContext( deleteContext.getSession(),
                searchRequest );

            EntryFilteringCursor cursor = wrapped.search( searchContext );

            cursor.beforeFirst();
            int nbEntry = 0;

            while ( cursor.next() && ( nbEntry < 2 ) )
            {
                nbEntry++;
            }

            cursor.close();

            return nbEntry;
        }
        catch ( Exception e )
        {
View Full Code Here

        {
            int newId = messageId.incrementAndGet();

            searchRequest.setMessageId( newId );

            EntryFilteringCursor entryCursor = session.search( searchRequest );
            entryCursor.beforeFirst();

            //TODO enforce the size and time limits, similar in the way SearchHandler does
            return new EntryToResponseCursor( newId, entryCursor );
        }
        catch ( Exception e )
View Full Code Here

     * @throws Exception if there are problems while searching the directory
     */
    public static Entry findPrincipalEntry( CoreSession session, Dn searchBaseDn, String principal )
        throws Exception
    {
        EntryFilteringCursor cursor = null;

        try
        {
            SchemaManager schemaManager = session.getDirectoryService().getSchemaManager();
            cursor = session.search( searchBaseDn, SearchScope.SUBTREE,
                getFilter( schemaManager, principal ), AliasDerefMode.DEREF_ALWAYS, "*" );

            cursor.beforeFirst();

            if ( cursor.next() )
            {
                Entry entry = cursor.get();
                LOG.debug( "Found entry {} for kerberos principal name {}", entry.getDn(), principal );
                LOG_KRB.debug( "Found entry {} for kerberos principal name {}", entry.getDn(), principal );

                while ( cursor.next() )
                {
                    LOG.error( I18n.err( I18n.ERR_149, principal, cursor.next() ) );
                }

                return entry;
            }
            else
            {
                LOG.warn( "No server entry found for kerberos principal name {}", principal );
                LOG_KRB.warn( "No server entry found for kerberos principal name {}", principal );

                return null;
            }
        }
        finally
        {
            if ( cursor != null )
            {
                cursor.close();
            }
        }
    }
View Full Code Here

            searchRequest.addAttributes( "entryUuid" );

            System.out.println( "-----------> Dumping the server <-----------" );
            System.out.println( "-----------> Looking for " + entryDn.getNormName() + " <-----------" );

            EntryFilteringCursor cursor = session.search( searchRequest );

            while ( cursor.next() )
            {
                Entry entry = cursor.get();

                if ( entry.getDn().equals( entryDn ) )
                {
                    System.out.println( "The searched entry exists !!!" );
                    System.out.println( "found Entry " + entry.getDn().getNormName() + " exists, entrtyUuid = "
                        + entry.get( "entryUuid" ) );
                    continue;
                }

                System.out.println( "Entry " + entry.getDn().getNormName() + " exists, entrtyUuid = "
                    + entry.get( "entryUuid" ) );
            }

            cursor.close();

            System.out.println( "-----------> Dump done <-----------" );
        }
        catch ( Exception le )
        {
View Full Code Here

     * @throws Exception If the Dn is not valid or if the deletion failed
     */
    private void deleteRecursive( Dn rootDn, Map<Dn, EntryFilteringCursor> cursorMap ) throws Exception
    {
        LOG.debug( "searching for {}", rootDn.getName() );
        EntryFilteringCursor cursor = null;

        try
        {
            if ( cursorMap == null )
            {
View Full Code Here

        {
            Dn base = new Dn( "dc=example,dc=com" );
            SearchScope scope = SearchScope.SUBTREE;
            ExprNode exprNode = FilterParser.parse( getService().getSchemaManager(), "(objectClass=*)" );
            AliasDerefMode aliasDerefMode = AliasDerefMode.DEREF_ALWAYS;
            EntryFilteringCursor cursor = getService().getAdminSession()
                .search( base, scope, exprNode, aliasDerefMode );

            // advancing the cursor forward and backward must give the same result
            for ( int count = 1; count < 20; count++ )
            {
                cursor.beforeFirst();

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

                while ( nextResults.size() < count && cursor.next() )
                {
                    nextResults.add( cursor.get().getDn().getName() );
                }

                cursor.next();

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

                while ( cursor.previous() )
                {
                    prevResults.add( 0, cursor.get().getDn().getName() );
                }

                assertEquals( nextResults.size(), prevResults.size() );
                assertEquals( nextResults, prevResults );
            }

            cursor.close();
        }
        catch ( UnsupportedOperationException e )
        {
            LOG.warn( "Partition doesn't support next/previous test" );
        }
View Full Code Here

        {
            Dn base = new Dn( "dc=example,dc=com" );
            SearchScope scope = SearchScope.SUBTREE;
            ExprNode exprNode = FilterParser.parse( getService().getSchemaManager(), "(objectClass=*)" );
            AliasDerefMode aliasDerefMode = AliasDerefMode.DEREF_ALWAYS;
            EntryFilteringCursor cursor = getService().getAdminSession()
                .search( base, scope, exprNode, aliasDerefMode );

            // advancing the cursor backward and forward must give the same result
            for ( int count = 1; count < 20; count++ )
            {
                cursor.afterLast();

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

                while ( prevResults.size() < count && cursor.previous() )
                {
                    prevResults.add( cursor.get().getDn().getName() );
                }

                cursor.previous();

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

                while ( cursor.next() )
                {
                    nextResults.add( 0, cursor.get().getDn().getName() );
                }

                assertEquals( nextResults.size(), prevResults.size() );
                assertEquals( nextResults, prevResults );
            }

            cursor.close();
        }
        catch ( UnsupportedOperationException e )
        {
            LOG.warn( "Partition doesn't support previous/next test" );
        }
View Full Code Here

        throws Exception
    {
        List<String> nextResults = new ArrayList<String>();

        ExprNode exprNode = FilterParser.parse( getService().getSchemaManager(), filter );
        EntryFilteringCursor cursor = getService().getAdminSession().search( new Dn( base ), scope, exprNode,
            aliasDerefMode );
        cursor.beforeFirst();

        while ( cursor.next() )
        {
            nextResults.add( cursor.get().getDn().getName() );
        }

        try
        {
            List<String> prevResults = new ArrayList<String>();
            cursor.afterLast();

            while ( cursor.previous() )
            {
                prevResults.add( 0, cursor.get().getDn().getName() );
            }

            assertEquals( nextResults.size(), prevResults.size() );
            assertEquals( nextResults, prevResults );
        }
        catch ( UnsupportedOperationException e )
        {
            LOG.warn( "Partition doesn't support previous test" );
        }
        finally
        {
            cursor.close();
        }

        return nextResults;
    }
View Full Code Here

                    SearchScope.ONELEVEL,
                    FilterParser.parse( originalPartition.getSchemaManager(), "(objectClass=*)" ), attributeIds ); //$NON-NLS-1$
                soc.setAliasDerefMode( AliasDerefMode.DEREF_ALWAYS );

                // Looking for the children of the current entry
                EntryFilteringCursor cursor = originalPartition.search( soc );

                while ( cursor.next() )
                {
                    originalEntries.add( ( ( ClonedServerEntry ) cursor.get() ).getClonedEntry() );
                }
            }

            // Reversing the list to allow deletion of leafs first (otherwise we would be deleting
            // higher nodes with children first).
            // Order for modified entries does not matter.
            Collections.reverse( modifications );

            // Looking up the destination base entry
            Entry destinationBaseEntry = destinationPartition
                .lookup( new LookupOperationContext( null, baseDn, attributeIds ) );
            if ( destinationBaseEntry == null )
            {
                throw new PartitionsDiffException( "Unable to find the base entry in the destination partition." ); //$NON-NLS-1$
            }

            // Creating the list containing all the destination entries to be processed
            // and adding it the destination base entry
            List<Entry> destinationEntries = new ArrayList<Entry>();
            destinationEntries.add( originalBaseEntry );

            // Looping until all destination entries are being processed
            while ( destinationEntries.size() > 0 )
            {
                // Getting the first destination entry from the list
                Entry destinationEntry = destinationEntries.remove( 0 );

                // Looking for the equivalent entry in the destination partition
                Entry originalEntry = originalPartition.lookup( new LookupOperationContext( null, destinationEntry
                    .getDn(), attributeIds ) );
                // We're only looking for new entries, modified or removed
                // entries have already been computed
                if ( originalEntry == null )
                {
                    // Creating a modification entry to hold all modifications
                    LdifEntry modificationEntry = new LdifEntry();
                    modificationEntry.setDn( destinationEntry.getDn() );

                    // Setting the changetype to addition
                    modificationEntry.setChangeType( ChangeType.Add );

                    // Copying attributes
                    for ( Attribute attribute : destinationEntry )
                    {
                        modificationEntry.addAttribute( attribute );
                    }

                    // Adding the modification entry to the list
                    modifications.add( modificationEntry );
                }

                // Creating a search operation context to get the children of the current entry
                SearchOperationContext soc = new SearchOperationContext( null, destinationEntry.getDn(),
                    SearchScope.ONELEVEL,
                    FilterParser.parse( originalPartition.getSchemaManager(), "(objectClass=*)" ), attributeIds ); //$NON-NLS-1$
                soc.setAliasDerefMode( AliasDerefMode.DEREF_ALWAYS );

                // Looking for the children of the current entry
                EntryFilteringCursor cursor = destinationPartition.search( soc );

                while ( cursor.next() )
                {
                    destinationEntries.add( ( ( ClonedServerEntry ) cursor.get() ).getClonedEntry() );
                }
            }
        }
        catch ( Exception e )
        {
View Full Code Here

TOP

Related Classes of org.apache.directory.server.core.api.filtering.EntryFilteringCursor

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.