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);
}
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);
}
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();
}
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();
}
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"));
}
Aggregations