Search in sources :

Example 71 with DBQuery

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;
}
Also used : DBQuery(org.olat.core.commons.persistence.DBQuery) DB(org.olat.core.commons.persistence.DB)

Example 72 with DBQuery

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;
}
Also used : DBQuery(org.olat.core.commons.persistence.DBQuery) List(java.util.List) ArrayList(java.util.ArrayList)

Example 73 with DBQuery

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();
}
Also used : DBQuery(org.olat.core.commons.persistence.DBQuery)

Example 74 with DBQuery

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;
}
Also used : DBQuery(org.olat.core.commons.persistence.DBQuery) Identity(org.olat.core.id.Identity)

Example 75 with DBQuery

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;
}
Also used : Calendar(java.util.Calendar) DBQuery(org.olat.core.commons.persistence.DBQuery) IdentityImpl(org.olat.basesecurity.IdentityImpl) Identity(org.olat.core.id.Identity)

Aggregations

DBQuery (org.olat.core.commons.persistence.DBQuery)108 EPStructureToArtefactLink (org.olat.portfolio.model.structel.EPStructureToArtefactLink)12 AbstractArtefact (org.olat.portfolio.model.artefacts.AbstractArtefact)10 PortfolioStructure (org.olat.portfolio.model.structel.PortfolioStructure)10 Calendar (java.util.Calendar)8 IdentityImpl (org.olat.basesecurity.IdentityImpl)6 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4 DB (org.olat.core.commons.persistence.DB)4 Publisher (org.olat.core.commons.services.notifications.Publisher)4 Tag (org.olat.core.commons.services.tagging.model.Tag)4 Identity (org.olat.core.id.Identity)4 EPStructureToStructureLink (org.olat.portfolio.model.structel.EPStructureToStructureLink)4 EPStructuredMap (org.olat.portfolio.model.structel.EPStructuredMap)4 EPStructuredMapTemplate (org.olat.portfolio.model.structel.EPStructuredMapTemplate)4 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 StringTokenizer (java.util.StringTokenizer)2