Search in sources :

Example 1 with QTI21Service

use of org.olat.ims.qti21.QTI21Service 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 2 with QTI21Service

use of org.olat.ims.qti21.QTI21Service in project openolat by klemens.

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)

Aggregations

FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 PathResourceLocator (org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator)2 QTI21Service (org.olat.ims.qti21.QTI21Service)2 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)2 BadResourceException (uk.ac.ed.ph.jqtiplus.provision.BadResourceException)2 AssessmentObjectXmlLoader (uk.ac.ed.ph.jqtiplus.reading.AssessmentObjectXmlLoader)2 QtiXmlInterpretationException (uk.ac.ed.ph.jqtiplus.reading.QtiXmlInterpretationException)2 QtiXmlReader (uk.ac.ed.ph.jqtiplus.reading.QtiXmlReader)2 ResolvedAssessmentItem (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem)2 FileResourceLocator (uk.ac.ed.ph.jqtiplus.xmlutils.locators.FileResourceLocator)2 ResourceLocator (uk.ac.ed.ph.jqtiplus.xmlutils.locators.ResourceLocator)2