mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

neil_a_wilson
18.46.2006 58f8bce131481d591be6cd8f19944fc45c26dd06
opendj-sdk/opends/src/server/org/opends/server/backends/MemoryBackend.java
@@ -409,11 +409,77 @@
                      String.valueOf(entry), String.valueOf(modifyDNOperation));
    // FIXME -- Consider adding support for this in the future.
    int    msgID   = MSGID_MEMORYBACKEND_MODDN_NOT_SUPPORTED;
    String message = getMessage(msgID);
    throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message,
                                 msgID);
    // Make sure that the target entry exists.
    if (! entryMap.containsKey(currentDN))
    {
      int    msgID   = MSGID_MEMORYBACKEND_ENTRY_DOESNT_EXIST;
      String message = getMessage(msgID, String.valueOf(currentDN));
      throw new DirectoryException(ResultCode.NO_SUCH_OBJECT, message, msgID);
    }
    // Make sure that the target entry doesn't have any children.
    HashSet<DN> children  = childDNs.get(currentDN);
    if (children != null)
    {
      if (children.isEmpty())
      {
        childDNs.remove(currentDN);
      }
      else
      {
        int    msgID   = MSGID_MEMORYBACKEND_CANNOT_RENAME_ENRY_WITH_CHILDREN;
        String message = getMessage(msgID, String.valueOf(currentDN));
        throw new DirectoryException(ResultCode.NOT_ALLOWED_ON_NONLEAF, message,
                                     msgID);
      }
    }
    // Make sure that no entry exists with the new DN.
    if (entryMap.containsKey(entry.getDN()))
    {
      int    msgID   = MSGID_MEMORYBACKEND_ENTRY_ALREADY_EXISTS;
      String message = getMessage(msgID, String.valueOf(entry.getDN()));
      throw new DirectoryException(ResultCode.NO_SUCH_OBJECT, message, msgID);
    }
    // Make sure that the new DN is in this backend.
    boolean matchFound = false;
    for (DN dn : baseDNs)
    {
      if (dn.isAncestorOf(entry.getDN()))
      {
        matchFound = true;
        break;
      }
    }
    if (! matchFound)
    {
      int    msgID   = MSGID_MEMORYBACKEND_CANNOT_RENAME_TO_ANOTHER_BACKEND;
      String message = getMessage(msgID, String.valueOf(currentDN));
      throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message,
                                   msgID);
    }
    // Make sure that the parent of the new entry exists.
    DN parentDN = entry.getDN().getParent();
    if ((parentDN == null) || (! entryMap.containsKey(parentDN)))
    {
      int    msgID   = MSGID_MEMORYBACKEND_RENAME_PARENT_DOESNT_EXIST;
      String message = getMessage(msgID, String.valueOf(currentDN),
                                  String.valueOf(parentDN));
      throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message,
                                   msgID);
    }
    // Delete the current entry and add the new one.
    deleteEntry(currentDN, null);
    addEntry(entry, null);
  }
opendj-sdk/opends/src/server/org/opends/server/messages/BackendMessages.java
@@ -2180,6 +2180,36 @@
  /**
   * The message ID for the message that will be used to indicate that an entry
   * cannot be renamed if it has children.  This takes a single argument, which
   * is the DN of the target entry.
   */
  public static final int MSGID_MEMORYBACKEND_CANNOT_RENAME_ENRY_WITH_CHILDREN =
       CATEGORY_MASK_BACKEND | SEVERITY_MASK_SEVERE_ERROR | 205;
  /**
   * The message ID for the message that will be used to indicate that an entry
   * cannot be renamed if it would move to another backend.  This takes a single
   * argument, which is the DN of the target entry.
   */
  public static final int MSGID_MEMORYBACKEND_CANNOT_RENAME_TO_ANOTHER_BACKEND =
       CATEGORY_MASK_BACKEND | SEVERITY_MASK_SEVERE_ERROR | 206;
  /**
   * The message ID for the message that will be used to indicate that an entry
   * cannot be renamed because the new parent doesn't exist.  This takes two
   * arguments, which are the current DN and the new parent DN.
   */
  public static final int MSGID_MEMORYBACKEND_RENAME_PARENT_DOESNT_EXIST =
       CATEGORY_MASK_BACKEND | SEVERITY_MASK_SEVERE_ERROR | 207;
  /**
   * Associates a set of generic messages with the message IDs defined in this
   * class.
   */
@@ -2977,6 +3007,15 @@
    registerMessage(MSGID_MEMORYBACKEND_BACKUP_RESTORE_NOT_SUPPORTED,
                    "The memory-based backend does not support backup or " +
                    "restore operations.");
    registerMessage(MSGID_MEMORYBACKEND_CANNOT_RENAME_ENRY_WITH_CHILDREN,
                    "Cannot rename entry %s because it has one or more " +
                    "subordinate entries.");
    registerMessage(MSGID_MEMORYBACKEND_CANNOT_RENAME_TO_ANOTHER_BACKEND,
                    "Cannot rename entry %s because the target entry is in a " +
                    "different backend.");
    registerMessage(MSGID_MEMORYBACKEND_RENAME_PARENT_DOESNT_EXIST,
                    "Cannot rename entry %s because the new parent entry %s " +
                    "doesn't exist.");
  }
}
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/protocols/internal/InternalClientConnectionTestCase.java
@@ -707,8 +707,7 @@
    ModifyDNOperation modifyDNOperation =
         conn.processModifyDN(new ASN1OctetString("cn=test,o=test"),
                              new ASN1OctetString("cn=test2"), true);
    assertEquals(modifyDNOperation.getResultCode(),
                 ResultCode.UNWILLING_TO_PERFORM);
    assertEquals(modifyDNOperation.getResultCode(), ResultCode.SUCCESS);
  }
@@ -776,8 +775,7 @@
    ModifyDNOperation modifyDNOperation =
         conn.processModifyDN(DN.decode("cn=test,o=test"),
                              RDN.decode("cn=test2"), true);
    assertEquals(modifyDNOperation.getResultCode(),
                 ResultCode.UNWILLING_TO_PERFORM);
    assertEquals(modifyDNOperation.getResultCode(), ResultCode.SUCCESS);
  }