Search in sources :

Example 1 with AddRequestImpl

use of org.apache.directory.api.ldap.model.message.AddRequestImpl in project ldapchai by ldapchai.

the class ApacheLdapProviderImpl method createEntry.

public void createEntry(final String entryDN, final Set<String> baseObjectClasses, final Map<String, String> stringAttributes) throws ChaiOperationException, ChaiUnavailableException, IllegalStateException {
    activityPreCheck();
    getInputValidator().createEntry(entryDN, baseObjectClasses, stringAttributes);
    try {
        final AddRequest addRequest = new AddRequestImpl();
        final Entry entry = new DefaultEntry();
        entry.setDn(entryDN);
        for (final String baseObjectClass : baseObjectClasses) {
            entry.add(ChaiConstant.ATTR_LDAP_OBJECTCLASS, baseObjectClass);
        }
        for (final Map.Entry<String, String> entryIter : stringAttributes.entrySet()) {
            final String name = entryIter.getKey();
            final String value = entryIter.getValue();
            entry.add(name, value);
        }
        final AddResponse response = connection.add(addRequest);
        processResponse(response);
    } catch (LdapException e) {
        throw ChaiOperationException.forErrorMessage(e.getMessage());
    }
}
Also used : AddRequest(org.apache.directory.api.ldap.model.message.AddRequest) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) AddRequestImpl(org.apache.directory.api.ldap.model.message.AddRequestImpl) AddResponse(org.apache.directory.api.ldap.model.message.AddResponse) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 2 with AddRequestImpl

use of org.apache.directory.api.ldap.model.message.AddRequestImpl in project directory-ldap-api by apache.

the class LdapNetworkConnection method addAsync.

/**
 * {@inheritDoc}
 */
@Override
public AddFuture addAsync(Entry entry) throws LdapException {
    if (entry == null) {
        String msg = "Cannot add null entry";
        LOG.debug(msg);
        throw new IllegalArgumentException(msg);
    }
    AddRequest addRequest = new AddRequestImpl();
    addRequest.setEntry(entry);
    return addAsync(addRequest);
}
Also used : AddRequest(org.apache.directory.api.ldap.model.message.AddRequest) AddRequestImpl(org.apache.directory.api.ldap.model.message.AddRequestImpl)

Example 3 with AddRequestImpl

use of org.apache.directory.api.ldap.model.message.AddRequestImpl in project directory-ldap-api by apache.

the class LdapNetworkConnection method add.

// ------------------------ The LDAP operations ------------------------//
// Add operations                                                      //
// ---------------------------------------------------------------------//
/**
 * {@inheritDoc}
 */
@Override
public void add(Entry entry) throws LdapException {
    if (entry == null) {
        String msg = "Cannot add an empty entry";
        LOG.debug(msg);
        throw new IllegalArgumentException(msg);
    }
    AddRequest addRequest = new AddRequestImpl();
    addRequest.setEntry(entry);
    AddResponse addResponse = add(addRequest);
    processResponse(addResponse);
}
Also used : AddRequest(org.apache.directory.api.ldap.model.message.AddRequest) AddRequestImpl(org.apache.directory.api.ldap.model.message.AddRequestImpl) AddResponse(org.apache.directory.api.ldap.model.message.AddResponse)

Example 4 with AddRequestImpl

use of org.apache.directory.api.ldap.model.message.AddRequestImpl in project directory-ldap-api by apache.

the class InitAddRequest method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<AddRequestDecorator> container) throws DecoderException {
    // Now, we can allocate the AddRequest Object
    int messageId = container.getMessageId();
    AddRequest internalAddRequest = new AddRequestImpl();
    internalAddRequest.setMessageId(messageId);
    AddRequestDecorator addRequest = new AddRequestDecorator(container.getLdapCodecService(), internalAddRequest);
    container.setMessage(addRequest);
    // We will check that the request is not null
    TLV tlv = container.getCurrentTLV();
    if (tlv.getLength() == 0) {
        String msg = I18n.err(I18n.ERR_04084);
        LOG.error(msg);
        // Will generate a PROTOCOL_ERROR
        throw new DecoderException(msg);
    }
}
Also used : AddRequest(org.apache.directory.api.ldap.model.message.AddRequest) DecoderException(org.apache.directory.api.asn1.DecoderException) AddRequestImpl(org.apache.directory.api.ldap.model.message.AddRequestImpl) AddRequestDecorator(org.apache.directory.api.ldap.codec.decorators.AddRequestDecorator) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Aggregations

AddRequest (org.apache.directory.api.ldap.model.message.AddRequest)4 AddRequestImpl (org.apache.directory.api.ldap.model.message.AddRequestImpl)4 AddResponse (org.apache.directory.api.ldap.model.message.AddResponse)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 DecoderException (org.apache.directory.api.asn1.DecoderException)1 TLV (org.apache.directory.api.asn1.ber.tlv.TLV)1 AddRequestDecorator (org.apache.directory.api.ldap.codec.decorators.AddRequestDecorator)1 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)1 Entry (org.apache.directory.api.ldap.model.entry.Entry)1 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)1