directory-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Göktürk Gezer <gokturk.ge...@gmail.com>
Subject Re: How to import LDIF file programmatically
Date Thu, 10 May 2012 22:13:10 GMT
Hi,

On Thu, May 10, 2012 at 8:06 PM, Marina <ppine7@yahoo.com> wrote:

>
>
> Hi, Gokturk,
> This example code does not compile - I get a few errors about
> missing/incorrect classes and method signatures....
> For example:
>

It is about your version of ApacheDS, as i said there may be changes based
on your version. Example is for 2.0.0 series.


>  if ( entry.isLdifContent() ) --> The method isLdifContent() is undefined
> for the type LdifEntry
>  ModifyDnRequest modDnRequest = new ModifyDnRequestImpl();  -->
> ModifyDnRequest class does not exist, and The constructor
> ModifyDnRequestImpl() is undefined
> and others....
>
But if you want to stick with 1.5.7,

if(entry.isLdifContext()) can be changed with  if(entry.getChangeType() ==
ChangeType.None)

For the other, errors, just find your best way based on which version
you're on and which mechanism you're using to issue operations.

>
> Which version of ApacheDS is it for? I'm using 1.5.7.
> Or, maybe I'm missing some libraries? I have apacheds-all-1.5.7.jar.
>
Yes you're missing definitions. But this is also possible in 1.5.7 nothing
special to 2.0.0. Just different.

>
> Are there some published APIS/ documentation for this kind of tasks?
>
As i understand your ldif entries have no change type, i mean they're for
addition only. If this is the case, then just add them without going
through modify/rename checks. But issue operations through CoreSession
reference so that your entry will contain necessary system attributes.

>
> thanks!
> Marina
>

Regards,

> ________________________________
> From: Göktürk Gezer <gokturk.gezer@gmail.com>
> To: users@directory.apache.org
> Sent: Wednesday, May 9, 2012 4:23 PM
> Subject: Re: How to import LDIF file programmatically
>
> You can use below code as your base. You might wanna slightly change it
> based on which version of ApacheDS you're using.
>
> And make sure your ldif file is constructed in correct order from the top
> to the bottom. I'd preffer to use CoreSession to issue operations to make
> sure they're checked, but you can issue operations on the Jdbm partition
> reference you've created as well..
>
> LdifReader ldifReader = new LdifReader(new
> FileInputStream("yourfile.ldif"));
> CoreSession conn; // Obtain it from embedded DirectoryService reference.
>
> for ( LdifEntry entry : ldifReader )
> {
>     if ( entry.isLdifContent() )
>     {
>         conn.add( entry.getEntry() );
>         continue;
>     }
>
>     switch ( entry.getChangeType() )
>     {
>         case ModRdn:
>         case ModDn:
>             ModifyDnRequest modDnRequest = new ModifyDnRequestImpl();
>             modDnRequest.setName( entry.getDn() );
>             modDnRequest.setDeleteOldRdn( entry.isDeleteOldRdn() );
>
>             if ( entry.getNewSuperior() != null )
>             {
>                 modDnRequest.setNewSuperior( new Dn( entry.getNewSuperior()
> ) );
>             }
>
>             if ( entry.getNewRdn() != null )
>             {
>                 modDnRequest.setNewRdn( new Rdn( entry.getNewRdn() ) );
>             }
>             conn.modifyDn( modDnRequest );
>             break;
>         case Delete:
>             conn.delete( entry.getDn() );
>             break;
>         case Modify:
>             conn.modify( entry.getDn(), entry.getModificationArray() );
>             break;
>         default:
>             throw new IllegalArgumentException( "Unknown change type in
> LdifEntry: "
>                 + entry.getChangeType().toString() );
>     }
> }
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message