Search in sources :

Example 81 with DBQuery

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

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 82 with DBQuery

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

the class EPStructureManager method countArtefacts.

/**
 * Return the number of artefacts hold by a structure element
 * @param structure
 * @return
 */
public int countArtefacts(PortfolioStructure structure) {
    StringBuilder sb = new StringBuilder();
    sb.append("select count(link) from ").append(EPStructureToArtefactLink.class.getName()).append(" link").append(" where link.structureElement=:structureEl");
    DBQuery query = dbInstance.createQuery(sb.toString());
    query.setEntity("structureEl", structure);
    Number count = (Number) query.uniqueResult();
    return count.intValue();
}
Also used : EPStructureToArtefactLink(org.olat.portfolio.model.structel.EPStructureToArtefactLink) DBQuery(org.olat.core.commons.persistence.DBQuery)

Example 83 with DBQuery

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

the class EPArtefactManager method getArtefacts.

/**
 * Used by the indexer to retrieve all the artefacts
 * @param artefactIds List of ids to seek (optional)
 * @param firstResult First position
 * @param maxResults Max number of returned artefacts (0 or below for all)
 * @return
 */
@SuppressWarnings("unchecked")
protected List<AbstractArtefact> getArtefacts(Identity author, List<Long> artefactIds, int firstResult, int maxResults) {
    StringBuilder sb = new StringBuilder();
    sb.append("select artefact from ").append(AbstractArtefact.class.getName()).append(" artefact");
    boolean where = false;
    if (author != null) {
        where = true;
        sb.append(" where artefact.author=:author");
    }
    if (artefactIds != null && !artefactIds.isEmpty()) {
        if (where)
            sb.append(" and ");
        else
            sb.append(" where ");
        sb.append(" artefact.id in (:artefactIds)");
    }
    DBQuery query = dbInstance.createQuery(sb.toString());
    if (maxResults > 0) {
        query.setMaxResults(maxResults);
    }
    if (firstResult >= 0) {
        query.setFirstResult(firstResult);
    }
    if (author != null) {
        query.setEntity("author", author);
    }
    if (artefactIds != null && !artefactIds.isEmpty()) {
        query.setParameterList("artefactIds", artefactIds);
    }
    List<AbstractArtefact> artefacts = query.list();
    return artefacts;
}
Also used : AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) DBQuery(org.olat.core.commons.persistence.DBQuery)

Example 84 with DBQuery

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

the class EPArtefactManager method loadArtefactByKey.

/**
 * Load the artefact by its primary key
 *
 * @param key The primary key
 * @return The artefact or null if nothing found
 */
protected AbstractArtefact loadArtefactByKey(Long key) {
    if (key == null)
        throw new NullPointerException();
    StringBuilder sb = new StringBuilder();
    sb.append("select artefact from ").append(AbstractArtefact.class.getName()).append(" artefact").append(" where artefact=:key");
    DBQuery query = dbInstance.createQuery(sb.toString());
    query.setLong("key", key);
    @SuppressWarnings("unchecked") List<AbstractArtefact> artefacts = query.list();
    // if not found, it is an empty list
    if (artefacts.isEmpty())
        return null;
    return artefacts.get(0);
}
Also used : AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) DBQuery(org.olat.core.commons.persistence.DBQuery)

Example 85 with DBQuery

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

the class EPArtefactManager method isArtefactClosed.

protected boolean isArtefactClosed(AbstractArtefact artefact) {
    StringBuilder sb = new StringBuilder();
    sb.append("select count(link) from ").append(EPStructureToArtefactLink.class.getName()).append(" link ").append(" inner join link.structureElement structure ").append(" inner join structure.root rootStructure").append(" where link.artefact=:artefact and rootStructure.status='closed'");
    DBQuery query = dbInstance.createQuery(sb.toString());
    query.setEntity("artefact", artefact);
    Number count = (Number) query.uniqueResult();
    return count.intValue() > 0;
}
Also used : EPStructureToArtefactLink(org.olat.portfolio.model.structel.EPStructureToArtefactLink) 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