Search in sources :

Example 6 with EPFilterSettings

use of org.olat.portfolio.model.EPFilterSettings in project openolat by klemens.

the class EPPerformanceTest method internalTestManyArtefactCreation.

private void internalTestManyArtefactCreation(int artefactAmount) {
    long start = System.currentTimeMillis();
    Runtime r = Runtime.getRuntime();
    for (int j = 0; j < artefactAmount; j++) {
        AbstractArtefact artefact = createAndFillArtefact(j);
        // tag the artefacts
        if (j % 2 == 0) {
            epFrontendManager.setArtefactTags(ident1, artefact, tagList1);
        } else {
            epFrontendManager.setArtefactTags(ident1, artefact, tagList2);
        }
        if (j % 10 == 0) {
            DBFactory.getInstance().closeSession();
        }
        if (j % 100 == 0) {
            logger.info("created another 100 artefacts! -> " + j);
            logger.info("  free memory: " + r.freeMemory());
        }
    }
    // for
    // load the whole artefact list
    long now = System.currentTimeMillis();
    logger.info("created " + artefactAmount + " artefacts in: " + (now - start) + " ms.");
    start = System.currentTimeMillis();
    List<AbstractArtefact> artList = epFrontendManager.getArtefactPoolForUser(ident1);
    now = System.currentTimeMillis();
    logger.info("querying all of them took: " + (now - start) + " ms.");
    assertEquals(artList.size(), artefactAmount);
    // filter artefacts by tags
    EPFilterSettings filterSettings = new EPFilterSettings();
    filterSettings.setTagFilter(new ArrayList<String>(Arrays.asList("Schule")));
    start = System.currentTimeMillis();
    artList = epFrontendManager.filterArtefactsByFilterSettings(filterSettings, ident1, new Roles(false, false, false, false, false, false, false));
    now = System.currentTimeMillis();
    logger.info("filter artefacts by one tag took: " + (now - start) + " ms.");
    assertEquals(artList.size(), artefactAmount / 2);
    filterSettings.setTagFilter(tagList1);
    start = System.currentTimeMillis();
    artList = epFrontendManager.filterArtefactsByFilterSettings(filterSettings, ident1, new Roles(false, false, false, false, false, false, false));
    now = System.currentTimeMillis();
    logger.info("filter artefacts by tagList1 took: " + (now - start) + " ms.");
    assertEquals(artList.size(), artefactAmount / 2);
}
Also used : EPFilterSettings(org.olat.portfolio.model.EPFilterSettings) AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) Roles(org.olat.core.id.Roles)

Example 7 with EPFilterSettings

use of org.olat.portfolio.model.EPFilterSettings in project openolat by klemens.

the class EPSettingsManager method setSavedFilterSettings.

public void setSavedFilterSettings(Identity ident, List<EPFilterSettings> filterList) {
    Property p = propertyManager.findProperty(ident, null, null, EPORTFOLIO_CATEGORY, EPORTFOLIO_FILTER_SETTINGS);
    if (p == null) {
        p = propertyManager.createUserPropertyInstance(ident, EPORTFOLIO_CATEGORY, EPORTFOLIO_FILTER_SETTINGS, null, null, null, null);
    }
    // don't persist filters without a name
    for (Iterator<EPFilterSettings> iterator = filterList.iterator(); iterator.hasNext(); ) {
        EPFilterSettings epFilterSettings = iterator.next();
        if (!StringHelper.containsNonWhitespace(epFilterSettings.getFilterName())) {
            iterator.remove();
        }
    }
    XStream xStream = XStreamHelper.createXStreamInstance();
    xStream.aliasType("EPFilterSettings", EPFilterSettings.class);
    String filterListXML = xStream.toXML(filterList);
    p.setTextValue(filterListXML);
    propertyManager.saveProperty(p);
}
Also used : EPFilterSettings(org.olat.portfolio.model.EPFilterSettings) XStream(com.thoughtworks.xstream.XStream) Property(org.olat.properties.Property)

Example 8 with EPFilterSettings

use of org.olat.portfolio.model.EPFilterSettings in project openolat by klemens.

the class EPSettingsManager method getSavedFilterSettings.

@SuppressWarnings("unchecked")
public List<EPFilterSettings> getSavedFilterSettings(Identity ident) {
    Property p = propertyManager.findProperty(ident, null, null, EPORTFOLIO_CATEGORY, EPORTFOLIO_FILTER_SETTINGS);
    List<EPFilterSettings> result = new ArrayList<EPFilterSettings>();
    if (p == null) {
        result.add(new EPFilterSettings());
    } else {
        XStream xStream = XStreamHelper.createXStreamInstance();
        xStream.aliasType("EPFilterSettings", EPFilterSettings.class);
        try {
            result = (List<EPFilterSettings>) xStream.fromXML(p.getTextValue());
        } catch (Exception e) {
            // it's not a live critical part
            logWarn("Cannot read filter settings", e);
        }
    }
    return result;
}
Also used : EPFilterSettings(org.olat.portfolio.model.EPFilterSettings) XStream(com.thoughtworks.xstream.XStream) ArrayList(java.util.ArrayList) Property(org.olat.properties.Property)

Example 9 with EPFilterSettings

use of org.olat.portfolio.model.EPFilterSettings in project openolat by klemens.

the class EPArtefactManager method getArtefactsAndTagCloud.

/**
 * This is an optimized method to filter a list of artefact by tags and return
 * the tags of this list of artefacts. This prevent to search two times or more the list
 * of tags of an artefact.
 * @param identity
 * @param tags
 * @return the filtered artefacts and their tags
 */
protected EPArtefactTagCloud getArtefactsAndTagCloud(Identity identity, List<String> tags) {
    List<AbstractArtefact> artefacts = getArtefactPoolForUser(identity);
    EPFilterSettings filterSettings = new EPFilterSettings();
    filterSettings.setTagFilter(tags);
    Set<String> newTags = new HashSet<String>();
    filterArtefactsByTags(artefacts, filterSettings, newTags);
    return new EPArtefactTagCloud(artefacts, newTags);
}
Also used : EPFilterSettings(org.olat.portfolio.model.EPFilterSettings) AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) HashSet(java.util.HashSet)

Example 10 with EPFilterSettings

use of org.olat.portfolio.model.EPFilterSettings in project openolat by klemens.

the class EPFrontendManager method filterArtefactsByFilterSettings.

/**
 * filter the provided list of artefacts with different filters
 *
 * @param allArtefacts the list to manipulate on
 * @param filterSettings Settings for the filter to work on
 * @return
 */
public List<AbstractArtefact> filterArtefactsByFilterSettings(EPFilterSettings filterSettings, Identity identity, Roles roles) {
    List<Long> artefactKeys = fulltextSearchAfterArtefacts(filterSettings, identity, roles);
    if (artefactKeys == null || artefactKeys.isEmpty()) {
        List<AbstractArtefact> allArtefacts = artefactManager.getArtefactPoolForUser(identity);
        return artefactManager.filterArtefactsByFilterSettings(allArtefacts, filterSettings);
    }
    List<AbstractArtefact> artefacts = artefactManager.getArtefacts(identity, artefactKeys, 0, 500);
    // remove the text-filter when the lucene-search got some results before
    EPFilterSettings settings = filterSettings.cloneAfterFullText();
    return artefactManager.filterArtefactsByFilterSettings(artefacts, settings);
}
Also used : EPFilterSettings(org.olat.portfolio.model.EPFilterSettings) AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact)

Aggregations

EPFilterSettings (org.olat.portfolio.model.EPFilterSettings)22 AbstractArtefact (org.olat.portfolio.model.artefacts.AbstractArtefact)8 XStream (com.thoughtworks.xstream.XStream)4 ArrayList (java.util.ArrayList)4 Property (org.olat.properties.Property)4 Date (java.util.Date)2 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)2 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)2 Roles (org.olat.core.id.Roles)2