in src/main/java/org/apache/directory/fortress/core/impl/DelAdminMgrImpl.java [261:329]
public OrgUnit delete(OrgUnit entity)
throws SecurityException
{
String methodName = "deleteOU";
assertContext(CLS_NM, methodName, entity, GlobalErrIds.ORG_NULL);
setEntitySession(CLS_NM, methodName, entity);
VUtil.assertNotNull(entity.getType(), GlobalErrIds.ORG_TYPE_NULL, CLS_NM + "." + methodName);
int numChildren;
if (entity.getType() == OrgUnit.Type.USER)
{
numChildren = UsoUtil.getInstance().numChildren( entity.getName(), entity.getContextId() );
}
else
{
numChildren = PsoUtil.getInstance().numChildren( entity.getName(), entity.getContextId() );
}
if (numChildren > 0)
{
String error = methodName + " orgunit [" + entity.getName() + "] must remove [" + numChildren + "] descendants before deletion";
throw new SecurityException(GlobalErrIds.HIER_DEL_FAILED_HAS_CHILD, error, null);
}
if (entity.getType() == OrgUnit.Type.USER)
{
// Ensure the org unit is not assigned to any users, but set the sizeLimit to "true" to limit result set size.
List<User> assignedUsers = userP.search(entity, true);
if (CollectionUtils.isNotEmpty( assignedUsers ))
{
String error = methodName + " orgunit [" + entity.getName() + "] must unassign [" + assignedUsers.size() + "] users before deletion";
throw new SecurityException(GlobalErrIds.ORG_DEL_FAILED_USER, error, null);
}
}
else
{
// Ensure the org unit is not assigned to any permission objects but set the sizeLimit to "true" to limit result set size..
// pass a "false" which places no restrictions on how many records server returns.
List<PermObj> assignedPerms = permP.search(entity, false);
if (CollectionUtils.isNotEmpty( assignedPerms ))
{
String error = methodName + " orgunit [" + entity.getName() + "] must unassign [" + assignedPerms.size() + "] perm objs before deletion";
throw new SecurityException(GlobalErrIds.ORG_DEL_FAILED_PERM, error, null);
}
}
// remove all parent relationships from this org graph:
Set<String> parents;
if (entity.getType() == OrgUnit.Type.USER)
{
parents = UsoUtil.getInstance().getParents(entity.getName(), this.contextId);
}
else
{
parents = PsoUtil.getInstance().getParents(entity.getName(), this.contextId);
}
if(parents != null)
{
for(String parent : parents)
{
if (entity.getType() == OrgUnit.Type.USER)
{
UsoUtil.getInstance().updateHier(this.contextId, new Relationship(entity.getName().toUpperCase(), parent.toUpperCase()), Hier.Op.REM);
}
else
{
PsoUtil.getInstance().updateHier(this.contextId, new Relationship(entity.getName().toUpperCase(), parent.toUpperCase()), Hier.Op.REM);
}
}
}
// everything checked out good - remove the org unit from the OrgUnit data set:
return ouP.delete(entity);
}