Search in sources :

Example 16 with QPoolSPI

use of org.olat.modules.qpool.QPoolSPI in project OpenOLAT by OpenOLAT.

the class QuestionPoolServiceImpl method importItems.

@Override
public List<QuestionItem> importItems(Identity owner, Locale defaultLocale, String filename, File file) {
    List<QuestionItem> importedItem = null;
    List<QPoolSPI> providers = qpoolModule.getQuestionPoolProviders();
    for (QPoolSPI provider : providers) {
        if (provider.isCompatible(filename, file)) {
            importedItem = provider.importItems(owner, defaultLocale, filename, file);
        }
    }
    dbInstance.commit();
    index(importedItem);
    return importedItem;
}
Also used : QPoolSPI(org.olat.modules.qpool.QPoolSPI) QuestionItem(org.olat.modules.qpool.QuestionItem)

Example 17 with QPoolSPI

use of org.olat.modules.qpool.QPoolSPI in project OpenOLAT by OpenOLAT.

the class QuestionPoolServiceImpl method convertItems.

@Override
public List<QuestionItem> convertItems(Identity cloner, List<QuestionItemShort> itemsToConvert, String format, Locale locale) {
    QPoolSPI sp = qpoolModule.getQuestionPoolProvider(format);
    List<QuestionItem> convertedQuestions = new ArrayList<>(itemsToConvert.size());
    for (QuestionItemShort item : itemsToConvert) {
        QuestionItem convertedQuestion = sp.convert(cloner, item, locale);
        licenseService.copy(item, convertedQuestion);
        if (convertedQuestion != null) {
            convertedQuestions.add(convertedQuestion);
        }
    }
    dbInstance.commit();
    index(convertedQuestions);
    return convertedQuestions;
}
Also used : QPoolSPI(org.olat.modules.qpool.QPoolSPI) QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) ArrayList(java.util.ArrayList) QuestionItem(org.olat.modules.qpool.QuestionItem)

Example 18 with QPoolSPI

use of org.olat.modules.qpool.QPoolSPI in project OpenOLAT by OpenOLAT.

the class QuestionPoolServiceImpl method exportItem.

@Override
public void exportItem(QuestionItemShort item, ZipOutputStream zout, Locale locale, Set<String> names) {
    QPoolSPI provider = qpoolModule.getQuestionPoolProvider(item.getFormat());
    if (provider == null) {
        log.error("Not found provider for this format: " + item.getFormat());
    } else {
        QuestionItemFull fullItem;
        if (item instanceof QuestionItemFull) {
            fullItem = (QuestionItemFull) item;
        } else {
            fullItem = questionItemDao.loadById(item.getKey());
        }
        provider.exportItem(fullItem, zout, locale, names);
    }
}
Also used : QuestionItemFull(org.olat.modules.qpool.QuestionItemFull) QPoolSPI(org.olat.modules.qpool.QPoolSPI)

Example 19 with QPoolSPI

use of org.olat.modules.qpool.QPoolSPI in project OpenOLAT by OpenOLAT.

the class QuestionListController method doConfirmConversion.

private void doConfirmConversion(UserRequest ureq, List<QuestionItemShort> items) {
    Map<String, List<QuestionItemShort>> formatToItems = new HashMap<>();
    List<QPoolSPI> spies = qpoolModule.getQuestionPoolProviders();
    for (QuestionItemShort item : items) {
        for (QPoolSPI sp : spies) {
            if (sp != null && sp.isConversionPossible(item)) {
                List<QuestionItemShort> convertItems;
                if (formatToItems.containsKey(sp.getFormat())) {
                    convertItems = formatToItems.get(sp.getFormat());
                } else {
                    convertItems = new ArrayList<>(items.size());
                    formatToItems.put(sp.getFormat(), convertItems);
                }
                convertItems.add(item);
            }
        }
    }
    if (formatToItems.isEmpty()) {
        showWarning("convert.item.not.possible");
    } else {
        conversionConfirmationCtrl = new ConversionConfirmationController(ureq, getWindowControl(), formatToItems, getSource());
        listenTo(conversionConfirmationCtrl);
        cmc = new CloseableModalController(getWindowControl(), translate("close"), conversionConfirmationCtrl.getInitialComponent(), true, translate("convert.item"));
        cmc.activate();
        listenTo(cmc);
    }
}
Also used : HashMap(java.util.HashMap) QPoolSPI(org.olat.modules.qpool.QPoolSPI) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) QItemList(org.olat.modules.qpool.model.QItemList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 20 with QPoolSPI

use of org.olat.modules.qpool.QPoolSPI in project openolat by klemens.

the class NewItemOptionsController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    // title
    titleEl = uifactory.addTextElement("general.title", "general.title", 128, "", formLayout);
    // type
    List<QItemFactory> factories = new ArrayList<>();
    for (QPoolSPI spi : qpoolModule.getQuestionPoolProviders()) {
        for (QItemFactory factory : spi.getItemfactories()) {
            factories.add(factory);
        }
    }
    int count = 0;
    String[] typeKeys = new String[factories.size()];
    String[] valueKeys = new String[factories.size()];
    for (QItemFactory factory : factories) {
        String typeKey = "item.type." + count;
        typeKeys[count] = typeKey;
        keyToFactoryMap.put(typeKey, factory);
        valueKeys[count] = factory.getLabel(getLocale());
        count++;
    }
    typeEl = uifactory.addDropdownSingleselect("question.type", "menu.admin.types", formLayout, typeKeys, valueKeys, null);
    // subject
    taxonomyLevelEl = uifactory.addDropdownSingleselect("process.start.review.taxonomy.level", formLayout, qpoolTaxonomyTreeBuilder.getSelectableKeys(), qpoolTaxonomyTreeBuilder.getSelectableValues(), null);
    if (selectedTaxonomyLevel != null) {
        String selectedTaxonomyLevelKey = String.valueOf(selectedTaxonomyLevel.getKey());
        for (String taxonomyKey : qpoolTaxonomyTreeBuilder.getSelectableKeys()) {
            if (taxonomyKey.equals(selectedTaxonomyLevelKey)) {
                taxonomyLevelEl.select(taxonomyKey, true);
            }
        }
    }
    taxonomyLevelEl.setVisible(qPoolSecurityCallback.canUseTaxonomy());
    FormLayoutContainer buttonLayout = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
    buttonLayout.setRootForm(mainForm);
    formLayout.add(buttonLayout);
    uifactory.addFormSubmitButton("new.item", buttonLayout);
    uifactory.addFormCancelButton("cancel", buttonLayout, ureq, getWindowControl());
}
Also used : QItemFactory(org.olat.modules.qpool.QItemFactory) QPoolSPI(org.olat.modules.qpool.QPoolSPI) ArrayList(java.util.ArrayList) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)

Aggregations

QPoolSPI (org.olat.modules.qpool.QPoolSPI)24 ArrayList (java.util.ArrayList)10 QuestionItemShort (org.olat.modules.qpool.QuestionItemShort)10 QuestionItem (org.olat.modules.qpool.QuestionItem)6 QuestionItemImpl (org.olat.modules.qpool.model.QuestionItemImpl)6 HashMap (java.util.HashMap)4 List (java.util.List)4 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)4 QuestionItemFull (org.olat.modules.qpool.QuestionItemFull)4 StringTokenizer (java.util.StringTokenizer)2 Document (org.apache.lucene.document.Document)2 StringField (org.apache.lucene.document.StringField)2 TextField (org.apache.lucene.document.TextField)2 Test (org.junit.Test)2 ResourceLicense (org.olat.core.commons.services.license.ResourceLicense)2 Component (org.olat.core.gui.components.Component)2 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)2 MediaResource (org.olat.core.gui.media.MediaResource)2 Identity (org.olat.core.id.Identity)2 User (org.olat.core.id.User)2