Java Code Examples for org.apache.directory.api.ldap.model.message.ModifyDnRequest#setDeleteOldRdn()

The following examples show how to use org.apache.directory.api.ldap.model.message.ModifyDnRequest#setDeleteOldRdn() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ApacheLdapProviderImpl.java    From ldapchai with GNU Lesser General Public License v2.1 6 votes vote down vote up
@ChaiProvider.LdapOperation
@ChaiProvider.ModifyOperation
public void renameEntry( final String entryDN, final String newRDN, final String newParentDN )
        throws ChaiOperationException, ChaiUnavailableException, IllegalStateException
{
    try
    {
        final ModifyDnRequest modifyDnRequest = new ModifyDnRequestImpl();
        modifyDnRequest.setName( new Dn(  entryDN ) );
        modifyDnRequest.setDeleteOldRdn( true );
        modifyDnRequest.setNewRdn( new Rdn( newRDN ) );
        modifyDnRequest.setNewSuperior( new Dn( newParentDN ) );
        final ModifyDnResponse response = connection.modifyDn( modifyDnRequest );
        processResponse( response );
    }
    catch ( LdapException e )
    {
        throw ChaiOperationException.forErrorMessage( e.getMessage() );
    }
}
 
Example 2
Source File: LdapNetworkConnection.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void moveAndRename( Dn entryDn, Dn newDn, boolean deleteOldRdn ) throws LdapException
{
    // Check the parameters first
    if ( entryDn == null )
    {
        throw new IllegalArgumentException( I18n.err( I18n.ERR_04142_NULL_ENTRY_DN ) );
    }

    if ( entryDn.isRootDse() )
    {
        throw new IllegalArgumentException( I18n.err( I18n.ERR_04143_CANNOT_MOVE_ROOT_DSE ) );
    }

    if ( newDn == null )
    {
        throw new IllegalArgumentException( I18n.err( I18n.ERR_04144_NULL_NEW_DN ) );
    }

    if ( newDn.isRootDse() )
    {
        throw new IllegalArgumentException( I18n.err( I18n.ERR_04145_ROOT_DSE_CANNOT_BE_TARGET ) );
    }

    // Create the request
    ModifyDnRequest modDnRequest = new ModifyDnRequestImpl();
    modDnRequest.setName( entryDn );
    modDnRequest.setNewRdn( newDn.getRdn() );
    
    // Check if we really need to specify newSuperior.
    // newSuperior is optional [RFC4511, section 4.9]
    // Some servers (e.g. OpenDJ 2.6) require a special privilege if
    // newSuperior is specified even if it is the same as the old one. Therefore let's not
    // specify it if we do not need it. This is better interoperability. 
    Dn newDnParent = newDn.getParent();
    if ( newDnParent != null && !newDnParent.equals( entryDn.getParent() ) )
    {
        modDnRequest.setNewSuperior( newDnParent );
    }
    
    modDnRequest.setDeleteOldRdn( deleteOldRdn );

    ModifyDnResponse modifyDnResponse = modifyDn( modDnRequest );

    processResponse( modifyDnResponse );
}
 
Example 3
Source File: StoreModifyDnRequestDeleteOldRdn.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void action( LdapMessageContainer<ModifyDnRequest> container ) throws DecoderException
{
    ModifyDnRequest modifyDnRequest = container.getMessage();

    TLV tlv = container.getCurrentTLV();

    // We get the value. If it's a 0, it's a FALSE. If it's
    // a FF, it's a TRUE. Any other value should be an error,
    // but we could relax this constraint. So if we have
    // something
    // which is not 0, it will be interpreted as TRUE, but we
    // will generate a warning.
    BerValue value = tlv.getValue();

    try
    {
        modifyDnRequest.setDeleteOldRdn( BooleanDecoder.parse( value ) );
    }
    catch ( BooleanDecoderException bde )
    {
        LOG.error( I18n
            .err( I18n.ERR_05125_INVALID_OLD_RDN, Strings.dumpBytes( value.getData() ), bde.getMessage() ) );

        // This will generate a PROTOCOL_ERROR
        throw new DecoderException( bde.getMessage(), bde );
    }

    // We can have an END transition
    container.setGrammarEndAllowed( true );

    if ( LOG.isDebugEnabled() )
    {
        if ( modifyDnRequest.getDeleteOldRdn() )
        {
            LOG.debug( I18n.msg( I18n.MSG_05135_OID_RDN_ATT_WILL_BE_DELETED ) );
        }
        else
        {
            LOG.debug( I18n.msg( I18n.MSG_05136_OID_RDN_ATT_WILL_BE_RETAINED ) );
        }
    }
}