use of uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
the class AssessmentTestComposerController method doInsert.
private void doInsert(UserRequest ureq, AssessmentItemsPackage importPackage) {
TreeNode selectedNode = menuTree.getSelectedNode();
TreeNode sectionNode = getNearestSection(selectedNode);
String firstItemId = null;
boolean errorOnImport = false;
Map<AssessmentItemRef, AssessmentItem> flyingObjects = new HashMap<>();
try {
AssessmentSection section = (AssessmentSection) sectionNode.getUserObject();
List<AssessmentItemAndMetadata> itemsAndMetadata = importPackage.getItems();
for (AssessmentItemAndMetadata itemAndMetadata : itemsAndMetadata) {
if (itemAndMetadata.isHasError()) {
errorOnImport = true;
continue;
}
AssessmentItemBuilder itemBuilder = itemAndMetadata.getItemBuilder();
AssessmentItem assessmentItem = itemBuilder.getAssessmentItem();
AssessmentItemRef itemRef = doInsert(section, assessmentItem);
ManifestMetadataBuilder metadata = manifestBuilder.getResourceBuilderByHref(itemRef.getHref().toString());
metadata.setQtiMetadataInteractionTypes(itemBuilder.getInteractionNames());
itemAndMetadata.toBuilder(metadata, getLocale());
if (firstItemId == null) {
firstItemId = itemRef.getIdentifier().toString();
}
flyingObjects.put(itemRef, assessmentItem);
}
} catch (URISyntaxException e) {
errorOnImport = true;
logError("", e);
}
if (errorOnImport) {
showError("error.import.question");
}
if (firstItemId != null) {
// persist metadata
doSaveAssessmentTest(ureq, flyingObjects);
doSaveManifest();
updateTreeModel(false);
TreeNode newItemNode = menuTree.getTreeModel().getNodeById(firstItemId);
menuTree.setSelectedNode(newItemNode);
menuTree.open(newItemNode);
partEditorFactory(ureq, newItemNode);
}
}
use of uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection in project OpenOLAT by OpenOLAT.
the class AssessmentTestComposerController method doConfirmDelete.
private void doConfirmDelete(UserRequest ureq) {
if (confirmDeleteCtrl != null)
return;
TreeNode selectedNode = menuTree.getSelectedNode();
if (selectedNode == null) {
showWarning("warning.atleastone");
return;
}
Object uobject = selectedNode.getUserObject();
if (uobject instanceof AssessmentTest) {
showWarning("error.cannot.delete");
} else if (uobject instanceof TestPart) {
TestPart testPart = (TestPart) uobject;
if (testPart.getParent().getTestParts().size() == 1) {
showWarning("error.cannot.delete");
}
String msg = translate("delete.testPart");
confirmDeleteCtrl = activateYesNoDialog(ureq, translate("tools.change.delete"), msg, confirmDeleteCtrl);
confirmDeleteCtrl.setUserObject(selectedNode);
} else {
String msg;
if (uobject instanceof AssessmentSection) {
AssessmentSection section = (AssessmentSection) uobject;
if (checkAtLeastOneSection(section)) {
msg = translate("delete.section", selectedNode.getTitle());
} else {
showWarning("warning.atleastonesection");
return;
}
} else if (uobject instanceof AssessmentItemRef) {
msg = translate("delete.item", selectedNode.getTitle());
} else {
showError("error.cannot.delete");
return;
}
confirmDeleteCtrl = activateYesNoDialog(ureq, translate("tools.change.delete"), msg, confirmDeleteCtrl);
confirmDeleteCtrl.setUserObject(selectedNode);
}
}
use of uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection in project OpenOLAT by OpenOLAT.
the class AssessmentTestComposerController method doInsert.
private void doInsert(UserRequest ureq, List<QuestionItemView> items) {
TreeNode selectedNode = menuTree.getSelectedNode();
TreeNode sectionNode = getNearestSection(selectedNode);
boolean allOk = true;
String firstItemId = null;
Map<AssessmentItemRef, AssessmentItem> flyingObjects = new HashMap<>();
try {
AssessmentSection section = (AssessmentSection) sectionNode.getUserObject();
for (QuestionItemView item : items) {
QuestionItemFull qItem = qti21QPoolServiceProvider.getFullQuestionItem(item);
AssessmentItem assessmentItem = qti21QPoolServiceProvider.exportToQTIEditor(qItem, getLocale(), unzippedDirRoot);
if (assessmentItem != null) {
AssessmentItemRef itemRef = doInsert(section, assessmentItem);
if (firstItemId == null) {
firstItemId = itemRef.getIdentifier().toString();
}
flyingObjects.put(itemRef, assessmentItem);
ManifestMetadataBuilder metadata = manifestBuilder.getResourceBuilderByHref(itemRef.getHref().toString());
metadata.appendMetadataFrom(qItem, assessmentItem, getLocale());
metadata.setOpenOLATMetadataCopiedAt(new Date());
} else {
allOk &= false;
}
}
} catch (IOException | URISyntaxException e) {
showError("error.import.question");
logError("", e);
}
if (!allOk) {
showError("error.import.question");
}
if (firstItemId != null) {
// persist metadata
doSaveAssessmentTest(ureq, flyingObjects);
doSaveManifest();
updateTreeModel(false);
TreeNode newItemNode = menuTree.getTreeModel().getNodeById(firstItemId);
menuTree.setSelectedNode(newItemNode);
menuTree.open(newItemNode);
partEditorFactory(ureq, newItemNode);
}
}
use of uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection in project OpenOLAT by OpenOLAT.
the class AssessmentTestComposerController method doNewAssessmentItem.
/**
* The method create a simple single choice, save the assessment item
* and append it to the test, update the manifest file.
*
* @param ureq
* @param selectedNode
*/
private void doNewAssessmentItem(UserRequest ureq, TreeNode selectedNode, AssessmentItemBuilder itemBuilder) {
try {
TreeNode sectionNode = getNearestSection(selectedNode);
AssessmentSection section = (AssessmentSection) sectionNode.getUserObject();
AssessmentItemRef itemRef = new AssessmentItemRef(section);
String itemId = IdentifierGenerator.newAsString(itemBuilder.getQuestionType().getPrefix());
itemRef.setIdentifier(Identifier.parseString(itemId));
File itemFile = new File(unzippedDirRoot, itemId + ".xml");
itemRef.setHref(new URI(itemFile.getName()));
section.getSectionParts().add(itemRef);
AssessmentItem assessmentItem = itemBuilder.getAssessmentItem();
qtiService.persistAssessmentObject(itemFile, assessmentItem);
Map<AssessmentItemRef, AssessmentItem> flyingObjects = Collections.singletonMap(itemRef, assessmentItem);
doSaveAssessmentTest(ureq, flyingObjects);
manifestBuilder.appendAssessmentItem(itemFile.getName());
doSaveManifest();
updateTreeModel(false);
TreeNode newItemNode = menuTree.getTreeModel().getNodeById(itemId);
menuTree.setSelectedNode(newItemNode);
menuTree.open(newItemNode);
partEditorFactory(ureq, newItemNode);
} catch (URISyntaxException e) {
logError("", e);
}
}
Aggregations