Search in sources :

Example 6 with LDIFModifyDNChangeRecord

use of com.unboundid.ldif.LDIFModifyDNChangeRecord in project ldapsdk by pingidentity.

the class ChangeLogEntry method constructChangeLogEntry.

/**
 * Constructs a changelog entry from information contained in the provided
 * LDIF change record.
 *
 * @param  changeNumber  The change number to use for the constructed
 *                       changelog entry.
 * @param  changeRecord  The LDIF change record with the information to
 *                       include in the generated changelog entry.
 *
 * @return  The changelog entry constructed from the provided change record.
 *
 * @throws  LDAPException  If a problem is encountered while constructing the
 *                         changelog entry.
 */
@NotNull()
public static ChangeLogEntry constructChangeLogEntry(final long changeNumber, @NotNull final LDIFChangeRecord changeRecord) throws LDAPException {
    final Entry e = new Entry(ATTR_CHANGE_NUMBER + '=' + changeNumber + ",cn=changelog");
    e.addAttribute("objectClass", "top", "changeLogEntry");
    e.addAttribute(new Attribute(ATTR_CHANGE_NUMBER, IntegerMatchingRule.getInstance(), String.valueOf(changeNumber)));
    e.addAttribute(new Attribute(ATTR_TARGET_DN, DistinguishedNameMatchingRule.getInstance(), changeRecord.getDN()));
    e.addAttribute(ATTR_CHANGE_TYPE, changeRecord.getChangeType().getName());
    switch(changeRecord.getChangeType()) {
        case ADD:
            // The changes attribute should be an LDIF-encoded representation of the
            // attributes from the entry, which is the LDIF representation of the
            // entry without the first line (which contains the DN).
            final LDIFAddChangeRecord addRecord = (LDIFAddChangeRecord) changeRecord;
            final Entry addEntry = new Entry(addRecord.getDN(), addRecord.getAttributes());
            final String[] entryLdifLines = addEntry.toLDIF(0);
            final StringBuilder entryLDIFBuffer = new StringBuilder();
            for (int i = 1; i < entryLdifLines.length; i++) {
                entryLDIFBuffer.append(entryLdifLines[i]);
                entryLDIFBuffer.append(StaticUtils.EOL);
            }
            e.addAttribute(new Attribute(ATTR_CHANGES, OctetStringMatchingRule.getInstance(), entryLDIFBuffer.toString()));
            break;
        case DELETE:
            // No additional information is needed.
            break;
        case MODIFY:
            // The changes attribute should be an LDIF-encoded representation of the
            // modification, with the first two lines (the DN and changetype)
            // removed.
            final String[] modLdifLines = changeRecord.toLDIF(0);
            final StringBuilder modLDIFBuffer = new StringBuilder();
            for (int i = 2; i < modLdifLines.length; i++) {
                modLDIFBuffer.append(modLdifLines[i]);
                modLDIFBuffer.append(StaticUtils.EOL);
            }
            e.addAttribute(new Attribute(ATTR_CHANGES, OctetStringMatchingRule.getInstance(), modLDIFBuffer.toString()));
            break;
        case MODIFY_DN:
            final LDIFModifyDNChangeRecord modDNRecord = (LDIFModifyDNChangeRecord) changeRecord;
            e.addAttribute(new Attribute(ATTR_NEW_RDN, DistinguishedNameMatchingRule.getInstance(), modDNRecord.getNewRDN()));
            e.addAttribute(new Attribute(ATTR_DELETE_OLD_RDN, BooleanMatchingRule.getInstance(), (modDNRecord.deleteOldRDN() ? "TRUE" : "FALSE")));
            if (modDNRecord.getNewSuperiorDN() != null) {
                e.addAttribute(new Attribute(ATTR_NEW_SUPERIOR, DistinguishedNameMatchingRule.getInstance(), modDNRecord.getNewSuperiorDN()));
            }
            break;
    }
    return new ChangeLogEntry(e);
}
Also used : LDIFAddChangeRecord(com.unboundid.ldif.LDIFAddChangeRecord) LDIFModifyDNChangeRecord(com.unboundid.ldif.LDIFModifyDNChangeRecord) NotNull(com.unboundid.util.NotNull)

Example 7 with LDIFModifyDNChangeRecord

use of com.unboundid.ldif.LDIFModifyDNChangeRecord in project ldapsdk by pingidentity.

the class ChangeLogEntryTestCase method testConstructModifyDNChangeLogEntryNoNewSuperior.

/**
 * Tests the ability to construct a changelog entry for a modify DN operation
 * without a new superior.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testConstructModifyDNChangeLogEntryNoNewSuperior() throws Exception {
    final ChangeLogEntry e = ChangeLogEntry.constructChangeLogEntry(3L, new LDIFModifyDNChangeRecord("ou=People,dc=example,dc=com", "ou=Users", true, null));
    assertNotNull(e);
    assertEquals(e.getChangeNumber(), 3L);
    assertEquals(new DN(e.getTargetDN()), new DN("ou=People,dc=example,dc=com"));
    assertEquals(e.getChangeType(), ChangeType.MODIFY_DN);
    assertNull(e.getAddAttributes());
    assertNull(e.getDeletedEntryAttributes());
    assertNull(e.getModifications());
    assertEquals(new RDN(e.getNewRDN()), new RDN("ou=Users"));
    assertTrue(e.deleteOldRDN());
    assertNull(e.getNewSuperior());
    assertTrue(e.toLDIFChangeRecord() instanceof LDIFModifyDNChangeRecord);
}
Also used : LDIFModifyDNChangeRecord(com.unboundid.ldif.LDIFModifyDNChangeRecord) Test(org.testng.annotations.Test)

Example 8 with LDIFModifyDNChangeRecord

use of com.unboundid.ldif.LDIFModifyDNChangeRecord in project ldapsdk by pingidentity.

the class TransformLDIFTestCase method testExcludeRecordsWithoutChangeType.

/**
 * Tests the ability to exclude LDIF records without change types.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testExcludeRecordsWithoutChangeType() throws Exception {
    // Create the LDIF file to process.
    final File sourceLDIFFile = createTempFile("dn: dc=example,dc=com", "objectClass: top", "objectClass: domain", "dc: example", "", "dn: ou=People,dc=example,dc=com", "changetype: add", "objectClass: top", "objectClass: organizationalUnit", "ou: People", "", "dn: ou=People,dc=example,dc=com", "changetype: modify", "add: description", "description: foo", "", "dn: ou=People,dc=example,dc=com", "changetype: moddn", "newrdn: ou=Users", "deleteoldrdn: 1", "", "dn: ou=Users,dc=example,dc=com", "changetype: delete");
    final File outputFile = runTool("--sourceLDIF", sourceLDIFFile.getAbsolutePath(), "--excludeRecordsWithoutChangeType");
    final LDIFReader reader = new LDIFReader(outputFile);
    LDIFRecord r = reader.readLDIFRecord();
    assertNotNull(r);
    assertTrue(r instanceof LDIFAddChangeRecord);
    r = reader.readLDIFRecord();
    assertNotNull(r);
    assertTrue(r instanceof LDIFModifyChangeRecord);
    r = reader.readLDIFRecord();
    assertNotNull(r);
    assertTrue(r instanceof LDIFModifyDNChangeRecord);
    r = reader.readLDIFRecord();
    assertNotNull(r);
    assertTrue(r instanceof LDIFDeleteChangeRecord);
    assertNull(reader.readEntry());
    reader.close();
}
Also used : LDIFRecord(com.unboundid.ldif.LDIFRecord) LDIFAddChangeRecord(com.unboundid.ldif.LDIFAddChangeRecord) LDIFReader(com.unboundid.ldif.LDIFReader) LDIFModifyChangeRecord(com.unboundid.ldif.LDIFModifyChangeRecord) LDIFDeleteChangeRecord(com.unboundid.ldif.LDIFDeleteChangeRecord) File(java.io.File) LDIFModifyDNChangeRecord(com.unboundid.ldif.LDIFModifyDNChangeRecord) Test(org.testng.annotations.Test)

Example 9 with LDIFModifyDNChangeRecord

use of com.unboundid.ldif.LDIFModifyDNChangeRecord in project ldapsdk by pingidentity.

the class TransformLDIFTestCase method testExcludeChangeType.

/**
 * Tests the ability to exclude LDIF records with a specified set of change
 * types.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testExcludeChangeType() throws Exception {
    // Create the LDIF file to process.
    final File sourceLDIFFile = createTempFile("dn: dc=example,dc=com", "objectClass: top", "objectClass: domain", "dc: example", "", "dn: ou=People,dc=example,dc=com", "changetype: add", "objectClass: top", "objectClass: organizationalUnit", "ou: People", "", "dn: ou=People,dc=example,dc=com", "changetype: modify", "add: description", "description: foo", "", "dn: ou=People,dc=example,dc=com", "changetype: moddn", "newrdn: ou=Users", "deleteoldrdn: 1", "", "dn: ou=Users,dc=example,dc=com", "changetype: delete");
    final File outputFile = runTool("--sourceLDIF", sourceLDIFFile.getAbsolutePath(), "--excludeChangeType", "add", "--excludeChangeType", "delete");
    final LDIFReader reader = new LDIFReader(outputFile);
    LDIFRecord r = reader.readLDIFRecord();
    assertNotNull(r);
    assertTrue(r instanceof Entry);
    r = reader.readLDIFRecord();
    assertNotNull(r);
    assertTrue(r instanceof LDIFModifyChangeRecord);
    r = reader.readLDIFRecord();
    assertNotNull(r);
    assertTrue(r instanceof LDIFModifyDNChangeRecord);
    assertNull(reader.readEntry());
    reader.close();
}
Also used : Entry(com.unboundid.ldap.sdk.Entry) LDIFRecord(com.unboundid.ldif.LDIFRecord) LDIFReader(com.unboundid.ldif.LDIFReader) LDIFModifyChangeRecord(com.unboundid.ldif.LDIFModifyChangeRecord) File(java.io.File) LDIFModifyDNChangeRecord(com.unboundid.ldif.LDIFModifyDNChangeRecord) Test(org.testng.annotations.Test)

Example 10 with LDIFModifyDNChangeRecord

use of com.unboundid.ldif.LDIFModifyDNChangeRecord in project ldapsdk by pingidentity.

the class RedactAttributeTransformationTestCase method testTransformModDNChangeRecordProcessDNsTruePreserveCountTrue.

/**
 * Provides test coverage for the transformChangeRecord method for a modify DN
 * record with both processDNs and preserveValueCount arguments set to true.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testTransformModDNChangeRecordProcessDNsTruePreserveCountTrue() throws Exception {
    final Schema schema = Schema.getDefaultStandardSchema();
    final RedactAttributeTransformation t = new RedactAttributeTransformation(schema, true, true, "description", "displayName", "cn", "ou");
    LDIFChangeRecord r = t.transformChangeRecord(new LDIFModifyDNChangeRecord("cn=Test 1,ou=People,dc=example,dc=com", "cn=Test 2", true, null));
    assertNotNull(r);
    assertEquals(r, new LDIFModifyDNChangeRecord("cn=***REDACTED***,ou=***REDACTED***,dc=example,dc=com", "cn=***REDACTED***", true, null));
    r = t.transformChangeRecord(new LDIFModifyDNChangeRecord("cn=Test 1,ou=People,dc=example,dc=com", "cn=Test 2", true, "ou=Users,dc=example,dc=com"));
    assertNotNull(r);
    assertEquals(r, new LDIFModifyDNChangeRecord("cn=***REDACTED***,ou=***REDACTED***,dc=example,dc=com", "cn=***REDACTED***", true, "ou=***REDACTED***,dc=example,dc=com"));
}
Also used : LDIFChangeRecord(com.unboundid.ldif.LDIFChangeRecord) Schema(com.unboundid.ldap.sdk.schema.Schema) LDIFModifyDNChangeRecord(com.unboundid.ldif.LDIFModifyDNChangeRecord) Test(org.testng.annotations.Test)

Aggregations

LDIFModifyDNChangeRecord (com.unboundid.ldif.LDIFModifyDNChangeRecord)45 Test (org.testng.annotations.Test)35 LDIFModifyChangeRecord (com.unboundid.ldif.LDIFModifyChangeRecord)20 LDIFChangeRecord (com.unboundid.ldif.LDIFChangeRecord)19 LDIFAddChangeRecord (com.unboundid.ldif.LDIFAddChangeRecord)17 LDIFDeleteChangeRecord (com.unboundid.ldif.LDIFDeleteChangeRecord)17 Calendar (java.util.Calendar)13 GregorianCalendar (java.util.GregorianCalendar)13 Entry (com.unboundid.ldap.sdk.Entry)10 Modification (com.unboundid.ldap.sdk.Modification)8 ModifyRequest (com.unboundid.ldap.sdk.ModifyRequest)8 DN (com.unboundid.ldap.sdk.DN)7 LDAPException (com.unboundid.ldap.sdk.LDAPException)5 Schema (com.unboundid.ldap.sdk.schema.Schema)5 LDIFReader (com.unboundid.ldif.LDIFReader)4 Nullable (com.unboundid.util.Nullable)4 File (java.io.File)4 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)3 Attribute (com.unboundid.ldap.sdk.Attribute)3 RDN (com.unboundid.ldap.sdk.RDN)3