use of uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection in project openolat by klemens.
the class QTI12To21Converter method convert.
private void convert(Section section, TestPart testPart) throws URISyntaxException {
AssessmentSection assessmentSection = AssessmentTestFactory.appendAssessmentSection("Section", testPart);
assessmentSection.setTitle(section.getTitle());
convertDuration(section.getDuration(), assessmentSection);
RubricBlock rubricBlock = assessmentSection.getRubricBlocks().get(0);
rubricBlock.getBlocks().clear();
String objectives = section.getObjectives();
htmlBuilder.appendHtml(rubricBlock, blockedHtml(objectives));
boolean shuffle = SelectionOrdering.RANDOM.equals(section.getSelection_ordering().getOrderType());
assessmentSection.getOrdering().setShuffle(shuffle);
int selectionNum = section.getSelection_ordering().getSelectionNumber();
if (selectionNum > 0) {
Selection selection = new Selection(assessmentSection);
selection.setSelect(selectionNum);
assessmentSection.setSelection(selection);
}
List<Item> items = section.getItems();
for (Item item : items) {
AssessmentItemBuilder itemBuilder = null;
if (item != null && item.getQuestion() != null) {
int questionType = item.getQuestion().getType();
switch(questionType) {
case Question.TYPE_SC:
itemBuilder = convertSingleChoice(item);
break;
case Question.TYPE_MC:
itemBuilder = convertMultipleChoice(item);
break;
case Question.TYPE_KPRIM:
itemBuilder = convertKPrim(item);
break;
case Question.TYPE_FIB:
itemBuilder = convertFIB(item);
break;
case Question.TYPE_ESSAY:
itemBuilder = convertEssay(item);
break;
}
} else {
errors.add(item.getTitle());
log.error("Item without question: " + item);
}
if (itemBuilder != null) {
itemBuilder.build();
AssessmentItem assessmentItem = itemBuilder.getAssessmentItem();
AssessmentItemRef itemRef = new AssessmentItemRef(assessmentSection);
String itemId = IdentifierGenerator.newAsString(itemBuilder.getQuestionType().getPrefix());
itemRef.setIdentifier(Identifier.parseString(itemId));
convertItemBasics(item, itemRef);
File itemFile = new File(unzippedDirRoot, itemId + ".xml");
itemRef.setHref(new URI(itemFile.getName()));
assessmentSection.getSectionParts().add(itemRef);
persistAssessmentObject(itemFile, assessmentItem);
appendResourceAndMetadata(item, itemBuilder, itemFile);
// collect max score
Double maxScore = QtiNodesExtractor.extractMaxScore(assessmentItem);
if (maxScore != null && maxScore.doubleValue() > 0.0d) {
atomicMaxScore.add(maxScore.doubleValue());
}
}
}
}
use of uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection in project openolat by klemens.
the class QTI21AssessmentTestHandler method createMinimalAssessmentTest.
public void createMinimalAssessmentTest(String displayName, File directory, Locale locale) {
ManifestBuilder manifestBuilder = ManifestBuilder.createAssessmentTestBuilder();
Translator translator = Util.createPackageTranslator(AssessmentTestComposerController.class, locale);
// single choice
File itemFile = new File(directory, IdentifierGenerator.newAsString(QTI21QuestionType.sc.getPrefix()) + ".xml");
AssessmentItem assessmentItem = AssessmentItemFactory.createSingleChoice(translator.translate("new.sc"), translator.translate("new.answer"));
QtiSerializer qtiSerializer = qtiService.qtiSerializer();
manifestBuilder.appendAssessmentItem(itemFile.getName());
// test
File testFile = new File(directory, IdentifierGenerator.newAssessmentTestFilename());
AssessmentTest assessmentTest = AssessmentTestFactory.createAssessmentTest(displayName, translator.translate("new.section"));
manifestBuilder.appendAssessmentTest(testFile.getName());
// item -> test
try {
AssessmentSection section = assessmentTest.getTestParts().get(0).getAssessmentSections().get(0);
AssessmentTestFactory.appendAssessmentItem(section, itemFile.getName());
} catch (URISyntaxException e) {
log.error("", e);
}
try (FileOutputStream out = new FileOutputStream(itemFile)) {
qtiSerializer.serializeJqtiObject(assessmentItem, out);
} catch (Exception e) {
log.error("", e);
}
try (FileOutputStream out = new FileOutputStream(testFile)) {
qtiSerializer.serializeJqtiObject(assessmentTest, out);
} catch (Exception e) {
log.error("", e);
}
manifestBuilder.write(new File(directory, "imsmanifest.xml"));
}
use of uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection in project openolat by klemens.
the class QTI21ArchiveFormat method collectElementInfos.
private void collectElementInfos(AssessmentSection section) {
numOfSections++;
SectionInfos sectionInfos = new SectionInfos(section);
elementInfos.add(sectionInfos);
List<SectionPart> parts = section.getChildAbstractParts();
for (SectionPart part : parts) {
if (part instanceof AssessmentItemRef) {
AssessmentItemRef itemRef = (AssessmentItemRef) part;
ResolvedAssessmentItem resolvedItem = resolvedAssessmentTest.getResolvedAssessmentItem(itemRef);
AssessmentItem item = resolvedItem.getRootNodeLookup().extractIfSuccessful();
if (item != null) {
ItemInfos itemInfo = new ItemInfos(itemRef, item, item.getItemBody().findInteractions());
elementInfos.add(itemInfo);
sectionInfos.getItemInfos().add(itemInfo);
}
} else if (part instanceof AssessmentSection) {
collectElementInfos((AssessmentSection) part);
}
}
}
use of uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection in project openolat by klemens.
the class QTI21WordExport method exportTest.
private void exportTest(AssessmentTest assessmentTest, String header, ZipOutputStream out, boolean withResponses) {
try (ShieldOutputStream sout = new ShieldOutputStream(out);
ZipOutputStream zout = new ZipOutputStream(sout)) {
zout.setLevel(9);
OpenXMLDocument document = new OpenXMLDocument();
document.setMediaContainer(mediaContainer);
document.setDocumentHeader(header);
Translator translator = Util.createPackageTranslator(AssessmentTestDisplayController.class, locale, Util.createPackageTranslator(AssessmentTestComposerController.class, locale));
renderAssessmentTest(assessmentTest, document, translator);
for (TestPart testPart : assessmentTest.getChildAbstractParts()) {
List<AssessmentSection> assessmentSections = testPart.getAssessmentSections();
for (AssessmentSection assessmentSection : assessmentSections) {
renderAssessmentSection(assessmentSection, document, withResponses, translator);
}
}
OpenXMLDocumentWriter writer = new OpenXMLDocumentWriter();
writer.createDocument(zout, document);
} catch (Exception e) {
log.error("", e);
}
}
use of uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection in project openolat by klemens.
the class QTI21WordExport method renderAssessmentSection.
public void renderAssessmentSection(AssessmentSection assessmentSection, OpenXMLDocument document, boolean withResponses, Translator translator) {
String title = assessmentSection.getTitle();
document.appendHeading1(title, null);
List<RubricBlock> rubricBlocks = assessmentSection.getRubricBlocks();
for (RubricBlock rubricBlock : rubricBlocks) {
String htmlRubric = htmlBuilder.blocksString(rubricBlock.getBlocks());
document.appendHtmlText(htmlRubric, true);
}
for (SectionPart sectionPart : assessmentSection.getChildAbstractParts()) {
if (sectionPart instanceof AssessmentSection) {
renderAssessmentSection((AssessmentSection) sectionPart, document, withResponses, translator);
} else if (sectionPart instanceof AssessmentItemRef) {
AssessmentItemRef itemRef = (AssessmentItemRef) sectionPart;
ResolvedAssessmentItem resolvedAssessmentItem = resolvedAssessmentTest.getResolvedAssessmentItem(itemRef);
AssessmentItem assessmentItem = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
URI itemUri = resolvedAssessmentTest.getSystemIdByItemRefMap().get(itemRef);
renderAssessmentItem(assessmentItem, new File(itemUri), mediaDir, document, withResponses, translator, htmlBuilder);
document.appendPageBreak();
}
}
}
Aggregations