Search in sources :

Example 11 with AbstractArtefact

use of org.olat.portfolio.model.artefacts.AbstractArtefact in project OpenOLAT by OpenOLAT.

the class EPArtefactManager method getArtefactPoolForUser.

protected List<AbstractArtefact> getArtefactPoolForUser(Identity ident) {
    long start = System.currentTimeMillis();
    StringBuilder sb = new StringBuilder();
    sb.append("select artefact from ").append(AbstractArtefact.class.getName()).append(" artefact").append(" where author=:author");
    DBQuery query = dbInstance.createQuery(sb.toString());
    query.setEntity("author", ident);
    @SuppressWarnings("unchecked") List<AbstractArtefact> artefacts = query.list();
    if (artefacts.isEmpty())
        return null;
    long duration = System.currentTimeMillis() - start;
    if (isLogDebugEnabled())
        logDebug("loading the full artefact pool took " + duration + "ms");
    return artefacts;
}
Also used : AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) DBQuery(org.olat.core.commons.persistence.DBQuery)

Example 12 with AbstractArtefact

use of org.olat.portfolio.model.artefacts.AbstractArtefact in project OpenOLAT by OpenOLAT.

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 13 with AbstractArtefact

use of org.olat.portfolio.model.artefacts.AbstractArtefact 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 14 with AbstractArtefact

use of org.olat.portfolio.model.artefacts.AbstractArtefact in project OpenOLAT by OpenOLAT.

the class EPStructureManager method removeStructureRecursively.

public void removeStructureRecursively(PortfolioStructure struct) {
    List<PortfolioStructure> children = loadStructureChildren(struct);
    for (PortfolioStructure childstruct : children) {
        removeStructureRecursively(childstruct);
    }
    // remove artefact-links
    List<AbstractArtefact> thisStructsArtefacts = getArtefacts(struct);
    for (AbstractArtefact artefact : thisStructsArtefacts) {
        removeArtefactFromStructure(artefact, struct, false);
    }
    // remove from parent
    PortfolioStructure parent = loadStructureParent(struct);
    if (parent == null && struct.getRoot() != null)
        parent = struct.getRoot();
    removeStructure(parent, struct);
    // remove collect restriction
    struct.getCollectRestrictions().clear();
    // remove sharings
    if (struct instanceof EPAbstractMap) {
        ((EPAbstractMap) struct).getGroups().clear();
    }
    // remove comments and ratings
    CommentAndRatingService commentAndRatingService = CoreSpringFactory.getImpl(CommentAndRatingService.class);
    commentAndRatingService.deleteAllIgnoringSubPath(struct.getOlatResource());
    // FXOLAT-431 remove subscriptions if the current struct is a map
    if (struct instanceof EPAbstractMap) {
        SubscriptionContext subsContext = new SubscriptionContext(EPNotificationsHandler.TYPENNAME, struct.getResourceableId(), EPNotificationsHandler.TYPENNAME);
        NotificationsManager.getInstance().delete(subsContext);
    }
    // remove structure itself
    struct = (EPStructureElement) dbInstance.loadObject((EPStructureElement) struct);
    dbInstance.deleteObject(struct);
    if (struct instanceof EPAbstractMap) {
        removeBaseGroup((EPAbstractMap) struct);
    }
    // which need the resource
    if (!(struct instanceof EPStructuredMapTemplate)) {
        resourceManager.deleteOLATResourceable(struct);
    }
}
Also used : EPAbstractMap(org.olat.portfolio.model.structel.EPAbstractMap) EPStructuredMapTemplate(org.olat.portfolio.model.structel.EPStructuredMapTemplate) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) CommentAndRatingService(org.olat.core.commons.services.commentAndRating.CommentAndRatingService) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext)

Example 15 with AbstractArtefact

use of org.olat.portfolio.model.artefacts.AbstractArtefact in project OpenOLAT by OpenOLAT.

the class EPStructureManager method getRestrictionStatistics.

protected Integer[] getRestrictionStatistics(PortfolioStructure structure) {
    if (structure instanceof EPStructureElement) {
        EPStructureElement structEl = (EPStructureElement) structure;
        structEl = (EPStructureElement) reloadPortfolioStructure(structEl);
        final List<CollectRestriction> restrictions = structEl.getCollectRestrictions();
        if (restrictions != null && !restrictions.isEmpty()) {
            int todo = 0;
            int done = 0;
            List<AbstractArtefact> artefacts = getArtefacts(structEl);
            for (CollectRestriction cR : restrictions) {
                if (RestrictionsConstants.MIN.equals(cR.getRestriction()) || RestrictionsConstants.EQUAL.equals(cR.getRestriction())) {
                    todo += cR.getAmount();
                    int actualCRCount = countRestrictionType(artefacts, cR);
                    done += actualCRCount;
                }
            }
            return new Integer[] { done, todo };
        }
    }
    return null;
}
Also used : EPStructureElement(org.olat.portfolio.model.structel.EPStructureElement) AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) CollectRestriction(org.olat.portfolio.model.restriction.CollectRestriction)

Aggregations

AbstractArtefact (org.olat.portfolio.model.artefacts.AbstractArtefact)164 PortfolioStructure (org.olat.portfolio.model.structel.PortfolioStructure)70 Test (org.junit.Test)54 ArrayList (java.util.ArrayList)36 Date (java.util.Date)20 PortfolioStructureMap (org.olat.portfolio.model.structel.PortfolioStructureMap)18 DBQuery (org.olat.core.commons.persistence.DBQuery)10 Link (org.olat.core.gui.components.link.Link)10 Identity (org.olat.core.id.Identity)10 VFSContainer (org.olat.core.util.vfs.VFSContainer)10 CollectRestriction (org.olat.portfolio.model.restriction.CollectRestriction)10 List (java.util.List)8 EPFilterSettings (org.olat.portfolio.model.EPFilterSettings)8 GenericTreeNode (org.olat.core.gui.components.tree.GenericTreeNode)6 Step (org.olat.core.gui.control.generic.wizard.Step)6 StepRunnerCallback (org.olat.core.gui.control.generic.wizard.StepRunnerCallback)6 StepsMainRunController (org.olat.core.gui.control.generic.wizard.StepsMainRunController)6 OLATResourceable (org.olat.core.id.OLATResourceable)6 EPAbstractMap (org.olat.portfolio.model.structel.EPAbstractMap)6 EPStructureElement (org.olat.portfolio.model.structel.EPStructureElement)6