@Override
public void removeAdminUserFromOrganization( UUID userId, UUID organizationId, boolean force ) throws Exception {
if ( ( userId == null ) || ( organizationId == null ) ) {
return;
}
EntityManager em = emf.getEntityManager( smf.getManagementAppId() );
try {
Results collection = em.getCollection( new SimpleEntityRef( Group.ENTITY_TYPE, organizationId ),
"users", null, 2, Level.IDS, false );
int size = collection.size();
if ( !force && (size == 0 || (size == 1 && collection.getId() == userId))) {
throw new Exception();
}
}
catch ( Exception e ) {
throw new UnableToLeaveOrganizationException( "Organizations must have at least one member." );
}
em.removeFromCollection(new SimpleEntityRef(Group.ENTITY_TYPE, organizationId), "users",
new SimpleEntityRef(User.ENTITY_TYPE, userId));
invalidateManagementAppAuthCache();
}