Package org.apache.directory.api.ldap.model.message.controls

Examples of org.apache.directory.api.ldap.model.message.controls.SortResponseControlImpl


     * @param session the current session
     * @return a sort response control
     */
    private SortResponse canSort( SortRequest sortControl, LdapResult ldapResult, SchemaManager schemaManager )
    {
        SortResponse resp = new SortResponseControlImpl();

        List<SortKey> keys = sortControl.getSortKeys();

        // only ONE key is supported by the server for now
        if ( keys.size() > 1 )
        {
            ldapResult.setDiagnosticMessage( "Cannot sort results based on more than one attribute" );
            resp.setSortResult( SortResultCode.UNWILLINGTOPERFORM );
            return resp;
        }

        SortKey sk = keys.get( 0 );

        AttributeType at = schemaManager.getAttributeType( sk.getAttributeTypeDesc() );

        if ( at == null )
        {
            ldapResult.setDiagnosticMessage( "No attribute with the name " + sk.getAttributeTypeDesc()
                + " exists in the server's schema" );
            resp.setSortResult( SortResultCode.NOSUCHATTRIBUTE );
            resp.setAttributeName( sk.getAttributeTypeDesc() );
            return resp;
        }

        String mrOid = sk.getMatchingRuleId();

        if ( mrOid != null )
        {
            MatchingRule mr = at.getOrdering();

            if ( mr != null )
            {
                if ( !mrOid.equals( mr.getOid() ) )
                {
                    ldapResult.setDiagnosticMessage( "Given matchingrule " + mrOid
                        + " is not applicable for the attribute " + sk.getAttributeTypeDesc() );
                    resp.setSortResult( SortResultCode.INAPPROPRIATEMATCHING );
                    resp.setAttributeName( sk.getAttributeTypeDesc() );
                    return resp;
                }
            }

            try
            {
                schemaManager.lookupComparatorRegistry( mrOid );
            }
            catch ( LdapException e )
            {
                ldapResult.setDiagnosticMessage( "Given matchingrule " + mrOid + " is not supported" );
                resp.setSortResult( SortResultCode.INAPPROPRIATEMATCHING );
                resp.setAttributeName( sk.getAttributeTypeDesc() );
                return resp;
            }
        }
        else
        {
            MatchingRule mr = at.getOrdering();

            if ( mr == null )
            {
                mr = at.getEquality();
            }

            ldapResult.setDiagnosticMessage( "Matchingrule is required for sorting by the attribute "
                + sk.getAttributeTypeDesc() );
            resp.setSortResult( SortResultCode.INAPPROPRIATEMATCHING );
            resp.setAttributeName( sk.getAttributeTypeDesc() );

            if ( mr == null )
            {
                return resp;
            }

            try
            {
                schemaManager.lookupComparatorRegistry( mr.getOid() );
            }
            catch ( LdapException e )
            {
                return resp;
            }
        }

        resp.setSortResult( SortResultCode.SUCCESS );

        return resp;
    }
View Full Code Here


     *
     * @param codec the LDAP codec
     */
    public SortResponseDecorator( LdapApiService codec )
    {
        super( codec, new SortResponseControlImpl() );
    }
View Full Code Here

     *
     * @param codec the LDAP codec
     */
    public SortResponseDecorator( LdapApiService codec )
    {
        super( codec, new SortResponseControlImpl() );
    }
View Full Code Here

     * @param session the current session
     * @return a sort response control
     */
    private SortResponseControl canSort( SortRequestControl sortControl, LdapResult ldapResult, SchemaManager schemaManager )
    {
        SortResponseControl resp = new SortResponseControlImpl();
       
        List<SortKey> keys = sortControl.getSortKeys();
       
        // only ONE key is supported by the server for now
        if( keys.size() > 1 )
        {
            ldapResult.setDiagnosticMessage( "Cannot sort results based on more than one attribute" );
            resp.setSortResult( SortResultCode.UNWILLINGTOPERFORM );
            return resp;
        }
       
        SortKey sk = keys.get( 0 );
       
        AttributeType at = schemaManager.getAttributeType( sk.getAttributeTypeDesc() );
       
        if ( at == null )
        {
           ldapResult.setDiagnosticMessage( "No attribute with the name " + sk.getAttributeTypeDesc() + " exists in the server's schema" );
           resp.setSortResult( SortResultCode.NOSUCHATTRIBUTE );
           resp.setAttributeName( sk.getAttributeTypeDesc() );
           return resp;
        }
       
        String mrOid = sk.getMatchingRuleId();
       
        if( mrOid != null )
        {
            MatchingRule mr = at.getOrdering();
           
            if( mr != null )
            {
                if( !mrOid.equals( mr.getOid() ) )
                {
                    ldapResult.setDiagnosticMessage( "Given matchingrule " + mrOid + " is not applicable for the attribute " + sk.getAttributeTypeDesc() );
                    resp.setSortResult( SortResultCode.INAPPROPRIATEMATCHING );
                    resp.setAttributeName( sk.getAttributeTypeDesc() );
                    return resp;       
                }
            }
           
            try
            {
                schemaManager.lookupComparatorRegistry( mrOid );
            }
            catch ( LdapException e )
            {
                ldapResult.setDiagnosticMessage( "Given matchingrule " + mrOid + " is not supported" );
                resp.setSortResult( SortResultCode.INAPPROPRIATEMATCHING );
                resp.setAttributeName( sk.getAttributeTypeDesc() );
                return resp;       
            }
        }
        else
        {
            MatchingRule mr = at.getOrdering();
           
            if( mr == null )
            {
                mr = at.getEquality();
            }
           
            ldapResult.setDiagnosticMessage( "Matchingrule is required for sorting by the attribute " + sk.getAttributeTypeDesc() );
            resp.setSortResult( SortResultCode.INAPPROPRIATEMATCHING );
            resp.setAttributeName( sk.getAttributeTypeDesc() );
           
            if( mr == null )
            {
                return resp;
            }
           
            try
            {
                schemaManager.lookupComparatorRegistry( mr.getOid() );
            }
            catch ( LdapException e )
            {
                return resp;       
            }
        }
       
        resp.setSortResult( SortResultCode.SUCCESS );
       
        return resp;
    }
View Full Code Here

TOP

Related Classes of org.apache.directory.api.ldap.model.message.controls.SortResponseControlImpl

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.