use of uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef in project openolat by klemens.
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);
}
}
use of uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef in project openolat by klemens.
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.AssessmentItemRef in project openolat by klemens.
the class AssessmentTestComposerController method recalculateMaxScoreAssessmentTest.
private void recalculateMaxScoreAssessmentTest(Map<AssessmentItemRef, AssessmentItem> flyingObjects) {
DoubleAdder atomicMaxScore = new DoubleAdder();
AssessmentTest assessmentTest = (AssessmentTest) menuTree.getTreeModel().getRootNode().getUserObject();
AssessmentTestHelper.visit(assessmentTest, new AssessmentTestVisitor() {
@Override
public void visit(TestPart testPart) {
/* */
}
@Override
public void visit(SectionPart sectionPart) {
if (sectionPart instanceof AssessmentItemRef) {
AssessmentItemRef itemRef = (AssessmentItemRef) sectionPart;
ResolvedAssessmentItem resolvedAssessmentItem = resolvedAssessmentTest.getResolvedAssessmentItem(itemRef);
checkAndFixAbsolutePath(itemRef);
AssessmentItem assessmentItem = null;
if (resolvedAssessmentItem != null) {
assessmentItem = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
}
if (assessmentItem == null && flyingObjects != null && flyingObjects.containsKey(itemRef)) {
assessmentItem = flyingObjects.get(itemRef);
}
if (assessmentItem != null) {
Double maxScore = QtiNodesExtractor.extractMaxScore(assessmentItem);
if (maxScore != null) {
atomicMaxScore.add(maxScore.doubleValue());
}
}
}
}
});
double sumMaxScore = atomicMaxScore.sum();
if (sumMaxScore > 0.0d) {
assessmentTestBuilder.setMaxScore(sumMaxScore);
} else {
assessmentTestBuilder.setMaxScore(null);
}
}
use of uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef in project openolat by klemens.
the class CorrectionAssessmentItemListController method doSelect.
private void doSelect(UserRequest ureq, AssessmentItemListEntry listEntry, List<? extends AssessmentItemListEntry> selectedItemSessions) {
removeAsListenerAndDispose(identityItemCtrl);
doUnlock();
AssessmentItemRef itemRef = listEntry.getItemRef();
AssessmentItemSession reloadItemSession = null;
if (listEntry.getItemSession() != null) {
reloadItemSession = qtiService.getAssessmentItemSession(listEntry.getItemSession());
}
// lock on item, need to check the lock on identity / test
String lockSubKey = "item-" + listEntry.getAssessedIdentity().getKey() + "-" + listEntry.getItemRef().getIdentifier().toString();
OLATResourceable testOres = OresHelper.clone(model.getTestEntry().getOlatResource());
lockResult = CoordinatorManager.getInstance().getCoordinator().getLocker().acquireLock(testOres, getIdentity(), lockSubKey);
if (lockResult.isSuccess()) {
Identity assessedIdentity = listEntry.getAssessedIdentity();
AssessmentTestSession candidateSession = listEntry.getTestSession();
TestSessionState testSessionState = qtiService.loadTestSessionState(listEntry.getTestSession());
List<TestPlanNode> nodes = testSessionState.getTestPlan().getNodes(itemRef.getIdentifier());
if (nodes.size() == 1) {
TestPlanNode itemNode = nodes.get(0);
ItemSessionState itemSessionState = testSessionState.getItemSessionStates().get(itemNode.getKey());
AssessmentItemCorrection itemCorrection = new AssessmentItemCorrection(assessedIdentity, candidateSession, testSessionState, reloadItemSession, itemSessionState, itemRef, itemNode);
itemCorrection.setItemSession(reloadItemSession);
identityItemCtrl = new CorrectionIdentityAssessmentItemNavigationController(ureq, getWindowControl(), model.getTestEntry(), model.getResolvedAssessmentTest(), itemCorrection, listEntry, selectedItemSessions, model);
listenTo(identityItemCtrl);
updatePreviousNext();
stackPanel.pushController(listEntry.getLabel(), identityItemCtrl);
}
} else {
String lockOwnerName = userManager.getUserDisplayName(lockResult.getOwner());
showWarning("warning.assessment.item.locked", new String[] { lockOwnerName });
}
}
use of uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef in project openolat by klemens.
the class CorrectionAssessmentItemListController method doSelect.
private void doSelect(UserRequest ureq, CorrectionAssessmentItemRow row, Predicate<AssessmentItemListEntry> filter) {
removeAsListenerAndDispose(identityItemCtrl);
AssessmentItemRef itemRef = row.getItemRef();
String itemRefIdentifier = row.getItemRef().getIdentifier().toString();
List<AssessmentItemSession> allItemSessions = qtiService.getAssessmentItemSessions(model.getCourseEntry(), model.getSubIdent(), model.getTestEntry(), itemRefIdentifier);
Map<AssessmentTestSession, AssessmentItemSession> testToItemSession = new HashMap<>();
for (AssessmentItemSession itemSession : allItemSessions) {
AssessmentTestSession testSession = itemSession.getAssessmentTestSession();
testToItemSession.put(testSession, itemSession);
}
// reorder to match the list of identities
int count = 1;
List<Identity> assessedIdentities = model.getAssessedIdentities();
List<AssessmentItemListEntry> reorderItemSessions = new ArrayList<>(assessedIdentities.size());
for (Identity assessedIdentity : assessedIdentities) {
AssessmentTestSession testSession = model.getLastSessions().get(assessedIdentity);
if (testSession != null) {
AssessmentItemSession itemSession = testToItemSession.get(testSession);
String title;
if (anonymous) {
title = translate("number.assessed.identity", new String[] { Integer.toString(count++) });
} else {
title = userManager.getUserDisplayName(assessedIdentity);
}
AssessmentItemListEntry entry = new AssessmentItemListEntry(assessedIdentity, testSession, itemSession, itemRef, title, "o_icon_user");
if (filter.test(entry)) {
reorderItemSessions.add(entry);
}
}
}
if (!reorderItemSessions.isEmpty()) {
doSelect(ureq, reorderItemSessions.get(0), reorderItemSessions);
} else {
showWarning("waring.atleast.one");
}
}
Aggregations