Search in sources :

Example 16 with DBQuery

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

the class EPStructureManager method countStructureChildren.

/**
 * Number of children
 */
public int countStructureChildren(PortfolioStructure structure) {
    if (structure == null)
        throw new NullPointerException();
    StringBuilder sb = new StringBuilder();
    sb.append("select count(link) from ").append(EPStructureToStructureLink.class.getName()).append(" link").append(" where link.parent=:structureEl");
    DBQuery query = dbInstance.createQuery(sb.toString());
    query.setEntity("structureEl", structure);
    Number count = (Number) query.uniqueResult();
    return count.intValue();
}
Also used : EPStructureToStructureLink(org.olat.portfolio.model.structel.EPStructureToStructureLink) DBQuery(org.olat.core.commons.persistence.DBQuery)

Example 17 with DBQuery

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

the class EPStructureManager method isArtefactInStructure.

protected boolean isArtefactInStructure(AbstractArtefact artefact, PortfolioStructure structure) {
    StringBuilder sb = new StringBuilder();
    sb.append("select link.key from ").append(EPStructureToArtefactLink.class.getName()).append(" link").append(" where link.structureElement=:structureEl and link.artefact=:artefact");
    DBQuery query = dbInstance.createQuery(sb.toString());
    query.setEntity("structureEl", structure);
    query.setEntity("artefact", artefact);
    @SuppressWarnings("unchecked") List<Long> key = query.list();
    return key.size() == 1 ? true : false;
}
Also used : EPStructureToArtefactLink(org.olat.portfolio.model.structel.EPStructureToArtefactLink) DBQuery(org.olat.core.commons.persistence.DBQuery)

Example 18 with DBQuery

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

the class EPStructureManager method loadOlatResourceFromStructureElByKey.

public OLATResource loadOlatResourceFromStructureElByKey(Long key) {
    if (key == null)
        throw new NullPointerException();
    StringBuilder sb = new StringBuilder();
    sb.append("select element.olatResource from ").append(EPStructureElement.class.getName()).append(" element").append(" where element.key=:key or element.olatResource.resId=:key ");
    DBQuery query = dbInstance.createQuery(sb.toString());
    query.setLong("key", key);
    @SuppressWarnings("unchecked") List<OLATResource> resources = query.list();
    // if not found, it is an empty list
    if (resources.isEmpty())
        return null;
    return resources.get(0);
}
Also used : EPStructureElement(org.olat.portfolio.model.structel.EPStructureElement) DBQuery(org.olat.core.commons.persistence.DBQuery) OLATResource(org.olat.resource.OLATResource)

Example 19 with DBQuery

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

the class EPStructureManager method getArtefacts.

/**
 * Return the list of artefacts glued to this structure element
 * @param structure
 * @param firstResult
 * @param maxResults
 * @return
 */
public List<AbstractArtefact> getArtefacts(PortfolioStructure structure, int firstResult, int maxResults) {
    StringBuilder sb = new StringBuilder();
    sb.append("select link.artefact from ").append(EPStructureToArtefactLink.class.getName()).append(" link").append(" where link.structureElement.key=:structureElKey order by link.order");
    DBQuery query = dbInstance.createQuery(sb.toString());
    query.setLong("structureElKey", structure.getKey());
    if (firstResult > 0) {
        query.setFirstResult(firstResult);
    }
    if (maxResults > 0) {
        query.setMaxResults(maxResults);
    }
    @SuppressWarnings("unchecked") List<AbstractArtefact> artefacts = query.list();
    return artefacts;
}
Also used : EPStructureToArtefactLink(org.olat.portfolio.model.structel.EPStructureToArtefactLink) AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) DBQuery(org.olat.core.commons.persistence.DBQuery)

Example 20 with DBQuery

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

the class EPStructureManager method isTemplateInUse.

public boolean isTemplateInUse(PortfolioStructureMap template, OLATResourceable targetOres, String targetSubPath, String targetBusinessPath) {
    StringBuilder sb = new StringBuilder();
    sb.append("select count(map) from ").append(EPStructuredMap.class.getName()).append(" map").append(" where map.structuredMapSource=:template");
    if (targetOres != null) {
        sb.append(" and map.targetResource.resourceableId=:resourceId").append(" and map.targetResource.resourceableTypeName=:resourceType");
    }
    if (targetSubPath != null) {
        sb.append(" and map.targetResource.subPath=:subPath");
    }
    if (targetBusinessPath != null) {
        sb.append(" and map.targetResource.businessPath=:businessPath");
    }
    DBQuery query = dbInstance.createQuery(sb.toString());
    query.setEntity("template", template);
    if (targetOres != null) {
        query.setLong("resourceId", targetOres.getResourceableId());
        query.setString("resourceType", targetOres.getResourceableTypeName());
    }
    if (targetSubPath != null) {
        query.setString("subPath", targetSubPath);
    }
    if (targetBusinessPath != null) {
        query.setString("businessPath", targetBusinessPath);
    }
    Number count = (Number) query.uniqueResult();
    return count.intValue() > 0;
}
Also used : EPStructuredMap(org.olat.portfolio.model.structel.EPStructuredMap) 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