use of uk.ac.ed.ph.jqtiplus.node.test.TestPart in project OpenOLAT by OpenOLAT.
the class AssessmentTestHelper method getParentSection.
public static ParentPartItemRefs getParentSection(TestPlanNodeKey itemKey, TestSessionState testSessionState, ResolvedAssessmentTest resolvedAssessmentTest) {
ParentPartItemRefs parentParts = new ParentPartItemRefs();
try {
TestPlanNode currentItem = testSessionState.getTestPlan().getNode(itemKey);
List<AssessmentItemRef> itemRefs = resolvedAssessmentTest.getItemRefsBySystemIdMap().get(currentItem.getItemSystemId());
AssessmentItemRef itemRef = null;
if (itemRefs.size() == 1) {
itemRef = itemRefs.get(0);
} else {
Identifier itemId = itemKey.getIdentifier();
for (AssessmentItemRef ref : itemRefs) {
if (ref.getIdentifier().equals(itemId)) {
itemRef = ref;
break;
}
}
}
if (itemRef != null) {
for (QtiNode parentPart = itemRef.getParent(); parentPart != null; parentPart = parentPart.getParent()) {
if (parentParts.getSectionIdentifier() == null && parentPart instanceof AssessmentSection) {
AssessmentSection section = (AssessmentSection) parentPart;
parentParts.setSectionIdentifier(section.getIdentifier().toString());
} else if (parentParts.getTestPartIdentifier() == null && parentPart instanceof TestPart) {
TestPart testPart = (TestPart) parentPart;
parentParts.setTestPartIdentifier(testPart.getIdentifier().toString());
}
}
}
} catch (Exception e) {
log.error("", e);
}
return parentParts;
}
use of uk.ac.ed.ph.jqtiplus.node.test.TestPart in project OpenOLAT by OpenOLAT.
the class QTI21ArchiveFormat method getItemInfos.
private List<AbstractInfos> getItemInfos() {
if (elementInfos == null) {
numOfSections = 0;
elementInfos = new ArrayList<>();
AssessmentTest assessmentTest = resolvedAssessmentTest.getRootNodeLookup().extractAssumingSuccessful();
for (TestPart part : assessmentTest.getTestParts()) {
for (AssessmentSection section : part.getAssessmentSections()) {
collectElementInfos(section);
}
}
}
return elementInfos;
}
use of uk.ac.ed.ph.jqtiplus.node.test.TestPart 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.TestPart in project OpenOLAT by OpenOLAT.
the class AssessmentTestComposerController method doDelete.
private void doDelete(UserRequest ureq, TreeNode selectedNode) {
Object uobject = selectedNode.getUserObject();
if (uobject instanceof TestPart) {
doDeleteTestPart(ureq, (TestPart) uobject);
} else if (uobject instanceof AssessmentSection) {
AssessmentSection section = (AssessmentSection) uobject;
if (checkAtLeastOneSection(section)) {
doDeleteAssessmentSection(ureq, section);
} else {
showWarning("warning.atleastonesection");
}
} else if (uobject instanceof AssessmentItemRef) {
doDeleteAssessmentItemRef(ureq, (AssessmentItemRef) uobject);
} else {
// cannot delete test or test part
return;
}
doSaveAssessmentTest(ureq, null);
doSaveManifest();
updateTreeModel(false);
if (selectedNode != null && selectedNode.getParent() != null) {
TreeNode parentNode = (TreeNode) selectedNode.getParent();
menuTree.setSelectedNode(parentNode);
menuTree.open(parentNode);
partEditorFactory(ureq, parentNode);
}
}
use of uk.ac.ed.ph.jqtiplus.node.test.TestPart in project OpenOLAT by OpenOLAT.
the class AssessmentTestComposerController method doDrop.
private void doDrop(UserRequest ureq, String droppedNodeId, String targetnodeId, boolean asChild) {
TreeNode droppedNode = menuTree.getTreeModel().getNodeById(droppedNodeId);
TreeNode targetNode = menuTree.getTreeModel().getNodeById(targetnodeId);
if (droppedNode == null || targetNode == null)
return;
Object droppedObject = droppedNode.getUserObject();
Object targetObject = targetNode.getUserObject();
if (droppedObject == null || targetObject == null || droppedObject == targetObject)
return;
if (asChild) {
if (droppedObject instanceof AssessmentItemRef && (targetObject instanceof AssessmentSection || targetObject instanceof AssessmentItemRef)) {
AssessmentItemRef droppedItemRef = (AssessmentItemRef) droppedObject;
droppedItemRef.getParentSection().getSectionParts().remove(droppedItemRef);
if (targetObject instanceof AssessmentSection) {
AssessmentSection targetSection = (AssessmentSection) targetObject;
targetSection.getSectionParts().add(droppedItemRef);
} else if (targetObject instanceof AssessmentItemRef) {
AssessmentItemRef targetItemRef = (AssessmentItemRef) targetObject;
AssessmentSection targetSection = targetItemRef.getParentSection();
int pos = targetSection.getChildAbstractParts().indexOf(targetItemRef);
targetSection.getChildAbstractParts().add(pos, droppedItemRef);
}
} else if (droppedObject instanceof AssessmentSection && (targetObject instanceof AssessmentSection || targetObject instanceof TestPart || (targetObject instanceof AssessmentTest && ((AssessmentTest) targetObject).getTestParts().size() == 1))) {
AssessmentSection droppedSection = (AssessmentSection) droppedObject;
if (droppedSection.getParentSection() != null) {
droppedSection.getParentSection().getSectionParts().remove(droppedSection);
} else {
droppedSection.getParent().getChildAbstractParts().remove(droppedSection);
}
if (targetObject instanceof AssessmentSection) {
AssessmentSection targetSection = (AssessmentSection) targetObject;
targetSection.getChildAbstractParts().add(droppedSection);
} else if (targetObject instanceof TestPart) {
TestPart targetTestPart = (TestPart) targetObject;
targetTestPart.getAssessmentSections().add(droppedSection);
} else if (targetObject instanceof AssessmentTest) {
TestPart targetTestPart = ((AssessmentTest) targetObject).getTestParts().get(0);
targetTestPart.getAssessmentSections().add(droppedSection);
}
}
} else {
if (droppedObject instanceof AssessmentItemRef && targetObject instanceof AssessmentItemRef) {
AssessmentItemRef droppedItemRef = (AssessmentItemRef) droppedObject;
droppedItemRef.getParentSection().getSectionParts().remove(droppedItemRef);
AssessmentItemRef targetItemRef = (AssessmentItemRef) targetObject;
AssessmentSection targetSection = targetItemRef.getParentSection();
int pos = targetSection.getChildAbstractParts().indexOf(targetItemRef) + 1;
if (pos < 0) {
targetSection.getChildAbstractParts().add(droppedItemRef);
} else if (pos >= targetSection.getChildAbstractParts().size()) {
targetSection.getChildAbstractParts().add(droppedItemRef);
} else {
targetSection.getChildAbstractParts().add(pos, droppedItemRef);
}
} else if (droppedObject instanceof AssessmentSection && targetObject instanceof AssessmentSection) {
AssessmentSection droppedSection = (AssessmentSection) droppedObject;
if (droppedSection.getParentSection() != null) {
droppedSection.getParentSection().getSectionParts().remove(droppedSection);
} else {
droppedSection.getParent().getChildAbstractParts().remove(droppedSection);
}
AssessmentSection targetSection = (AssessmentSection) targetObject;
if (targetSection.getParentSection() != null) {
AssessmentSection targetParentSection = targetSection.getParentSection();
int pos = targetParentSection.getChildAbstractParts().indexOf(targetSection) + 1;
if (pos >= targetParentSection.getChildAbstractParts().size()) {
targetParentSection.getChildAbstractParts().add(droppedSection);
} else {
targetParentSection.getChildAbstractParts().add(pos, droppedSection);
}
} else if (targetSection.getParent() instanceof TestPart) {
TestPart targetTestPart = (TestPart) targetSection.getParent();
int pos = targetTestPart.getChildAbstractParts().indexOf(targetSection) + 1;
if (pos >= targetTestPart.getChildAbstractParts().size()) {
targetTestPart.getChildAbstractParts().add(droppedSection);
} else {
targetTestPart.getChildAbstractParts().add(pos, droppedSection);
}
}
}
}
// quickly saved the assessment test with wrong parent
doSaveAssessmentTest(ureq, null);
// reload a clean instance
updateTreeModel(false);
TreeNode droppedItemNode = menuTree.getTreeModel().getNodeById(droppedNode.getIdent());
if (droppedItemNode != null) {
menuTree.setSelectedNode(droppedItemNode);
menuTree.open(droppedItemNode);
partEditorFactory(ureq, droppedItemNode);
}
}
Aggregations