Menu

Filtering Duplicated Values in Modifications in a LDIFAddChangeRecord

2015-09-02
2015-09-03
  • Jason "JRSofty" Reed

    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?

     
  • Neil Wilson

    Neil Wilson - 2015-09-02

    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.

     
  • Jason "JRSofty" Reed

    I see, that seems pretty straight forward. Thanks Neil, I'll have to give that a try.

     

Log in to post a comment.