Search in sources :

Example 6 with DBQuery

use of org.olat.core.commons.persistence.DBQuery in project OpenOLAT by OpenOLAT.

the class UserDeletionManager method getIdentitiesInDeletionProcess.

/**
 * Return list of identities which are in user-deletion-process.
 * user-deletion-process means delete-announcement.email send, duration of waiting for response is not expired.
 * @param deleteEmailDuration  Duration of user-deletion-process in days
 * @return List of Identity objects
 */
public List<Identity> getIdentitiesInDeletionProcess(int deleteEmailDuration) {
    Calendar deleteEmailLimit = Calendar.getInstance();
    deleteEmailLimit.add(Calendar.DAY_OF_MONTH, -(deleteEmailDuration - 1));
    logDebug("deleteEmailLimit=" + deleteEmailLimit);
    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 ident.status = " + Identity.STATUS_ACTIV + " and le.persistentTypeName ='" + IdentityImpl.class.getName() + "'" + " and le.action ='" + SEND_DELETE_EMAIL_ACTION + "' and le.lcTimestamp >= :deleteEmailDate ";
    DBQuery dbq = DBFactory.getInstance().createQuery(queryStr);
    dbq.setDate("deleteEmailDate", deleteEmailLimit.getTime());
    return dbq.list();
}
Also used : Calendar(java.util.Calendar) DBQuery(org.olat.core.commons.persistence.DBQuery) IdentityImpl(org.olat.basesecurity.IdentityImpl)

Example 7 with DBQuery

use of org.olat.core.commons.persistence.DBQuery in project OpenOLAT by OpenOLAT.

the class UserDeletionManager method getIdentitiesReadyToDelete.

/**
 * Return list of identities which are ready-to-delete in user-deletion-process.
 * (delete-announcement.email send, duration of waiting for response is expired).
 * @param deleteEmailDuration  Duration of user-deletion-process in days
 * @return List of Identity objects
 */
public List<Identity> getIdentitiesReadyToDelete(int deleteEmailDuration) {
    Calendar deleteEmailLimit = Calendar.getInstance();
    deleteEmailLimit.add(Calendar.DAY_OF_MONTH, -(deleteEmailDuration - 1));
    logDebug("deleteEmailLimit=" + deleteEmailLimit);
    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 ident.status = " + Identity.STATUS_ACTIV + " and le.persistentTypeName ='" + IdentityImpl.class.getName() + "'" + " and le.action ='" + SEND_DELETE_EMAIL_ACTION + "' and le.lcTimestamp < :deleteEmailDate ";
    DBQuery dbq = DBFactory.getInstance().createQuery(queryStr);
    dbq.setDate("deleteEmailDate", deleteEmailLimit.getTime());
    return dbq.list();
}
Also used : Calendar(java.util.Calendar) DBQuery(org.olat.core.commons.persistence.DBQuery) IdentityImpl(org.olat.basesecurity.IdentityImpl)

Example 8 with DBQuery

use of org.olat.core.commons.persistence.DBQuery in project OpenOLAT by OpenOLAT.

the class InfoMessageManagerImpl method queryInfoMessageByResource.

private DBQuery queryInfoMessageByResource(OLATResourceable ores, String subPath, String businessPath, Date after, Date before, boolean count) {
    StringBuilder sb = new StringBuilder();
    sb.append("select ");
    if (count)
        sb.append("count(msg.key)");
    else
        sb.append("msg");
    sb.append(" from ").append(InfoMessageImpl.class.getName()).append(" msg");
    if (!count) {
        sb.append(" left join fetch msg.author author").append(" left join fetch author.user").append(" left join fetch msg.modifier modifier").append(" left join fetch modifier.user");
    }
    if (ores != null) {
        appendAnd(sb, "msg.resId=:resId and msg.resName=:resName ");
    }
    if (StringHelper.containsNonWhitespace(subPath)) {
        appendAnd(sb, "msg.resSubPath=:subPath");
    }
    if (StringHelper.containsNonWhitespace(businessPath)) {
        appendAnd(sb, "msg.businessPath=:businessPath");
    }
    if (after != null) {
        appendAnd(sb, "msg.creationDate>=:after");
    }
    if (before != null) {
        appendAnd(sb, "msg.creationDate<=:before");
    }
    if (!count) {
        sb.append(" order by msg.creationDate desc");
    }
    DBQuery query = dbInstance.createQuery(sb.toString());
    if (ores != null) {
        query.setLong("resId", ores.getResourceableId());
        query.setString("resName", ores.getResourceableTypeName());
    }
    if (StringHelper.containsNonWhitespace(subPath)) {
        query.setString("subPath", subPath);
    }
    if (StringHelper.containsNonWhitespace(businessPath)) {
        query.setString("businessPath", normalizeBusinessPath(businessPath));
    }
    if (after != null) {
        query.setTimestamp("after", after);
    }
    if (before != null) {
        query.setTimestamp("before", before);
    }
    return query;
}
Also used : DBQuery(org.olat.core.commons.persistence.DBQuery)

Example 9 with DBQuery

use of org.olat.core.commons.persistence.DBQuery in project OpenOLAT by OpenOLAT.

the class InfoMessageManagerImpl method countInfoMessageByResource.

@Override
public int countInfoMessageByResource(OLATResourceable ores, String subPath, String businessPath, Date after, Date before) {
    DBQuery query = queryInfoMessageByResource(ores, subPath, businessPath, after, before, true);
    Number count = (Number) query.uniqueResult();
    return count.intValue();
}
Also used : DBQuery(org.olat.core.commons.persistence.DBQuery)

Example 10 with DBQuery

use of org.olat.core.commons.persistence.DBQuery in project OpenOLAT by OpenOLAT.

the class QuotaManagerImpl method getCustomQuota.

/**
 * Get the quota (in KB) for this path. Important: Must provide a path with a
 * valid base.
 *
 * @param path
 * @return Quota object.
 */
@Override
public Quota getCustomQuota(String path) {
    if (defaultQuotas == null) {
        throw new OLATRuntimeException(QuotaManagerImpl.class, "Quota manager has not been initialized properly! Must call init() first.", null);
    }
    StringBuilder query = new StringBuilder();
    query.append("select prop.name, prop.stringValue from ").append(Property.class.getName()).append(" as prop where ").append(" prop.category='").append(QUOTA_CATEGORY).append("'").append(" and prop.resourceTypeName='").append(quotaResource.getResourceableTypeName()).append("'").append(" and prop.resourceTypeId=").append(quotaResource.getResourceableId()).append(" and prop.name=:name").append(" and prop.identity is null and prop.grp is null");
    DBQuery dbquery = DBFactory.getInstance().createQuery(query.toString());
    dbquery.setString("name", path);
    dbquery.setCacheable(true);
    @SuppressWarnings("unchecked") List<Object[]> props = dbquery.list();
    if (props.isEmpty()) {
        return null;
    }
    Object[] p = props.get(0);
    return parseQuota((String) p[0], (String) p[1]);
}
Also used : OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) DBQuery(org.olat.core.commons.persistence.DBQuery)

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