Package org.apache.directory.shared.ldap.model.ldif

Examples of org.apache.directory.shared.ldap.model.ldif.LdifEntry


        file.read( entry1Data );

        String ldif = Strings.utf8ToString( entry1Data );

        LdifEntry ldifEntry = reader.parseLdif( ldif ).get( 0 );

        assertEquals( entry1, new DefaultEntry( schemaManager, ldifEntry.getEntry() ) );

        //"description: desc of entry1\n"

        modOpCtx = new ModifyOperationContext( mockSession );
        modOpCtx.setEntry( new ClonedServerEntry( entry1 ) );
        modOpCtx.setDn( entry1.getDn() );

        modItems = new ArrayList<Modification>();

        attribute = new DefaultAttribute( schemaManager.lookupAttributeTypeRegistry( "description" ) );
        attribute.add( "desc of entry1" ); // reversed "this is description"

        mod = new DefaultModification();
        mod.setOperation( ModificationOperation.REMOVE_ATTRIBUTE );
        mod.setAttribute( attribute );

        modItems.add( mod );
        modOpCtx.setModItems( modItems );

        partition.modify( modOpCtx );

        file.seek( ctxEntryLen );

        entry1Len = getEntryLdifLen( entry1 );
        entry1Data = new byte[( int ) entry1Len];

        file.read( entry1Data );

        ldif = Strings.utf8ToString( entry1Data );

        ldifEntry = reader.parseLdif( ldif ).get( 0 );

        assertEquals( entry1, new DefaultEntry( schemaManager, ldifEntry.getEntry() ) );

        partition = reloadPartition();
        assertExists( partition, contextEntry );
        assertExists( partition, entry1 );
        assertExists( partition, entry2 );
View Full Code Here


     *
     * @throws NamingException on error
     */
    protected void createData() throws Exception
    {
        LdifEntry akarasulu = getUserAddLdif();
        getService().getAdminSession().add(
            new DefaultEntry( getService().getSchemaManager(), akarasulu.getEntry() ) );

        LdapContext sysRoot = getSystemContext( getService() );

        /*
         * create ou=testing00,ou=system
View Full Code Here

{

    @Test
    public void testObjectFactory() throws Exception
    {
        LdifEntry akarasulu = getUserAddLdif();
        getService().getAdminSession().add(
            new DefaultEntry( getService().getSchemaManager(), akarasulu.getEntry() ) );

        LdapContext sysRoot = getSystemContext( getService() );
        sysRoot.addToEnvironment( Context.OBJECT_FACTORIES, PersonObjectFactory.class.getName() );
        Object obj = sysRoot.lookup( "uid=akarasulu, ou=users" );
        Attributes attrs = sysRoot.getAttributes( "uid=akarasulu, ou=users" );
View Full Code Here

   
        LdifReader reader = new LdifReader( new StringReader( ldif ) );
   
        while ( reader.hasNext() )
        {
            LdifEntry entry = reader.next();
            getLdapServer().getDirectoryService().getAdminSession().add(
                new DefaultEntry( getLdapServer().getDirectoryService().getSchemaManager(), entry.getEntry() ) );
        }
    }
View Full Code Here

    public static LdifEntry getUserAddLdif( String dnstr, byte[] password, String cn, String sn )
        throws LdapException
    {
        Dn dn = new Dn( dnstr );
        LdifEntry ldif = new LdifEntry();
        ldif.setDn( dnstr );
        ldif.setChangeType( ChangeType.Add );

        Attribute attr = new DefaultAttribute( "objectClass",
            "top", "person", "organizationalPerson", "inetOrgPerson" );
        ldif.addAttribute( attr );

        attr = new DefaultAttribute( "ou", "Engineering", "People" );
        ldif.addAttribute( attr );

        String uid = dn.getRdn().getNormValue().getString();
        ldif.putAttribute( "uid", uid );

        ldif.putAttribute( "l", "Bogusville" );
        ldif.putAttribute( "cn", cn );
        ldif.putAttribute( "sn", sn );
        ldif.putAttribute( "mail", uid + "@apache.org" );
        ldif.putAttribute( "telephoneNumber", "+1 408 555 4798" );
        ldif.putAttribute( "facsimileTelephoneNumber", "+1 408 555 9751" );
        ldif.putAttribute( "roomnumber", "4612" );
        ldif.putAttribute( "userPassword", password );

        String givenName = cn.split( " " )[0];
        ldif.putAttribute( "givenName", givenName );
        return ldif;
    }
View Full Code Here

    {
        try
        {
            LdifReader ldifReader = new LdifReader( in );
            boolean first = true;
            LdifEntry ldifEntry = null;

            while ( ldifReader.hasNext() )
            {
                if ( first )
                {
                    ldifEntry = ldifReader.next();

                    if ( ldifEntry.get( SchemaConstants.ENTRY_UUID_AT ) == null )
                    {
                        // No UUID, let's create one
                        UUID entryUuid = UUID.randomUUID();
                        ldifEntry.addAttribute( SchemaConstants.ENTRY_UUID_AT, entryUuid.toString() );
                    }
                    if ( ldifEntry.get( SchemaConstants.ENTRY_CSN_AT ) == null )
                    {
                        // No CSN, let's create one
                        Csn csn = csnFactory.newInstance();
                        ldifEntry.addAttribute( SchemaConstants.ENTRY_CSN_AT, csn.toString() );
                    }

                    first = false;
                }
                else
                {
                    // throw an exception : we should not have more than one entry per schema ldif file
                    String msg = I18n.err( I18n.ERR_08003, source );
                    LOG.error( msg );
                    throw new InvalidObjectException( msg );
                }
            }

            ldifReader.close();

            // inject the entry
            Entry entry = new DefaultEntry( schemaManager, ldifEntry.getEntry() );
            AddOperationContext addContext = new AddOperationContext( null, entry );
            partition.add( addContext );
        }
        catch ( LdapLdifException ne )
        {
View Full Code Here

            opRevision = revision.incrementAndGet();

            // Store the added entry
            Entry addEntry = addContext.getEntry();

            LdifEntry ldif = new LdifEntry();
            ldif.setChangeType( ChangeType.Add );
            ldif.setDn( addContext.getDn() );

            for ( Attribute attribute : addEntry.getAttributes() )
            {
                AttributeType attributeType = attribute.getAttributeType();
                ldif.addAttribute( addEntry.get( attributeType ).clone() );
            }

            log( addContext, opRevision, ldif );
        }
View Full Code Here

        if ( journalEnabled )
        {
            opRevision = revision.incrementAndGet();

            // Store the deleted entry
            LdifEntry ldif = new LdifEntry();
            ldif.setChangeType( ChangeType.Delete );
            ldif.setDn( deleteContext.getDn() );

            journal.log( getPrincipal( deleteContext ), opRevision, ldif );
        }

        try
View Full Code Here

        if ( journalEnabled )
        {
            opRevision = revision.incrementAndGet();

            // Store the modified entry
            LdifEntry ldif = new LdifEntry();
            ldif.setChangeType( ChangeType.Modify );
            ldif.setDn( modifyContext.getDn() );

            // Store the modifications
            for ( Modification modification : modifyContext.getModItems() )
            {
                ldif.addModification( modification );
            }

            journal.log( getPrincipal( modifyContext ), opRevision, ldif );
        }
View Full Code Here

        if ( journalEnabled )
        {
            opRevision = revision.incrementAndGet();

            // Store the moved entry
            LdifEntry ldif = new LdifEntry();
            ldif.setChangeType( ChangeType.ModDn );
            ldif.setDn( moveContext.getDn() );
            ldif.setNewSuperior( moveContext.getNewSuperior().getNormName() );

            journal.log( getPrincipal( moveContext ), opRevision, ldif );
        }

        try
View Full Code Here

TOP

Related Classes of org.apache.directory.shared.ldap.model.ldif.LdifEntry

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.