Search in sources :

Example 6 with ResolvedAssessmentTest

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

the class CopyAndConvertVisitor method validate.

private boolean validate(Path inputFile, InputType type, boolean verbose) {
    try {
        QtiXmlReader qtiXmlReader = new QtiXmlReader(new JqtiExtensionManager());
        ResourceLocator fileResourceLocator = new PathResourceLocator(inputFile.getParent());
        AssessmentObjectXmlLoader assessmentObjectXmlLoader = new AssessmentObjectXmlLoader(qtiXmlReader, fileResourceLocator);
        RootNode rootNode = null;
        BadResourceException e = null;
        URI uri = new URI("zip", inputFile.getFileName().toString(), null);
        if (type == InputType.assessmentItem) {
            ItemValidationResult itemResult = assessmentObjectXmlLoader.loadResolveAndValidateItem(uri);
            e = itemResult.getResolvedAssessmentItem().getItemLookup().getBadResourceException();
            ResolvedAssessmentItem resolvedAssessmentItem = assessmentObjectXmlLoader.loadAndResolveAssessmentItem(uri);
            rootNode = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
        } else if (type == InputType.assessmentTest) {
            TestValidationResult testResult = assessmentObjectXmlLoader.loadResolveAndValidateTest(uri);
            e = testResult.getResolvedAssessmentTest().getTestLookup().getBadResourceException();
            ResolvedAssessmentTest resolvedAssessmentTest = assessmentObjectXmlLoader.loadAndResolveAssessmentTest(uri);
            rootNode = resolvedAssessmentTest.getRootNodeLookup().extractIfSuccessful();
        }
        if (e != null && verbose) {
            StringBuilder err = new StringBuilder();
            BadRessourceHelper.extractMessage(e, err);
            log.warn(err.toString());
        }
        return (rootNode != null) && (e == null || (e instanceof QtiXmlInterpretationException && ((QtiXmlInterpretationException) e).getXmlParseResult().getFatalErrors().isEmpty()));
    } catch (URISyntaxException e) {
        log.error("", e);
        return false;
    }
}
Also used : AssessmentObjectXmlLoader(uk.ac.ed.ph.jqtiplus.reading.AssessmentObjectXmlLoader) RootNode(uk.ac.ed.ph.jqtiplus.node.RootNode) BadResourceException(uk.ac.ed.ph.jqtiplus.provision.BadResourceException) TestValidationResult(uk.ac.ed.ph.jqtiplus.validation.TestValidationResult) QtiXmlInterpretationException(uk.ac.ed.ph.jqtiplus.reading.QtiXmlInterpretationException) URISyntaxException(java.net.URISyntaxException) ResolvedAssessmentTest(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest) URI(java.net.URI) QtiXmlReader(uk.ac.ed.ph.jqtiplus.reading.QtiXmlReader) JqtiExtensionManager(uk.ac.ed.ph.jqtiplus.JqtiExtensionManager) PathResourceLocator(org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) FileResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.FileResourceLocator) ResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.ResourceLocator) PathResourceLocator(org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator) ItemValidationResult(uk.ac.ed.ph.jqtiplus.validation.ItemValidationResult)

Example 7 with ResolvedAssessmentTest

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

the class QTI21AssessmentDetailsController method doCorrection.

private void doCorrection(UserRequest ureq, AssessmentTestSession session) {
    File unzippedDirRoot = FileResourceManager.getInstance().unzipFileResource(testEntry.getOlatResource());
    ResolvedAssessmentTest resolvedAssessmentTest = qtiService.loadAndResolveAssessmentTest(unzippedDirRoot, false, false);
    ManifestBuilder manifestBuilder = ManifestBuilder.read(new File(unzippedDirRoot, "imsmanifest.xml"));
    TestSessionState testSessionState = qtiService.loadTestSessionState(session);
    CorrectionOverviewModel model = new CorrectionOverviewModel(entry, subIdent, testEntry, resolvedAssessmentTest, manifestBuilder, Collections.singletonMap(assessedIdentity, session), Collections.singletonMap(assessedIdentity, testSessionState));
    correctionCtrl = new CorrectionIdentityAssessmentItemListController(ureq, getWindowControl(), stackPanel, model, session, assessedIdentity);
    listenTo(correctionCtrl);
    stackPanel.pushController(translate("correction"), correctionCtrl);
}
Also used : CorrectionOverviewModel(org.olat.ims.qti21.ui.assessment.CorrectionOverviewModel) ManifestBuilder(org.olat.ims.qti21.model.xml.ManifestBuilder) TestSessionState(uk.ac.ed.ph.jqtiplus.state.TestSessionState) CorrectionIdentityAssessmentItemListController(org.olat.ims.qti21.ui.assessment.CorrectionIdentityAssessmentItemListController) ResolvedAssessmentTest(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest) File(java.io.File)

Example 8 with ResolvedAssessmentTest

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

the class QTI21RuntimeController method getAssessableElement.

private AssessableResource getAssessableElement(RepositoryEntry testEntry) {
    FileResourceManager frm = FileResourceManager.getInstance();
    File fUnzippedDirRoot = frm.unzipFileResource(testEntry.getOlatResource());
    ResolvedAssessmentTest resolvedAssessmentTest = qtiService.loadAndResolveAssessmentTest(fUnzippedDirRoot, false, false);
    AssessmentTest assessmentTest = resolvedAssessmentTest.getRootNodeLookup().extractIfSuccessful();
    Double maxScore = QtiNodesExtractor.extractMaxScore(assessmentTest);
    Double minScore = QtiNodesExtractor.extractMinScore(assessmentTest);
    boolean hasScore = assessmentTest.getOutcomeDeclaration(QTI21Constants.SCORE_IDENTIFIER) != null;
    boolean hasPassed = assessmentTest.getOutcomeDeclaration(QTI21Constants.PASS_IDENTIFIER) != null;
    return new QTI21AssessableResource(hasScore, hasPassed, true, true, minScore, maxScore, null);
}
Also used : ResolvedAssessmentTest(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest) AssessmentTest(uk.ac.ed.ph.jqtiplus.node.test.AssessmentTest) FileResourceManager(org.olat.fileresource.FileResourceManager) ResolvedAssessmentTest(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest) File(java.io.File)

Example 9 with ResolvedAssessmentTest

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

Example 10 with ResolvedAssessmentTest

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

the class QTI21ServiceImpl method needManualCorrection.

@Override
public boolean needManualCorrection(RepositoryEntry testEntry) {
    FileResourceManager frm = FileResourceManager.getInstance();
    File fUnzippedDirRoot = frm.unzipFileResource(testEntry.getOlatResource());
    ResolvedAssessmentTest resolvedAssessmentTest = loadAndResolveAssessmentTest(fUnzippedDirRoot, false, false);
    return AssessmentTestHelper.needManualCorrection(resolvedAssessmentTest);
}
Also used : FileResourceManager(org.olat.fileresource.FileResourceManager) ResolvedAssessmentTest(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest) File(java.io.File)

Aggregations

ResolvedAssessmentTest (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest)40 File (java.io.File)32 AssessmentTest (uk.ac.ed.ph.jqtiplus.node.test.AssessmentTest)24 FileResourceManager (org.olat.fileresource.FileResourceManager)16 ResolvedAssessmentItem (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem)10 URI (java.net.URI)8 ArrayList (java.util.ArrayList)8 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)8 AssessmentItemRef (uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef)8 TestSessionState (uk.ac.ed.ph.jqtiplus.state.TestSessionState)8 HashMap (java.util.HashMap)7 ManifestBuilder (org.olat.ims.qti21.model.xml.ManifestBuilder)6 ManifestMetadataBuilder (org.olat.ims.qti21.model.xml.ManifestMetadataBuilder)6 AssessmentObjectXmlLoader (uk.ac.ed.ph.jqtiplus.reading.AssessmentObjectXmlLoader)6 QtiXmlReader (uk.ac.ed.ph.jqtiplus.reading.QtiXmlReader)6 ResourceLocator (uk.ac.ed.ph.jqtiplus.xmlutils.locators.ResourceLocator)6 URISyntaxException (java.net.URISyntaxException)4 GenericTreeModel (org.olat.core.gui.components.tree.GenericTreeModel)4 Identity (org.olat.core.id.Identity)4 PathResourceLocator (org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator)4