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;
}
Aggregations