Search in sources :

Example 66 with AssessmentItem

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

the class QTI21QPoolServiceProvider method copyItem.

@Override
public void copyItem(QuestionItemFull original, QuestionItemFull copy) {
    VFSContainer originalDir = qpoolFileStorage.getContainer(original.getDirectory());
    VFSContainer copyDir = qpoolFileStorage.getContainer(copy.getDirectory());
    VFSManager.copyContent(originalDir, copyDir);
    File file = qpoolService.getRootFile(copy);
    File resourceDirectory = qpoolService.getRootDirectory(copy);
    URI assessmentItemUri = file.toURI();
    File itemFile = qpoolService.getRootFile(copy);
    ResolvedAssessmentItem resolvedAssessmentItem = qtiService.loadAndResolveAssessmentItem(assessmentItemUri, resourceDirectory);
    AssessmentItem assessmentItem = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
    assessmentItem.setTitle(copy.getTitle());
    qtiService.persistAssessmentObject(itemFile, assessmentItem);
}
Also used : ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) VFSContainer(org.olat.core.util.vfs.VFSContainer) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) File(java.io.File) URI(java.net.URI)

Example 67 with AssessmentItem

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

the class QTI21QPoolServiceProvider method exportToQTIEditor.

/**
 * Export to QTI editor an item from the pool. The ident of the item
 * is always regenerated as an UUID.
 * @param qitem
 * @param editorContainer
 * @return
 */
public AssessmentItem exportToQTIEditor(QuestionItemFull qitem, Locale locale, File editorContainer) throws IOException {
    QTI21ExportProcessor processor = new QTI21ExportProcessor(qtiService, qpoolFileStorage, locale);
    ResolvedAssessmentItem resolvedAssessmentItem = processor.exportToQTIEditor(qitem, editorContainer);
    if (resolvedAssessmentItem != null) {
        AssessmentItem assessmentItem = resolvedAssessmentItem.getItemLookup().extractAssumingSuccessful();
        assessmentItem.setIdentifier(QTI21QuestionType.generateNewIdentifier(assessmentItem.getIdentifier()));
        return assessmentItem;
    }
    return null;
}
Also used : ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)

Example 68 with AssessmentItem

use of uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem 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 69 with AssessmentItem

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

the class QTI21AssessmentTestHandler method createMinimalAssessmentTest.

public void createMinimalAssessmentTest(String displayName, File directory, Locale locale) {
    ManifestBuilder manifestBuilder = ManifestBuilder.createAssessmentTestBuilder();
    Translator translator = Util.createPackageTranslator(AssessmentTestComposerController.class, locale);
    // single choice
    File itemFile = new File(directory, IdentifierGenerator.newAsString(QTI21QuestionType.sc.getPrefix()) + ".xml");
    AssessmentItem assessmentItem = AssessmentItemFactory.createSingleChoice(translator.translate("new.sc"), translator.translate("new.answer"));
    QtiSerializer qtiSerializer = qtiService.qtiSerializer();
    manifestBuilder.appendAssessmentItem(itemFile.getName());
    // test
    File testFile = new File(directory, IdentifierGenerator.newAssessmentTestFilename());
    AssessmentTest assessmentTest = AssessmentTestFactory.createAssessmentTest(displayName, translator.translate("new.section"));
    manifestBuilder.appendAssessmentTest(testFile.getName());
    // item -> test
    try {
        AssessmentSection section = assessmentTest.getTestParts().get(0).getAssessmentSections().get(0);
        AssessmentTestFactory.appendAssessmentItem(section, itemFile.getName());
    } catch (URISyntaxException e) {
        log.error("", e);
    }
    try (FileOutputStream out = new FileOutputStream(itemFile)) {
        qtiSerializer.serializeJqtiObject(assessmentItem, out);
    } catch (Exception e) {
        log.error("", e);
    }
    try (FileOutputStream out = new FileOutputStream(testFile)) {
        qtiSerializer.serializeJqtiObject(assessmentTest, out);
    } catch (Exception e) {
        log.error("", e);
    }
    manifestBuilder.write(new File(directory, "imsmanifest.xml"));
}
Also used : AssessmentTest(uk.ac.ed.ph.jqtiplus.node.test.AssessmentTest) ManifestBuilder(org.olat.ims.qti21.model.xml.ManifestBuilder) Translator(org.olat.core.gui.translator.Translator) QtiSerializer(uk.ac.ed.ph.jqtiplus.serialization.QtiSerializer) AssessmentSection(uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection) FileOutputStream(java.io.FileOutputStream) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) URISyntaxException(java.net.URISyntaxException) File(java.io.File) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Example 70 with AssessmentItem

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

the class DrawingAssessmentItemBuilder method createAssessmentItem.

private static AssessmentItem createAssessmentItem(String title) {
    AssessmentItem assessmentItem = AssessmentItemFactory.createAssessmentItem(QTI21QuestionType.drawing, title);
    // define the response
    Identifier responseDeclarationId = Identifier.assumedLegal("RESPONSE_1");
    ResponseDeclaration responseDeclaration = createDrawingResponseDeclaration(assessmentItem, responseDeclarationId);
    assessmentItem.getNodeGroups().getResponseDeclarationGroup().getResponseDeclarations().add(responseDeclaration);
    // outcomes
    appendDefaultOutcomeDeclarations(assessmentItem, 1.0d);
    ItemBody itemBody = appendDefaultItemBody(assessmentItem);
    appendDrawingInteraction(itemBody, responseDeclarationId);
    // response processing
    ResponseProcessing responseProcessing = createResponseProcessing(assessmentItem, responseDeclarationId);
    assessmentItem.getNodeGroups().getResponseProcessingGroup().setResponseProcessing(responseProcessing);
    return assessmentItem;
}
Also used : Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) ItemBody(uk.ac.ed.ph.jqtiplus.node.content.ItemBody) AssessmentItemFactory.appendDefaultItemBody(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendDefaultItemBody) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) ResponseProcessing(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseProcessing) AssessmentItemFactory.createResponseProcessing(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createResponseProcessing) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration) AssessmentItemFactory.createDrawingResponseDeclaration(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createDrawingResponseDeclaration)

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