Search in sources :

Example 11 with QPoolSPI

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

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 12 with QPoolSPI

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

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

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

the class QuestionItemDetailsController method setQuestionController.

private void setQuestionController(UserRequest ureq, QuestionItem item, QuestionItemSecurityCallback securityCallback) {
    removeAsListenerAndDispose(questionCtrl);
    questionCtrl = null;
    QPoolSPI spi = poolModule.getQuestionPoolProvider(item.getFormat());
    boolean canEditContent = securityCallback.canEditQuestion() && (spi != null && spi.isTypeEditable());
    if (canEditContent && !lock.isSuccess()) {
        canEditContent = false;
        String displayName = "???";
        if (lock.getOwner() != null) {
            displayName = userManager.getUserDisplayName(lock.getOwner());
        }
        showWarning("locked.readonly", new String[] { displayName });
    }
    if (spi != null) {
        if (canEditContent) {
            questionCtrl = spi.getEditableController(ureq, getWindowControl(), item);
        } else {
            questionCtrl = spi.getReadOnlyController(ureq, getWindowControl(), item);
        }
    }
    if (questionCtrl == null && spi != null) {
        questionCtrl = spi.getPreviewController(ureq, getWindowControl(), item, false);
    }
    if (questionCtrl == null) {
        questionCtrl = new QuestionItemRawController(ureq, getWindowControl());
    }
    listenTo(questionCtrl);
    if (mainVC != null) {
        mainVC.put("type_specifics", questionCtrl.getInitialComponent());
    }
}
Also used : QPoolSPI(org.olat.modules.qpool.QPoolSPI)

Example 14 with QPoolSPI

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

the class QuestionItemPreviewController method updateItem.

public void updateItem(UserRequest ureq, QuestionItem updatedItem) {
    this.item = updatedItem;
    removeAsListenerAndDispose(previewCtrl);
    if (updatedItem == null) {
        previewCtrl = null;
        previewPanel.setContent(null);
    } else {
        Component content;
        QPoolSPI spi = poolModule.getQuestionPoolProvider(updatedItem.getFormat());
        if (spi == null) {
            content = getRawContent();
        } else {
            previewCtrl = spi.getPreviewController(ureq, getWindowControl(), updatedItem, true);
            if (previewCtrl == null) {
                content = getRawContent();
            } else {
                listenTo(previewCtrl);
                content = previewCtrl.getInitialComponent();
            }
        }
        previewPanel.setContent(content);
    }
}
Also used : QPoolSPI(org.olat.modules.qpool.QPoolSPI) Component(org.olat.core.gui.components.Component)

Example 15 with QPoolSPI

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

the class QuestionPoolServiceImpl method export.

@Override
public MediaResource export(List<QuestionItemShort> items, ExportFormatOptions format, Locale locale) {
    MediaResource mr = null;
    if (DefaultExportFormat.ZIP_EXPORT_FORMAT.equals(format)) {
        List<Long> keys = toKeys(items);
        List<QuestionItemFull> fullItems = questionItemDao.loadByIds(keys);
        mr = new ExportQItemsZipResource("UTF-8", locale, fullItems);
    // make a zip with all items
    } else {
        QPoolSPI selectedSp = null;
        List<QPoolSPI> sps = qpoolModule.getQuestionPoolProviders();
        for (QPoolSPI sp : sps) {
            if (sp.getTestExportFormats().contains(format)) {
                selectedSp = sp;
                break;
            }
        }
        if (selectedSp != null) {
            mr = selectedSp.exportTest(items, format, locale);
        }
    }
    return mr;
}
Also used : QuestionItemFull(org.olat.modules.qpool.QuestionItemFull) QPoolSPI(org.olat.modules.qpool.QPoolSPI) MediaResource(org.olat.core.gui.media.MediaResource)

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