@Test public void testReverseModifyDNMove() throws LdapException { Dn dn = new Dn( "cn=john doe, dc=example, dc=com" ); Dn newSuperior = new Dn( "ou=system" ); Rdn rdn = new Rdn( "cn=john doe" ); LdifEntry reversed = LdifRevertor.reverseMove( newSuperior, dn ); assertNotNull( reversed ); assertEquals( "cn=john doe,ou=system", reversed.getDn().getName() ); assertEquals( ChangeType.ModDn, reversed.getChangeType() ); assertFalse( reversed.isDeleteOldRdn() ); assertEquals( rdn.getName(), reversed.getNewRdn() ); assertEquals( "dc=example, dc=com", Strings.trim( reversed.getNewSuperior() ) ); assertNull( reversed.getEntry() ); }
public static LdifEntry reverseMove( Dn newSuperiorDn, Dn modifiedDn ) throws LdapException { LdifEntry entry = new LdifEntry(); Dn currentParent; Rdn currentRdn; Dn newDn; if ( newSuperiorDn == null ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13466_NEW_SUPERIOR_DN_NULL ) ); } if ( modifiedDn == null ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13467_NULL_MODIFIED_DN ) ); } if ( modifiedDn.size() == 0 ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13468_DONT_MOVE_ROOTDSE ) ); } currentParent = modifiedDn; currentRdn = currentParent.getRdn(); currentParent = currentParent.getParent(); newDn = newSuperiorDn; newDn = newDn.add( modifiedDn.getRdn() ); entry.setChangeType( ChangeType.ModDn ); entry.setDn( newDn ); entry.setNewRdn( currentRdn.getName() ); entry.setNewSuperior( currentParent.getName() ); entry.setDeleteOldRdn( false ); return entry; }
LdifRevertor { public static LdifEntry reverseMove( Dn newSuperiorDn, Dn modifiedDn ) throws LdapException { LdifEntry entry = new LdifEntry(); Dn currentParent; Rdn currentRdn; Dn newDn; if ( newSuperiorDn == null ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13466_NEW_SUPERIOR_DN_NULL ) ); } if ( modifiedDn == null ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13467_NULL_MODIFIED_DN ) ); } if ( modifiedDn.size() == 0 ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13468_DONT_MOVE_ROOTDSE ) ); } currentParent = modifiedDn; currentRdn = currentParent.getRdn(); currentParent = currentParent.getParent(); newDn = newSuperiorDn; newDn = newDn.add( modifiedDn.getRdn() ); entry.setChangeType( ChangeType.ModDn ); entry.setDn( newDn ); entry.setNewRdn( currentRdn.getName() ); entry.setNewSuperior( currentParent.getName() ); entry.setDeleteOldRdn( false ); return entry; } }
LdifRevertor { public static LdifEntry reverseMove( Dn newSuperiorDn, Dn modifiedDn ) throws LdapException { LdifEntry entry = new LdifEntry(); Dn currentParent; Rdn currentRdn; Dn newDn; if ( newSuperiorDn == null ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13466_NEW_SUPERIOR_DN_NULL ) ); } if ( modifiedDn == null ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13467_NULL_MODIFIED_DN ) ); } if ( modifiedDn.size() == 0 ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13468_DONT_MOVE_ROOTDSE ) ); } currentParent = modifiedDn; currentRdn = currentParent.getRdn(); currentParent = currentParent.getParent(); newDn = newSuperiorDn; newDn = newDn.add( modifiedDn.getRdn() ); entry.setChangeType( ChangeType.ModDn ); entry.setDn( newDn ); entry.setNewRdn( currentRdn.getName() ); entry.setNewSuperior( currentParent.getName() ); entry.setDeleteOldRdn( false ); return entry; } private  LdifRevertor(); }
LdifRevertor { public static LdifEntry reverseMove( Dn newSuperiorDn, Dn modifiedDn ) throws LdapException { LdifEntry entry = new LdifEntry(); Dn currentParent; Rdn currentRdn; Dn newDn; if ( newSuperiorDn == null ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13466_NEW_SUPERIOR_DN_NULL ) ); } if ( modifiedDn == null ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13467_NULL_MODIFIED_DN ) ); } if ( modifiedDn.size() == 0 ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13468_DONT_MOVE_ROOTDSE ) ); } currentParent = modifiedDn; currentRdn = currentParent.getRdn(); currentParent = currentParent.getParent(); newDn = newSuperiorDn; newDn = newDn.add( modifiedDn.getRdn() ); entry.setChangeType( ChangeType.ModDn ); entry.setDn( newDn ); entry.setNewRdn( currentRdn.getName() ); entry.setNewSuperior( currentParent.getName() ); entry.setDeleteOldRdn( false ); return entry; } private  LdifRevertor(); static LdifEntry reverseAdd( Dn dn ); static LdifEntry reverseDel( Dn dn, Entry deletedEntry ); static LdifEntry reverseModify( Dn dn, List<Modification> forwardModifications, Entry modifiedEntry ); static LdifEntry reverseMove( Dn newSuperiorDn, Dn modifiedDn ); static List<LdifEntry> reverseRename( Entry entry, Rdn newRdn, boolean deleteOldRdn ); static List<LdifEntry> reverseMoveAndRename( Entry entry, Dn newSuperior, Rdn newRdn, boolean deleteOldRdn ); }
LdifRevertor { public static LdifEntry reverseMove( Dn newSuperiorDn, Dn modifiedDn ) throws LdapException { LdifEntry entry = new LdifEntry(); Dn currentParent; Rdn currentRdn; Dn newDn; if ( newSuperiorDn == null ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13466_NEW_SUPERIOR_DN_NULL ) ); } if ( modifiedDn == null ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13467_NULL_MODIFIED_DN ) ); } if ( modifiedDn.size() == 0 ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13468_DONT_MOVE_ROOTDSE ) ); } currentParent = modifiedDn; currentRdn = currentParent.getRdn(); currentParent = currentParent.getParent(); newDn = newSuperiorDn; newDn = newDn.add( modifiedDn.getRdn() ); entry.setChangeType( ChangeType.ModDn ); entry.setDn( newDn ); entry.setNewRdn( currentRdn.getName() ); entry.setNewSuperior( currentParent.getName() ); entry.setDeleteOldRdn( false ); return entry; } private  LdifRevertor(); static LdifEntry reverseAdd( Dn dn ); static LdifEntry reverseDel( Dn dn, Entry deletedEntry ); static LdifEntry reverseModify( Dn dn, List<Modification> forwardModifications, Entry modifiedEntry ); static LdifEntry reverseMove( Dn newSuperiorDn, Dn modifiedDn ); static List<LdifEntry> reverseRename( Entry entry, Rdn newRdn, boolean deleteOldRdn ); static List<LdifEntry> reverseMoveAndRename( Entry entry, Dn newSuperior, Rdn newRdn, boolean deleteOldRdn ); static final boolean DELETE_OLD_RDN; static final boolean KEEP_OLD_RDN; }