use of org.olat.ims.qti.editor.beecom.objects.Section in project OpenOLAT by OpenOLAT.
the class QTIWordExport method exportTest.
private void exportTest(String header, OutputStream out, boolean withResponses) {
ZipOutputStream zout = null;
try {
OpenXMLDocument document = new OpenXMLDocument();
document.setMediaContainer(mediaContainer);
document.setDocumentHeader(header);
Translator translator = Util.createPackageTranslator(QTIWordExport.class, locale, Util.createPackageTranslator(QTIEditorMainController.class, locale));
Assessment assessment = rootNode.getAssessment();
renderAssessment(assessment, document, translator);
for (Section section : assessment.getSections()) {
renderSection(section, document);
List<Item> items = section.getItems();
for (Iterator<Item> itemIt = items.iterator(); itemIt.hasNext(); ) {
Item item = itemIt.next();
if (item.isAlient()) {
renderAlienItem(item, document, translator);
} else {
renderItem(item, document, withResponses, translator);
}
if (itemIt.hasNext()) {
document.appendPageBreak();
}
}
}
zout = new ZipOutputStream(out);
zout.setLevel(9);
OpenXMLDocumentWriter writer = new OpenXMLDocumentWriter();
writer.createDocument(zout, document);
} catch (Exception e) {
log.error("", e);
} finally {
if (zout != null) {
try {
zout.finish();
} catch (IOException e) {
log.error("", e);
}
}
}
}
use of org.olat.ims.qti.editor.beecom.objects.Section in project OpenOLAT by OpenOLAT.
the class SectionParser method parse.
public Object parse(Element element) {
// assert element.getName().equalsIgnoreCase("questestinterop");
Section section = new Section();
// attributes
section.setIdent(element.attribute("ident").getValue());
section.setTitle(element.attribute("title").getValue());
// elements
// DURATION
Duration duration = (Duration) parserManager.parse(element.element("duration"));
section.setDuration(duration);
List sectioncontrolsXML = element.elements("sectioncontrol");
List<Object> sectioncontrols = new ArrayList<>();
for (Iterator i = sectioncontrolsXML.iterator(); i.hasNext(); ) {
sectioncontrols.add(parserManager.parse((Element) i.next()));
}
if (sectioncontrols.size() == 0) {
sectioncontrols.add(new Control());
}
section.setSectioncontrols(sectioncontrols);
// SELECTION ORDERING
SelectionOrdering selectionOrdering = (SelectionOrdering) parserManager.parse(element.element("selection_ordering"));
if (selectionOrdering != null) {
section.setSelection_ordering(selectionOrdering);
} else {
section.setSelection_ordering(new SelectionOrdering());
}
// SECTIONS
List sectionsXML = element.elements("section");
List<Object> sections = new ArrayList<>();
for (Iterator i = sectionsXML.iterator(); i.hasNext(); ) {
sections.add(parserManager.parse((Element) i.next()));
}
section.setSections(sections);
// ITEMS
List itemsXML = element.elements("item");
List<Object> items = new ArrayList<>();
for (Iterator i = itemsXML.iterator(); i.hasNext(); ) {
items.add(parserManager.parse((Element) i.next()));
}
section.setItems(items);
// OBJECTIVES
Element mattext = (Element) element.selectSingleNode("./objectives/material/mattext");
if (mattext != null)
section.setObjectives(mattext.getTextTrim());
// FEEDBACKS
List feedbacksXML = element.elements("sectionfeedback");
List<QTIObject> feedbacks = new ArrayList<>();
for (Iterator i = feedbacksXML.iterator(); i.hasNext(); ) {
QTIObject tmp = (QTIObject) parserManager.parse((Element) i.next());
feedbacks.add(tmp);
}
section.setSectionfeedbacks(feedbacks);
// OUTCOMES_PROCESSING
// TODO: maybe we should use the OutcomesProcessing object and parser here? Same as on
// assessment level?
QTIObject outcomes_processing = (QTIObject) parserManager.parse(element.element("outcomes_processing"));
section.setOutcomes_processing(outcomes_processing);
return section;
}
use of org.olat.ims.qti.editor.beecom.objects.Section in project OpenOLAT by OpenOLAT.
the class QTIEditorTreeModel method init.
/**
* takes the assessment object tree and converts it to a QTIEditorTreeModel
*/
private void init() {
Assessment ass = qtiPackage.getQTIDocument().getAssessment();
GenericQtiNode rootNode = new AssessmentNode(ass, qtiPackage);
this.setRootNode(rootNode);
// Sections with their Items
List<Section> sections = ass.getSections();
for (int i = 0; i < sections.size(); i++) {
// get section data
Section elem = sections.get(i);
GenericQtiNode sectionNode = new SectionNode(elem, qtiPackage);
List<Item> items = elem.getItems();
for (int j = 0; j < items.size(); j++) {
// get item data
Item elem2 = items.get(j);
GenericQtiNode itemNode = new ItemNode(elem2, qtiPackage);
// add item to its parent section
sectionNode.addChild(itemNode);
}
// add section with its items to the rootNode
rootNode.addChild(sectionNode);
}
}
use of org.olat.ims.qti.editor.beecom.objects.Section in project OpenOLAT by OpenOLAT.
the class QTI12ResultDetailsController method checkEssay.
private boolean checkEssay() {
QTIDocument doc = TestFileResource.getQTIDocument(repositoryEntry.getOlatResource());
if (doc != null && doc.getAssessment() != null) {
Assessment ass = doc.getAssessment();
// Sections with their Items
List<Section> sections = ass.getSections();
for (Section section : sections) {
List<Item> items = section.getItems();
for (Item item : items) {
String ident = item.getIdent();
if (ident != null && ident.startsWith("QTIEDIT:ESSAY")) {
return true;
}
}
}
}
return false;
}
use of org.olat.ims.qti.editor.beecom.objects.Section in project OpenOLAT by OpenOLAT.
the class QTI12To21Converter method convert.
public AssessmentTest convert(VFSContainer originalContainer, QTIDocument doc, QTI21DeliveryOptions qti21Options) throws URISyntaxException {
Assessment assessment = doc.getAssessment();
AssessmentTest assessmentTest = new AssessmentTest();
String assessmentTestIdentifier = IdentifierGenerator.newAssessmentTestFilename();
File testFile = new File(unzippedDirRoot, assessmentTestIdentifier + ".xml");
manifest.appendAssessmentTest(testFile.getName());
assessmentTest.setIdentifier(assessmentTestIdentifier);
assessmentTest.setTitle(assessment.getTitle());
assessmentTest.setToolName(QTI21Constants.TOOLNAME);
assessmentTest.setToolVersion(Settings.getVersion());
convertDuration((Duration) assessment.getDuration(), assessmentTest);
TestPart testPart = AssessmentTestFactory.createTestPart(assessmentTest);
ItemSessionControl itemSessionControl = testPart.getItemSessionControl();
Control tmpControl = QTIEditHelper.getControl(assessment);
if (tmpControl.getSolution() == Control.CTRL_YES) {
itemSessionControl.setShowSolution(Boolean.TRUE);
}
if (qti21Options != null) {
qti21Options.setHideFeedbacks(false);
if (assessment.isInheritControls() && tmpControl.getFeedback() != Control.CTRL_YES) {
qti21Options.setHideFeedbacks(true);
}
}
AssessmentTestBuilder assessmentTestBuilder = new AssessmentTestBuilder(assessmentTest);
// root
List<Section> sections = assessment.getSections();
for (Section section : sections) {
convert(section, testPart);
}
// this are lost in QTI 2.1
// assessment.getSelection_ordering().getOrderType();
// assessment.getSelection_ordering().getSelectionNumber();
OutcomesProcessing outcomesProcessing = assessment.getOutcomes_processing();
if (outcomesProcessing != null) {
String cutValue = outcomesProcessing.getField(OutcomesProcessing.CUTVALUE);
if (StringHelper.containsNonWhitespace(cutValue)) {
try {
assessmentTestBuilder.setCutValue(Double.valueOf(cutValue));
} catch (NumberFormatException e) {
log.error("Cannot parse cut value: " + cutValue, e);
}
}
}
assessmentTestBuilder.setMaxScore(atomicMaxScore.doubleValue());
assessmentTest = assessmentTestBuilder.build();
persistAssessmentObject(testFile, assessmentTest);
manifest.write(new File(unzippedDirRoot, "imsmanifest.xml"));
copyMaterial(originalContainer);
return assessmentTest;
}
Aggregations