Using OpenAdaptor with LDIF Translations
Novell Cool Solutions: Feature
By Andrey Karyagin
|
Digg This -
Slashdot This
Posted: 14 Jun 2006 |
Problem
There is a problem translating XML to LDIF and CSV to LDIF. It is possible to translate CSV to LDIF with the ICE utility, but ICE always produces "changetype: add" in the output LDIF file, while in some cases "changetype: modify" or "changetype: delete" is required. Also, the ICE utility can't be used for XML to LDIF translation at all.Solution
OpenAdaptorTM may be successfully used for this purpose. It is freeware, open-source utility written entirely in Java. The current stable version of OpenAdaptor is 1.7.1, and it may be downloaded from http://www.openadaptor.org
Example
PEOPLE.XML, included in the OpenAdaptor distribution, may be translated to an LDIF file with the following configuration properties file:
#==============================================================================
#PEOPLELDIF.PROPS
# SET TAB SIZE TO 4
#
# Extract messages from a file of XML-ed DataObjects and write to
# FileSink/SimpleReportWriter.
#
# Adaptor A:
# ==========
#
# C1 -> C2
# (FileSource) (FileSink/SimpleReportWriter)
#
#==============================================================================
#------------------------------------------------------------------------------
# Logging:
#------------------------------------------------------------------------------
A.Logging.LogSetting1 = INFO DEFAULT
A.Logging.LoggingTimeInfo = false
A.Logging.LoggingThreadInfo = false
A.Logging.LoggingPackageInfo = false
#------------------------------------------------------------------------------
# Components
#------------------------------------------------------------------------------
A.Component1.Name = C1
A.Component2.Name = C2
A.C1.LinkTo1 = C2
#------------------------------------------------------------------------------
# C1: FileSource - reads in DO-XML
#------------------------------------------------------------------------------
A.C1.ClassName = org.openadaptor.adaptor.standard.FileSource
A.C1.DOStringReader = org.openadaptor.dostrings.XMLStreamReader
A.C1.DiscardRootObjectTag = true
A.C1.InputFileName = people.xml
#------------------------------------------------------------------------------
# C2: FileSink
#------------------------------------------------------------------------------
A.C2.ClassName = org.openadaptor.adaptor.standard.FileSink
A.C2.OutputFileName = peoples.ldif
A.C2.WriteMode = Overwrite
##A.C2.WriteMode = Append
A.C2.DOStringWriter = org.openadaptor.dostrings.SimpleReportWriter
# string that is prepended at the start of each message
A.C2.Header1 = #This LDIF file was generated by OpenAdaptor(TM) v1.7.1
A.C2.Header2 = version: 1\r\n
# string that is appended at the end of each message (ie. if you set BatchSize=0
# then the footer will only be applied at the very end of the file)
# A.C6.Footer1 = \r\n#EOF
# each row of the record is a string with attribute value substitution defined
# by "{}" attribute name placeholders. Note that the placeholders can include
# additional formatting
A.C2.Body1 = dn: cn={FirstName}_{LastName},ou=OrgUnit,o=Org
A.C2.Body2 = changetype: add
A.C2.Body3 = cn: {FirstName}_{LastName}
A.C2.Body4 = givenName: {FirstName}
A.C2.Body5 = sn: {LastName}
A.C2.Body6 = description: {DOB}
A.C2.Body7 = uid: {SSN}
A.C2.Body8 = fullName: {FirstName}_{LastName}
A.C2.Body9 = mail: {FirstName}.{LastName}@somecompany.com
A.C2.Body10 = objectClass: inetOrgPerson
A.C2.Body11 = objectClass: organizationalPerson
A.C2.Body12 = objectClass: person
A.C2.Body13 = objectClass: top
A.C2.Body14 = objectClass: ndsLoginProperties
A.C2.Body15 = objectClass: homeInfo
# defines the char/string to use as a line seperator. defaults to a carriage return
#A.C2.LineSeperator= \n
OpenAdaptor should be started using the following command:
java org.openadaptor.adaptor.RunAdaptor peopleldif.props
An output PEOPLE.LDIF file will contain the following records:
#This LDIF file was generated by OpenAdaptor(TM) v1.7.1 version: 1 dn: cn=Scott_Smith,ou=OrgUnit,o=Org changetype: add cn: Scott_Smith givenName: Scott sn: Smith description: Nov 20, 1965 uid: 123-45-6789 fullName: Scott_Smith mail: Scott.Smith@somecompany.com objectClass: inetOrgPerson objectClass: organizationalPerson objectClass: person objectClass: top objectClass: ndsLoginProperties objectClass: homeInfo dn: cn=Kyle_Smith,ou=OrgUnit,o=Org changetype: add cn: Kyle_Smith givenName: Kyle sn: Smith description: Jan 5, 1997 uid: 255-12-12345 fullName: Kyle_Smith mail: Kyle.Smith@somecompany.com objectClass: inetOrgPerson objectClass: organizationalPerson objectClass: person objectClass: top objectClass: ndsLoginProperties objectClass: homeInfo dn: cn=Nicole_Smith,ou=OrgUnit,o=Org changetype: add cn: Nicole_Smith givenName: Nicole sn: Smith description: Mar 22, 1999 uid: 123-65-3123 fullName: Nicole_Smith mail: Nicole.Smith@somecompany.com objectClass: inetOrgPerson objectClass: organizationalPerson objectClass: person objectClass: top objectClass: ndsLoginProperties objectClass: homeInfo dn: cn=Fred_Jones,ou=OrgUnit,o=Org changetype: add cn: Fred_Jones givenName: Fred sn: Jones description: Jan 1, 1950 uid: 111-22-3113 fullName: Fred_Jones mail: Fred.Jones@somecompany.com objectClass: inetOrgPerson objectClass: organizationalPerson objectClass: person objectClass: top objectClass: ndsLoginProperties objectClass: homeInfo dn: cn=George_Burdell,ou=OrgUnit,o=Org changetype: add cn: George_Burdell givenName: George sn: Burdell description: July 4, 1947 uid: 111-22-8458 fullName: George_Burdell mail: George.Burdell@somecompany.com objectClass: inetOrgPerson objectClass: organizationalPerson objectClass: person objectClass: top objectClass: ndsLoginProperties objectClass: homeInfo
Although "changetype: add" was hardcoded in the PEOPLELDIF.PROPS file, it is quite easy to implement an ACTION_CODE tag in the input XML file and translate it to LDIF using the following construction:
A.C2.Body2 = changetype: {ACTION_CODE}
It is possible to implement more complicated XML or CSV to LDIF translation. OpenAdaptor makes it possible to add missing input attributes, such as loginactivationTime, modify existing attribute values, apply different rules to filter input data, and so on. In a future Cool Solutions tip, I'll try to describe how to monitor eDirectory attributes with OpenAdaptor and how to implement some kind of event-driven system.
Note: This solution was tested with the following environment:
- Any operating system with JDK 1.3.1 or later installed. This may be, for example, NetWare 5.1 with JDK 1.3.1 or NetWare 6.x with JDK 1.4.2.
- OpenAdaptor v1.7.1. installed
The user should be familiar with Java CLASSPATH configuration requirements.
Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions. www.webwiseone.com

