Search in sources :

Example 16 with EPFilterSettings

use of org.olat.portfolio.model.EPFilterSettings in project OpenOLAT by OpenOLAT.

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 17 with EPFilterSettings

use of org.olat.portfolio.model.EPFilterSettings in project OpenOLAT by OpenOLAT.

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 18 with EPFilterSettings

use of org.olat.portfolio.model.EPFilterSettings in project OpenOLAT by OpenOLAT.

the class EPFilterSelectController method initForm.

/**
 * @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#initForm(org.olat.core.gui.components.form.flexible.FormItemContainer, org.olat.core.gui.control.Controller, org.olat.core.gui.UserRequest)
 */
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    List<EPFilterSettings> existingFilters = ePFMgr.getSavedFilterSettings(getIdentity());
    for (Iterator<EPFilterSettings> existingFilterIt = existingFilters.iterator(); existingFilterIt.hasNext(); ) {
        if (existingFilterIt.next().isFilterEmpty()) {
            existingFilterIt.remove();
        }
    }
    int amount = existingFilters.size() + 1;
    nonEmptyFilters = new ArrayList<EPFilterSettings>(amount);
    String[] theKeys = new String[amount];
    String[] theValues = new String[amount];
    theKeys[0] = String.valueOf(0);
    theValues[0] = translate("filter.all");
    int i = 1;
    String presetFilterIndex = "0";
    for (EPFilterSettings epFilterSettings : existingFilters) {
        theKeys[i] = epFilterSettings.getFilterId();
        theValues[i] = epFilterSettings.getFilterName();
        if (presetFilterID != null && presetFilterID.equals(epFilterSettings.getFilterId())) {
            presetFilterIndex = epFilterSettings.getFilterId();
        }
        nonEmptyFilters.add(epFilterSettings);
        i++;
    }
    // don't show anything if no filter exists
    if (!nonEmptyFilters.isEmpty()) {
        String page = velocity_root + "/filter_select.html";
        FormLayoutContainer selection = FormLayoutContainer.createCustomFormLayout("filter_selection", getTranslator(), page);
        selection.setRootForm(mainForm);
        selection.setLabel("filter.select", null);
        formLayout.add(selection);
        filterSel = uifactory.addDropdownSingleselect("filter.select", selection, theKeys, theValues, null);
        filterSel.addActionListener(FormEvent.ONCHANGE);
        filterSel.select(presetFilterIndex, true);
        adaptBtn = uifactory.addFormLink("filter.adapt", selection);
        adaptBtn.setVisible(!presetFilterIndex.equals("0"));
    }
}
Also used : EPFilterSettings(org.olat.portfolio.model.EPFilterSettings) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)

Example 19 with EPFilterSettings

use of org.olat.portfolio.model.EPFilterSettings in project OpenOLAT by OpenOLAT.

the class PortfolioFilterController method formInnerEvent.

/**
 * @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#formInnerEvent(org.olat.core.gui.UserRequest,
 *      org.olat.core.gui.components.form.flexible.FormItem,
 *      org.olat.core.gui.components.form.flexible.impl.FormEvent)
 */
@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
    if (source instanceof FormLink) {
        FormLink link = (FormLink) source;
        if (link.getName().startsWith(TAG_CMP_IDENTIFIER)) {
            // a tag-Link got clicked, find out which
            String selectedTag = (String) link.getUserObject();
            if (!selectedTagsList.contains(selectedTag)) {
                selectedTagsList.add(selectedTag);
                tagAllBtn.toggleOff();
                tagNoneBtn.toggleOff();
            } else {
                selectedTagsList.remove(selectedTag);
                if (selectedTagsList.isEmpty())
                    tagAllBtn.toggleOn();
            }
            filterSettings.setTagFilter(selectedTagsList);
            fireEvent(ureq, new PortfolioFilterChangeEvent(filterSettings));
        } else if (link.getName().startsWith(HANDLER_PREFIX)) {
            // a type-link got clicked
            String selectedType = (String) link.getUserObject();
            if (!selectedTypeList.contains(selectedType)) {
                selectedTypeList.add(selectedType);
                typeAllBtn.toggleOff();
            } else {
                selectedTypeList.remove(selectedType);
                if (selectedTypeList.isEmpty())
                    typeAllBtn.toggleOn();
            }
            filterSettings.setTypeFilter(selectedTypeList);
            fireEvent(ureq, new PortfolioFilterChangeEvent(filterSettings));
        }
    }
    if (source == tagAllBtn) {
        resetTagLinks();
        tagNoneBtn.toggleOff();
        filterSettings.setTagFilter(selectedTagsList);
        fireEvent(ureq, new PortfolioFilterChangeEvent(filterSettings));
    } else if (source == tagNoneBtn) {
        resetTagLinks();
        tagAllBtn.toggleOff();
        filterSettings.setNoTagFilter();
        fireEvent(ureq, new PortfolioFilterChangeEvent(filterSettings));
    } else if (source == typeAllBtn) {
        resetTypeLinks();
        filterSettings.setTypeFilter(selectedTypeList);
        fireEvent(ureq, new PortfolioFilterChangeEvent(filterSettings));
    } else if (source == dateStart || source == dateEnd) {
        if (validateFormLogic(ureq)) {
            List<Date> dateList = new ArrayList<Date>();
            Date selStartDate = dateStart.getDate();
            Date selEndDate = dateEnd.getDate();
            dateList.add(selStartDate);
            dateList.add(selEndDate);
            filterSettings.setDateFilter(dateList);
            fireEvent(ureq, new PortfolioFilterChangeEvent(filterSettings));
        }
    } else if (source == typeEditBtn) {
        popupTypesCallout(ureq);
    } else if (source == tagEditBtn) {
        popupTagsCallout(ureq);
    } else if (source == searchFld) {
        String searchText = searchFld.getValue();
        filterSettings.setTextFilter(searchText);
        fireEvent(ureq, new PortfolioFilterChangeEvent(filterSettings));
    } else if (source == filterSave) {
        if (StringHelper.containsNonWhitespace(filterName.getValue())) {
            String oldFilterName = filterSettings.getFilterName();
            filterSettings.setFilterName(filterName.getValue());
            filterSettings.setTextFilter(searchFld.getValue());
            if (filterSave.getUserObject() != null && filterName.getValue().equals(oldFilterName)) {
                // fake update, delete before adding again
                String filterID = (String) filterSave.getUserObject();
                ePFMgr.deleteFilterFromUsersList(getIdentity(), filterID);
            }
            if (!filterName.getValue().equals(oldFilterName) && oldFilterName != null) {
                // set another id, to distinguish from old
                filterSettings.setFilterIdToUniqueId();
            }
            List<EPFilterSettings> filterList = ePFMgr.getSavedFilterSettings(getIdentity());
            // create a new or insert existing again
            filterList.add(filterSettings);
            ePFMgr.setSavedFilterSettings(getIdentity(), filterList);
            toggleSaveUpdateFilterButtons(true);
            showInfo("filter.saved", filterSettings.getFilterName());
            updateUI(filterSettings);
        }
    } else if (source == filterDel) {
        if (filterDel.getUserObject() != null) {
            ePFMgr.deleteFilterFromUsersList(getIdentity(), (String) filterDel.getUserObject());
            // refresh ui
            filterName.setValue("");
            toggleSaveUpdateFilterButtons(false);
            showInfo("filter.deleted");
            updateUI(new EPFilterSettings());
        }
    } else if (source == filterName) {
        String oldFilterName = filterSettings.getFilterName();
        if (filterSave.getUserObject() != null && !filterName.getValue().equals(oldFilterName)) {
            toggleSaveUpdateFilterButtons(false);
        } else if (filterName.getValue().equals(oldFilterName)) {
            toggleSaveUpdateFilterButtons(true);
        }
    } else if (source == filterSel) {
        if (filterSel.isOneSelected()) {
            int filterIndex = filterSel.getSelected();
            if (filterIndex == 0) {
                EPFilterSettings newSettings = new EPFilterSettings();
                updateUI(newSettings);
                fireEvent(ureq, new PortfolioFilterChangeEvent(newSettings));
            } else if (filterIndex > 0 && filterIndex - 1 < nonEmptyFilters.size()) {
                EPFilterSettings newSettings = nonEmptyFilters.get(filterIndex - 1);
                if (!filterSettings.getFilterId().equals(newSettings.getFilterId())) {
                    updateUI(newSettings);
                    fireEvent(ureq, new PortfolioFilterChangeEvent(newSettings));
                }
            }
        }
    }
}
Also used : EPFilterSettings(org.olat.portfolio.model.EPFilterSettings) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) Date(java.util.Date)

Example 20 with EPFilterSettings

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

the class EPSettingsManager method deleteFilterFromUsersList.

public void deleteFilterFromUsersList(Identity ident, String filterID) {
    List<EPFilterSettings> usersFilters = getSavedFilterSettings(ident);
    for (Iterator<EPFilterSettings> iterator = usersFilters.iterator(); iterator.hasNext(); ) {
        EPFilterSettings epFilterSettings = iterator.next();
        if (epFilterSettings.getFilterId().equals(filterID))
            iterator.remove();
    }
    setSavedFilterSettings(ident, usersFilters);
}
Also used : EPFilterSettings(org.olat.portfolio.model.EPFilterSettings)

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