Search in sources :

Example 1 with AssessmentItemAndMetadata

use of org.olat.ims.qti21.questionimport.AssessmentItemAndMetadata in project OpenOLAT by OpenOLAT.

the class QuestionListController method doOpenExcelImportQTI21.

private void doOpenExcelImportQTI21(UserRequest ureq) {
    removeAsListenerAndDispose(excelImportWizard);
    Step additionalStep = null;
    if (getSource().askEditable()) {
        additionalStep = new EditableStep(ureq);
    }
    final AssessmentItemsPackage importPackage = new AssessmentItemsPackage();
    final ImportOptions options = new ImportOptions();
    options.setShuffle(true);
    Step start = new QImport_1_InputStep(ureq, importPackage, options, additionalStep);
    StepRunnerCallback finish = new StepRunnerCallback() {

        @Override
        public Step execute(UserRequest uureq, WindowControl wControl, StepsRunContext runContext) {
            QTI21QPoolServiceProvider spi = CoreSpringFactory.getImpl(QTI21QPoolServiceProvider.class);
            List<AssessmentItemAndMetadata> items = importPackage.getItems();
            List<QuestionItem> importItems = new ArrayList<>();
            for (AssessmentItemAndMetadata item : items) {
                QuestionItem importedItem = spi.importExcelItem(getIdentity(), item, getLocale());
                if (importedItem != null) {
                    importItems.add(importedItem);
                }
            }
            for (QuestionItem item : importItems) {
                QuestionItemAuditLogBuilder builder = qpoolService.createAuditLogBuilder(getIdentity(), Action.CREATE_QUESTION_ITEM_BY_IMPORT);
                builder.withAfter(item);
                qpoolService.persist(builder.create());
            }
            boolean editable = true;
            if (getSource().askEditable()) {
                Object editableCtx = runContext.get("editable");
                editable = (editableCtx instanceof Boolean) ? ((Boolean) editableCtx).booleanValue() : false;
            }
            qpoolService.index(importItems);
            int postImported = getSource().postImport(importItems, editable);
            if (postImported > 0) {
                getItemsTable().reset();
            }
            return StepsMainRunController.DONE_MODIFIED;
        }
    };
    excelImportWizard = new StepsMainRunController(ureq, getWindowControl(), start, finish, null, translate("import.excellike.21"), "o_sel_qpool_excel_import_wizard");
    listenTo(excelImportWizard);
    getWindowControl().pushAsModalDialog(excelImportWizard.getInitialComponent());
}
Also used : ArrayList(java.util.ArrayList) QImport_1_InputStep(org.olat.ims.qti21.questionimport.QImport_1_InputStep) Step(org.olat.core.gui.control.generic.wizard.Step) Export_1_TypeStep(org.olat.modules.qpool.ui.wizard.Export_1_TypeStep) ImportAuthor_1_ChooseMemberStep(org.olat.modules.qpool.ui.wizard.ImportAuthor_1_ChooseMemberStep) WindowControl(org.olat.core.gui.control.WindowControl) StepsRunContext(org.olat.core.gui.control.generic.wizard.StepsRunContext) QImport_1_InputStep(org.olat.ims.qti21.questionimport.QImport_1_InputStep) QuestionItemAuditLogBuilder(org.olat.modules.qpool.QuestionItemAuditLogBuilder) QTI21QPoolServiceProvider(org.olat.ims.qti21.pool.QTI21QPoolServiceProvider) AssessmentItemAndMetadata(org.olat.ims.qti21.questionimport.AssessmentItemAndMetadata) AssessmentItemsPackage(org.olat.ims.qti21.questionimport.AssessmentItemsPackage) StepsMainRunController(org.olat.core.gui.control.generic.wizard.StepsMainRunController) QuestionItem(org.olat.modules.qpool.QuestionItem) ImportOptions(org.olat.ims.qti21.questionimport.ImportOptions) StepRunnerCallback(org.olat.core.gui.control.generic.wizard.StepRunnerCallback) UserRequest(org.olat.core.gui.UserRequest)

Example 2 with AssessmentItemAndMetadata

use of org.olat.ims.qti21.questionimport.AssessmentItemAndMetadata in project OpenOLAT by OpenOLAT.

the class QTI21QPoolServiceProvider method importExcelItem.

public QuestionItemImpl importExcelItem(Identity owner, AssessmentItemAndMetadata itemAndMetadata, Locale defaultLocale) {
    QTI21ImportProcessor processor = new QTI21ImportProcessor(owner, defaultLocale);
    String editor = itemAndMetadata.getEditor();
    String editorVersion = itemAndMetadata.getEditorVersion();
    AssessmentItemBuilder itemBuilder = itemAndMetadata.getItemBuilder();
    itemBuilder.build();
    AssessmentItem assessmentItem = itemBuilder.getAssessmentItem();
    QuestionItemImpl qitem = processor.processItem(assessmentItem, null, null, editor, editorVersion, itemAndMetadata);
    String originalItemFilename = qitem.getRootFilename();
    File itemStorage = qpoolFileStorage.getDirectory(qitem.getDirectory());
    File itemFile = new File(itemStorage, originalItemFilename);
    qtiService.persistAssessmentObject(itemFile, assessmentItem);
    // create manifest
    ManifestBuilder manifest = ManifestBuilder.createAssessmentItemBuilder();
    ResourceType resource = manifest.appendAssessmentItem(UUID.randomUUID().toString(), originalItemFilename);
    ManifestMetadataBuilder metadataBuilder = manifest.getMetadataBuilder(resource, true);
    itemAndMetadata.toBuilder(metadataBuilder, defaultLocale);
    manifest.write(new File(itemStorage, "imsmanifest.xml"));
    return qitem;
}
Also used : ManifestBuilder(org.olat.ims.qti21.model.xml.ManifestBuilder) QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) ResourceType(org.olat.imscp.xml.manifest.ResourceType) HotspotAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.HotspotAssessmentItemBuilder) UploadAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.UploadAssessmentItemBuilder) FIBAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder) SingleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder) HottextAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.HottextAssessmentItemBuilder) DrawingAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.DrawingAssessmentItemBuilder) EssayAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.EssayAssessmentItemBuilder) MatchAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.MatchAssessmentItemBuilder) AssessmentItemBuilder(org.olat.ims.qti21.model.xml.AssessmentItemBuilder) KPrimAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.KPrimAssessmentItemBuilder) MultipleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.MultipleChoiceAssessmentItemBuilder) File(java.io.File) ManifestMetadataBuilder(org.olat.ims.qti21.model.xml.ManifestMetadataBuilder)

Example 3 with AssessmentItemAndMetadata

use of org.olat.ims.qti21.questionimport.AssessmentItemAndMetadata in project OpenOLAT by OpenOLAT.

the class CSVToAssessmentItemConverter method processType.

private void processType(String[] parts) {
    if (currentItem != null) {
        build();
        items.add(currentItem);
        currentItem = null;
    }
    if (parts.length > 1) {
        String type = parts[1].toLowerCase();
        AssessmentItemBuilder itemBuilder;
        switch(type) {
            case "fib":
                {
                    FIBAssessmentItemBuilder fibItemBuilder = new FIBAssessmentItemBuilder("Gap text", EntryType.text, qtiSerializer);
                    itemBuilder = initFIBAssessmentItemBuilder(fibItemBuilder);
                    break;
                }
            case "mc":
                {
                    MultipleChoiceAssessmentItemBuilder mcItemBuilder = new MultipleChoiceAssessmentItemBuilder("Multiple choice", "New answer", qtiSerializer);
                    itemBuilder = initMultipleChoiceAssessmentItemBuilder(mcItemBuilder);
                    break;
                }
            case "sc":
                {
                    SingleChoiceAssessmentItemBuilder scItemBuilder = new SingleChoiceAssessmentItemBuilder("Single choice", "New answer", qtiSerializer);
                    itemBuilder = initSingleChoiceAssessmentItemBuilder(scItemBuilder);
                    break;
                }
            case "kprim":
                {
                    kprimPosition = 0;
                    itemBuilder = new KPrimAssessmentItemBuilder("Kprim", "New answer", qtiSerializer);
                    break;
                }
            case "essay":
                {
                    itemBuilder = new EssayAssessmentItemBuilder("Essay", qtiSerializer);
                    break;
                }
            case "matrix":
                {
                    MatchAssessmentItemBuilder matchBuilder = new MatchAssessmentItemBuilder("Matrix", QTI21Constants.CSS_MATCH_MATRIX, qtiSerializer);
                    itemBuilder = initMatchAssessmentItemBuilder(matchBuilder);
                    break;
                }
            case "drag&drop":
                {
                    MatchAssessmentItemBuilder matchBuilder = new MatchAssessmentItemBuilder("Matrix", QTI21Constants.CSS_MATCH_DRAG_AND_DROP, qtiSerializer);
                    itemBuilder = initMatchAssessmentItemBuilder(matchBuilder);
                    break;
                }
            case "truefalse":
                {
                    Translator trans = Util.createPackageTranslator(AssessmentItemEditorController.class, locale);
                    MatchAssessmentItemBuilder matchBuilder = new MatchAssessmentItemBuilder("Matrix", QTI21Constants.CSS_MATCH_TRUE_FALSE, trans.translate("match.unanswered"), trans.translate("match.true"), trans.translate("match.false"), qtiSerializer);
                    itemBuilder = initMatchAssessmentItemBuilderForTrueFalse(matchBuilder);
                    break;
                }
            default:
                {
                    itemBuilder = null;
                }
        }
        if (itemBuilder != null) {
            currentItem = new AssessmentItemAndMetadata(itemBuilder);
        } else {
            log.warn("Question type not supported: " + type);
            currentItem = null;
        }
    }
}
Also used : FIBAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder) KPrimAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.KPrimAssessmentItemBuilder) SingleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder) Translator(org.olat.core.gui.translator.Translator) AssessmentItemEditorController(org.olat.ims.qti21.ui.editor.AssessmentItemEditorController) EssayAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.EssayAssessmentItemBuilder) SimpleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.SimpleChoiceAssessmentItemBuilder) EssayAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.EssayAssessmentItemBuilder) FIBAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder) MatchAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.MatchAssessmentItemBuilder) SingleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder) AssessmentItemBuilder(org.olat.ims.qti21.model.xml.AssessmentItemBuilder) KPrimAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.KPrimAssessmentItemBuilder) MultipleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.MultipleChoiceAssessmentItemBuilder) MultipleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.MultipleChoiceAssessmentItemBuilder) MatchAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.MatchAssessmentItemBuilder)

Example 4 with AssessmentItemAndMetadata

use of org.olat.ims.qti21.questionimport.AssessmentItemAndMetadata in project openolat by klemens.

the class QTI21QPoolServiceProvider method importExcelItem.

public QuestionItemImpl importExcelItem(Identity owner, AssessmentItemAndMetadata itemAndMetadata, Locale defaultLocale) {
    QTI21ImportProcessor processor = new QTI21ImportProcessor(owner, defaultLocale);
    String editor = itemAndMetadata.getEditor();
    String editorVersion = itemAndMetadata.getEditorVersion();
    AssessmentItemBuilder itemBuilder = itemAndMetadata.getItemBuilder();
    itemBuilder.build();
    AssessmentItem assessmentItem = itemBuilder.getAssessmentItem();
    QuestionItemImpl qitem = processor.processItem(assessmentItem, null, null, editor, editorVersion, itemAndMetadata);
    String originalItemFilename = qitem.getRootFilename();
    File itemStorage = qpoolFileStorage.getDirectory(qitem.getDirectory());
    File itemFile = new File(itemStorage, originalItemFilename);
    qtiService.persistAssessmentObject(itemFile, assessmentItem);
    // create manifest
    ManifestBuilder manifest = ManifestBuilder.createAssessmentItemBuilder();
    ResourceType resource = manifest.appendAssessmentItem(UUID.randomUUID().toString(), originalItemFilename);
    ManifestMetadataBuilder metadataBuilder = manifest.getMetadataBuilder(resource, true);
    itemAndMetadata.toBuilder(metadataBuilder, defaultLocale);
    manifest.write(new File(itemStorage, "imsmanifest.xml"));
    return qitem;
}
Also used : ManifestBuilder(org.olat.ims.qti21.model.xml.ManifestBuilder) QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) ResourceType(org.olat.imscp.xml.manifest.ResourceType) HotspotAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.HotspotAssessmentItemBuilder) UploadAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.UploadAssessmentItemBuilder) FIBAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder) SingleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder) HottextAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.HottextAssessmentItemBuilder) DrawingAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.DrawingAssessmentItemBuilder) EssayAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.EssayAssessmentItemBuilder) MatchAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.MatchAssessmentItemBuilder) AssessmentItemBuilder(org.olat.ims.qti21.model.xml.AssessmentItemBuilder) KPrimAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.KPrimAssessmentItemBuilder) MultipleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.MultipleChoiceAssessmentItemBuilder) File(java.io.File) ManifestMetadataBuilder(org.olat.ims.qti21.model.xml.ManifestMetadataBuilder)

Example 5 with AssessmentItemAndMetadata

use of org.olat.ims.qti21.questionimport.AssessmentItemAndMetadata in project openolat by klemens.

the class CSVToAssessmentItemConverter method processType.

private void processType(String[] parts) {
    if (currentItem != null) {
        build();
        items.add(currentItem);
        currentItem = null;
    }
    if (parts.length > 1) {
        String type = parts[1].toLowerCase();
        AssessmentItemBuilder itemBuilder;
        switch(type) {
            case "fib":
                {
                    FIBAssessmentItemBuilder fibItemBuilder = new FIBAssessmentItemBuilder("Gap text", EntryType.text, qtiSerializer);
                    itemBuilder = initFIBAssessmentItemBuilder(fibItemBuilder);
                    break;
                }
            case "mc":
                {
                    MultipleChoiceAssessmentItemBuilder mcItemBuilder = new MultipleChoiceAssessmentItemBuilder("Multiple choice", "New answer", qtiSerializer);
                    itemBuilder = initMultipleChoiceAssessmentItemBuilder(mcItemBuilder);
                    break;
                }
            case "sc":
                {
                    SingleChoiceAssessmentItemBuilder scItemBuilder = new SingleChoiceAssessmentItemBuilder("Single choice", "New answer", qtiSerializer);
                    itemBuilder = initSingleChoiceAssessmentItemBuilder(scItemBuilder);
                    break;
                }
            case "kprim":
                {
                    kprimPosition = 0;
                    itemBuilder = new KPrimAssessmentItemBuilder("Kprim", "New answer", qtiSerializer);
                    break;
                }
            case "essay":
                {
                    itemBuilder = new EssayAssessmentItemBuilder("Essay", qtiSerializer);
                    break;
                }
            case "matrix":
                {
                    MatchAssessmentItemBuilder matchBuilder = new MatchAssessmentItemBuilder("Matrix", QTI21Constants.CSS_MATCH_MATRIX, qtiSerializer);
                    itemBuilder = initMatchAssessmentItemBuilder(matchBuilder);
                    break;
                }
            case "drag&drop":
                {
                    MatchAssessmentItemBuilder matchBuilder = new MatchAssessmentItemBuilder("Matrix", QTI21Constants.CSS_MATCH_DRAG_AND_DROP, qtiSerializer);
                    itemBuilder = initMatchAssessmentItemBuilder(matchBuilder);
                    break;
                }
            case "truefalse":
                {
                    Translator trans = Util.createPackageTranslator(AssessmentItemEditorController.class, locale);
                    MatchAssessmentItemBuilder matchBuilder = new MatchAssessmentItemBuilder("Matrix", QTI21Constants.CSS_MATCH_TRUE_FALSE, trans.translate("match.unanswered"), trans.translate("match.true"), trans.translate("match.false"), qtiSerializer);
                    itemBuilder = initMatchAssessmentItemBuilderForTrueFalse(matchBuilder);
                    break;
                }
            default:
                {
                    itemBuilder = null;
                }
        }
        if (itemBuilder != null) {
            currentItem = new AssessmentItemAndMetadata(itemBuilder);
        } else {
            log.warn("Question type not supported: " + type);
            currentItem = null;
        }
    }
}
Also used : FIBAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder) KPrimAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.KPrimAssessmentItemBuilder) SingleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder) Translator(org.olat.core.gui.translator.Translator) AssessmentItemEditorController(org.olat.ims.qti21.ui.editor.AssessmentItemEditorController) EssayAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.EssayAssessmentItemBuilder) SimpleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.SimpleChoiceAssessmentItemBuilder) EssayAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.EssayAssessmentItemBuilder) FIBAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder) MatchAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.MatchAssessmentItemBuilder) SingleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder) AssessmentItemBuilder(org.olat.ims.qti21.model.xml.AssessmentItemBuilder) KPrimAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.KPrimAssessmentItemBuilder) MultipleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.MultipleChoiceAssessmentItemBuilder) MultipleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.MultipleChoiceAssessmentItemBuilder) MatchAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.MatchAssessmentItemBuilder)

Aggregations

AssessmentItemBuilder (org.olat.ims.qti21.model.xml.AssessmentItemBuilder)6 EssayAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.EssayAssessmentItemBuilder)6 FIBAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder)6 KPrimAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.KPrimAssessmentItemBuilder)6 MatchAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.MatchAssessmentItemBuilder)6 MultipleChoiceAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.MultipleChoiceAssessmentItemBuilder)6 SingleChoiceAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder)6 ManifestMetadataBuilder (org.olat.ims.qti21.model.xml.ManifestMetadataBuilder)4 DrawingAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.DrawingAssessmentItemBuilder)4 HotspotAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.HotspotAssessmentItemBuilder)4 HottextAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.HottextAssessmentItemBuilder)4 UploadAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.UploadAssessmentItemBuilder)4 AssessmentItemAndMetadata (org.olat.ims.qti21.questionimport.AssessmentItemAndMetadata)4 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)4 ResolvedAssessmentItem (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem)4 File (java.io.File)2 URISyntaxException (java.net.URISyntaxException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 UserRequest (org.olat.core.gui.UserRequest)2