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

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


        reader.close();

        assertEquals( 1, entries.size() );

        // Entry
        LdifEntry entry = entries.get( 0 );

        assertEquals( "dc=example,dc=com", entry.getDn().getName() );

        assertTrue( entry.isLdifChange() );
        assertTrue( entry.isChangeAdd() );

        assertEquals( 2, entry.getEntry().size() );

        Attribute attr = entry.get( "attr1" );
        assertEquals( 2, attr.size() );
        assertTrue( attr.contains( "ATTR1" ) );
        assertTrue( attr.contains( "ATTR2" ) );

        Attribute attr2 = entry.get( "attr2" );
        assertEquals( 1, attr2.size() );
        assertTrue( attr2.contains( "ATTR1" ) );
    }
View Full Code Here


        reader.close();

        assertEquals( 1, entries.size() );

        // Entry
        LdifEntry entry = entries.get( 0 );

        assertEquals( "dc=example,dc=com", entry.getDn().getName() );

        assertTrue( entry.isLdifChange() );
        assertTrue( entry.isChangeDelete() );
    }
View Full Code Here

        reader.close();

        assertEquals( 1, entries.size() );

        // Entry
        LdifEntry entry = entries.get( 0 );

        assertEquals( "dc=example,dc=com", entry.getDn().getName() );

        assertTrue( entry.isLdifChange() );
        assertTrue( entry.isChangeDelete() );

        assertTrue( entry.hasControls() );
        assertEquals( 1, entry.getControls().size() );

        LdifControl control = entry.getControl( "1.1.1" );

        assertEquals( "1.1.1", control.getOid() );
        assertFalse( control.isCritical() );
        assertNull( control.getValue() );
    }
View Full Code Here

        reader.close();

        assertEquals( 1, entries.size() );

        // Entry
        LdifEntry entry = entries.get( 0 );

        assertEquals( "dc=example,dc=com", entry.getDn().getName() );

        assertTrue( entry.isLdifChange() );
        assertTrue( entry.isChangeDelete() );

        assertTrue( entry.hasControls() );
        assertEquals( 6, entry.getControls().size() );

        // First control
        LdifControl control = entry.getControl( "1.1.1" );

        assertEquals( "1.1.1", control.getOid() );
        assertFalse( control.isCritical() );
        assertNull( control.getValue() );

        // Second control
        control = entry.getControl( "1.1.2" );

        assertEquals( "1.1.2", control.getOid() );
        assertTrue( control.isCritical() );
        assertNull( control.getValue() );

        // Third control
        control = entry.getControl( "1.1.3" );

        assertEquals( "1.1.3", control.getOid() );
        assertFalse( control.isCritical() );
        assertEquals( "ABCDEF", Strings.utf8ToString( control.getValue() ) );

        // Forth control
        control = entry.getControl( "1.1.4" );

        assertEquals( "1.1.4", control.getOid() );
        assertTrue( control.isCritical() );
        assertEquals( "ABCDEF", Strings.utf8ToString( control.getValue() ) );

        // Fifth control
        control = entry.getControl( "1.1.5" );

        assertEquals( "1.1.5", control.getOid() );
        assertFalse( control.isCritical() );
        assertEquals( "Emmanuel L\u00e9charny", Strings.utf8ToString( control.getValue() ) );

        // Sixth control
        control = entry.getControl( "1.1.6" );

        assertEquals( "1.1.6", control.getOid() );
        assertTrue( control.isCritical() );
        assertEquals( "Emmanuel L\u00e9charny", Strings.utf8ToString( control.getValue() ) );
    }
View Full Code Here

  {
    for ( LdifEntry testEntry : testEntries )
    {
      try
      {
        LdifEntry ldifEntry = testEntry.clone();
        Entry entry = ldifEntry.getEntry();
        String dn = ldifEntry.getDn().getName();

        try
        {
          getAdminSession().add( new DefaultEntry( schemaManager, entry ) );
        }
View Full Code Here

            {
                // Getting the first original entry from the list
                Entry originalEntry = originalEntries.remove( 0 );

                // Creating a modification entry to hold all modifications
                LdifEntry modificationEntry = new LdifEntry();
                modificationEntry.setDn( originalEntry.getDn() );

                // Looking for the equivalent entry in the destination partition
                Entry destinationEntry = destinationPartition.lookup( new LookupOperationContext( null, originalEntry
                    .getDn(), attributeIds ) );
                if ( destinationEntry != null )
                {
                    // Setting the changetype to delete
                    modificationEntry.setChangeType( ChangeType.Modify );

                    // Comparing both entries
                    compareEntries( originalEntry, destinationEntry, modificationEntry );
                }
                else
                {
                    // The original entry is no longer present in the destination partition

                    // Setting the changetype to delete
                    modificationEntry.setChangeType( ChangeType.Delete );
                }

                // Checking if modifications occurred on the original entry
                ChangeType modificationEntryChangeType = modificationEntry.getChangeType();
                if ( modificationEntryChangeType != ChangeType.None )
                {
                    if ( modificationEntryChangeType == ChangeType.Delete
                        || ( modificationEntryChangeType == ChangeType.Modify && modificationEntry
                            .getModifications().size() > 0 ) )
                    {
                        // Adding the modification entry to the list
                        modifications.add( modificationEntry );
                    }
                }

                // Creating a search operation context to get the children of the current entry
                SearchOperationContext soc = new SearchOperationContext( null, originalEntry.getDn(),
                    SearchScope.ONELEVEL,
                    FilterParser.parse( originalPartition.getSchemaManager(), "(objectClass=*)" ), attributeIds ); //$NON-NLS-1$
                soc.setAliasDerefMode( AliasDerefMode.DEREF_ALWAYS );

                // Looking for the children of the current entry
                EntryFilteringCursor cursor = originalPartition.search( soc );

                while ( cursor.next() )
                {
                    originalEntries.add( ( ( ClonedServerEntry ) cursor.get() ).getClonedEntry() );
                }
            }

            // Reversing the list to allow deletion of leafs first (otherwise we would be deleting
            // higher nodes with children first).
            // Order for modified entries does not matter.
            Collections.reverse( modifications );

            // Looking up the destination base entry
            Entry destinationBaseEntry = destinationPartition
                .lookup( new LookupOperationContext( null, baseDn, attributeIds ) );
            if ( destinationBaseEntry == null )
            {
                throw new PartitionsDiffException( "Unable to find the base entry in the destination partition." ); //$NON-NLS-1$
            }

            // Creating the list containing all the destination entries to be processed
            // and adding it the destination base entry
            List<Entry> destinationEntries = new ArrayList<Entry>();
            destinationEntries.add( originalBaseEntry );

            // Looping until all destination entries are being processed
            while ( destinationEntries.size() > 0 )
            {
                // Getting the first destination entry from the list
                Entry destinationEntry = destinationEntries.remove( 0 );

                // Looking for the equivalent entry in the destination partition
                Entry originalEntry = originalPartition.lookup( new LookupOperationContext( null, destinationEntry
                    .getDn(), attributeIds ) );
                // We're only looking for new entries, modified or removed
                // entries have already been computed
                if ( originalEntry == null )
                {
                    // Creating a modification entry to hold all modifications
                    LdifEntry modificationEntry = new LdifEntry();
                    modificationEntry.setDn( destinationEntry.getDn() );

                    // Setting the changetype to addition
                    modificationEntry.setChangeType( ChangeType.Add );

                    // Copying attributes
                    for ( Attribute attribute : destinationEntry )
                    {
                        modificationEntry.addAttribute( attribute );
                    }

                    // Adding the modification entry to the list
                    modifications.add( modificationEntry );
                }
View Full Code Here

            {
                // Getting out of the loop if we found both entries
                break;
            }

            LdifEntry entry = reader.next();
            checkedEntries++;

            // Checking if this is the config entry
            if ( !configEntryFound )
            {
                if ( configEntryDn.getName().equalsIgnoreCase( entry.getDn().getNormName() ) )
                {
                    configEntryFound = true;
                    continue;
                }
            }

            // Checking if this is the directory service entry
            if ( !directoryServiceEntryFound )
            {
                if ( directoryServiceDn.getName().equalsIgnoreCase( entry.getDn().getNormName() ) )
                {
                    directoryServiceEntryFound = true;
                    continue;
                }
            }
View Full Code Here

       
        try
        {
            ldifReader = new LdifReader( source );
            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() );
                    }

                    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 );
                }
            }

            // Add the version at the first line, to avoid a warning
            String ldifString = "version: 1\n" + ldifEntry.toString();

            out.write( ldifString );
            out.flush();
        }
        catch ( LdapLdifException ne )
View Full Code Here

    @Test
    public void testLogCheckRevision() throws Exception
    {
        assertEquals( "first revision is always 0", 0, store.getCurrentRevision() );

        LdifEntry forward = new LdifEntry();
        forward.setDn( "ou=system" );
        forward.setChangeType( ChangeType.Add );
        forward.putAttribute( "objectClass", "organizationalUnit" );
        forward.putAttribute( "ou", "system" );

        LdifEntry reverse = LdifRevertor.reverseAdd( forward.getDn() );
        assertEquals( 1, store.log( new LdapPrincipal( schemaManager ), forward, reverse ).getRevision() );
        assertEquals( 1, store.getCurrentRevision() );
    }
View Full Code Here

        systemDn.apply( schemaManager );

        Dn adminDn = new Dn( schemaManager, "uid=admin, ou=system" );
        adminDn.apply( schemaManager );

        LdifEntry forward = new LdifEntry();
        forward.setDn( systemDn );
        forward.setChangeType( ChangeType.Add );
        forward.putAttribute( "objectClass", "organizationalUnit" );
        forward.putAttribute( "ou", "system" );

        Dn reverseDn = forward.getDn();
        reverseDn.apply( schemaManager );

        LdifEntry reverse = LdifRevertor.reverseAdd( reverseDn );

        String zuluTime = DateUtils.getGeneralizedTime();
        long revision = 1L;

        LdapPrincipal principal = new LdapPrincipal( schemaManager, adminDn, AuthenticationLevel.SIMPLE,
View Full Code Here

TOP

Related Classes of org.apache.directory.api.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.