Search in sources :

Example 6 with AbstractArtefact

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

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

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

the class EPArtefactManager method filterArtefactsByString.

private void filterArtefactsByString(List<AbstractArtefact> artefacts, String textFilter) {
    if (StringHelper.containsNonWhitespace(textFilter)) {
        List<AbstractArtefact> toRemove = new ArrayList<AbstractArtefact>();
        for (AbstractArtefact artefact : artefacts) {
            String textCompare = artefact.getTitle() + artefact.getDescription() + artefact.getFulltextContent();
            if (!textCompare.toLowerCase().contains(textFilter.toLowerCase())) {
                toRemove.add(artefact);
            }
        }
        artefacts.removeAll(toRemove);
    }
}
Also used : AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) ArrayList(java.util.ArrayList)

Example 8 with AbstractArtefact

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

the class EPArtefactManager method filterArtefactsByDate.

/**
 * date comparison will first set startDate to 00:00:00 and set endDate to
 * 23:59:59 else there might be no results if start = end date. dateList must
 * be set according to: dateList(0) = startDate dateList(1) = endDate
 */
private void filterArtefactsByDate(List<AbstractArtefact> artefacts, List<Date> dateList) {
    if (dateList != null && dateList.size() != 0) {
        if (dateList.size() == 2) {
            Date startDate = dateList.get(0);
            Date endDate = dateList.get(1);
            Calendar cal = Calendar.getInstance();
            if (startDate == null) {
                cal.set(1970, 1, 1);
            } else {
                cal.setTime(startDate);
            }
            cal.set(Calendar.HOUR_OF_DAY, 0);
            cal.set(Calendar.MINUTE, 0);
            cal.set(Calendar.SECOND, 0);
            startDate = cal.getTime();
            cal.setTime(endDate);
            cal.set(Calendar.HOUR_OF_DAY, 23);
            cal.set(Calendar.MINUTE, 59);
            cal.set(Calendar.SECOND, 59);
            endDate = cal.getTime();
            List<AbstractArtefact> toRemove = new ArrayList<AbstractArtefact>();
            for (AbstractArtefact artefact : artefacts) {
                Date creationDate = artefact.getCreationDate();
                if (!(creationDate.before(endDate) && creationDate.after(startDate))) {
                    toRemove.add(artefact);
                }
            }
            artefacts.removeAll(toRemove);
        } else
            throw new AssertException("provided DateList must contain exactly two Date-objects");
    }
}
Also used : AssertException(org.olat.core.logging.AssertException) Calendar(java.util.Calendar) AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) ArrayList(java.util.ArrayList) Date(java.util.Date)

Example 9 with AbstractArtefact

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

the class EPArtefactManager method filterArtefactsByType.

private void filterArtefactsByType(List<AbstractArtefact> artefacts, List<String> type) {
    if (type != null && type.size() != 0) {
        List<AbstractArtefact> toRemove = new ArrayList<AbstractArtefact>();
        for (AbstractArtefact artefact : artefacts) {
            if (!type.contains(artefact.getResourceableTypeName())) {
                toRemove.add(artefact);
            }
        }
        artefacts.removeAll(toRemove);
    }
}
Also used : AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) ArrayList(java.util.ArrayList)

Example 10 with AbstractArtefact

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

the class EPArtefactManager method createAndPersistArtefact.

/**
 * Create and persist an artefact of the given type
 *
 * @param type
 * @return The persisted artefact
 */
protected AbstractArtefact createAndPersistArtefact(Identity identity, String type) {
    EPArtefactHandler<?> handler = portfolioModule.getArtefactHandler(type);
    if (handler != null && handler.isEnabled()) {
        AbstractArtefact artefact = handler.createArtefact();
        artefact.setAuthor(identity);
        dbInstance.saveObject(artefact);
        saveArtefactFulltextContent(artefact);
        return artefact;
    } else {
        return null;
    }
}
Also used : AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact)

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