Package org.apache.directory.ldapstudio.browser.core.model

Examples of org.apache.directory.ldapstudio.browser.core.model.SearchParameter


                else
                {
                    if ( this.rootDSE.getAttribute( IRootDSE.ROOTDSE_ATTRIBUTE_SUBSCHEMASUBENTRY ) != null )
                    {
                        // check if schema is up-to-date
                        SearchParameter sp = new SearchParameter();
                        sp.setSearchBase( new DN( this.rootDSE.getAttribute(
                            IRootDSE.ROOTDSE_ATTRIBUTE_SUBSCHEMASUBENTRY ).getStringValue() ) );
                        sp.setFilter( Schema.SCHEMA_FILTER );
                        sp.setScope( ISearch.SCOPE_OBJECT );
                        sp.setReturningAttributes( new String[]
                            { IAttribute.OPERATIONAL_ATTRIBUTE_CREATE_TIMESTAMP,
                                IAttribute.OPERATIONAL_ATTRIBUTE_MODIFY_TIMESTAMP, } );
                        ISearch search = new Search( this, sp );
                        // ISearch search = new Search(null, this, new
                        // DN(this.rootDSE.getAttribute("subschemaSubentry").getStringValue()),
View Full Code Here


        try
        {

            if ( this.rootDSE.getAttribute( IRootDSE.ROOTDSE_ATTRIBUTE_SUBSCHEMASUBENTRY ) != null )
            {
                SearchParameter sp = new SearchParameter();
                sp.setSearchBase( new DN( this.rootDSE.getAttribute( IRootDSE.ROOTDSE_ATTRIBUTE_SUBSCHEMASUBENTRY )
                    .getStringValue() ) );
                sp.setFilter( Schema.SCHEMA_FILTER );
                sp.setScope( ISearch.SCOPE_OBJECT );
                sp.setReturningAttributes( new String[]
                    { Schema.SCHEMA_ATTRIBUTE_OBJECTCLASSES, Schema.SCHEMA_ATTRIBUTE_ATTRIBUTETYPES,
                        Schema.SCHEMA_ATTRIBUTE_LDAPSYNTAXES, Schema.SCHEMA_ATTRIBUTE_MATCHINGRULES,
                        Schema.SCHEMA_ATTRIBUTE_MATCHINGRULEUSE, IAttribute.OPERATIONAL_ATTRIBUTE_CREATE_TIMESTAMP,
                        IAttribute.OPERATIONAL_ATTRIBUTE_MODIFY_TIMESTAMP, } );
                LdifEnumeration le = this.connectionProvider.search( sp, monitor );
View Full Code Here

    {
        this.connection = conn;
        this.searchResults = null;
        this.countLimitExceeded = false;

        this.searchParameter = new SearchParameter();
        this.searchParameter.setName( searchName );
        this.searchParameter.setSearchBase( searchBase );
        this.searchParameter.setFilter( filter );
        this.searchParameter.setReturningAttributes( returningAttributes );
        this.searchParameter.setScope( scope );
View Full Code Here

            int numberInBatch;
            do
            {
                numberInBatch = 0;

                SearchParameter subParam = new SearchParameter();
                subParam.setSearchBase( entry.getDn() );
                subParam.setFilter( ISearch.FILTER_TRUE );
                subParam.setScope( ISearch.SCOPE_ONELEVEL );
                subParam.setAliasesDereferencingMethod( IConnection.DEREFERENCE_ALIASES_NEVER );
                subParam.setReferralsHandlingMethod( IConnection.HANDLE_REFERRALS_IGNORE );
                subParam.setReturningAttributes( new String[]
                    { IAttribute.OBJECTCLASS_ATTRIBUTE, IAttribute.REFERRAL_ATTRIBUTE } );
                subParam.setCountLimit( 100 );
                ISearch search = new Search( entry.getConnection(), subParam );
                entry.getConnection().search( search, monitor );

                ISearchResult[] srs = search.getSearchResults();
                for ( int i = 0; !monitor.isCanceled() && srs != null && i < srs.length; i++ )
                {
                    IEntry childEntry = srs[i].getEntry();
                    numberOfDeletedEntries = this.deleteEntryRecursive( childEntry, true, numberOfDeletedEntries,
                        monitor );
                    numberInBatch++;
                }
            }
            while ( numberInBatch > 0 && !monitor.isCanceled() && !monitor.errorsReported() );

            if ( !monitor.isCanceled() && !monitor.errorsReported() )
            {

                // check for referrals
                if ( !refInitialized )
                {
                    SearchParameter param = new SearchParameter();
                    param.setSearchBase( entry.getDn() );
                    param.setFilter( ISearch.FILTER_TRUE );
                    param.setScope( ISearch.SCOPE_OBJECT );
                    param.setAliasesDereferencingMethod( IConnection.DEREFERENCE_ALIASES_NEVER );
                    param.setReferralsHandlingMethod( IConnection.HANDLE_REFERRALS_IGNORE );
                    param.setReturningAttributes( new String[]
                        { IAttribute.OBJECTCLASS_ATTRIBUTE, IAttribute.REFERRAL_ATTRIBUTE } );
                    ISearch search = new Search( entry.getConnection(), param );
                    entry.getConnection().search( search, monitor );

                    ISearchResult[] srs = search.getSearchResults();
View Full Code Here

    }


    boolean existsEntry( DN dn, ExtendedProgressMonitor monitor )
    {
        SearchParameter sp = new SearchParameter();
        sp.setSearchBase( dn );
        sp.setFilter( ISearch.FILTER_TRUE );
        sp.setScope( ISearch.SCOPE_OBJECT );
        sp.setReturningAttributes( ISearch.NO_ATTRIBUTES );

        try
        {
            LdifEnumeration le = connection.connectionProvider.search( sp, monitor );
            return le.hasNext( monitor );
View Full Code Here

            if ( !monitor.isCanceled() )
            {

                // add returning attributes for children and alias detection
                SearchParameter searchParameter = getSearchParameter( search );
                ArrayList searchResultList = new ArrayList();

                try
                {
View Full Code Here

    }


    private SearchParameter getSearchParameter( ISearch search )
    {
        SearchParameter searchParameter = ( SearchParameter ) search.getSearchParameter().clone();

        // add children detetion attributes
        if ( search.isInitHasChildrenFlag() )
        {
            if ( search.getConnection().getSchema().hasAttributeTypeDescription(
                IAttribute.OPERATIONAL_ATTRIBUTE_HAS_SUBORDINATES )
                && !Utils.containsIgnoreCase( Arrays.asList( searchParameter.getReturningAttributes() ),
                    IAttribute.OPERATIONAL_ATTRIBUTE_HAS_SUBORDINATES ) )
            {
                String[] returningAttributes = new String[searchParameter.getReturningAttributes().length + 1];
                System.arraycopy( searchParameter.getReturningAttributes(), 0, returningAttributes, 0, searchParameter
                    .getReturningAttributes().length );
                returningAttributes[returningAttributes.length - 1] = IAttribute.OPERATIONAL_ATTRIBUTE_HAS_SUBORDINATES;
                searchParameter.setReturningAttributes( returningAttributes );
            }
            else if ( search.getConnection().getSchema().hasAttributeTypeDescription(
                IAttribute.OPERATIONAL_ATTRIBUTE_NUM_SUBORDINATES )
                && !Utils.containsIgnoreCase( Arrays.asList( searchParameter.getReturningAttributes() ),
                    IAttribute.OPERATIONAL_ATTRIBUTE_NUM_SUBORDINATES ) )
            {
                String[] returningAttributes = new String[searchParameter.getReturningAttributes().length + 1];
                System.arraycopy( searchParameter.getReturningAttributes(), 0, returningAttributes, 0, searchParameter
                    .getReturningAttributes().length );
                returningAttributes[returningAttributes.length - 1] = IAttribute.OPERATIONAL_ATTRIBUTE_NUM_SUBORDINATES;
                searchParameter.setReturningAttributes( returningAttributes );
            }
            else if ( search.getConnection().getSchema().hasAttributeTypeDescription(
                IAttribute.OPERATIONAL_ATTRIBUTE_SUBORDINATE_COUNT )
                && !Utils.containsIgnoreCase( Arrays.asList( searchParameter.getReturningAttributes() ),
                    IAttribute.OPERATIONAL_ATTRIBUTE_SUBORDINATE_COUNT ) )
            {
                String[] returningAttributes = new String[searchParameter.getReturningAttributes().length + 1];
                System.arraycopy( searchParameter.getReturningAttributes(), 0, returningAttributes, 0, searchParameter
                    .getReturningAttributes().length );
                returningAttributes[returningAttributes.length - 1] = IAttribute.OPERATIONAL_ATTRIBUTE_SUBORDINATE_COUNT;
                searchParameter.setReturningAttributes( returningAttributes );
            }
        }

        // to init the alias/referral flag we need the objectClass
        if ( search.isInitAliasAndReferralFlag() )
        {
            if ( !Utils.containsIgnoreCase( Arrays.asList( searchParameter.getReturningAttributes() ),
                IAttribute.OBJECTCLASS_ATTRIBUTE ) )
            {
                String[] returningAttributes = new String[searchParameter.getReturningAttributes().length + 1];
                System.arraycopy( searchParameter.getReturningAttributes(), 0, returningAttributes, 0, searchParameter
                    .getReturningAttributes().length );
                returningAttributes[returningAttributes.length - 1] = IAttribute.OBJECTCLASS_ATTRIBUTE;
                searchParameter.setReturningAttributes( returningAttributes );
            }
        }

        // if returning attributes are requested but objectClass isn't included
        // then add it
        if ( search.getReturningAttributes() == null || search.getReturningAttributes().length > 0 )
        {
            if ( !Utils.containsIgnoreCase( Arrays.asList( searchParameter.getReturningAttributes() ),
                IAttribute.OBJECTCLASS_ATTRIBUTE ) )
            {
                String[] returningAttributes = new String[searchParameter.getReturningAttributes().length + 1];
                System.arraycopy( searchParameter.getReturningAttributes(), 0, returningAttributes, 0, searchParameter
                    .getReturningAttributes().length );
                returningAttributes[returningAttributes.length - 1] = IAttribute.OBJECTCLASS_ATTRIBUTE;
                searchParameter.setReturningAttributes( returningAttributes );
            }
        }

        // filter controls if not supported by server
        if ( searchParameter.getControls() != null )
        {

            Set suppportedConrolSet = new HashSet();
            if ( connection.getRootDSE() != null
                && connection.getRootDSE().getAttribute( IRootDSE.ROOTDSE_ATTRIBUTE_SUPPORTEDCONTROL ) != null )
            {
                IAttribute scAttribute = connection.getRootDSE().getAttribute(
                    IRootDSE.ROOTDSE_ATTRIBUTE_SUPPORTEDCONTROL );
                String[] supportedControls = scAttribute.getStringValues();
                for ( int i = 0; i < supportedControls.length; i++ )
                {
                    suppportedConrolSet.add( supportedControls[i].toLowerCase() );
                }
            }

            Control[] controls = searchParameter.getControls();
            List controlList = new ArrayList();
            for ( int i = 0; i < controls.length; i++ )
            {
                if ( suppportedConrolSet.contains( controls[i].getOid().toLowerCase() ) )
                {
                    controlList.add( controls[i] );
                }
            }
            searchParameter.setControls( ( Control[] ) controlList.toArray( new Control[controlList.size()] ) );
        }

        return searchParameter;
    }
View Full Code Here

    private int copyEntryRecursive( IEntry entryToCopy, IEntry parent, int scope, int num,
        ExtendedProgressMonitor monitor )
    {
        try
        {
            SearchParameter param = new SearchParameter();
            param.setSearchBase( entryToCopy.getDn() );
            param.setFilter( ISearch.FILTER_TRUE );
            param.setScope( ISearch.SCOPE_OBJECT );
            param.setAliasesDereferencingMethod( IConnection.DEREFERENCE_ALIASES_NEVER );
            param.setReferralsHandlingMethod( IConnection.HANDLE_REFERRALS_IGNORE );
            param.setReturningAttributes( new String[]
                { ISearch.ALL_USER_ATTRIBUTES, IAttribute.REFERRAL_ATTRIBUTE } );
            ISearch search = new Search( entryToCopy.getConnection(), param );
            entryToCopy.getConnection().search( search, monitor );

            ISearchResult[] srs = search.getSearchResults();
            if ( !monitor.isCanceled() && srs != null && srs.length == 1 )
            {
                entryToCopy = srs[0].getEntry();
                IAttribute[] attributesToCopy = entryToCopy.getAttributes();

                // create new entry
                RDN rdn = entryToCopy.getRdn();
                IEntry newEntry = new Entry( parent, rdn );

                // change RDN if entry already exists
                ExtendedProgressMonitor testMonitor = new ExtendedProgressMonitor( monitor );
                IEntry testEntry = parent.getConnection().getEntry( newEntry.getDn(), testMonitor );
                if ( testEntry != null )
                {
                    String rdnValue = rdn.getValue();
                    String newRdnValue = BrowserCoreMessages.bind( BrowserCoreMessages.copy_n_of_s, "", rdnValue ); //$NON-NLS-1$
                    RDN newRdn = getNewRdn( rdn, newRdnValue );
                    newEntry = new Entry( parent, newRdn );
                    testEntry = parent.getConnection().getEntry( newEntry.getDn(), testMonitor );
                    for ( int i = 2; testEntry != null; i++ )
                    {
                        newRdnValue = BrowserCoreMessages.bind( BrowserCoreMessages.copy_n_of_s, i + " ", rdnValue ); //$NON-NLS-1$
                        newRdn = getNewRdn( rdn, newRdnValue );
                        newEntry = new Entry( parent, newRdn );
                        testEntry = parent.getConnection().getEntry( newEntry.getDn(), testMonitor );
                    }
                }

                // copy attributes
                for ( int i = 0; i < attributesToCopy.length; i++ )
                {
                    IAttribute attributeToCopy = attributesToCopy[i];

                    if ( SchemaUtils.isModifyable( attributeToCopy.getAttributeTypeDescription() )
                        || IAttribute.REFERRAL_ATTRIBUTE.equalsIgnoreCase( attributeToCopy.getDescription() ) )
                    {
                        IAttribute newAttribute = new Attribute( newEntry, attributeToCopy.getDescription() );
                        newEntry.addAttribute( newAttribute );
                        IValue[] valuesToCopy = attributeToCopy.getValues();
                        for ( int j = 0; j < valuesToCopy.length; j++ )
                        {
                            IValue valueToCopy = valuesToCopy[j];
                            IValue newValue = new Value( newAttribute, valueToCopy.getRawValue() );
                            newAttribute.addValue( newValue );
                        }
                    }
                }

                // check if RDN attributes ar present
                RDN newRdn = newEntry.getRdn();
                RDNPart[] oldRdnParts = rdn.getParts();
                for ( int i = 0; i < oldRdnParts.length; i++ )
                {
                    RDNPart part = oldRdnParts[i];
                    IAttribute rdnAttribute = newEntry.getAttribute( part.getType() );
                    if ( rdnAttribute != null )
                    {
                        IValue[] values = rdnAttribute.getValues();
                        for ( int ii = 0; ii < values.length; ii++ )
                        {
                            if ( part.getUnencodedValue().equals( values[ii].getRawValue() ) )
                            {
                                rdnAttribute.deleteValue( values[ii] );
                            }
                            if ( rdnAttribute.getValueSize() == 0 )
                            {
                                newEntry.deleteAttribute( rdnAttribute );
                            }
                        }
                    }
                }
                RDNPart[] newRdnParts = newRdn.getParts();
                for ( int i = 0; i < newRdnParts.length; i++ )
                {
                    RDNPart part = newRdnParts[i];
                    IAttribute rdnAttribute = newEntry.getAttribute( part.getType() );
                    if ( rdnAttribute == null )
                    {
                        rdnAttribute = new Attribute( newEntry, part.getType() );
                        newEntry.addAttribute( rdnAttribute );
                        rdnAttribute.addValue( new Value( rdnAttribute, part.getUnencodedValue() ) );
                    }
                    else
                    {
                        boolean mustAdd = true;
                        IValue[] values = rdnAttribute.getValues();
                        for ( int ii = 0; ii < values.length; ii++ )
                        {
                            if ( part.getUnencodedValue().equals( values[ii].getStringValue() ) )
                            {
                                mustAdd = false;
                                break;
                            }
                        }
                        if ( mustAdd )
                        {
                            rdnAttribute.addValue( new Value( rdnAttribute, part.getUnencodedValue() ) );
                        }
                    }
                }

                newEntry.getConnection().create( newEntry, monitor );
                newEntry.getParententry().addChild( newEntry );
                newEntry.setHasChildrenHint( false );

                num++;
                monitor.reportProgress( BrowserCoreMessages.bind( BrowserCoreMessages.model__copied_n_entries,
                    new String[]
                        { Integer.toString( num ) } ) );

                // check for children
                if ( !monitor.isCanceled() && ( scope == ISearch.SCOPE_ONELEVEL || scope == ISearch.SCOPE_SUBTREE ) )
                {

                    SearchParameter subParam = new SearchParameter();
                    subParam.setSearchBase( entryToCopy.getDn() );
                    subParam.setFilter( ISearch.FILTER_TRUE );
                    subParam.setScope( ISearch.SCOPE_ONELEVEL );
                    subParam.setReturningAttributes( ISearch.NO_ATTRIBUTES );
                    ISearch subSearch = new Search( entryToCopy.getConnection(), subParam );
                    entryToCopy.getConnection().search( subSearch, monitor );

                    ISearchResult[] subSrs = subSearch.getSearchResults();
                    if ( !monitor.isCanceled() && subSrs != null && subSrs.length > 0 )
View Full Code Here

            int numberInBatch;
            do
            {
                numberInBatch = 0;

                SearchParameter subParam = new SearchParameter();
                subParam.setSearchBase( entry.getDn() );
                subParam.setFilter( ISearch.FILTER_TRUE );
                subParam.setScope( ISearch.SCOPE_ONELEVEL );
                subParam.setAliasesDereferencingMethod( IConnection.DEREFERENCE_ALIASES_NEVER );
                subParam.setReferralsHandlingMethod( IConnection.HANDLE_REFERRALS_IGNORE );
                subParam.setReturningAttributes( new String[]
                    { IAttribute.OBJECTCLASS_ATTRIBUTE, IAttribute.REFERRAL_ATTRIBUTE } );
                subParam.setCountLimit( 100 );
                ISearch search = new Search( entry.getConnection(), subParam );
                entry.getConnection().search( search, monitor );

                ISearchResult[] srs = search.getSearchResults();
                for ( int i = 0; !monitor.isCanceled() && srs != null && i < srs.length; i++ )
                {
                    IEntry childEntry = srs[i].getEntry();
                    numberOfDeletedEntries = this.deleteEntryRecursive( childEntry, true, numberOfDeletedEntries,
                        monitor );
                    numberInBatch++;
                }
            }
            while ( numberInBatch > 0 && !monitor.isCanceled() && !monitor.errorsReported() );

            if ( !monitor.isCanceled() && !monitor.errorsReported() )
            {

                // check for referrals
                if ( !refInitialized )
                {
                    SearchParameter param = new SearchParameter();
                    param.setSearchBase( entry.getDn() );
                    param.setFilter( ISearch.FILTER_TRUE );
                    param.setScope( ISearch.SCOPE_OBJECT );
                    param.setAliasesDereferencingMethod( IConnection.DEREFERENCE_ALIASES_NEVER );
                    param.setReferralsHandlingMethod( IConnection.HANDLE_REFERRALS_IGNORE );
                    param.setReturningAttributes( new String[]
                        { IAttribute.OBJECTCLASS_ATTRIBUTE, IAttribute.REFERRAL_ATTRIBUTE } );
                    ISearch search = new Search( entry.getConnection(), param );
                    entry.getConnection().search( search, monitor );

                    ISearchResult[] srs = search.getSearchResults();
View Full Code Here

    }


    boolean existsEntry( DN dn, ExtendedProgressMonitor monitor )
    {
        SearchParameter sp = new SearchParameter();
        sp.setSearchBase( dn );
        sp.setFilter( ISearch.FILTER_TRUE );
        sp.setScope( ISearch.SCOPE_OBJECT );
        sp.setReturningAttributes( ISearch.NO_ATTRIBUTES );

        try
        {
            LdifEnumeration le = connection.connectionProvider.search( sp, monitor );
            return le.hasNext( monitor );
View Full Code Here

TOP

Related Classes of org.apache.directory.ldapstudio.browser.core.model.SearchParameter

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.