use of org.olat.core.commons.persistence.DBQuery in project OpenOLAT by OpenOLAT.
the class BaseSecurityManager method countIdentitiesOfSecurityGroup.
/**
* @see org.olat.basesecurity.Manager#countIdentitiesOfSecurityGroup(org.olat.basesecurity.SecurityGroup)
*/
@Override
public int countIdentitiesOfSecurityGroup(SecurityGroup secGroup) {
DB db = DBFactory.getInstance();
String q = "select count(sgm) from org.olat.basesecurity.SecurityGroupMembershipImpl sgm where sgm.securityGroup = :group";
DBQuery query = db.createQuery(q);
query.setEntity("group", secGroup);
query.setCacheable(true);
int result = ((Long) query.list().get(0)).intValue();
return result;
}
use of org.olat.core.commons.persistence.DBQuery in project OpenOLAT by OpenOLAT.
the class BaseSecurityManager method countUniqueUserLoginsSince.
/**
* @see org.olat.basesecurity.Manager#countUniqueUserLoginsSince(java.util.Date)
*/
@Override
public Long countUniqueUserLoginsSince(Date lastLoginLimit) {
String queryStr = "Select count(ident) from org.olat.core.id.Identity as ident where " + "ident.lastLogin > :lastLoginLimit and ident.lastLogin != ident.creationDate";
DBQuery dbq = DBFactory.getInstance().createQuery(queryStr);
dbq.setDate("lastLoginLimit", lastLoginLimit);
List res = dbq.list();
Long cntL = (Long) res.get(0);
return cntL;
}
use of org.olat.core.commons.persistence.DBQuery in project OpenOLAT by OpenOLAT.
the class BaseSecurityManager method countIdentitiesByPowerSearch.
@Override
public long countIdentitiesByPowerSearch(String login, Map<String, String> userproperties, boolean userPropertiesAsIntersectionSearch, SecurityGroup[] groups, PermissionOnResourceable[] permissionOnResources, String[] authProviders, Date createdAfter, Date createdBefore, Date userLoginAfter, Date userLoginBefore, Integer status) {
DBQuery dbq = createIdentitiesByPowerQuery(new SearchIdentityParams(login, userproperties, userPropertiesAsIntersectionSearch, groups, permissionOnResources, authProviders, createdAfter, createdBefore, userLoginAfter, userLoginBefore, status), true);
Number count = (Number) dbq.uniqueResult();
return count.longValue();
}
use of org.olat.core.commons.persistence.DBQuery in project OpenOLAT by OpenOLAT.
the class BaseSecurityManager method getIdentitiesByPowerSearch.
@Override
public List<Identity> getIdentitiesByPowerSearch(SearchIdentityParams params, int firstResult, int maxResults) {
DBQuery dbq = createIdentitiesByPowerQuery(params, false);
if (firstResult >= 0) {
dbq.setFirstResult(firstResult);
}
if (maxResults > 0) {
dbq.setMaxResults(maxResults);
}
@SuppressWarnings("unchecked") List<Identity> identities = dbq.list();
return identities;
}
use of org.olat.core.commons.persistence.DBQuery in project OpenOLAT by OpenOLAT.
the class UserDeletionManager method getDeletableIdentities.
/**
* Return list of identities which have last-login older than 'lastLoginDuration' parameter.
* This user are ready to start with user-deletion process.
* @param lastLoginDuration last-login duration in month
* @return List of Identity objects
*/
public List<Identity> getDeletableIdentities(int lastLoginDuration) {
Calendar lastLoginLimit = Calendar.getInstance();
lastLoginLimit.add(Calendar.MONTH, -lastLoginDuration);
logDebug("lastLoginLimit=" + lastLoginLimit);
// 1. get all 'active' identities with lastlogin > x
StringBuilder sb = new StringBuilder();
sb.append("select ident from ").append(IdentityImpl.class.getName()).append(" as ident").append(" inner join fetch ident.user as user").append(" where ident.status=").append(Identity.STATUS_ACTIV).append(" and (ident.lastLogin = null or ident.lastLogin < :lastLogin)");
List<Identity> identities = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Identity.class).setParameter("lastLogin", lastLoginLimit.getTime(), TemporalType.TIMESTAMP).getResultList();
// 2. get all 'active' identities in deletion process
String queryStr = "select ident from org.olat.core.id.Identity as ident" + " , org.olat.commons.lifecycle.LifeCycleEntry as le" + " where ident.key = le.persistentRef " + " and le.persistentTypeName ='" + IdentityImpl.class.getName() + "'" + " and le.action ='" + SEND_DELETE_EMAIL_ACTION + "' ";
DBQuery dbq = DBFactory.getInstance().createQuery(queryStr);
List<Identity> identitiesInProcess = dbq.list();
// 3. Remove all identities in deletion-process from all inactive-identities
identities.removeAll(identitiesInProcess);
return identities;
}
Aggregations