Search in sources :

Example 26 with QuestionItemImpl

use of org.olat.modules.qpool.model.QuestionItemImpl in project OpenOLAT by OpenOLAT.

the class QTI21ImportProcessor method processItem.

protected QuestionItemImpl processItem(AssessmentItem assessmentItem, String comment, String originalItemFilename, String editor, String editorVersion, String dir, AssessmentItemMetadata metadata) {
    // filename
    String filename;
    String ident = assessmentItem.getIdentifier();
    if (originalItemFilename != null) {
        filename = originalItemFilename;
    } else if (StringHelper.containsNonWhitespace(ident)) {
        filename = StringHelper.transformDisplayNameToFileSystemName(ident) + ".xml";
    } else {
        filename = "item.xml";
    }
    // title
    String title = assessmentItem.getTitle();
    if (!StringHelper.containsNonWhitespace(title)) {
        title = assessmentItem.getLabel();
    }
    if (!StringHelper.containsNonWhitespace(title)) {
        title = ident;
    }
    QuestionItemImpl poolItem = questionItemDao.create(title, QTI21Constants.QTI_21_FORMAT, dir, filename);
    // description
    poolItem.setDescription(comment);
    // language from default
    poolItem.setLanguage(defaultLocale.getLanguage());
    // question type first
    if (StringHelper.containsNonWhitespace(editor)) {
        poolItem.setEditor(editor);
        poolItem.setEditorVersion(editorVersion);
    }
    // if question type not found, can be overridden by the metadatas
    processItemMetadata(poolItem, metadata);
    if (poolItem.getType() == null) {
        QItemType defType = convertType(assessmentItem);
        poolItem.setType(defType);
    }
    questionItemDao.persist(owner, poolItem);
    createLicense(poolItem, metadata);
    return poolItem;
}
Also used : QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) QItemType(org.olat.modules.qpool.model.QItemType)

Example 27 with QuestionItemImpl

use of org.olat.modules.qpool.model.QuestionItemImpl in project OpenOLAT by OpenOLAT.

the class OLATUpgrade_12_3_0 method migrateQpoolTitles.

private void migrateQpoolTitles() {
    int counter = 0;
    List<QuestionItemImpl> items;
    do {
        items = getQuestionItems(counter, BATCH_SIZE);
        for (QuestionItemImpl item : items) {
            try {
                migrateQPoolTitle(item);
                log.info("QPool item successfully migrated: " + item);
            } catch (Exception e) {
                log.error("Not able to migrate question title: " + item, e);
            }
        }
        counter += items.size();
        dbInstance.commitAndCloseSession();
        log.info(counter + " QPool items processed.");
    } while (items.size() == BATCH_SIZE);
}
Also used : QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) ConversionException(com.thoughtworks.xstream.converters.ConversionException)

Example 28 with QuestionItemImpl

use of org.olat.modules.qpool.model.QuestionItemImpl in project OpenOLAT by OpenOLAT.

the class QTI21QPoolServiceProvider method convert.

@Override
public QuestionItem convert(Identity owner, QuestionItemShort itemToConvert, Locale locale) {
    if (QTIConstants.QTI_12_FORMAT.equals(itemToConvert.getFormat())) {
        VFSLeaf leaf = qpoolService.getRootLeaf(itemToConvert);
        if (leaf == null) {
            return null;
        } else {
            Item qtiItem = QTIEditHelper.readItemXml(leaf);
            if (qtiItem != null && !qtiItem.isAlient()) {
                QuestionItemImpl original = questionItemDao.loadById(itemToConvert.getKey());
                QuestionItemImpl copy = questionItemDao.copy(original);
                copy.setTitle(original.getTitle());
                copy.setFormat(getFormat());
                VFSContainer originalDir = qpoolFileStorage.getContainer(original.getDirectory());
                File copyDir = qpoolFileStorage.getDirectory(copy.getDirectory());
                QTI12To21Converter converter = new QTI12To21Converter(copyDir, locale);
                if (converter.convert(copy, qtiItem, originalDir)) {
                    questionItemDao.persist(owner, copy);
                    return copy;
                }
            }
        }
    }
    return null;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) Item(org.olat.ims.qti.editor.beecom.objects.Item) VFSItem(org.olat.core.util.vfs.VFSItem) QuestionItem(org.olat.modules.qpool.QuestionItem) QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) VFSContainer(org.olat.core.util.vfs.VFSContainer) File(java.io.File)

Example 29 with QuestionItemImpl

use of org.olat.modules.qpool.model.QuestionItemImpl 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 30 with QuestionItemImpl

use of org.olat.modules.qpool.model.QuestionItemImpl in project OpenOLAT by OpenOLAT.

the class QTI21QPoolServiceProvider method createItem.

public QuestionItem createItem(Identity identity, QTI21QuestionType type, String title, Locale locale) {
    AssessmentItemBuilder itemBuilder = null;
    Translator translator = Util.createPackageTranslator(AssessmentTestComposerController.class, locale);
    switch(type) {
        case sc:
            itemBuilder = new SingleChoiceAssessmentItemBuilder(translator.translate("new.sc"), translator.translate("new.answer"), qtiService.qtiSerializer());
            break;
        case mc:
            itemBuilder = new MultipleChoiceAssessmentItemBuilder(translator.translate("new.mc"), translator.translate("new.answer"), qtiService.qtiSerializer());
            break;
        case kprim:
            itemBuilder = new KPrimAssessmentItemBuilder(translator.translate("new.kprim"), translator.translate("new.answer"), qtiService.qtiSerializer());
            break;
        case match:
            itemBuilder = new MatchAssessmentItemBuilder(translator.translate("new.match"), QTI21Constants.CSS_MATCH_MATRIX, qtiService.qtiSerializer());
            break;
        case matchdraganddrop:
            itemBuilder = new MatchAssessmentItemBuilder(translator.translate("new.match"), QTI21Constants.CSS_MATCH_DRAG_AND_DROP, qtiService.qtiSerializer());
            break;
        case matchtruefalse:
            itemBuilder = new MatchAssessmentItemBuilder(translator.translate("new.match"), QTI21Constants.CSS_MATCH_TRUE_FALSE, translator.translate("match.unanswered"), translator.translate("match.true"), translator.translate("match.false"), qtiService.qtiSerializer());
            break;
        case fib:
            itemBuilder = new FIBAssessmentItemBuilder(translator.translate("new.fib"), EntryType.text, qtiService.qtiSerializer());
            break;
        case numerical:
            itemBuilder = new FIBAssessmentItemBuilder(translator.translate("new.fib.numerical"), EntryType.numerical, qtiService.qtiSerializer());
            break;
        case essay:
            itemBuilder = new EssayAssessmentItemBuilder(translator.translate("new.essay"), qtiService.qtiSerializer());
            break;
        case upload:
            itemBuilder = new UploadAssessmentItemBuilder(translator.translate("new.upload"), qtiService.qtiSerializer());
            break;
        case drawing:
            itemBuilder = new DrawingAssessmentItemBuilder(translator.translate("new.drawing"), qtiService.qtiSerializer());
            break;
        case hotspot:
            itemBuilder = new HotspotAssessmentItemBuilder(translator.translate("new.hotspot"), qtiService.qtiSerializer());
            break;
        case hottext:
            itemBuilder = new HottextAssessmentItemBuilder(translator.translate("new.hottext"), translator.translate("new.hottext.start"), translator.translate("new.hottext.text"), qtiService.qtiSerializer());
            break;
        default:
            return null;
    }
    AssessmentItem assessmentItem = itemBuilder.getAssessmentItem();
    assessmentItem.setLabel(title);
    assessmentItem.setTitle(title);
    AssessmentItemMetadata itemMetadata = new AssessmentItemMetadata();
    itemMetadata.setQuestionType(type);
    QTI21ImportProcessor processor = new QTI21ImportProcessor(identity, locale);
    QuestionItemImpl qitem = processor.processItem(assessmentItem, "", null, "OpenOLAT", Settings.getVersion(), itemMetadata);
    VFSContainer baseDir = qpoolFileStorage.getContainer(qitem.getDirectory());
    VFSLeaf leaf = baseDir.createChildLeaf(qitem.getRootFilename());
    File itemFile = ((LocalImpl) leaf).getBasefile();
    qtiService.persistAssessmentObject(itemFile, assessmentItem);
    // create imsmanifest
    ManifestBuilder manifest = ManifestBuilder.createAssessmentItemBuilder();
    manifest.appendAssessmentItem(itemFile.getName());
    manifest.write(new File(itemFile.getParentFile(), "imsmanifest.xml"));
    return qitem;
}
Also used : HottextAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.HottextAssessmentItemBuilder) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) ManifestBuilder(org.olat.ims.qti21.model.xml.ManifestBuilder) SingleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder) QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) VFSContainer(org.olat.core.util.vfs.VFSContainer) EssayAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.EssayAssessmentItemBuilder) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) 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) MultipleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.MultipleChoiceAssessmentItemBuilder) MatchAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.MatchAssessmentItemBuilder) FIBAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder) KPrimAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.KPrimAssessmentItemBuilder) Translator(org.olat.core.gui.translator.Translator) AssessmentItemMetadata(org.olat.ims.qti21.model.xml.AssessmentItemMetadata) HotspotAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.HotspotAssessmentItemBuilder) UploadAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.UploadAssessmentItemBuilder) LocalImpl(org.olat.core.util.vfs.LocalImpl) File(java.io.File) DrawingAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.DrawingAssessmentItemBuilder)

Aggregations

QuestionItemImpl (org.olat.modules.qpool.model.QuestionItemImpl)108 QuestionItem (org.olat.modules.qpool.QuestionItem)32 Test (org.junit.Test)20 QuestionItemAuditLogBuilder (org.olat.modules.qpool.QuestionItemAuditLogBuilder)16 TaxonomyLevel (org.olat.modules.taxonomy.TaxonomyLevel)16 Identity (org.olat.core.id.Identity)14 VFSContainer (org.olat.core.util.vfs.VFSContainer)14 QuestionItemView (org.olat.modules.qpool.QuestionItemView)14 File (java.io.File)12 VFSItem (org.olat.core.util.vfs.VFSItem)12 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)12 QItemEdited (org.olat.modules.qpool.ui.events.QItemEdited)12 ArrayList (java.util.ArrayList)10 QItemType (org.olat.modules.qpool.model.QItemType)10 SearchQuestionItemParams (org.olat.modules.qpool.model.SearchQuestionItemParams)10 ManifestBuilder (org.olat.ims.qti21.model.xml.ManifestBuilder)8 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)8 ResolvedAssessmentItem (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem)8 QuestionItemShort (org.olat.modules.qpool.QuestionItemShort)7 Taxonomy (org.olat.modules.taxonomy.Taxonomy)7