in src/main/java/org/apache/directory/fortress/core/impl/OrgUnitDAO.java [333:398]
OrgUnit findByKey( OrgUnit entity ) throws FinderException
{
OrgUnit oe = null;
LdapConnection ld = null;
Dn dn = getDn( entity );
try
{
ld = getAdminConnection();
Entry findEntry = read( ld, dn, ORGUNIT_ATRS );
if ( findEntry == null )
{
String warning = "findByKey orgUnit name [" + entity.getName() + "] type ["
+ entity.getType() + "] COULD NOT FIND ENTRY for dn [" + dn + "]";
int errCode;
if ( entity.getType() == OrgUnit.Type.PERM )
{
errCode = GlobalErrIds.ORG_NOT_FOUND_PERM;
}
else
{
errCode = GlobalErrIds.ORG_NOT_FOUND_USER;
}
throw new FinderException( errCode, warning );
}
oe = getEntityFromLdapEntry( findEntry, 0, entity.getContextId() );
}
catch ( LdapNoSuchObjectException e )
{
String warning = "findByKey orgUnit name [" + entity.getName() + "] type ["
+ entity.getType() + "] COULD NOT FIND ENTRY for dn [" + dn + "]";
int errCode;
if ( entity.getType() == OrgUnit.Type.PERM )
{
errCode = GlobalErrIds.ORG_NOT_FOUND_PERM;
}
else
{
errCode = GlobalErrIds.ORG_NOT_FOUND_USER;
}
throw new FinderException( errCode, warning );
}
catch ( LdapException e )
{
String error = "findByKey orgUnitName [" + entity.getName() + "] type [" + entity.getType()
+ "] dn [" + dn + "] caught LdapException=" + e;
int errCode;
if ( entity.getType() == OrgUnit.Type.PERM )
{
errCode = GlobalErrIds.ORG_READ_FAILED_PERM;
}
else
{
errCode = GlobalErrIds.ORG_READ_FAILED_USER;
}
throw new FinderException( errCode, error, e );
}
finally
{
closeAdminConnection( ld );
}
return oe;
}