Search in sources :

Example 31 with QuestionItemFull

use of org.olat.modules.qpool.QuestionItemFull in project OpenOLAT by OpenOLAT.

the class AssessmentTestComposerController method doInsert.

private void doInsert(UserRequest ureq, List<QuestionItemView> items) {
    TreeNode selectedNode = menuTree.getSelectedNode();
    TreeNode sectionNode = getNearestSection(selectedNode);
    boolean allOk = true;
    String firstItemId = null;
    Map<AssessmentItemRef, AssessmentItem> flyingObjects = new HashMap<>();
    try {
        AssessmentSection section = (AssessmentSection) sectionNode.getUserObject();
        for (QuestionItemView item : items) {
            QuestionItemFull qItem = qti21QPoolServiceProvider.getFullQuestionItem(item);
            AssessmentItem assessmentItem = qti21QPoolServiceProvider.exportToQTIEditor(qItem, getLocale(), unzippedDirRoot);
            if (assessmentItem != null) {
                AssessmentItemRef itemRef = doInsert(section, assessmentItem);
                if (firstItemId == null) {
                    firstItemId = itemRef.getIdentifier().toString();
                }
                flyingObjects.put(itemRef, assessmentItem);
                ManifestMetadataBuilder metadata = manifestBuilder.getResourceBuilderByHref(itemRef.getHref().toString());
                metadata.appendMetadataFrom(qItem, assessmentItem, getLocale());
                metadata.setOpenOLATMetadataCopiedAt(new Date());
            } else {
                allOk &= false;
            }
        }
    } catch (IOException | URISyntaxException e) {
        showError("error.import.question");
        logError("", e);
    }
    if (!allOk) {
        showError("error.import.question");
    }
    if (firstItemId != null) {
        // persist metadata
        doSaveAssessmentTest(ureq, flyingObjects);
        doSaveManifest();
        updateTreeModel(false);
        TreeNode newItemNode = menuTree.getTreeModel().getNodeById(firstItemId);
        menuTree.setSelectedNode(newItemNode);
        menuTree.open(newItemNode);
        partEditorFactory(ureq, newItemNode);
    }
}
Also used : HashMap(java.util.HashMap) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) Date(java.util.Date) ManifestMetadataBuilder(org.olat.ims.qti21.model.xml.ManifestMetadataBuilder) QuestionItemFull(org.olat.modules.qpool.QuestionItemFull) TreeNode(org.olat.core.gui.components.tree.TreeNode) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) AssessmentSection(uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection) AssessmentItemRef(uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef) QuestionItemView(org.olat.modules.qpool.QuestionItemView)

Example 32 with QuestionItemFull

use of org.olat.modules.qpool.QuestionItemFull in project OpenOLAT by OpenOLAT.

the class QTI12And21PoolWordExport method exportItems.

private void exportItems(List<QuestionItemFull> fullItems, OutputStream out, boolean withResponses) {
    ZipOutputStream zout = null;
    try {
        OpenXMLDocument document = new OpenXMLDocument();
        document.setDocumentHeader("");
        Translator qti12Translator = Util.createPackageTranslator(QTIWordExport.class, locale);
        Translator translator = Util.createPackageTranslator(AssessmentTestDisplayController.class, locale, Util.createPackageTranslator(AssessmentTestComposerController.class, locale, qti12Translator));
        AssessmentHtmlBuilder htmlBuilder = new AssessmentHtmlBuilder();
        for (Iterator<QuestionItemFull> itemIt = fullItems.iterator(); itemIt.hasNext(); ) {
            QuestionItemFull fullItem = itemIt.next();
            if (QTIConstants.QTI_12_FORMAT.equals(fullItem.getFormat())) {
                String dir = fullItem.getDirectory();
                VFSContainer container = qpoolFileStorage.getContainer(dir);
                document.setMediaContainer(container);
                VFSItem rootItem = container.resolve(fullItem.getRootFilename());
                Item item = QTIEditHelper.readItemXml((VFSLeaf) rootItem);
                if (item.isAlient()) {
                    QTIWordExport.renderAlienItem(item, document, translator);
                } else {
                    QTIWordExport.renderItem(item, document, withResponses, translator);
                }
            } else {
                File resourceDirectory = qpoolService.getRootDirectory(fullItem);
                VFSContainer resourceContainer = qpoolService.getRootContainer(fullItem);
                document.setMediaContainer(resourceContainer);
                File resourceFile = qpoolService.getRootFile(fullItem);
                URI assessmentItemUri = resourceFile.toURI();
                ResolvedAssessmentItem resolvedAssessmentItem = qtiService.loadAndResolveAssessmentItem(assessmentItemUri, resourceDirectory);
                AssessmentItem item = resolvedAssessmentItem.getItemLookup().extractIfSuccessful();
                QTI21WordExport.renderAssessmentItem(item, resourceFile, resourceDirectory, document, withResponses, translator, htmlBuilder);
            }
            if (itemIt.hasNext()) {
                document.appendPageBreak();
            }
        }
        zout = new ZipOutputStream(out);
        zout.setLevel(9);
        OpenXMLDocumentWriter writer = new OpenXMLDocumentWriter();
        writer.createDocument(zout, document);
    } catch (Exception e) {
        log.error("", e);
    } finally {
        if (zout != null) {
            try {
                zout.finish();
            } catch (IOException e) {
                log.error("", e);
            }
        }
    }
}
Also used : VFSContainer(org.olat.core.util.vfs.VFSContainer) OpenXMLDocument(org.olat.core.util.openxml.OpenXMLDocument) AssessmentHtmlBuilder(org.olat.ims.qti21.model.xml.AssessmentHtmlBuilder) VFSItem(org.olat.core.util.vfs.VFSItem) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) IOException(java.io.IOException) URI(java.net.URI) IOException(java.io.IOException) 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) QuestionItemFull(org.olat.modules.qpool.QuestionItemFull) OpenXMLDocumentWriter(org.olat.core.util.openxml.OpenXMLDocumentWriter) Translator(org.olat.core.gui.translator.Translator) ZipOutputStream(java.util.zip.ZipOutputStream) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentTestComposerController(org.olat.ims.qti21.ui.editor.AssessmentTestComposerController) File(java.io.File)

Example 33 with QuestionItemFull

use of org.olat.modules.qpool.QuestionItemFull in project OpenOLAT by OpenOLAT.

the class QTI21QPoolServiceProvider method loadQuestionFullItems.

private List<QuestionItemFull> loadQuestionFullItems(List<QuestionItemShort> items) {
    List<Long> itemKeys = toKeys(items);
    List<QuestionItemFull> fullItems = questionItemDao.loadByIds(itemKeys);
    Map<Long, QuestionItemFull> fullItemMap = new HashMap<>();
    for (QuestionItemFull fullItem : fullItems) {
        fullItemMap.put(fullItem.getKey(), fullItem);
    }
    // reorder the fullItems;
    List<QuestionItemFull> reorderedFullItems = new ArrayList<>(fullItems.size());
    for (QuestionItemShort item : items) {
        QuestionItemFull itemFull = fullItemMap.get(item.getKey());
        if (itemFull != null) {
            reorderedFullItems.add(itemFull);
        }
    }
    return reorderedFullItems;
}
Also used : QuestionItemFull(org.olat.modules.qpool.QuestionItemFull) HashMap(java.util.HashMap) QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) ArrayList(java.util.ArrayList)

Example 34 with QuestionItemFull

use of org.olat.modules.qpool.QuestionItemFull in project openolat by klemens.

the class QuestionDAOTest method getItems_all.

@Test
public void getItems_all() {
    // create an author with 2 items
    QItemType fibType = qItemTypeDao.loadByType(QuestionType.FIB.name());
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("QOwn-all-" + UUID.randomUUID().toString());
    QuestionItem item = questionDao.createAndPersist(id, "NGC all", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, fibType);
    dbInstance.commitAndCloseSession();
    // retrieve all items
    List<QuestionItemFull> items = questionDao.getAllItems(0, -1);
    Assert.assertNotNull(items);
    Assert.assertTrue(items.size() >= 1);
    Assert.assertTrue(items.contains(item));
}
Also used : QuestionItemFull(org.olat.modules.qpool.QuestionItemFull) Identity(org.olat.core.id.Identity) QuestionItem(org.olat.modules.qpool.QuestionItem) QItemType(org.olat.modules.qpool.model.QItemType) Test(org.junit.Test)

Example 35 with QuestionItemFull

use of org.olat.modules.qpool.QuestionItemFull in project openolat by klemens.

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)

Aggregations

QuestionItemFull (org.olat.modules.qpool.QuestionItemFull)44 File (java.io.File)18 QuestionItem (org.olat.modules.qpool.QuestionItem)18 Test (org.junit.Test)16 VFSItem (org.olat.core.util.vfs.VFSItem)16 IOException (java.io.IOException)14 VFSContainer (org.olat.core.util.vfs.VFSContainer)14 URL (java.net.URL)12 InputStream (java.io.InputStream)10 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)10 ZipOutputStream (java.util.zip.ZipOutputStream)8 Document (org.dom4j.Document)8 Node (org.dom4j.Node)8 XMLParser (org.olat.core.util.xml.XMLParser)8 IMSEntityResolver (org.olat.ims.resources.IMSEntityResolver)8 ResolvedAssessmentItem (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem)8 URISyntaxException (java.net.URISyntaxException)6 ArrayList (java.util.ArrayList)6 ZipEntry (java.util.zip.ZipEntry)6 Element (org.dom4j.Element)6