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);
}
}
}
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;
}
}
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;
}
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>");
}
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;
});
}
Aggregations