Search in sources :

Example 21 with Section

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);
            }
        }
    }
}
Also used : Item(org.olat.ims.qti.editor.beecom.objects.Item) OpenXMLDocumentWriter(org.olat.core.util.openxml.OpenXMLDocumentWriter) Translator(org.olat.core.gui.translator.Translator) QTIEditorMainController(org.olat.ims.qti.editor.QTIEditorMainController) ZipOutputStream(java.util.zip.ZipOutputStream) Assessment(org.olat.ims.qti.editor.beecom.objects.Assessment) OpenXMLDocument(org.olat.core.util.openxml.OpenXMLDocument) IOException(java.io.IOException) Section(org.olat.ims.qti.editor.beecom.objects.Section) IOException(java.io.IOException)

Example 22 with Section

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;
}
Also used : Control(org.olat.ims.qti.editor.beecom.objects.Control) QTIObject(org.olat.ims.qti.editor.beecom.objects.QTIObject) SelectionOrdering(org.olat.ims.qti.editor.beecom.objects.SelectionOrdering) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) Duration(org.olat.ims.qti.editor.beecom.objects.Duration) List(java.util.List) ArrayList(java.util.ArrayList) QTIObject(org.olat.ims.qti.editor.beecom.objects.QTIObject) Section(org.olat.ims.qti.editor.beecom.objects.Section)

Example 23 with 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);
    }
}
Also used : Item(org.olat.ims.qti.editor.beecom.objects.Item) Assessment(org.olat.ims.qti.editor.beecom.objects.Assessment) Section(org.olat.ims.qti.editor.beecom.objects.Section)

Example 24 with Section

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;
}
Also used : QTIDocument(org.olat.ims.qti.editor.beecom.objects.QTIDocument) Item(org.olat.ims.qti.editor.beecom.objects.Item) Assessment(org.olat.ims.qti.editor.beecom.objects.Assessment) Section(org.olat.ims.qti.editor.beecom.objects.Section)

Example 25 with Section

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;
}
Also used : AssessmentTest(uk.ac.ed.ph.jqtiplus.node.test.AssessmentTest) ItemSessionControl(uk.ac.ed.ph.jqtiplus.node.test.ItemSessionControl) AssessmentTestBuilder(org.olat.ims.qti21.model.xml.AssessmentTestBuilder) ItemSessionControl(uk.ac.ed.ph.jqtiplus.node.test.ItemSessionControl) Control(org.olat.ims.qti.editor.beecom.objects.Control) Assessment(org.olat.ims.qti.editor.beecom.objects.Assessment) TestPart(uk.ac.ed.ph.jqtiplus.node.test.TestPart) OutcomesProcessing(org.olat.ims.qti.editor.beecom.objects.OutcomesProcessing) File(java.io.File) Section(org.olat.ims.qti.editor.beecom.objects.Section) AssessmentSection(uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection)

Aggregations

Section (org.olat.ims.qti.editor.beecom.objects.Section)34 Item (org.olat.ims.qti.editor.beecom.objects.Item)28 Assessment (org.olat.ims.qti.editor.beecom.objects.Assessment)18 ItemNode (org.olat.ims.qti.editor.tree.ItemNode)10 SectionNode (org.olat.ims.qti.editor.tree.SectionNode)10 VFSItem (org.olat.core.util.vfs.VFSItem)8 ArrayList (java.util.ArrayList)6 Iterator (java.util.Iterator)6 List (java.util.List)6 AssessmentNode (org.olat.ims.qti.editor.tree.AssessmentNode)6 Control (org.olat.ims.qti.editor.beecom.objects.Control)5 Element (org.dom4j.Element)4 Translator (org.olat.core.gui.translator.Translator)4 INode (org.olat.core.util.nodes.INode)4 VFSContainer (org.olat.core.util.vfs.VFSContainer)4 Response (org.olat.ims.qti.editor.beecom.objects.Response)4 GenericQtiNode (org.olat.ims.qti.editor.tree.GenericQtiNode)4 QTIDocument (org.olat.ims.qti.editor.beecom.objects.QTIDocument)3 QTIObject (org.olat.ims.qti.editor.beecom.objects.QTIObject)3 File (java.io.File)2