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