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

neil_a_wilson
12.43.2007 c62997c0408c0caf3ee4824bbf6bdb3ea147d964
Update the ldif-diff tool so that it provides an option that allows
differences between entries to be split into multiple modifications each of
which has only a single value (as opposed to one modification containing all
changes to the entry). This can be useful when attempting to apply
configuration changes during an upgrade.

OpenDS Issue Number: 1228
2 files modified
73 ■■■■■ changed files
opendj-sdk/opends/src/server/org/opends/server/messages/ToolMessages.java 13 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/tools/LDIFDiff.java 60 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/messages/ToolMessages.java
@@ -7559,6 +7559,15 @@
  /**
   * The message ID for the message that will be used as the description of the
   * singleValueChanges argument.  This does not take any arguments.
   */
  public static final int MSGID_LDIFDIFF_DESCRIPTION_SINGLE_VALUE_CHANGES =
       CATEGORY_MASK_TOOLS | SEVERITY_MASK_INFORMATIONAL | 794;
  /**
   * Associates a set of generic messages with the message IDs defined in this
   * class.
   */
@@ -8940,6 +8949,10 @@
    registerMessage(MSGID_LDIFDIFF_DESCRIPTION_OUTPUT_LDIF,
                    "Specifies the file to which the output should be " +
                    "written.");
    registerMessage(MSGID_LDIFDIFF_DESCRIPTION_SINGLE_VALUE_CHANGES,
                    "Indicates that each attribute-level change should be " +
                    "written as a separate modification per attribute value " +
                    "rather than one modification per entry.");
    registerMessage(MSGID_LDIFDIFF_DESCRIPTION_OVERWRITE_EXISTING,
                    "Indicates that any existing output file should be " +
                    "overwritten rather than appending to it.");
opendj-sdk/opends/src/server/org/opends/server/tools/LDIFDiff.java
@@ -126,6 +126,7 @@
  {
    BooleanArgument overwriteExisting;
    BooleanArgument showUsage;
    BooleanArgument singleValueChanges;
    StringArgument  configClass;
    StringArgument  configFile;
    StringArgument  outputLDIF;
@@ -159,6 +160,11 @@
                               MSGID_LDIFDIFF_DESCRIPTION_OVERWRITE_EXISTING);
      argParser.addArgument(overwriteExisting);
      singleValueChanges =
           new BooleanArgument("singlevaluechanges", 'S', "singleValueChanges",
                               MSGID_LDIFDIFF_DESCRIPTION_SINGLE_VALUE_CHANGES);
      argParser.addArgument(singleValueChanges);
      configFile = new StringArgument("configfile", 'c', "configFile", false,
                                      false, true, "{configFile}", null, null,
                                      MSGID_LDIFDIFF_DESCRIPTION_CONFIG_FILE);
@@ -478,7 +484,8 @@
          {
            // The DNs are the same, so check to see if the entries are the
            // same or have been modified.
            if (writeModify(writer, sourceEntry, targetEntry))
            if (writeModify(writer, sourceEntry, targetEntry,
                            singleValueChanges.isPresent()))
            {
              differenceFound = true;
            }
@@ -602,10 +609,13 @@
   * user attributes.  It will ignore differences in the DN and operational
   * attributes.
   *
   * @param  writer       The writer to which the modify record should be
   *                      written.
   * @param  sourceEntry  The source form of the entry.
   * @param  targetEntry  The target form of the entry.
   * @param  writer              The writer to which the modify record should be
   *                             written.
   * @param  sourceEntry         The source form of the entry.
   * @param  targetEntry         The target form of the entry.
   * @param  singleValueChanges  Indicates whether each attribute-level change
   *                             should be written in a separate modification
   *                             per attribute value.
   *
   * @return  <CODE>true</CODE> if there were any differences found between the
   *          source and target entries, or <CODE>false</CODE> if not.
@@ -614,7 +624,8 @@
   *                       change record.
   */
  private static boolean writeModify(LDIFWriter writer, Entry sourceEntry,
                                     Entry targetEntry)
                                     Entry targetEntry,
                                     boolean singleValueChanges)
          throws IOException
  {
    // Create a list to hold the modifications that are found.
@@ -786,7 +797,42 @@
    }
    else
    {
      writer.writeModifyChangeRecord(sourceEntry.getDN(), modifications);
      if (singleValueChanges)
      {
        for (Modification m : modifications)
        {
          Attribute a = m.getAttribute();
          LinkedHashSet<AttributeValue> values = a.getValues();
          if (values.isEmpty())
          {
            LinkedList<Modification> attrMods = new LinkedList<Modification>();
            attrMods.add(m);
            writer.writeModifyChangeRecord(sourceEntry.getDN(), attrMods);
          }
          else
          {
            LinkedList<Modification> attrMods = new LinkedList<Modification>();
            LinkedHashSet<AttributeValue> valueSet =
                 new LinkedHashSet<AttributeValue>();
            for (AttributeValue v : values)
            {
              valueSet.clear();
              valueSet.add(v);
              Attribute attr = new Attribute(a.getAttributeType(),
                                             a.getName(), valueSet);
              attrMods.clear();
              attrMods.add(new Modification(m.getModificationType(), attr));
              writer.writeModifyChangeRecord(sourceEntry.getDN(), attrMods);
            }
          }
        }
      }
      else
      {
        writer.writeModifyChangeRecord(sourceEntry.getDN(), modifications);
      }
      return true;
    }
  }