Search in sources :

Example 6 with DefaultEntry

use of org.apache.directory.api.ldap.model.entry.DefaultEntry 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 7 with DefaultEntry

use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project syncope by apache.

the class LdifInputStreamLoader method execute.

/**
 * Opens the LDIF file and loads the entries into the context.
 *
 * @return The count of entries created.
 */
public int execute() {
    try {
        try {
            for (LdifEntry ldifEntry : new LdifReader(ldif)) {
                Dn dn = ldifEntry.getDn();
                if (ldifEntry.isEntry()) {
                    Entry entry = ldifEntry.getEntry();
                    try {
                        coreSession.lookup(dn);
                        LOG.debug("Found {}, will not create.", dn);
                    } catch (Exception e) {
                        try {
                            coreSession.add(new DefaultEntry(coreSession.getDirectoryService().getSchemaManager(), entry));
                            count++;
                            LOG.debug("Created {}.", dn);
                        } catch (LdapException e1) {
                            LOG.error("Could not create entry " + entry, e1);
                        }
                    }
                } else {
                    // modify
                    List<Modification> items = ldifEntry.getModifications();
                    try {
                        coreSession.modify(dn, items);
                        LOG.debug("Modified: " + dn + " with modificationItems: " + items);
                    } catch (LdapException e) {
                        LOG.debug("Could not modify: " + dn + " with modificationItems: " + items, e);
                    }
                }
            }
        } finally {
            ldif.close();
        }
    } catch (Exception ioe) {
        LOG.error(I18n.err(I18n.ERR_174), ioe);
    }
    return count;
}
Also used : Modification(org.apache.directory.api.ldap.model.entry.Modification) LdifReader(org.apache.directory.api.ldap.model.ldif.LdifReader) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Dn(org.apache.directory.api.ldap.model.name.Dn) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 8 with DefaultEntry

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

the class SchemaElementImpl method nameToLdif.

/**
 * @return the Names as Ldif lines
 * @throws org.apache.directory.api.ldap.model.exception.LdapException If the conversion goes wrong
 */
private String nameToLdif() throws LdapException {
    if (names.isEmpty()) {
        return "";
    } else {
        Entry entry = new DefaultEntry();
        Attribute attribute = new DefaultAttribute("m-name");
        for (String name : names) {
            attribute.add(name);
        }
        entry.put(attribute);
        return LdifUtils.convertAttributesToLdif(entry);
    }
}
Also used : DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute)

Example 9 with DefaultEntry

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

the class SchemaElementImpl method descToLdif.

/**
 * @return The description as a ldif line
 * @throws org.apache.directory.api.ldap.model.exception.LdapException If the conversion goes wrong
 */
private String descToLdif() throws LdapException {
    if (Strings.isEmpty(description)) {
        return "";
    } else {
        Entry entry = new DefaultEntry();
        Attribute attribute = new DefaultAttribute("m-description", description);
        entry.put(attribute);
        return LdifUtils.convertAttributesToLdif(entry);
    }
}
Also used : DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute)

Example 10 with DefaultEntry

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

the class SchemaElementImpl method extensionsToLdif.

/**
 * Return the extensions formated as Ldif lines
 *
 * @param id The attributeId : can be m-objectClassExtension or
 * m-attributeTypeExtension
 * @return The extensions formated as ldif lines
 * @throws org.apache.directory.api.ldap.model.exception.LdapException If the conversion goes wrong
 */
protected String extensionsToLdif(String id) throws LdapException {
    StringBuilder sb = new StringBuilder();
    Entry entry = new DefaultEntry();
    Attribute attribute = new DefaultAttribute(id);
    for (String extension : extensions.keySet()) {
        attribute.add(extension);
    }
    sb.append(LdifUtils.convertAttributesToLdif(entry));
    return sb.toString();
}
Also used : DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute)

Aggregations

DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)128 Entry (org.apache.directory.api.ldap.model.entry.Entry)116 Test (org.junit.Test)55 DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)41 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)39 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)23 LdifEntry (org.apache.directory.api.ldap.model.ldif.LdifEntry)20 Modification (org.apache.directory.api.ldap.model.entry.Modification)16 LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)16 Dn (org.apache.directory.api.ldap.model.name.Dn)15 CreateException (org.apache.directory.fortress.core.CreateException)15 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)14 Value (org.apache.directory.api.ldap.model.entry.Value)12 LdifReader (org.apache.directory.api.ldap.model.ldif.LdifReader)12 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)5 IOException (java.io.IOException)4 ObjectInputStream (java.io.ObjectInputStream)4 ObjectOutputStream (java.io.ObjectOutputStream)4