davemckain / qtiworks

**This project will be closed in early 2023!** IMS QTI 2.1 assessment delivery engine and Java development library (JQTI+). Supports the MathAssess extensions. Replacement for QTIEngine/JQTI and MathAssessEngine/JQTI. Note that this project has now ended and no further work is currently planned.
Other
67 stars 55 forks source link

Loading AssessmentResult throws exception #77

Closed pikaju closed 4 years ago

pikaju commented 4 years ago

I use the following code to load a QTI file exported from OpenOLAT containing an assessmentResult:

ResourceLocator locator = new FileResourceLocator();
QtiXmlReader xmlReader = new QtiXmlReader();
QtiObjectReader objectReader = xmlReader.createQtiObjectReader(locator, false);
return objectReader.lookupRootNode(inputFile.toURI(), AssessmentResult.class).getRootNode();

This throws the following exception:

java.lang.ClassCastException: class uk.ac.ed.ph.jqtiplus.node.result.ResponseVariable cannot be cast to class uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.result.ResponseVariable and uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration are in unnamed module of loader 'app')
    at uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse.getParent(CorrectResponse.java:98)
    at uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse.getCardinality(CorrectResponse.java:132)
    at uk.ac.ed.ph.jqtiplus.node.shared.FieldValue.getBaseType(FieldValue.java:141)
    at uk.ac.ed.ph.jqtiplus.node.shared.FieldValue.loadChildren(FieldValue.java:174)
    at uk.ac.ed.ph.jqtiplus.node.AbstractNode.load(AbstractNode.java:188)
    at uk.ac.ed.ph.jqtiplus.group.AbstractNodeGroup.loadChildIfSupported(AbstractNodeGroup.java:136)
    at uk.ac.ed.ph.jqtiplus.group.NodeGroupList.load(NodeGroupList.java:326)
    at uk.ac.ed.ph.jqtiplus.node.AbstractNode.loadChildren(AbstractNode.java:208)
    at uk.ac.ed.ph.jqtiplus.node.AbstractNode.load(AbstractNode.java:188)
    at uk.ac.ed.ph.jqtiplus.group.AbstractNodeGroup.loadChildIfSupported(AbstractNodeGroup.java:136)
    at uk.ac.ed.ph.jqtiplus.group.NodeGroupList.load(NodeGroupList.java:326)
    at uk.ac.ed.ph.jqtiplus.node.AbstractNode.loadChildren(AbstractNode.java:208)
    at uk.ac.ed.ph.jqtiplus.node.AbstractNode.load(AbstractNode.java:188)
    at uk.ac.ed.ph.jqtiplus.group.AbstractNodeGroup.loadChildIfSupported(AbstractNodeGroup.java:136)
    at uk.ac.ed.ph.jqtiplus.group.NodeGroupList.load(NodeGroupList.java:326)
    at uk.ac.ed.ph.jqtiplus.node.AbstractNode.loadChildren(AbstractNode.java:208)
    at uk.ac.ed.ph.jqtiplus.node.AbstractNode.load(AbstractNode.java:188)
    at uk.ac.ed.ph.jqtiplus.group.AbstractNodeGroup.loadChildIfSupported(AbstractNodeGroup.java:136)
    at uk.ac.ed.ph.jqtiplus.group.NodeGroupList.load(NodeGroupList.java:326)
    at uk.ac.ed.ph.jqtiplus.node.AbstractNode.loadChildren(AbstractNode.java:208)
    at uk.ac.ed.ph.jqtiplus.node.AbstractNode.load(AbstractNode.java:188)
    at uk.ac.ed.ph.jqtiplus.node.RootNodeTypes.load(RootNodeTypes.java:171)
    at uk.ac.ed.ph.jqtiplus.reading.QtiObjectReader.lookupRootNode(QtiObjectReader.java:182)
    at de.uhh.selamp.olat2sql.common.loader.AssessmentResultLoader.load(AssessmentResultLoader.java:23)
    at de.uhh.selamp.olat2sql.common.loader.OLATObjectLoader.load(OLATObjectLoader.java:36)
    at de.uhh.selamp.olat2sql.cli.OLAT2SQL.main(OLAT2SQL.java:66)

Is loading AssessmentResults not supported by QTIWorks?

davemckain commented 4 years ago

Hi. Thanks for the bug report. Sadly it does look like you've discovered a long standing bug in the model - the current CorrectResponse model class only expects to be a child of ResponseDeclaration, which isn't the case when it appears in an AssessmentResult.

pikaju commented 4 years ago

Hey, thank you for your answer. Just to clarify: Is this a known bug that won't be fixed, or will you fix it in the near future? And, if it won't be fixed, do you think it would be easy for us to fix it ourselves? How should we go about doing so? Are you open for pull requests?

davemckain commented 4 years ago

I've pushed a hopeful fix to this to a new branch: issue-77.

However this part of the code is pretty old / cold! (It comes from the original JQTI back in 2009/2010, and my last significant refactoring of this was 2013.)

So I'm no longer familiar with how it all fits together and I'm therefore a bit wary of merging this back into the master branch without doing a bit more testing.

@Pikaju: Could you maybe try building this branch and see if it now works for you? Alternative I can build a replacement JAR for you to try out.

pikaju commented 4 years ago

It does appear to be working now, thank you so much!

davemckain commented 4 years ago

Thanks for testing! I've now merged this fix into the master branch, and it will appear in the next production release.