Tracing.logDebug("lastLoginLimit=" + lastUsageLimit, this.getClass());
// 1. get all businness-groups with lastusage > x
String query = "select gr from org.olat.group.BusinessGroupImpl as gr "
+ " where (gr.lastUsage = null or gr.lastUsage < :lastUsage)"
+ " and gr.type = :type ";
DBQuery dbq = DBFactory.getInstance().createQuery(query);
dbq.setDate("lastUsage", lastUsageLimit.getTime());
dbq.setString("type", BusinessGroup.TYPE_BUDDYGROUP);
List groups = dbq.list();
// 2. get all businness-groups in deletion-process (email send)
query = "select gr from org.olat.group.BusinessGroupImpl as gr"
+ " , org.olat.commons.lifecycle.LifeCycleEntry as le"
+ " where gr.key = le.persistentRef "
+ " and le.persistentTypeName ='org.olat.group.BusinessGroupImpl'"
+ " and le.action ='" + SEND_DELETE_EMAIL_ACTION + "' ";
dbq = DBFactory.getInstance().createQuery(query);
List groupsInProcess = dbq.list();
// 3. Remove all groups in deletion-process from all unused-groups
groups.removeAll(groupsInProcess);
return groups;
}