Java Code Examples for org.apache.directory.api.ldap.model.entry.Modification#getOperation()

The following examples show how to use org.apache.directory.api.ldap.model.entry.Modification#getOperation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServerEntryUtils.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * Convert a Modification to an instance of a ServerModification object.
 *
 * @param modificationImpl the modification instance to convert
 * @param attributeType the associated attributeType
 * @return a instance of a ServerModification object
 */
private static Modification toServerModification( Modification modification, AttributeType attributeType )
    throws LdapException
{
    Modification serverModification = new DefaultModification(
        modification.getOperation(),
        new DefaultAttribute( attributeType, modification.getAttribute() ) );

    return serverModification;

}
 
Example 2
Source File: ServerEntryUtils.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * Convert a Modification to an instance of a ServerModification object.
 *
 * @param modificationImpl the modification instance to convert
 * @param attributeType the associated attributeType
 * @return a instance of a ServerModification object
 */
private static Modification toServerModification( Modification modification, AttributeType attributeType )
    throws LdapException
{
    Modification serverModification = new DefaultModification(
        modification.getOperation(),
        new DefaultAttribute( attributeType, modification.getAttribute() ) );

    return serverModification;

}
 
Example 3
Source File: ModifyRequestDsml.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Element toDsml( Element root )
{
    Element element = super.toDsml( root );

    ModifyRequest request = getDecorated();

    // Dn
    if ( request.getName() != null )
    {
        element.addAttribute( "dn", request.getName().getName() );
    }

    // Modifications
    Collection<Modification> modifications = request.getModifications();

    for ( Modification modification : modifications )
    {
        Element modElement = element.addElement( "modification" );

        if ( modification.getAttribute() != null )
        {
            modElement.addAttribute( "name", modification.getAttribute().getId() );

            for ( Value value : modification.getAttribute() )
            {
                if ( value.getString() != null )
                {
                    if ( ParserUtils.needsBase64Encoding( value.getString() ) )
                    {
                        Namespace xsdNamespace = new Namespace( "xsd", ParserUtils.XML_SCHEMA_URI );
                        Namespace xsiNamespace = new Namespace( "xsi", ParserUtils.XML_SCHEMA_INSTANCE_URI );
                        element.getDocument().getRootElement().add( xsdNamespace );
                        element.getDocument().getRootElement().add( xsiNamespace );

                        Element valueElement = modElement.addElement( "value" ).addText(
                            ParserUtils.base64Encode( value.getString() ) );
                        valueElement.addAttribute( new QName( "type", xsiNamespace ), "xsd:"
                            + ParserUtils.BASE64BINARY );
                    }
                    else
                    {
                        modElement.addElement( "value" ).setText( value.getString() );
                    }
                }
            }
        }

        ModificationOperation operation = modification.getOperation();

        if ( operation == ModificationOperation.ADD_ATTRIBUTE )
        {
            modElement.addAttribute( "operation", "add" );
        }
        else if ( operation == ModificationOperation.REPLACE_ATTRIBUTE )
        {
            modElement.addAttribute( "operation", "replace" );
        }
        else if ( operation == ModificationOperation.REMOVE_ATTRIBUTE )
        {
            modElement.addAttribute( "operation", "delete" );
        }
        else if ( operation == ModificationOperation.INCREMENT_ATTRIBUTE )
        {
            modElement.addAttribute( "operation", "increment" );
        }
    }

    return element;
}
 
Example 4
Source File: ModifyRequestFactory.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Recursively encode the modifications, starting from the last one.
 * <pre>
 * 0x30 LL modification sequence
 *   0x0A 0x01 operation
 *   0x30 LL modification
 *     0x04 LL type
 *     0x31 LL vals
 *       0x04 LL attributeValue
 *       ...
 *       0x04 LL attributeValue
 * </pre>
 *
 * @param buffer The buffer where to put the PDU
 * @param modifications the modifications to encode
 */
private void encodeModifications( Asn1Buffer buffer, Iterator<Modification> modifications )
{
    if ( modifications.hasNext() )
    {
        Modification modification = modifications.next();

        // Recurse
        encodeModifications( buffer, modifications );

        int start = buffer.getPos();

        // The Attribute
        Attribute attribute = modification.getAttribute();

        // The values, if any
        if ( modification.getAttribute().size() != 0 )
        {
            encodeValues( buffer, modification.getAttribute().iterator() );

            // the value set
            BerValue.encodeSet( buffer, start );
        }
        else if ( modification.getOperation() != ModificationOperation.INCREMENT_ATTRIBUTE )
        {
            // the value set, if not a INCREMENT operation
            BerValue.encodeSet( buffer, start );
        }

        // The attribute type
        BerValue.encodeOctetString( buffer, attribute.getUpId() );

        // The attribute sequence
        BerValue.encodeSequence( buffer, start );

        // The operation
        BerValue.encodeEnumerated( buffer, modification.getOperation().getValue() );

        // The modification sequence
        BerValue.encodeSequence( buffer, start );
    }
}
 
Example 5
Source File: ServerEntryUtils.java    From MyVirtualDirectory with Apache License 2.0 4 votes vote down vote up
public static List<Modification> toServerModification( Modification[] modifications,
    SchemaManager schemaManager ) throws LdapException
{
    if ( modifications != null )
    {
        List<Modification> modificationsList = new ArrayList<Modification>();

        for ( Modification modification : modifications )
        {
            String attributeId = modification.getAttribute().getUpId();
            String id = stripOptions( attributeId );
            modification.getAttribute().setUpId( id );
            Set<String> options = getOptions( attributeId );

            // -------------------------------------------------------------------
            // DIRSERVER-646 Fix: Replacing an unknown attribute with no values 
            // (deletion) causes an error
            // -------------------------------------------------------------------
            if ( !schemaManager.getAttributeTypeRegistry().contains( id )
                && modification.getAttribute().size() == 0
                && modification.getOperation() == ModificationOperation.REPLACE_ATTRIBUTE )
            {
                // The attributeType does not exist in the schema.
                // It's an error
                String message = I18n.err( I18n.ERR_467, id );
                throw new LdapInvalidAttributeTypeException( message );
            }
            else
            {
                // TODO : handle options
                AttributeType attributeType = null;
                try {
                	attributeType = schemaManager.lookupAttributeTypeRegistry( id );
                } catch (LdapNoSuchAttributeException e) {
                	attributeType = ApacheDSUtil.addAttributeToSchema(modification.getAttribute(), schemaManager);
                }
                modificationsList.add( toServerModification( modification, attributeType ) );
            }
        }

        return modificationsList;
    }
    else
    {
        return null;
    }
}
 
Example 6
Source File: ServerEntryUtils.java    From MyVirtualDirectory with Apache License 2.0 4 votes vote down vote up
public static List<Modification> toServerModification( Modification[] modifications,
    SchemaManager schemaManager ) throws LdapException
{
    if ( modifications != null )
    {
        List<Modification> modificationsList = new ArrayList<Modification>();

        for ( Modification modification : modifications )
        {
            String attributeId = modification.getAttribute().getUpId();
            String id = stripOptions( attributeId );
            modification.getAttribute().setUpId( id );
            Set<String> options = getOptions( attributeId );

            // -------------------------------------------------------------------
            // DIRSERVER-646 Fix: Replacing an unknown attribute with no values 
            // (deletion) causes an error
            // -------------------------------------------------------------------
            if ( !schemaManager.getAttributeTypeRegistry().contains( id )
                && modification.getAttribute().size() == 0
                && modification.getOperation() == ModificationOperation.REPLACE_ATTRIBUTE )
            {
                // The attributeType does not exist in the schema.
                // It's an error
                String message = I18n.err( I18n.ERR_467, id );
                throw new LdapInvalidAttributeTypeException( message );
            }
            else
            {
                // TODO : handle options
                AttributeType attributeType = null;
                try {
                	attributeType = schemaManager.lookupAttributeTypeRegistry( id );
                } catch (LdapNoSuchAttributeException e) {
                	attributeType = ApacheDSUtil.addAttributeToSchema(modification.getAttribute(), schemaManager);
                }
                modificationsList.add( toServerModification( modification, attributeType ) );
            }
        }

        return modificationsList;
    }
    else
    {
        return null;
    }
}