Search in sources :

Example 16 with CreateException

use of org.apache.directory.fortress.core.CreateException in project directory-fortress-core by apache.

the class OrgUnitDAO method create.

/**
 * @param entity
 * @return
 * @throws org.apache.directory.fortress.core.CreateException
 */
OrgUnit create(OrgUnit entity) throws CreateException {
    LdapConnection ld = null;
    Dn dn = getDn(entity);
    try {
        Entry entry = new DefaultEntry(dn);
        entry.add(SchemaConstants.OBJECT_CLASS_AT, ORGUNIT_OBJ_CLASS);
        entity.setId();
        entry.add(GlobalIds.FT_IID, entity.getId());
        String description = entity.getDescription();
        if (!Strings.isEmpty(description)) {
            entry.add(SchemaConstants.DESCRIPTION_AT, description);
        }
        // organizational name requires OU attribute:
        entry.add(SchemaConstants.OU_AT, entity.getName());
        // These multi-valued attributes are optional.  The utility function will return quietly if no items are loaded into collection:
        loadAttrs(entity.getParents(), entry, GlobalIds.PARENT_NODES);
        ld = getAdminConnection();
        add(ld, entry, entity);
    } catch (LdapException e) {
        String error = "create orgUnit name [" + entity.getName() + "] type [" + entity.getType() + "] root [" + dn + "] caught LdapException=" + e;
        int errCode;
        if (entity.getType() == OrgUnit.Type.PERM) {
            errCode = GlobalErrIds.ORG_ADD_FAILED_PERM;
        } else {
            errCode = GlobalErrIds.ORG_ADD_FAILED_USER;
        }
        throw new CreateException(errCode, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return entity;
}
Also used : 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) Dn(org.apache.directory.api.ldap.model.name.Dn) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) CreateException(org.apache.directory.fortress.core.CreateException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Aggregations

LdapException (org.apache.directory.api.ldap.model.exception.LdapException)16 CreateException (org.apache.directory.fortress.core.CreateException)16 LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)16 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)15 Entry (org.apache.directory.api.ldap.model.entry.Entry)15 LdapEntryAlreadyExistsException (org.apache.directory.api.ldap.model.exception.LdapEntryAlreadyExistsException)2 ArrayList (java.util.ArrayList)1 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)1 Modification (org.apache.directory.api.ldap.model.entry.Modification)1 Dn (org.apache.directory.api.ldap.model.name.Dn)1 PermissionAttribute (org.apache.directory.fortress.core.model.PermissionAttribute)1