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();
}
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();
}
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;
}
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();
}
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]);
}
Aggregations