Search in sources :

Example 51 with DBQuery

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

the class EPStructureManager method loadPortfolioRepositoryEntryByMapKey.

/**
 * Load the repository entry of a template with the map key
 * @param key The template key
 * @return The repository entry
 */
public RepositoryEntry loadPortfolioRepositoryEntryByMapKey(Long key) {
    if (key == null)
        throw new NullPointerException();
    StringBuilder sb = new StringBuilder();
    sb.append("select repo from ").append(RepositoryEntry.class.getName()).append(" repo").append(" where repo.olatResource in (select map.olatResource from ").append(EPStructuredMapTemplate.class.getName()).append(" map where map.key=:key").append(")");
    DBQuery query = dbInstance.createQuery(sb.toString());
    query.setLong("key", key);
    @SuppressWarnings("unchecked") List<RepositoryEntry> entries = query.list();
    // if not found, it is an empty list
    if (entries.isEmpty())
        return null;
    return entries.get(0);
}
Also used : EPStructuredMapTemplate(org.olat.portfolio.model.structel.EPStructuredMapTemplate) DBQuery(org.olat.core.commons.persistence.DBQuery) RepositoryEntry(org.olat.repository.RepositoryEntry)

Example 52 with DBQuery

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

the class EPStructureManager method getStructureElements.

protected List<PortfolioStructure> getStructureElements(int firstResult, int maxResults, ElementType... types) {
    StringBuilder sb = new StringBuilder();
    sb.append("select stEl from ").append(EPStructureElement.class.getName()).append(" stEl");
    sb.append(" where type(stEl) in (");
    boolean first = true;
    for (ElementType type : types) {
        if (first)
            first = false;
        else
            sb.append(",");
        sb.append(getImplementation(type).getName());
    }
    sb.append(")");
    DBQuery query = dbInstance.createQuery(sb.toString());
    if (firstResult > 0) {
        query.setFirstResult(firstResult);
    }
    if (maxResults > 0) {
        query.setMaxResults(maxResults);
    }
    @SuppressWarnings("unchecked") List<PortfolioStructure> pStructs = query.list();
    return pStructs;
}
Also used : ElementType(org.olat.portfolio.model.structel.ElementType) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) DBQuery(org.olat.core.commons.persistence.DBQuery)

Example 53 with DBQuery

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

the class EPStructureManager method getOpenStructuredMapAfterDeadline.

protected List<PortfolioStructureMap> getOpenStructuredMapAfterDeadline() {
    StringBuilder sb = new StringBuilder();
    sb.append("select map from ").append(EPStructuredMap.class.getName()).append(" as map");
    sb.append(" where (map.status is null or not(map.status = 'closed'))").append(" and map.deadLine<:currentDate");
    DBQuery query = dbInstance.createQuery(sb.toString());
    query.setDate("currentDate", new Date());
    @SuppressWarnings("unchecked") List<PortfolioStructureMap> maps = query.list();
    return maps;
}
Also used : PortfolioStructureMap(org.olat.portfolio.model.structel.PortfolioStructureMap) DBQuery(org.olat.core.commons.persistence.DBQuery) Date(java.util.Date)

Example 54 with DBQuery

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

the class EPNotificationManager method getPageNotifications.

private List<EPStructureElementNotification> getPageNotifications(Long mapKey, Date compareDate) {
    StringBuilder sb = new StringBuilder();
    sb.append("select notification from ").append(EPStructureElementNotification.class.getName()).append(" as notification");
    sb.append(" where notification.creationDate>=:currentDate and (notification.key=:mapKey or notification.rootMapKey=:mapKey)");
    DBQuery query = dbInstance.createQuery(sb.toString());
    query.setDate("currentDate", compareDate);
    query.setLong("mapKey", mapKey);
    @SuppressWarnings("unchecked") List<EPStructureElementNotification> notifications = query.list();
    return notifications;
}
Also used : EPStructureElementNotification(org.olat.portfolio.model.notification.EPStructureElementNotification) DBQuery(org.olat.core.commons.persistence.DBQuery)

Example 55 with DBQuery

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

the class EPArtefactManager method loadArtefactsByBusinessPath.

protected List<AbstractArtefact> loadArtefactsByBusinessPath(String businessPath, Identity author) {
    if (!StringHelper.containsNonWhitespace(businessPath))
        return null;
    StringBuilder sb = new StringBuilder();
    sb.append("select artefact from ").append(AbstractArtefact.class.getName()).append(" artefact").append(" where artefact.businessPath=:bpath");
    if (author != null) {
        sb.append(" and artefact.author=:ident");
    }
    DBQuery query = dbInstance.createQuery(sb.toString());
    query.setString("bpath", businessPath);
    if (author != null) {
        query.setEntity("ident", author);
    }
    @SuppressWarnings("unchecked") List<AbstractArtefact> artefacts = query.list();
    // if not found, it is an empty list
    if (artefacts.isEmpty())
        return null;
    return artefacts;
}
Also used : AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) 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