Search in sources :

Example 1 with ItemSessionControl

use of uk.ac.ed.ph.jqtiplus.node.test.ItemSessionControl in project OpenOLAT by OpenOLAT.

the class BigAssessmentTestPackageBuilder method createAssessmentTest.

@Test
public void createAssessmentTest() throws URISyntaxException {
    String date = format.format(new Date());
    File directory = new File("/HotCoffee/qti/" + date + "/");
    directory.mkdirs();
    ManifestBuilder manifest = ManifestBuilder.createAssessmentTestBuilder();
    System.out.println(directory);
    // test
    File testFile = new File(directory, IdentifierGenerator.newAssessmentTestFilename());
    AssessmentTest assessmentTest = AssessmentTestFactory.createAssessmentTest("Big test " + date, "Section");
    manifest.appendAssessmentTest(testFile.getName());
    TestPart part = assessmentTest.getTestParts().get(0);
    part.getAssessmentSections().clear();
    // section
    for (int i = 0; i < numOfSections; i++) {
        AssessmentSection section = new AssessmentSection(part);
        section.setFixed(Boolean.TRUE);
        section.setVisible(Boolean.TRUE);
        section.setTitle((i + 1) + ". Section");
        section.setIdentifier(IdentifierGenerator.newAsIdentifier("sec"));
        part.getAssessmentSections().add(section);
        Ordering ordering = new Ordering(section);
        ordering.setShuffle(true);
        section.setOrdering(ordering);
        Selection selection = new Selection(section);
        selection.setSelect(4);
        section.setSelection(selection);
        ItemSessionControl itemSessionControl = new ItemSessionControl(section);
        itemSessionControl.setAllowSkipping(Boolean.TRUE);
        itemSessionControl.setAllowComment(Boolean.FALSE);
        itemSessionControl.setShowFeedback(Boolean.FALSE);
        section.setItemSessionControl(itemSessionControl);
        RubricBlock rubrickBlock = new RubricBlock(section);
        rubrickBlock.setViews(Collections.singletonList(View.CANDIDATE));
        section.getRubricBlocks().add(rubrickBlock);
        for (int j = 0; j < numOfQuestions; j++) {
            // single choice
            String itemId = IdentifierGenerator.newAsString(QTI21QuestionType.sc.getPrefix());
            File itemFile = new File(directory, itemId + ".xml");
            AssessmentItem assessmentItem = AssessmentItemFactory.createSingleChoice("Single choice", "New answer");
            assessmentItem.setTitle((i + 1) + "." + (j + 1) + ". Question SC");
            AssessmentTestFactory.appendAssessmentItem(section, itemFile.getName());
            manifest.appendAssessmentItem(itemFile.getName());
            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);
    }
    manifest.write(new File(directory, "imsmanifest.xml"));
}
Also used : ManifestBuilder(org.olat.ims.qti21.model.xml.ManifestBuilder) Selection(uk.ac.ed.ph.jqtiplus.node.test.Selection) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) ResolvedAssessmentTest(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest) AssessmentTest(uk.ac.ed.ph.jqtiplus.node.test.AssessmentTest) ItemSessionControl(uk.ac.ed.ph.jqtiplus.node.test.ItemSessionControl) AssessmentSection(uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection) FileOutputStream(java.io.FileOutputStream) TestPart(uk.ac.ed.ph.jqtiplus.node.test.TestPart) Ordering(uk.ac.ed.ph.jqtiplus.node.test.Ordering) File(java.io.File) RubricBlock(uk.ac.ed.ph.jqtiplus.node.content.variable.RubricBlock) ResolvedAssessmentTest(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest) AssessmentTest(uk.ac.ed.ph.jqtiplus.node.test.AssessmentTest) Test(org.junit.Test)

Example 2 with ItemSessionControl

use of uk.ac.ed.ph.jqtiplus.node.test.ItemSessionControl in project OpenOLAT by OpenOLAT.

the class ItemSessionControlController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    String[] yesNoValues = new String[] { translate("yes"), translate("no") };
    String[] yesNoInheritValues = new String[] { translate("yes"), translate("no"), translate("inherit") };
    // inherit is allowed?
    String[] aKeys = allowInherit ? yesNoInheritKeys : yesnoKeys;
    String[] aValues = allowInherit ? yesNoInheritValues : yesNoValues;
    // can be null
    ItemSessionControl itemSessionControl = part.getItemSessionControl();
    Integer maxAttempts = null;
    if (itemSessionControl != null) {
        maxAttempts = itemSessionControl.getMaxAttempts();
    }
    limitAttemptsEl = uifactory.addRadiosHorizontal("form.imd.limittries", formLayout, aKeys, aValues);
    limitAttemptsEl.addActionListener(FormEvent.ONCLICK);
    limitAttemptsEl.setHelpTextKey("item.session.control.attempts.hint", null);
    String maxAttemptsStr = maxAttempts == null ? "" : maxAttempts.toString();
    maxAttemptsEl = uifactory.addTextElement("attempts", "item.session.control.attempts", 4, maxAttemptsStr, formLayout);
    if (maxAttempts == null) {
        if (aKeys.length == 2) {
            limitAttemptsEl.select(YES, true);
            maxAttemptsEl.setValue("1");
        } else {
            limitAttemptsEl.select(INHERIT, true);
        }
    } else if (maxAttempts.intValue() == 0) {
        limitAttemptsEl.select(NO, true);
    } else {
        limitAttemptsEl.select(YES, true);
    }
    limitAttemptsEl.setEnabled(!restrictedEdit && editable);
    maxAttemptsEl.setVisible(limitAttemptsEl.isSelected(0));
    maxAttemptsEl.setEnabled(!restrictedEdit && editable);
    allowSkippingEl = uifactory.addRadiosHorizontal("item.session.control.allow.skipping", formLayout, aKeys, aValues);
    allowSkippingEl.addActionListener(FormEvent.ONCHANGE);
    allowSkippingEl.setEnabled(!restrictedEdit && editable);
    allowSkippingEl.setHelpText(translate("item.session.control.allow.skipping.hint"));
    // the default value is allowSkipping=true
    if (itemSessionControl != null && itemSessionControl.getAllowSkipping() != null) {
        String key = itemSessionControl.getAllowSkipping().booleanValue() ? YES : NO;
        allowSkippingEl.select(key, true);
    } else {
        String key = allowInherit ? INHERIT : YES;
        allowSkippingEl.select(key, true);
    }
    allowCommentEl = uifactory.addRadiosHorizontal("item.session.control.allow.comment", formLayout, aKeys, aValues);
    allowCommentEl.addActionListener(FormEvent.ONCHANGE);
    allowCommentEl.setEnabled(!restrictedEdit && editable);
    allowCommentEl.setHelpText(translate("item.session.control.allow.comment.hint"));
    if (itemSessionControl != null && itemSessionControl.getAllowComment() != null) {
        String key = itemSessionControl.getAllowComment().booleanValue() ? YES : NO;
        allowCommentEl.select(key, true);
    } else {
        String key = allowInherit ? INHERIT : YES;
        allowCommentEl.select(key, true);
    }
    allowReviewEl = uifactory.addRadiosHorizontal("item.session.control.allow.review", formLayout, aKeys, aValues);
    allowReviewEl.addActionListener(FormEvent.ONCHANGE);
    allowReviewEl.setEnabled(!restrictedEdit && editable);
    allowReviewEl.setHelpText(translate("item.session.control.allow.review.hint"));
    if (itemSessionControl != null && itemSessionControl.getAllowReview() != null) {
        String key = itemSessionControl.getAllowReview().booleanValue() ? YES : NO;
        allowReviewEl.select(key, true);
    } else {
        String key = allowInherit ? INHERIT : NO;
        allowReviewEl.select(key, true);
    }
    showSolutionEl = uifactory.addRadiosHorizontal("item.session.control.show.solution", formLayout, aKeys, aValues);
    showSolutionEl.addActionListener(FormEvent.ONCHANGE);
    showSolutionEl.setEnabled(!restrictedEdit && editable);
    showSolutionEl.setHelpText(translate("item.session.control.show.solution.hint"));
    if (itemSessionControl != null && itemSessionControl.getShowSolution() != null) {
        String key = itemSessionControl.getShowSolution().booleanValue() ? YES : NO;
        showSolutionEl.select(key, true);
    } else {
        String key = allowInherit ? INHERIT : NO;
        showSolutionEl.select(key, false);
    }
}
Also used : ItemSessionControl(uk.ac.ed.ph.jqtiplus.node.test.ItemSessionControl)

Example 3 with ItemSessionControl

use of uk.ac.ed.ph.jqtiplus.node.test.ItemSessionControl in project OpenOLAT by OpenOLAT.

the class ItemSessionControlController method formOK.

@Override
protected void formOK(UserRequest ureq) {
    // can be null
    ItemSessionControl itemSessionControl = part.getItemSessionControl();
    // need to be first!
    if (allowSkippingEl.isOneSelected()) {
        if (allowSkippingEl.isSelected(0)) {
            // yes
            checkNotNull(itemSessionControl).setAllowSkipping(Boolean.TRUE);
        } else if (allowSkippingEl.isSelected(1)) {
            // no
            checkNotNull(itemSessionControl).setAllowSkipping(Boolean.FALSE);
        } else if (itemSessionControl != null) {
            // inherit
            itemSessionControl.setAllowSkipping(null);
        }
    }
    if (allowCommentEl.isOneSelected()) {
        if (allowCommentEl.isSelected(0)) {
            checkNotNull(itemSessionControl).setAllowComment(Boolean.TRUE);
        } else if (allowCommentEl.isSelected(1)) {
            checkNotNull(itemSessionControl).setAllowComment(Boolean.FALSE);
        } else if (itemSessionControl != null) {
            itemSessionControl.setAllowComment(null);
        }
    }
    if (allowReviewEl.isOneSelected()) {
        if (allowReviewEl.isSelected(0)) {
            checkNotNull(itemSessionControl).setAllowReview(Boolean.TRUE);
        } else if (allowReviewEl.isSelected(1)) {
            checkNotNull(itemSessionControl).setAllowReview(Boolean.FALSE);
        } else if (itemSessionControl != null) {
            itemSessionControl.setAllowReview(null);
        }
    }
    if (showSolutionEl.isOneSelected()) {
        if (showSolutionEl.isSelected(0)) {
            checkNotNull(itemSessionControl).setShowSolution(Boolean.TRUE);
        } else if (showSolutionEl.isSelected(1)) {
            checkNotNull(itemSessionControl).setShowSolution(Boolean.FALSE);
        } else if (itemSessionControl != null) {
            itemSessionControl.setShowSolution(null);
        }
    }
    if (limitAttemptsEl.isSelected(0) && maxAttemptsEl != null && maxAttemptsEl.isVisible() && StringHelper.isLong(maxAttemptsEl.getValue())) {
        int maxAttempts = Integer.parseInt(maxAttemptsEl.getValue());
        checkNotNull(itemSessionControl).setMaxAttempts(new Integer(maxAttempts));
    } else if (limitAttemptsEl.isSelected(1)) {
        checkNotNull(itemSessionControl).setMaxAttempts(0);
    } else if (itemSessionControl != null) {
        itemSessionControl.setMaxAttempts(null);
    }
}
Also used : ItemSessionControl(uk.ac.ed.ph.jqtiplus.node.test.ItemSessionControl)

Example 4 with ItemSessionControl

use of uk.ac.ed.ph.jqtiplus.node.test.ItemSessionControl in project OpenOLAT by OpenOLAT.

the class ItemSessionControlController method checkNotNull.

private ItemSessionControl checkNotNull(ItemSessionControl itemSessionControl) {
    if (itemSessionControl == null) {
        itemSessionControl = new ItemSessionControl(part);
        part.setItemSessionControl(itemSessionControl);
    }
    return itemSessionControl;
}
Also used : ItemSessionControl(uk.ac.ed.ph.jqtiplus.node.test.ItemSessionControl)

Example 5 with ItemSessionControl

use of uk.ac.ed.ph.jqtiplus.node.test.ItemSessionControl in project OpenOLAT by OpenOLAT.

the class AssessmentItemRefEditorController method getOrCreateItemSessionControl.

protected final ItemSessionControl getOrCreateItemSessionControl() {
    ItemSessionControl itemSessionControl = assessmentItemRef.getItemSessionControl();
    if (itemSessionControl == null) {
        itemSessionControl = new ItemSessionControl(assessmentItemRef);
        assessmentItemRef.setItemSessionControl(itemSessionControl);
    }
    return itemSessionControl;
}
Also used : ItemSessionControl(uk.ac.ed.ph.jqtiplus.node.test.ItemSessionControl)

Aggregations

ItemSessionControl (uk.ac.ed.ph.jqtiplus.node.test.ItemSessionControl)18 TestPart (uk.ac.ed.ph.jqtiplus.node.test.TestPart)8 AssessmentSection (uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection)6 File (java.io.File)4 RubricBlock (uk.ac.ed.ph.jqtiplus.node.content.variable.RubricBlock)4 AssessmentTest (uk.ac.ed.ph.jqtiplus.node.test.AssessmentTest)4 Ordering (uk.ac.ed.ph.jqtiplus.node.test.Ordering)4 FileOutputStream (java.io.FileOutputStream)2 URISyntaxException (java.net.URISyntaxException)2 Date (java.util.Date)2 Test (org.junit.Test)2 Assessment (org.olat.ims.qti.editor.beecom.objects.Assessment)2 Control (org.olat.ims.qti.editor.beecom.objects.Control)2 OutcomesProcessing (org.olat.ims.qti.editor.beecom.objects.OutcomesProcessing)2 Section (org.olat.ims.qti.editor.beecom.objects.Section)2 AssessmentTestBuilder (org.olat.ims.qti21.model.xml.AssessmentTestBuilder)2 ManifestBuilder (org.olat.ims.qti21.model.xml.ManifestBuilder)2 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)2 Selection (uk.ac.ed.ph.jqtiplus.node.test.Selection)2 TimeLimits (uk.ac.ed.ph.jqtiplus.node.test.TimeLimits)2