Search in sources :

Example 1 with DefaultAttribute

use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project ldapchai by ldapchai.

the class ApacheLdapProviderImpl method writeStringAttributes.

public void writeStringAttributes(final String entryDN, final Map<String, String> attributeValueProps, final boolean overwrite) throws ChaiOperationException, ChaiUnavailableException, IllegalStateException {
    activityPreCheck();
    getInputValidator().writeStringAttributes(entryDN, attributeValueProps, overwrite);
    try {
        final ModifyRequest modifyRequest = new ModifyRequestImpl();
        modifyRequest.setName(new Dn(entryDN));
        for (final Map.Entry<String, String> entry : attributeValueProps.entrySet()) {
            final String name = entry.getKey();
            final String value = entry.getValue();
            final Modification modification = new DefaultModification();
            modification.setOperation(overwrite ? ModificationOperation.REPLACE_ATTRIBUTE : ModificationOperation.ADD_ATTRIBUTE);
            modification.setAttribute(new DefaultAttribute(name, value));
            modifyRequest.addModification(modification);
        }
        final ModifyResponse response = connection.modify(modifyRequest);
        processResponse(response);
    } catch (LdapException e) {
        throw ChaiOperationException.forErrorMessage(e.getMessage());
    }
}
Also used : DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Modification(org.apache.directory.api.ldap.model.entry.Modification) ModifyRequestImpl(org.apache.directory.api.ldap.model.message.ModifyRequestImpl) DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Dn(org.apache.directory.api.ldap.model.name.Dn) ModifyRequest(org.apache.directory.api.ldap.model.message.ModifyRequest) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) ModifyResponse(org.apache.directory.api.ldap.model.message.ModifyResponse)

Example 2 with DefaultAttribute

use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project ldapchai by ldapchai.

the class ApacheLdapProviderImpl method replaceAttributeImpl.

private void replaceAttributeImpl(final String entryDN, final String attributeName, final Value oldValue, final Value newValue) throws ChaiOperationException {
    try {
        final ModifyRequest modifyRequest = new ModifyRequestImpl();
        modifyRequest.setName(new Dn(entryDN));
        {
            final Modification modification = new DefaultModification();
            modification.setOperation(ModificationOperation.REMOVE_ATTRIBUTE);
            modification.setAttribute(new DefaultAttribute(attributeName, oldValue));
            modifyRequest.addModification(modification);
        }
        {
            final Modification modification = new DefaultModification();
            modification.setOperation(ModificationOperation.ADD_ATTRIBUTE);
            modification.setAttribute(new DefaultAttribute(attributeName, newValue));
            modifyRequest.addModification(modification);
        }
        final ModifyResponse response = connection.modify(modifyRequest);
        processResponse(response);
    } catch (LdapException e) {
        throw ChaiOperationException.forErrorMessage(e.getMessage());
    }
}
Also used : DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Modification(org.apache.directory.api.ldap.model.entry.Modification) ModifyRequestImpl(org.apache.directory.api.ldap.model.message.ModifyRequestImpl) DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Dn(org.apache.directory.api.ldap.model.name.Dn) ModifyRequest(org.apache.directory.api.ldap.model.message.ModifyRequest) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) ModifyResponse(org.apache.directory.api.ldap.model.message.ModifyResponse)

Example 3 with DefaultAttribute

use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project ldapchai by ldapchai.

the class ApacheLdapProviderImpl method writeBinaryAttribute.

public void writeBinaryAttribute(final String entryDN, final String attributeName, final byte[][] values, final boolean overwrite) throws ChaiUnavailableException, ChaiOperationException {
    activityPreCheck();
    getInputValidator().writeBinaryAttribute(entryDN, attributeName, values, overwrite);
    try {
        final ModifyRequest modifyRequest = new ModifyRequestImpl();
        modifyRequest.setName(new Dn(entryDN));
        {
            final Modification modification = new DefaultModification();
            modification.setOperation(overwrite ? ModificationOperation.REPLACE_ATTRIBUTE : ModificationOperation.ADD_ATTRIBUTE);
            modification.setAttribute(new DefaultAttribute(attributeName, values));
            modifyRequest.addModification(modification);
        }
        final ModifyResponse response = connection.modify(modifyRequest);
        processResponse(response);
    } catch (LdapException e) {
        throw ChaiOperationException.forErrorMessage(e.getMessage());
    }
}
Also used : DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Modification(org.apache.directory.api.ldap.model.entry.Modification) ModifyRequestImpl(org.apache.directory.api.ldap.model.message.ModifyRequestImpl) DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Dn(org.apache.directory.api.ldap.model.name.Dn) ModifyRequest(org.apache.directory.api.ldap.model.message.ModifyRequest) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) ModifyResponse(org.apache.directory.api.ldap.model.message.ModifyResponse)

Example 4 with DefaultAttribute

use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project ldapchai by ldapchai.

the class ApacheLdapProviderImpl method writeStringAttribute.

public void writeStringAttribute(final String entryDN, final String attributeName, final Set<String> values, final boolean overwrite) throws ChaiOperationException, ChaiUnavailableException, IllegalStateException {
    activityPreCheck();
    getInputValidator().writeStringAttribute(entryDN, attributeName, values, overwrite);
    try {
        final ModifyRequest modifyRequest = new ModifyRequestImpl();
        modifyRequest.setName(new Dn(entryDN));
        {
            final Modification modification = new DefaultModification();
            modification.setOperation(overwrite ? ModificationOperation.REPLACE_ATTRIBUTE : ModificationOperation.ADD_ATTRIBUTE);
            modification.setAttribute(new DefaultAttribute(attributeName, values.toArray(new String[values.size()])));
            modifyRequest.addModification(modification);
        }
        final ModifyResponse response = connection.modify(modifyRequest);
        processResponse(response);
    } catch (LdapException e) {
        throw ChaiOperationException.forErrorMessage(e.getMessage());
    }
}
Also used : DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Modification(org.apache.directory.api.ldap.model.entry.Modification) ModifyRequestImpl(org.apache.directory.api.ldap.model.message.ModifyRequestImpl) DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Dn(org.apache.directory.api.ldap.model.name.Dn) ModifyRequest(org.apache.directory.api.ldap.model.message.ModifyRequest) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) ModifyResponse(org.apache.directory.api.ldap.model.message.ModifyResponse)

Example 5 with DefaultAttribute

use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.

the class AttributeValueItemTest method initNames.

/**
 * Initialize maxValueCountItem instances
 */
@Before
public void initNames() throws Exception {
    attributeA = new HashSet<Attribute>();
    attributeA.add(new DefaultAttribute("aa", "aa"));
    attributeA.add(new DefaultAttribute("aa", "bb"));
    attributeA.add(new DefaultAttribute("aa", "cc"));
    // Sets aren't ordered, so adding order must not matter
    attributeB = new HashSet<Attribute>();
    attributeB.add(new DefaultAttribute("aa", "bb"));
    attributeB.add(new DefaultAttribute("aa", "cc"));
    attributeB.add(new DefaultAttribute("aa", "aa"));
    attributeC = new HashSet<Attribute>();
    attributeC.add(new DefaultAttribute("aa", "aa"));
    attributeC.add(new DefaultAttribute("bb", "bb"));
    attributeC.add(new DefaultAttribute("aa", "cc"));
    attributeD = new HashSet<Attribute>();
    attributeD.add(new DefaultAttribute("aa", "aa"));
    attributeD.add(new DefaultAttribute("aa", "bb"));
    attributeD.add(new DefaultAttribute("aa", "dd"));
    attributeValueItemA = new AttributeValueItem(attributeA);
    attributeValueItemACopy = new AttributeValueItem(attributeA);
    attributeValueItemB = new AttributeValueItem(attributeB);
    attributeValueItemC = new AttributeValueItem(attributeC);
    attributeValueItemD = new AttributeValueItem(attributeD);
}
Also used : DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) AttributeValueItem(org.apache.directory.api.ldap.aci.protectedItem.AttributeValueItem) Before(org.junit.Before)

Aggregations

DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)159 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)131 Test (org.junit.Test)106 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)41 Modification (org.apache.directory.api.ldap.model.entry.Modification)40 Entry (org.apache.directory.api.ldap.model.entry.Entry)36 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)35 Value (org.apache.directory.api.ldap.model.entry.Value)20 ByteArrayInputStream (java.io.ByteArrayInputStream)13 ObjectInputStream (java.io.ObjectInputStream)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)12 ObjectOutputStream (java.io.ObjectOutputStream)12 Dn (org.apache.directory.api.ldap.model.name.Dn)12 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)11 AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)11 LdapInvalidAttributeValueException (org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException)8 ModifyRequest (org.apache.directory.api.ldap.model.message.ModifyRequest)7 ModifyRequestImpl (org.apache.directory.api.ldap.model.message.ModifyRequestImpl)7 ModifyResponse (org.apache.directory.api.ldap.model.message.ModifyResponse)7 HashSet (java.util.HashSet)6