Class LdifRevertor


  • public final class LdifRevertor
    extends Object
    A helper class which provides methods to reverse a LDIF modification operation.
    Author:
    Apache Directory Project
    • Field Detail

      • DELETE_OLD_RDN

        public static final boolean DELETE_OLD_RDN
        Flag used when we want to delete the old Rdn
        See Also:
        Constant Field Values
      • KEEP_OLD_RDN

        public static final boolean KEEP_OLD_RDN
        Flag used when we want to keep the old Rdn
        See Also:
        Constant Field Values
    • Constructor Detail

      • LdifRevertor

        private LdifRevertor()
        Private constructor.
    • Method Detail

      • reverseAdd

        public static LdifEntry reverseAdd​(Dn dn)
        Compute a reverse LDIF of an AddRequest. It's simply a delete request of the added entry
        Parameters:
        dn - the dn of the added entry
        Returns:
        a reverse LDIF
      • reverseDel

        public static LdifEntry reverseDel​(Dn dn,
                                           Entry deletedEntry)
                                    throws LdapException
        Compute a reverse LDIF of a DeleteRequest. We have to get the previous entry in order to restore it.
        Parameters:
        dn - The deleted entry Dn
        deletedEntry - The entry which has been deleted
        Returns:
        A reverse LDIF
        Throws:
        LdapException - If something went wrong
      • reverseModify

        public static LdifEntry reverseModify​(Dn dn,
                                              List<Modification> forwardModifications,
                                              Entry modifiedEntry)
                                       throws LdapException
        Compute the reversed LDIF for a modify request. We will deal with the three kind of modifications :
        • add
        • remove
        • replace
        As the modifications should be issued in a reversed order ( ie, for the initials modifications {A, B, C}, the reversed modifications will be ordered like {C, B, A}), we will change the modifications order.
        Parameters:
        dn - the dn of the modified entry
        forwardModifications - the modification items for the forward change
        modifiedEntry - The modified entry. Necessary for the destructive modifications
        Returns:
        A reversed LDIF
        Throws:
        LdapException - If something went wrong
      • reverseMove

        public static LdifEntry reverseMove​(Dn newSuperiorDn,
                                            Dn modifiedDn)
                                     throws LdapException
        Compute a reverse LDIF for a forward change which if in LDIF format would represent a Move operation. Hence there is no newRdn in the picture here.
        Parameters:
        newSuperiorDn - the new parent dn to be (must not be null)
        modifiedDn - the dn of the entry being moved (must not be null)
        Returns:
        a reverse LDIF
        Throws:
        LdapException - if something went wrong
      • revertEntry

        private static LdifEntry revertEntry​(Entry entry,
                                             Dn newDn,
                                             Dn newSuperior,
                                             Rdn oldRdn,
                                             Rdn newRdn)
                                      throws LdapInvalidDnException
        A small helper class to compute the simple revert.
        Parameters:
        entry - The entry to revert
        newDn - The new Dn
        newSuperior - The new superior, if it has changed (null otherwise)
        oldRdn - The old Rdn
        newRdn - The new RDN if the RDN has changed
        Returns:
        The reverted entry
        Throws:
        LdapInvalidDnException - If the Dn is invalid
      • generateModify

        private static LdifEntry generateModify​(Dn parentDn,
                                                Entry entry,
                                                Rdn oldRdn,
                                                Rdn newRdn)
        A helper method to generate the modified attribute after a rename.
        Parameters:
        parentDn - The parent Dn
        entry - The entry to revert
        oldRdn - The old Rdn
        newRdn - The new Rdn
        Returns:
        The modified entry
      • generateReverted

        private static LdifEntry generateReverted​(Dn newSuperior,
                                                  Rdn newRdn,
                                                  Dn newDn,
                                                  Rdn oldRdn,
                                                  boolean deleteOldRdn)
                                           throws LdapInvalidDnException
        A helper method which generates a reverted entry for a MODDN operation
        Parameters:
        newSuperior - The new superior, if it has changed (null otherwise)
        newRdn - The new RDN if the RDN has changed
        newDn - The new Dn
        oldRdn - The old Rdn
        deleteOldRdn - If the old Rdn attributes must be deleted or not
        Returns:
        The reverted entry
        Throws:
        LdapInvalidDnException - If the DN is invalid
      • reverseRename

        public static List<LdifEntry> reverseRename​(Entry entry,
                                                    Rdn newRdn,
                                                    boolean deleteOldRdn)
                                             throws LdapInvalidDnException
        Revert a Dn to it's previous version by removing the first Rdn and adding the given Rdn. It's a rename operation. The biggest issue is that we have many corner cases, depending on the RDNs we are manipulating, and on the content of the initial entry.
        Parameters:
        entry - The initial Entry
        newRdn - The new Rdn
        deleteOldRdn - A flag which tells to delete the old Rdn AVAs
        Returns:
        A list of LDIF reverted entries
        Throws:
        LdapInvalidDnException - If the name reverting failed
      • reverseMoveAndRename

        public static List<LdifEntry> reverseMoveAndRename​(Entry entry,
                                                           Dn newSuperior,
                                                           Rdn newRdn,
                                                           boolean deleteOldRdn)
                                                    throws LdapInvalidDnException
        Revert a Dn to it's previous version by removing the first Rdn and adding the given Rdn. It's a rename operation. The biggest issue is that we have many corner cases, depending on the RDNs we are manipulating, and on the content of the initial entry.
        Parameters:
        entry - The initial Entry
        newSuperior - The new superior Dn (can be null if it's just a rename)
        newRdn - The new Rdn
        deleteOldRdn - A flag which tells to delete the old Rdn AVAs
        Returns:
        A list of LDIF reverted entries
        Throws:
        LdapInvalidDnException - If the name reverting failed