Search in sources :

Example 61 with AssessmentItem

use of uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem in project openolat by klemens.

the class QTI12To21Converter method convertItemBasics.

private void convertItemBasics(Item item, AssessmentItemBuilder itemBuilder) {
    AssessmentItem assessmentItem = itemBuilder.getAssessmentItem();
    if (StringHelper.containsNonWhitespace(item.getTitle())) {
        assessmentItem.setTitle(item.getTitle());
    }
    if (StringHelper.containsNonWhitespace(item.getLabel())) {
        assessmentItem.setLabel(item.getLabel());
    }
    Question question = item.getQuestion();
    String questionText = question.getQuestion().renderAsHtmlForEditor();
    questionText = blockedHtml(questionText);
    if (StringHelper.isHtml(questionText)) {
        itemBuilder.setQuestion(questionText);
    } else {
        itemBuilder.setQuestion("<p>" + questionText + "</p>");
    }
    String hintText = question.getHintText();
    if (StringHelper.containsNonWhitespace(hintText)) {
        ModalFeedbackBuilder hint = itemBuilder.createHint();
        Translator translator = Util.createPackageTranslator(QTIModule.class, locale);
        hint.setTitle(translator.translate("render.hint"));
        hint.setText(hintText);
    }
    String solutionText = question.getSolutionText();
    if (StringHelper.containsNonWhitespace(solutionText)) {
        ModalFeedbackBuilder solution = itemBuilder.createCorrectSolutionFeedback();
        solutionText = blockedHtml(solutionText);
        solution.setText(solutionText);
    }
    String feedbackMastery = QTIEditHelper.getFeedbackMasteryText(item);
    if (StringHelper.containsNonWhitespace(feedbackMastery)) {
        ModalFeedbackBuilder feedback = itemBuilder.createCorrectFeedback();
        feedbackMastery = blockedHtml(feedbackMastery);
        feedback.setText(feedbackMastery);
    }
    String feedbackFail = QTIEditHelper.getFeedbackFailText(item);
    if (StringHelper.containsNonWhitespace(feedbackFail)) {
        ModalFeedbackBuilder feedback = itemBuilder.createIncorrectFeedback();
        feedbackFail = blockedHtml(feedbackFail);
        feedback.setText(feedbackFail);
    }
}
Also used : ModalFeedbackBuilder(org.olat.ims.qti21.model.xml.ModalFeedbackBuilder) Translator(org.olat.core.gui.translator.Translator) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) EssayQuestion(org.olat.ims.qti.editor.beecom.objects.EssayQuestion) ChoiceQuestion(org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion) Question(org.olat.ims.qti.editor.beecom.objects.Question)

Example 62 with AssessmentItem

use of uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem in project openolat by klemens.

the class QTI12To21Converter method convertItem.

/**
 * @param item
 * @return The name of the assesssmentItem file
 */
private boolean convertItem(QuestionItemImpl convertedQuestion, Item item) {
    QItemTypeDAO qItemTypeDao = CoreSpringFactory.getImpl(QItemTypeDAO.class);
    AssessmentItemBuilder itemBuilder = null;
    int questionType = item.getQuestion().getType();
    switch(questionType) {
        case Question.TYPE_SC:
            itemBuilder = convertSingleChoice(item);
            convertedQuestion.setType(qItemTypeDao.loadByType(QuestionType.SC.name()));
            break;
        case Question.TYPE_MC:
            itemBuilder = convertMultipleChoice(item);
            convertedQuestion.setType(qItemTypeDao.loadByType(QuestionType.MC.name()));
            break;
        case Question.TYPE_KPRIM:
            itemBuilder = convertKPrim(item);
            convertedQuestion.setType(qItemTypeDao.loadByType(QuestionType.KPRIM.name()));
            break;
        case Question.TYPE_FIB:
            itemBuilder = convertFIB(item);
            convertedQuestion.setType(qItemTypeDao.loadByType(QuestionType.FIB.name()));
            break;
        case Question.TYPE_ESSAY:
            itemBuilder = convertEssay(item);
            convertedQuestion.setType(qItemTypeDao.loadByType(QuestionType.ESSAY.name()));
            break;
    }
    if (itemBuilder != null) {
        itemBuilder.build();
        AssessmentItem assessmentItem = itemBuilder.getAssessmentItem();
        String itemId = IdentifierGenerator.newAsString(itemBuilder.getQuestionType().getPrefix());
        File itemFile = new File(unzippedDirRoot, itemId + ".xml");
        persistAssessmentObject(itemFile, assessmentItem);
        appendResourceAndMetadata(item, itemBuilder, itemFile);
        convertedQuestion.setRootFilename(itemFile.getName());
        return true;
    }
    return false;
}
Also used : QItemTypeDAO(org.olat.modules.qpool.manager.QItemTypeDAO) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) EssayAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.EssayAssessmentItemBuilder) 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) SimpleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.SimpleChoiceAssessmentItemBuilder) FIBAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder) SingleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder) File(java.io.File)

Example 63 with AssessmentItem

use of uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem in project openolat by klemens.

the class QTI21EditorController method event.

@Override
protected void event(UserRequest ureq, Controller source, Event event) {
    if (source == editorCtrl) {
        if (event instanceof AssessmentItemEvent) {
            AssessmentItemEvent aie = (AssessmentItemEvent) event;
            AssessmentItem assessmentItem = aie.getAssessmentItem();
            qtiService.persistAssessmentObject(resourceFile, assessmentItem);
            updateQuestionItem(ureq, assessmentItem);
        }
    }
}
Also used : ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) AssessmentItemEvent(org.olat.ims.qti21.ui.editor.events.AssessmentItemEvent)

Example 64 with AssessmentItem

use of uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem in project openolat by klemens.

the class AssessmentItemFactory method createAssessmentItem.

public static AssessmentItem createAssessmentItem(QTI21QuestionType type, String defaultTitle) {
    AssessmentItem assessmentItem = new AssessmentItem();
    if (type != null) {
        assessmentItem.setIdentifier(IdentifierGenerator.newAsString(type.getPrefix()));
    } else {
        assessmentItem.setIdentifier(IdentifierGenerator.newAsString("item"));
    }
    assessmentItem.setTitle(defaultTitle);
    assessmentItem.setToolName(QTI21Constants.TOOLNAME);
    assessmentItem.setToolVersion(Settings.getVersion());
    assessmentItem.setAdaptive(Boolean.FALSE);
    assessmentItem.setTimeDependent(Boolean.FALSE);
    return assessmentItem;
}
Also used : AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)

Example 65 with AssessmentItem

use of uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem in project openolat by klemens.

the class QTI21QPoolServiceProvider method importRepositoryEntry.

public List<QuestionItem> importRepositoryEntry(Identity owner, RepositoryEntry repositoryEntry, Locale defaultLocale) {
    FileResourceManager frm = FileResourceManager.getInstance();
    File unzippedDirRoot = frm.unzipFileResource(repositoryEntry.getOlatResource());
    ResolvedAssessmentTest resolvedAssessmentTest = qtiService.loadAndResolveAssessmentTest(unzippedDirRoot, false, true);
    ManifestBuilder clonedManifestBuilder = ManifestBuilder.read(new File(unzippedDirRoot, "imsmanifest.xml"));
    List<AssessmentItemRef> itemRefs = resolvedAssessmentTest.getAssessmentItemRefs();
    List<QuestionItem> importedItems = new ArrayList<>(itemRefs.size());
    for (AssessmentItemRef itemRef : itemRefs) {
        ResolvedAssessmentItem resolvedAssessmentItem = resolvedAssessmentTest.getResolvedAssessmentItem(itemRef);
        RootNodeLookup<AssessmentItem> rootNode = resolvedAssessmentItem.getItemLookup();
        URI itemUri = rootNode.getSystemId();
        File itemFile = new File(itemUri);
        String relativePathToManifest = unzippedDirRoot.toPath().relativize(itemFile.toPath()).toString();
        AssessmentItem assessmentItem = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
        ResourceType resource = clonedManifestBuilder.getResourceTypeByHref(relativePathToManifest);
        ManifestMetadataBuilder metadata = clonedManifestBuilder.getMetadataBuilder(resource, true);
        QuestionItem qitem = importAssessmentItemRef(owner, assessmentItem, itemFile, metadata, defaultLocale);
        importedItems.add(qitem);
    }
    return importedItems;
}
Also used : ManifestBuilder(org.olat.ims.qti21.model.xml.ManifestBuilder) ArrayList(java.util.ArrayList) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) ResourceType(org.olat.imscp.xml.manifest.ResourceType) ResolvedAssessmentTest(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest) URI(java.net.URI) ManifestMetadataBuilder(org.olat.ims.qti21.model.xml.ManifestMetadataBuilder) FileResourceManager(org.olat.fileresource.FileResourceManager) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItemRef(uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef) File(java.io.File) QuestionItem(org.olat.modules.qpool.QuestionItem)

Aggregations

AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)174 ResolvedAssessmentItem (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem)132 Test (org.junit.Test)56 File (java.io.File)42 JqtiExtensionManager (uk.ac.ed.ph.jqtiplus.JqtiExtensionManager)42 QtiSerializer (uk.ac.ed.ph.jqtiplus.serialization.QtiSerializer)42 URL (java.net.URL)34 Interaction (uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction)34 AssessmentItemRef (uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef)32 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)32 ItemBody (uk.ac.ed.ph.jqtiplus.node.content.ItemBody)28 ChoiceInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction)28 ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)28 URI (java.net.URI)26 ResponseProcessing (uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseProcessing)22 URISyntaxException (java.net.URISyntaxException)20 AssessmentItemFactory.appendDefaultItemBody (org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendDefaultItemBody)20 AssessmentItemFactory.createResponseProcessing (org.olat.ims.qti21.model.xml.AssessmentItemFactory.createResponseProcessing)20 MultipleChoiceAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.MultipleChoiceAssessmentItemBuilder)20 SingleChoiceAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder)20