Search in sources :

Example 21 with QuestionItemImpl

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

the class RightsMetadataEditController method doOpenAuthorManager.

private void doOpenAuthorManager(UserRequest ureq) {
    if (item instanceof QuestionItemImpl) {
        QuestionItemImpl itemImpl = (QuestionItemImpl) item;
        groupController = new GroupController(ureq, getWindowControl(), true, true, false, true, false, false, itemImpl.getOwnerGroup());
        listenTo(groupController);
        cmc = new CloseableModalController(getWindowControl(), translate("close"), groupController.getInitialComponent(), true, translate("manage.owners"));
        cmc.activate();
        listenTo(cmc);
    }
}
Also used : QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) GroupController(org.olat.admin.securitygroup.gui.GroupController) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)

Example 22 with QuestionItemImpl

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

the class QTIImportProcessorTest method testImport_SC.

/**
 * This test check every methods of the import process in details
 * @throws IOException
 * @throws URISyntaxException
 */
@Test
public void testImport_SC() throws IOException, URISyntaxException {
    URL itemUrl = QTIImportProcessorTest.class.getResource("mchc_i_002.xml");
    Assert.assertNotNull(itemUrl);
    File itemFile = new File(itemUrl.toURI());
    // get the document informations
    QTIImportProcessor proc = new QTIImportProcessor(owner, Locale.ENGLISH, itemFile.getName(), itemFile);
    List<DocInfos> docInfoList = proc.getDocInfos();
    Assert.assertNotNull(docInfoList);
    Assert.assertEquals(1, docInfoList.size());
    DocInfos docInfos = docInfoList.get(0);
    Assert.assertNotNull(docInfos);
    Assert.assertNotNull(docInfos.getFilename());
    Assert.assertNotNull(docInfos.getDocument());
    Assert.assertEquals("mchc_i_002.xml", docInfos.getFilename());
    // get the question DOM's
    List<ItemInfos> itemInfos = proc.getItemList(docInfos);
    Assert.assertNotNull(itemInfos);
    Assert.assertEquals(1, itemInfos.size());
    // process item, files...
    QuestionItemImpl item = proc.processItem(docInfos, itemInfos.get(0), null);
    Assert.assertNotNull(item);
    dbInstance.commitAndCloseSession();
    proc.processFiles(item, itemInfos.get(0), null);
    // reload and check what is saved
    QuestionItemFull reloadItem = questionItemDao.loadById(item.getKey());
    Assert.assertNotNull(reloadItem);
    Assert.assertNotNull(reloadItem.getCreationDate());
    Assert.assertNotNull(reloadItem.getLastModified());
    Assert.assertEquals(QuestionStatus.draft, reloadItem.getQuestionStatus());
    Assert.assertEquals(QTIConstants.QTI_12_FORMAT, reloadItem.getFormat());
    // title
    Assert.assertEquals("Standard Multiple Choice with Images Item", reloadItem.getTitle());
    // description -> qticomment
    Assert.assertEquals("This is a multiple-choice example with image content. The rendering is a standard radio button style. No response processing is incorporated.", reloadItem.getDescription());
    // question type
    Assert.assertNotNull(reloadItem.getType());
    Assert.assertEquals(QuestionType.SC.name().toLowerCase(), reloadItem.getType().getType());
    // check that the file is storead
    VFSContainer itemDir = qpoolFileStorage.getContainer(reloadItem.getDirectory());
    Assert.assertNotNull(itemDir);
    VFSItem qtiLeaf = itemDir.resolve(reloadItem.getRootFilename());
    Assert.assertNotNull(qtiLeaf);
    Assert.assertTrue(qtiLeaf instanceof VFSLeaf);
    Assert.assertTrue(qtiLeaf.exists());
    Assert.assertEquals(itemFile.length(), ((VFSLeaf) qtiLeaf).getSize());
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) QuestionItemFull(org.olat.modules.qpool.QuestionItemFull) QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) DocInfos(org.olat.ims.qti.qpool.QTIImportProcessor.DocInfos) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) ItemInfos(org.olat.ims.qti.qpool.QTIImportProcessor.ItemInfos) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Example 23 with QuestionItemImpl

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

the class QuestionDAOTest method resetAllStatesToDraft.

@Test
public void resetAllStatesToDraft() {
    QItemType mcType = qItemTypeDao.loadByType(QuestionType.MC.name());
    QuestionItemImpl item1 = questionDao.createAndPersist(null, "RES DRAFT 1", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
    item1.setQuestionStatus(QuestionStatus.endOfLife);
    questionDao.loadForUpdate(item1);
    QuestionItemImpl item2 = questionDao.createAndPersist(null, "RES DRAFT 2", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
    item2.setQuestionStatus(QuestionStatus.review);
    questionDao.loadForUpdate(item2);
    QuestionItemImpl item3 = questionDao.createAndPersist(null, "RES DRAFT 3", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
    item3.setQuestionStatus(QuestionStatus.revised);
    questionDao.loadForUpdate(item3);
    questionDao.createAndPersist(null, "RES DRAFT 4", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
    dbInstance.commitAndCloseSession();
    questionDao.resetAllStatesToDraft();
    dbInstance.commitAndCloseSession();
    List<QuestionItemFull> allItems = questionDao.getAllItems(0, -1);
    for (QuestionItem item : allItems) {
        Assert.assertEquals(QuestionStatus.draft, item.getQuestionStatus());
    }
}
Also used : QuestionItemFull(org.olat.modules.qpool.QuestionItemFull) QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) QuestionItem(org.olat.modules.qpool.QuestionItem) QItemType(org.olat.modules.qpool.model.QItemType) Test(org.junit.Test)

Example 24 with QuestionItemImpl

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

the class QuestionPoolServiceImplTest method shouldGetExportFormatOptions.

@Test
public void shouldGetExportFormatOptions() {
    String formatA = "A";
    String formatB = "B";
    QuestionItemImpl formatAItem = new QuestionItemImpl();
    formatAItem.setFormat(formatA);
    List<QuestionItemShort> items = Arrays.asList(formatAItem);
    ExportFormatOptions exportFormatAR = new DefaultExportFormat(formatA, Outcome.repository, null);
    ExportFormatOptions exportFormatAD = new DefaultExportFormat(formatA, Outcome.download, null);
    List<ExportFormatOptions> exportFormatsA = Arrays.asList(exportFormatAD, exportFormatAR);
    ExportFormatOptions exportFormatBR = new DefaultExportFormat(formatA, Outcome.repository, null);
    List<ExportFormatOptions> exportFormatsB = Arrays.asList(exportFormatBR);
    QPoolSPI spiA = mock(QPoolSPI.class);
    when(spiA.getTestExportFormats()).thenReturn(exportFormatsA);
    when(qPoolModuleMock.getQuestionPoolProvider(formatA)).thenReturn(spiA);
    QPoolSPI spiB = mock(QPoolSPI.class);
    when(spiB.getTestExportFormats()).thenReturn(exportFormatsB);
    when(qPoolModuleMock.getQuestionPoolProvider(formatB)).thenReturn(spiB);
    Set<ExportFormatOptions> exportFormatOptions = sut.getExportFormatOptions(items, Outcome.repository);
    assertThat(exportFormatOptions).hasSize(1).containsExactly(exportFormatAR);
}
Also used : ExportFormatOptions(org.olat.modules.qpool.ExportFormatOptions) QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) QPoolSPI(org.olat.modules.qpool.QPoolSPI) QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) DefaultExportFormat(org.olat.modules.qpool.model.DefaultExportFormat) Test(org.junit.Test)

Example 25 with QuestionItemImpl

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

the class QTI21ImportProcessor method processResource.

private QuestionItem processResource(ResourceType resource, Path imsmanifestPath, ManifestMetadataBuilder metadataBuilder) {
    try {
        String href = resource.getHref();
        Path parentPath = imsmanifestPath.getParent();
        Path assessmentItemPath = parentPath.resolve(href);
        if (Files.notExists(assessmentItemPath)) {
            return null;
        }
        String dir = qpoolFileStorage.generateDir();
        // storage
        File itemStorage = qpoolFileStorage.getDirectory(dir);
        File outputFile = new File(itemStorage, href);
        if (!outputFile.getParentFile().exists()) {
            outputFile.getParentFile().mkdirs();
        }
        QTI21Infos infos = getInfos(imsmanifestPath);
        convertXmlFile(assessmentItemPath, outputFile.toPath(), infos);
        QtiXmlReader qtiXmlReader = new QtiXmlReader(qtiService.jqtiExtensionManager());
        ResourceLocator fileResourceLocator = new FileResourceLocator();
        ResourceLocator inputResourceLocator = ImsQTI21Resource.createResolvingResourceLocator(fileResourceLocator);
        URI assessmentObjectSystemId = outputFile.toURI();
        AssessmentObjectXmlLoader assessmentObjectXmlLoader = new AssessmentObjectXmlLoader(qtiXmlReader, inputResourceLocator);
        ResolvedAssessmentItem resolvedAssessmentItem = assessmentObjectXmlLoader.loadAndResolveAssessmentItem(assessmentObjectSystemId);
        AssessmentItem assessmentItem = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
        if (!AssessmentItemChecker.checkAndCorrect(assessmentItem)) {
            qtiService.persistAssessmentObject(outputFile, assessmentItem);
        }
        AssessmentItemMetadata metadata = new AssessmentItemMetadata(metadataBuilder);
        String editor = null;
        String editorVersion = null;
        if (StringHelper.containsNonWhitespace(assessmentItem.getToolName())) {
            editor = assessmentItem.getToolName();
        }
        if (StringHelper.containsNonWhitespace(assessmentItem.getToolVersion())) {
            editorVersion = assessmentItem.getToolVersion();
        }
        QuestionItemImpl qitem = processItem(assessmentItem, null, href, editor, editorVersion, dir, metadata);
        // create manifest
        ManifestBuilder manifest = ManifestBuilder.createAssessmentItemBuilder();
        String itemId = IdentifierGenerator.newAsIdentifier("item").toString();
        ResourceType importedResource = manifest.appendAssessmentItem(itemId, href);
        ManifestMetadataBuilder importedMetadataBuilder = manifest.getMetadataBuilder(importedResource, true);
        importedMetadataBuilder.setMetadata(metadataBuilder.getMetadata());
        manifest.write(new File(itemStorage, "imsmanifest.xml"));
        // process material
        List<String> materials = ImportExportHelper.getMaterials(assessmentItem);
        for (String material : materials) {
            if (material.indexOf("://") < 0) {
                // material can be an external URL
                Path materialFile = assessmentItemPath.getParent().resolve(material);
                PathUtils.copyFileToDir(materialFile, outputFile.getParentFile(), material);
            }
        }
        return qitem;
    } catch (Exception e) {
        log.error("", e);
        return null;
    }
}
Also used : Path(java.nio.file.Path) AssessmentObjectXmlLoader(uk.ac.ed.ph.jqtiplus.reading.AssessmentObjectXmlLoader) 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) URI(java.net.URI) IOException(java.io.IOException) ManifestMetadataBuilder(org.olat.ims.qti21.model.xml.ManifestMetadataBuilder) QtiXmlReader(uk.ac.ed.ph.jqtiplus.reading.QtiXmlReader) QTI21Infos(org.olat.ims.qti21.model.xml.QTI21Infos) FileResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.FileResourceLocator) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItemMetadata(org.olat.ims.qti21.model.xml.AssessmentItemMetadata) File(java.io.File) FileResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.FileResourceLocator) ResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.ResourceLocator)

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