We have one issue, our customer's directory service (based on DirX apparently) allows them to have duplicate attribute values for an entry. For example they may have multiple values in the mhsDLMembers attribute including duplicated values. Now this is completely incompatible with the directory server that they wish to synchronize too (ISODE M-Vault as you mentioned previously based on X.500).
The good news is that I can identify these duplicates using an implementation of the LDIFReaderChangeRecordTranslator (your version 3.0.1), I can identify them and trigger an LDIFException with them so that they can be displayed as errors. The problem I'm having is that we should provide them an option to ignore or filter out these duplicate attribute values and merge anyway. I'm figuring ignoring would probably be easier but would risk causing problems to the directory structure or at least causing problems overall, I would more prefer to filter them if possible. However, I'm not seeing a way to remove a Modification from an LDIFAddChangeRecord. Is there something I could be missing?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
By default, the LDAP SDK will strip out duplicate values when reading data from LDIF (although you can configure that via the LDIFReader.setDuplicateValueBehavior method), and calls to Entry.addAttribute will also ignore values that already exist in the entry. But it assumes that an entry retrieved from a directory server over LDAP will not have duplicate values so it doesn't do anything special to detect or handle that.
The LDIFAddChangeRecord class is immutable (as are all other LDIFChangeRecord classes), so you can't make changes directly to objects of that type. However, the LDIFReaderChangeRecordTranslator interface allows you to create and return a new LDIFChangeRecord instance. So you could do something like:
public LDIFChangeRecord translate(LDIFChangeRecord changeRecord,
long firstLineNumber)
{
if (changeRecord instanceof LDIFAddChangeRecord)
{
LDIFAddChangeRecord addRecord =
(LDIFAddChangeRecord) changeRecord;
Entry entryToAdd = addRecord.getEntryToAdd();
// Make whatever changes you want to the entry
return new LDIFAddChangeRecord(entryToAdd);
}
else
{
return changeRecord;
}
}
If you can identify the changes that you want to apply to the entry as a set of modifications, then the Entry.applyModifications method can do that. It looks like attempts to remove a particular attribute value will remove all copies of that value in the attribute, so you might have to account for that if you want to keep one of the values.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
We have one issue, our customer's directory service (based on DirX apparently) allows them to have duplicate attribute values for an entry. For example they may have multiple values in the mhsDLMembers attribute including duplicated values. Now this is completely incompatible with the directory server that they wish to synchronize too (ISODE M-Vault as you mentioned previously based on X.500).
The good news is that I can identify these duplicates using an implementation of the LDIFReaderChangeRecordTranslator (your version 3.0.1), I can identify them and trigger an LDIFException with them so that they can be displayed as errors. The problem I'm having is that we should provide them an option to ignore or filter out these duplicate attribute values and merge anyway. I'm figuring ignoring would probably be easier but would risk causing problems to the directory structure or at least causing problems overall, I would more prefer to filter them if possible. However, I'm not seeing a way to remove a Modification from an LDIFAddChangeRecord. Is there something I could be missing?
By default, the LDAP SDK will strip out duplicate values when reading data from LDIF (although you can configure that via the LDIFReader.setDuplicateValueBehavior method), and calls to Entry.addAttribute will also ignore values that already exist in the entry. But it assumes that an entry retrieved from a directory server over LDAP will not have duplicate values so it doesn't do anything special to detect or handle that.
The LDIFAddChangeRecord class is immutable (as are all other LDIFChangeRecord classes), so you can't make changes directly to objects of that type. However, the LDIFReaderChangeRecordTranslator interface allows you to create and return a new LDIFChangeRecord instance. So you could do something like:
If you can identify the changes that you want to apply to the entry as a set of modifications, then the Entry.applyModifications method can do that. It looks like attempts to remove a particular attribute value will remove all copies of that value in the attribute, so you might have to account for that if you want to keep one of the values.
I see, that seems pretty straight forward. Thanks Neil, I'll have to give that a try.