Search in sources :

Example 71 with ResolvedAssessmentItem

use of uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem in project OpenOLAT by OpenOLAT.

the class QTI21ExportProcessor method collectMaterials.

protected void collectMaterials(QuestionItemFull fullItem, AssessmentItemsAndResources materials) {
    String dir = fullItem.getDirectory();
    String rootFilename = fullItem.getRootFilename();
    File resourceDirectory = qpoolFileStorage.getDirectory(dir);
    File itemFile = new File(resourceDirectory, rootFilename);
    if (itemFile.exists()) {
        ResolvedAssessmentItem resolvedAssessmentItem = qtiService.loadAndResolveAssessmentItemForCopy(itemFile.toURI(), resourceDirectory);
        AssessmentItem assessmentItem = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
        if (assessmentItem != null) {
            // enrichScore(itemEl);
            // enrichWithMetadata(fullItem, itemEl);
            ImportExportHelper.getMaterials(assessmentItem, itemFile, materials);
            materials.addItemEl(resolvedAssessmentItem);
        }
    }
}
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) File(java.io.File)

Example 72 with ResolvedAssessmentItem

use of uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem in project OpenOLAT by OpenOLAT.

the class QTI21ExportProcessor method process.

public void process(QuestionItemFull qitem, ZipOutputStream zout) {
    String dir = qitem.getDirectory();
    File rootDirectory = qpoolFileStorage.getDirectory(dir);
    String rootDir = "qitem_" + qitem.getKey();
    File imsmanifest = new File(rootDirectory, "imsmanifest.xml");
    ManifestBuilder manifestBuilder;
    if (imsmanifest.exists()) {
        manifestBuilder = ManifestBuilder.read(imsmanifest);
    } else {
        manifestBuilder = new ManifestBuilder();
    }
    File resourceFile = new File(rootDirectory, qitem.getRootFilename());
    URI assessmentItemUri = resourceFile.toURI();
    ResolvedAssessmentItem resolvedAssessmentItem = qtiService.loadAndResolveAssessmentItemForCopy(assessmentItemUri, rootDirectory);
    enrichWithMetadata(qitem, resolvedAssessmentItem, manifestBuilder);
    try {
        zout.putNextEntry(new ZipEntry(rootDir + "/imsmanifest.xml"));
        manifestBuilder.write(new ShieldOutputStream(zout));
        zout.closeEntry();
    } catch (Exception e) {
        log.error("", e);
    }
    try {
        Files.walkFileTree(rootDirectory.toPath(), new SimpleFileVisitor<Path>() {

            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                String filename = file.getFileName().toString();
                if (!"imsmanifest.xml".equals(filename) && !filename.startsWith(".")) {
                    String relPath = rootDirectory.toPath().relativize(file).toString();
                    ZipUtil.addFileToZip(rootDir + "/" + relPath, file, zout);
                }
                return FileVisitResult.CONTINUE;
            }
        });
    } catch (IOException e) {
        log.error("", e);
    }
}
Also used : Path(java.nio.file.Path) ManifestBuilder(org.olat.ims.qti21.model.xml.ManifestBuilder) ZipEntry(java.util.zip.ZipEntry) FileVisitResult(java.nio.file.FileVisitResult) IOException(java.io.IOException) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) ShieldOutputStream(org.olat.core.util.io.ShieldOutputStream) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) File(java.io.File) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes)

Example 73 with ResolvedAssessmentItem

use of uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem 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 74 with ResolvedAssessmentItem

use of uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem in project OpenOLAT by OpenOLAT.

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 75 with ResolvedAssessmentItem

use of uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem in project OpenOLAT by OpenOLAT.

the class QTI21WordExport method renderAssessmentSection.

public void renderAssessmentSection(AssessmentSection assessmentSection, OpenXMLDocument document, boolean withResponses, Translator translator) {
    String title = assessmentSection.getTitle();
    document.appendHeading1(title, null);
    List<RubricBlock> rubricBlocks = assessmentSection.getRubricBlocks();
    for (RubricBlock rubricBlock : rubricBlocks) {
        String htmlRubric = htmlBuilder.blocksString(rubricBlock.getBlocks());
        document.appendHtmlText(htmlRubric, true);
    }
    for (SectionPart sectionPart : assessmentSection.getChildAbstractParts()) {
        if (sectionPart instanceof AssessmentSection) {
            renderAssessmentSection((AssessmentSection) sectionPart, document, withResponses, translator);
        } else if (sectionPart instanceof AssessmentItemRef) {
            AssessmentItemRef itemRef = (AssessmentItemRef) sectionPart;
            ResolvedAssessmentItem resolvedAssessmentItem = resolvedAssessmentTest.getResolvedAssessmentItem(itemRef);
            AssessmentItem assessmentItem = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
            URI itemUri = resolvedAssessmentTest.getSystemIdByItemRefMap().get(itemRef);
            renderAssessmentItem(assessmentItem, new File(itemUri), mediaDir, document, withResponses, translator, htmlBuilder);
            document.appendPageBreak();
        }
    }
}
Also used : SectionPart(uk.ac.ed.ph.jqtiplus.node.test.SectionPart) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentSection(uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection) AssessmentItemRef(uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) RubricBlock(uk.ac.ed.ph.jqtiplus.node.content.variable.RubricBlock) URI(java.net.URI) File(java.io.File)

Aggregations

ResolvedAssessmentItem (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem)106 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)76 File (java.io.File)38 URI (java.net.URI)32 AssessmentItemRef (uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef)26 AssessmentObjectXmlLoader (uk.ac.ed.ph.jqtiplus.reading.AssessmentObjectXmlLoader)26 QtiXmlReader (uk.ac.ed.ph.jqtiplus.reading.QtiXmlReader)26 ResourceLocator (uk.ac.ed.ph.jqtiplus.xmlutils.locators.ResourceLocator)26 PathResourceLocator (org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator)22 ItemSessionState (uk.ac.ed.ph.jqtiplus.state.ItemSessionState)22 IOException (java.io.IOException)20 JqtiExtensionManager (uk.ac.ed.ph.jqtiplus.JqtiExtensionManager)20 URISyntaxException (java.net.URISyntaxException)16 ManifestMetadataBuilder (org.olat.ims.qti21.model.xml.ManifestMetadataBuilder)16 ResolvedAssessmentTest (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest)14 ArrayList (java.util.ArrayList)12 ManifestBuilder (org.olat.ims.qti21.model.xml.ManifestBuilder)12 AssessmentSection (uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection)12 BadResourceException (uk.ac.ed.ph.jqtiplus.provision.BadResourceException)12 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)12