Search in sources :

Example 31 with ResolvedAssessmentItem

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

the class CorrectionIdentityAssessmentItemListController method doSelect.

private void doSelect(UserRequest ureq, CorrectionIdentityAssessmentItemRow row) {
    removeAsListenerAndDispose(identityItemCtrl);
    doUnlock();
    AssessmentItemRef itemRef = row.getItemRef();
    TestSessionState testSessionState = qtiService.loadTestSessionState(candidateSession);
    List<TestPlanNode> nodes = testSessionState.getTestPlan().getNodes(itemRef.getIdentifier());
    AssessmentItemSession reloadItemSession = null;
    if (nodes.size() == 1) {
        TestPlanNode itemNode = nodes.get(0);
        String stringuifiedIdentifier = itemNode.getKey().getIdentifier().toString();
        ParentPartItemRefs parentParts = AssessmentTestHelper.getParentSection(itemNode.getKey(), testSessionState, model.getResolvedAssessmentTest());
        reloadItemSession = qtiService.getOrCreateAssessmentItemSession(candidateSession, parentParts, stringuifiedIdentifier);
    }
    // lock on item, need to check the lock on identity / test
    String lockSubKey = "item-" + reloadItemSession.getKey();
    OLATResourceable testOres = OresHelper.clone(model.getTestEntry().getOlatResource());
    lockResult = CoordinatorManager.getInstance().getCoordinator().getLocker().acquireLock(testOres, getIdentity(), lockSubKey);
    if (lockResult.isSuccess()) {
        if (nodes.size() == 1) {
            TestPlanNode itemNode = nodes.get(0);
            ItemSessionState itemSessionState = testSessionState.getItemSessionStates().get(itemNode.getKey());
            AssessmentItemCorrection itemCorrection = new AssessmentItemCorrection(assessedIdentity, candidateSession, testSessionState, reloadItemSession, itemSessionState, itemRef, itemNode);
            itemCorrection.setItemSession(reloadItemSession);
            ResolvedAssessmentItem resolvedAssessmentItem = model.getResolvedAssessmentTest().getResolvedAssessmentItem(itemRef);
            AssessmentItem assessmentItem = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
            identityItemCtrl = new CorrectionIdentityAssessmentItemNavigationController(ureq, getWindowControl(), model.getTestEntry(), model.getResolvedAssessmentTest(), itemCorrection, row, tableModel.getObjects(), model);
            listenTo(identityItemCtrl);
            stackPanel.pushController(assessmentItem.getTitle(), identityItemCtrl);
            updatePreviousNext();
        }
    } else {
        String lockOwnerName = userManager.getUserDisplayName(lockResult.getOwner());
        showWarning("warning.assessment.item.locked", new String[] { lockOwnerName });
    }
}
Also used : TestPlanNode(uk.ac.ed.ph.jqtiplus.state.TestPlanNode) ParentPartItemRefs(org.olat.ims.qti21.model.ParentPartItemRefs) TestSessionState(uk.ac.ed.ph.jqtiplus.state.TestSessionState) OLATResourceable(org.olat.core.id.OLATResourceable) ItemSessionState(uk.ac.ed.ph.jqtiplus.state.ItemSessionState) AssessmentItemCorrection(org.olat.ims.qti21.ui.assessment.model.AssessmentItemCorrection) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItemSession(org.olat.ims.qti21.AssessmentItemSession) AssessmentItemRef(uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef)

Example 32 with ResolvedAssessmentItem

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

the class AssessmentResultController method initFormItemResult.

private Results initFormItemResult(FormLayoutContainer layoutCont, TestPlanNode node, Map<Identifier, AssessmentItemRef> identifierToRefs, Map<TestPlanNode, Results> resultsMap) {
    TestPlanNodeKey testPlanNodeKey = node.getKey();
    Identifier identifier = testPlanNodeKey.getIdentifier();
    AssessmentItemRef itemRef = identifierToRefs.get(identifier);
    ResolvedAssessmentItem resolvedAssessmentItem = resolvedAssessmentTest.getResolvedAssessmentItem(itemRef);
    AssessmentItem assessmentItem = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
    QTI21QuestionType type = QTI21QuestionType.getType(assessmentItem);
    AssessmentItemSession itemSession = identifierToItemSession.get(identifier.toString());
    Results r = new Results(false, node.getSectionPartTitle(), type.getCssClass(), options.isQuestionSummary());
    // init
    r.setSessionStatus(null);
    r.setItemIdentifier(node.getIdentifier().toString());
    ItemSessionState sessionState = testSessionState.getItemSessionStates().get(testPlanNodeKey);
    if (sessionState != null) {
        r.setSessionState(sessionState);
        SessionStatus sessionStatus = sessionState.getSessionStatus();
        if (sessionState != null) {
            r.setSessionStatus(sessionStatus);
        }
    }
    ItemResult itemResult = assessmentResult.getItemResult(identifier.toString());
    if (itemResult != null) {
        extractOutcomeVariable(itemResult.getItemVariables(), r);
    }
    if (itemSession != null) {
        if (itemSession.getManualScore() != null) {
            r.setScore(itemSession.getManualScore());
            r.setManualScore(itemSession.getManualScore());
        }
        r.setComment(itemSession.getCoachComment());
    }
    // update max score of section
    if (options.isUserSolutions() || options.isCorrectSolutions()) {
        InteractionResults interactionResults = initFormItemInteractions(layoutCont, sessionState, resolvedAssessmentItem);
        r.setInteractionResults(interactionResults);
        if (options.isCorrectSolutions()) {
            String correctSolutionId = "correctSolutionItem" + count++;
            FeedbackResultFormItem correctSolutionItem = new FeedbackResultFormItem(correctSolutionId, resolvedAssessmentItem);
            initInteractionResultFormItem(correctSolutionItem, sessionState);
            layoutCont.add(correctSolutionId, correctSolutionItem);
            r.setCorrectSolutionItem(correctSolutionItem);
        }
    }
    updateSectionScoreInformations(node, r, resultsMap);
    return r;
}
Also used : ItemSessionState(uk.ac.ed.ph.jqtiplus.state.ItemSessionState) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) ItemResult(uk.ac.ed.ph.jqtiplus.node.result.ItemResult) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItemSession(org.olat.ims.qti21.AssessmentItemSession) SessionStatus(uk.ac.ed.ph.jqtiplus.node.result.SessionStatus) AssessmentItemRef(uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef) QTI21QuestionType(org.olat.ims.qti21.model.QTI21QuestionType) FeedbackResultFormItem(org.olat.ims.qti21.ui.components.FeedbackResultFormItem) TestPlanNodeKey(uk.ac.ed.ph.jqtiplus.state.TestPlanNodeKey)

Example 33 with ResolvedAssessmentItem

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

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

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

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

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

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