Search in sources :

Example 26 with ResolvedAssessmentItem

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

the class CopyAndConvertVisitor method checkAssessmentItem.

private void checkAssessmentItem(Path outputFile) {
    QTI21Service qtiService = CoreSpringFactory.getImpl(QTI21Service.class);
    QtiXmlReader qtiXmlReader = new QtiXmlReader(qtiService.jqtiExtensionManager());
    ResourceLocator fileResourceLocator = new FileResourceLocator();
    ResourceLocator inputResourceLocator = ImsQTI21Resource.createResolvingResourceLocator(fileResourceLocator);
    URI assessmentObjectSystemId = outputFile.toFile().toURI();
    AssessmentObjectXmlLoader assessmentObjectXmlLoader = new AssessmentObjectXmlLoader(qtiXmlReader, inputResourceLocator);
    ResolvedAssessmentItem resolvedAssessmentItem = assessmentObjectXmlLoader.loadAndResolveAssessmentItem(assessmentObjectSystemId);
    AssessmentItem assessmentItem = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
    if (!AssessmentItemChecker.checkAndCorrect(assessmentItem)) {
        try (FileOutputStream out = new FileOutputStream(outputFile.toFile())) {
            qtiService.qtiSerializer().serializeJqtiObject(assessmentItem, out);
        } catch (Exception e) {
            log.error("", e);
        }
    }
}
Also used : AssessmentObjectXmlLoader(uk.ac.ed.ph.jqtiplus.reading.AssessmentObjectXmlLoader) QtiXmlReader(uk.ac.ed.ph.jqtiplus.reading.QtiXmlReader) QTI21Service(org.olat.ims.qti21.QTI21Service) FileResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.FileResourceLocator) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) FileOutputStream(java.io.FileOutputStream) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) QtiXmlInterpretationException(uk.ac.ed.ph.jqtiplus.reading.QtiXmlInterpretationException) BadResourceException(uk.ac.ed.ph.jqtiplus.provision.BadResourceException) IOException(java.io.IOException) 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)

Example 27 with ResolvedAssessmentItem

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

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

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

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

the class AssessmentTestComponentRenderer method renderTestItemBody.

private void renderTestItemBody(AssessmentRenderer renderer, StringOutput sb, AssessmentTestComponent component, TestPlanNode itemNode, URLBuilder ubu, Translator translator, RenderingRequest options) {
    final ItemSessionState itemSessionState = component.getItemSessionState(itemNode.getKey());
    URI itemSystemId = itemNode.getItemSystemId();
    ResolvedAssessmentItem resolvedAssessmentItem = component.getResolvedAssessmentTest().getResolvedAssessmentItemBySystemIdMap().get(itemSystemId);
    if (resolvedAssessmentItem == null) {
        log.error("Missing assessment item: " + itemSystemId);
        renderMissingItem(sb, translator);
        return;
    }
    final AssessmentItem assessmentItem = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
    sb.append("<div class='o_assessmentitem_wrapper'>");
    // title + status
    sb.append("<h4 class='itemTitle'>");
    renderItemStatus(sb, itemSessionState, options, translator);
    renderMaxScoreItem(sb, component, itemSessionState, translator);
    String title;
    if (component.isShowTitles()) {
        title = StringHelper.escapeHtml(itemNode.getSectionPartTitle());
    } else {
        int num = component.getCandidateSessionContext().getNumber(itemNode);
        title = translator.translate("question.title", new String[] { Integer.toString(num) });
    }
    sb.append(title).append("</h4>").append("<div id='itemBody' class='o_qti_item_body clearfix'>");
    // render itemBody
    assessmentItem.getItemBody().getBlocks().forEach(block -> renderBlock(renderer, sb, component, resolvedAssessmentItem, itemSessionState, block, ubu, translator));
    // comment
    renderComment(renderer, sb, component, itemSessionState, translator);
    // end body
    sb.append("</div>");
    // Display active modal feedback (only after responseProcessing)
    if (component.isItemFeedbackAllowed(itemNode, assessmentItem, options)) {
        renderTestItemModalFeedback(renderer, sb, component, resolvedAssessmentItem, itemSessionState, ubu, translator);
    }
    // end wrapper
    sb.append("</div>");
}
Also used : ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) 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) AssessmentRenderFunctions.contentAsString(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.contentAsString) URI(java.net.URI)

Example 30 with ResolvedAssessmentItem

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

the class CorrectionOverviewModel method isManualCorrection.

public boolean isManualCorrection(AssessmentItemRef itemRef) {
    String identifier = itemRef.getIdentifier().toString();
    return manualCorrections.computeIfAbsent(identifier, id -> {
        ResolvedAssessmentItem resolvedAssessmentItem = resolvedAssessmentTest.getResolvedAssessmentItem(itemRef);
        AssessmentItem item = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
        List<Interaction> interactions = item.getItemBody().findInteractions();
        for (Interaction interaction : interactions) {
            if (interaction instanceof UploadInteraction || interaction instanceof DrawingInteraction || interaction instanceof ExtendedTextInteraction) {
                return true;
            }
        }
        return false;
    });
}
Also used : UploadInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.UploadInteraction) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) UploadInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.UploadInteraction) Interaction(uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction) DrawingInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.DrawingInteraction) ExtendedTextInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.ExtendedTextInteraction) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) ExtendedTextInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.ExtendedTextInteraction) DrawingInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.DrawingInteraction)

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