use of uk.ac.ed.ph.jqtiplus.state.TestPlanNode 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.state.TestPlanNode in project OpenOLAT by OpenOLAT.
the class AssessmentTreeComponentRenderer method renderNavigation.
private void renderNavigation(AssessmentRenderer renderer, StringOutput sb, AssessmentTreeComponent component, URLBuilder ubu, Translator translator, RenderingRequest options) {
sb.append("<div id='o_qti_menu' class='qtiworks o_assessmenttest o_testpartnavigation o_qti_menu_menustyle'>");
// part, sections and item refs
TestPlanNode currentTestPartNode = component.getCurrentTestPartNode();
if (currentTestPartNode != null) {
sb.append("<ul class='o_testpartnavigation list-unstyled'>");
currentTestPartNode.getChildren().forEach((node) -> renderNavigation(renderer, sb, component, node, ubu, translator, options));
sb.append("</ul>");
}
sb.append("</div>");
}
use of uk.ac.ed.ph.jqtiplus.state.TestPlanNode in project OpenOLAT by OpenOLAT.
the class QTI21ServiceImpl method reopenTestPart.
private TestPlanNodeKey reopenTestPart(TestPlanNode lastItem, TestSessionState testSessionState) {
TestPlan plan = testSessionState.getTestPlan();
List<TestPlanNode> testPartNodes = lastItem.searchAncestors(TestNodeType.TEST_PART);
if (testPartNodes.isEmpty()) {
return null;
}
// reopen the test part of the selected item
TestPlanNode partNode = testPartNodes.get(0);
TestPlanNodeKey partKey = partNode.getKey();
TestPartSessionState partState = testSessionState.getTestPartSessionStates().get(partKey);
partState.setEndTime(null);
partState.setExitTime(null);
// reopen all sections the test part
for (Map.Entry<TestPlanNodeKey, AssessmentSectionSessionState> sectionEntry : testSessionState.getAssessmentSectionSessionStates().entrySet()) {
TestPlanNodeKey sectionKey = sectionEntry.getKey();
TestPlanNode sectionNode = plan.getNode(sectionKey);
if (sectionNode.hasAncestor(partNode)) {
AssessmentSectionSessionState sectionState = sectionEntry.getValue();
sectionState.setEndTime(null);
sectionState.setExitTime(null);
}
}
// reopen all items the test part
for (Map.Entry<TestPlanNodeKey, ItemSessionState> itemEntry : testSessionState.getItemSessionStates().entrySet()) {
TestPlanNodeKey itemKey = itemEntry.getKey();
TestPlanNode itemNode = plan.getNode(itemKey);
if (itemNode.hasAncestor(partNode)) {
ItemSessionState itemState = itemEntry.getValue();
itemState.setEndTime(null);
itemState.setExitTime(null);
}
}
return partKey;
}
use of uk.ac.ed.ph.jqtiplus.state.TestPlanNode in project OpenOLAT by OpenOLAT.
the class QTI21ServiceImpl method reopenAssessmentTestSession.
/*
@Override
public AssessmentTestSession reopenAssessmentTestSession(AssessmentTestSession session, Identity actor) {
// update test session on the database
AssessmentTestSession reloadedSession = testSessionDao.loadByKey(session.getKey());
//update the XMl test session state
TestSessionState testSessionState = loadTestSessionState(reloadedSession);
testSessionState.setEndTime(null);
testSessionState.setExitTime(null);
for(TestPartSessionState testPartSessionState:testSessionState.getTestPartSessionStates().values()) {
testPartSessionState.setEndTime(null);
testPartSessionState.setExitTime(null);
}
for(AssessmentSectionSessionState sessionState:testSessionState.getAssessmentSectionSessionStates().values()) {
sessionState.setEndTime(null);
sessionState.setExitTime(null);
}
TestPlanNodeKey lastEntryItemKey = null;
ItemSessionState lastEntryItemSessionState = null;
for(Map.Entry<TestPlanNodeKey, ItemSessionState> entry:testSessionState.getItemSessionStates().entrySet()) {
ItemSessionState itemSessionState = entry.getValue();
itemSessionState.setEndTime(null);
itemSessionState.setExitTime(null);
if(itemSessionState.getEntryTime() != null &&
(lastEntryItemSessionState == null || itemSessionState.getEntryTime().after(lastEntryItemSessionState.getEntryTime()))) {
lastEntryItemKey = entry.getKey();
lastEntryItemSessionState = itemSessionState;
}
}
if(lastEntryItemKey != null) {
Date now = new Date();
TestPlan plan = testSessionState.getTestPlan();
TestPlanNodeKey currentTestPartKey = null;
for(TestPlanNode currentNode = plan.getNode(lastEntryItemKey); currentNode != null; currentNode = currentNode.getParent()) {
TestNodeType type = currentNode.getTestNodeType();
TestPlanNodeKey currentNodeKey = currentNode.getKey();
switch(type) {
case TEST_PART: {
currentTestPartKey = currentNodeKey;
TestPartSessionState state = testSessionState.getTestPartSessionStates().get(currentNodeKey);
if(state != null) {
state.setDurationIntervalStartTime(now);
}
break;
}
case ASSESSMENT_SECTION: {
AssessmentSectionSessionState sessionState = testSessionState.getAssessmentSectionSessionStates().get(currentNodeKey);
if(sessionState != null) {
sessionState.setDurationIntervalStartTime(now);
}
break;
}
case ASSESSMENT_ITEM_REF: {
ItemSessionState itemState = testSessionState.getItemSessionStates().get(currentNodeKey);
if(itemState != null) {
itemState.setDurationIntervalStartTime(now);
}
break;
}
default: {
//root doesn't match any session state
break;
}
}
}
//if all the elements are started again, allow to reopen the test
if(currentTestPartKey != null) {
testSessionState.setCurrentTestPartKey(currentTestPartKey);
testSessionState.setCurrentItemKey(lastEntryItemKey);
storeTestSessionState(reloadedSession, testSessionState);
reloadedSession.setFinishTime(null);
reloadedSession.setTerminationTime(null);
reloadedSession = testSessionDao.update(reloadedSession);
AssessmentSessionAuditLogger candidateAuditLogger = getAssessmentSessionAuditLogger(session, false);
candidateAuditLogger.logTestReopen(session, actor);
RetrieveAssessmentTestSessionEvent event = new RetrieveAssessmentTestSessionEvent(session.getKey());
OLATResourceable sessionOres = OresHelper.createOLATResourceableInstance(AssessmentTestSession.class, session.getKey());
coordinatorManager.getCoordinator().getEventBus().fireEventToListenersOf(event, sessionOres);
return reloadedSession;
}
}
return null;
}*/
@Override
public AssessmentTestSession reopenAssessmentTestSession(AssessmentTestSession session, Identity actor) {
AssessmentTestSession reloadedSession = testSessionDao.loadByKey(session.getKey());
// update the XMl test session state
TestSessionState testSessionState = loadTestSessionState(reloadedSession);
testSessionState.setEndTime(null);
testSessionState.setExitTime(null);
TestPlanNodeKey lastEntryItemKey = null;
ItemSessionState lastEntryItemSessionState = null;
for (Map.Entry<TestPlanNodeKey, ItemSessionState> entry : testSessionState.getItemSessionStates().entrySet()) {
ItemSessionState itemSessionState = entry.getValue();
if (itemSessionState.getEntryTime() != null && (lastEntryItemSessionState == null || itemSessionState.getEntryTime().after(lastEntryItemSessionState.getEntryTime()))) {
lastEntryItemKey = entry.getKey();
lastEntryItemSessionState = itemSessionState;
}
}
if (lastEntryItemKey != null) {
TestPlan plan = testSessionState.getTestPlan();
TestPlanNode lastItem = plan.getNode(lastEntryItemKey);
TestPlanNodeKey partKey = reopenTestPart(lastItem, testSessionState);
resumeItem(lastEntryItemKey, testSessionState);
// if all the elements are started again, allow to reopen the test
if (partKey != null) {
testSessionState.setCurrentTestPartKey(partKey);
testSessionState.setCurrentItemKey(lastEntryItemKey);
storeTestSessionState(reloadedSession, testSessionState);
reloadedSession.setFinishTime(null);
reloadedSession.setTerminationTime(null);
reloadedSession = testSessionDao.update(reloadedSession);
AssessmentSessionAuditLogger candidateAuditLogger = getAssessmentSessionAuditLogger(session, false);
candidateAuditLogger.logTestReopen(session, actor);
RetrieveAssessmentTestSessionEvent event = new RetrieveAssessmentTestSessionEvent(session.getKey());
OLATResourceable sessionOres = OresHelper.createOLATResourceableInstance(AssessmentTestSession.class, session.getKey());
coordinatorManager.getCoordinator().getEventBus().fireEventToListenersOf(event, sessionOres);
return reloadedSession;
}
}
return null;
}
use of uk.ac.ed.ph.jqtiplus.state.TestPlanNode in project OpenOLAT by OpenOLAT.
the class AssessmentTestDisplayController method processAdvanceTestPart.
private void processAdvanceTestPart(UserRequest ureq) {
/* Get current JQTI state and create JQTI controller */
NotificationRecorder notificationRecorder = new NotificationRecorder(NotificationLevel.INFO);
TestSessionState testSessionState = testSessionController.getTestSessionState();
/* Perform action */
final TestPlanNode nextTestPart;
final Date currentTimestamp = ureq.getRequestTimestamp();
try {
nextTestPart = testSessionController.enterNextAvailableTestPart(currentTimestamp);
} catch (final QtiCandidateStateException e) {
candidateAuditLogger.logAndThrowCandidateException(candidateSession, CandidateExceptionReason.CANNOT_ADVANCE_TEST_PART, e);
logError("CANNOT_ADVANCE_TEST_PART", e);
return;
} catch (final RuntimeException e) {
candidateAuditLogger.logAndThrowCandidateException(candidateSession, CandidateExceptionReason.CANNOT_ADVANCE_TEST_PART, e);
logError("RuntimeException", e);
// handleExplosion(e, candidateSession);
return;
}
CandidateTestEventType eventType;
if (nextTestPart != null) {
/* Moved into next test part */
eventType = CandidateTestEventType.ADVANCE_TEST_PART;
} else {
/* No more test parts.
*
* For single part tests, we terminate the test completely now as the test feedback was shown with the testPart feedback.
* For multi-part tests, we shall keep the test open so that the test feedback can be viewed.
*/
if (testSessionState.getTestPlan().getTestPartNodes().size() == 1) {
eventType = CandidateTestEventType.EXIT_TEST;
testSessionController.exitTest(currentTimestamp);
candidateSession.setTerminationTime(currentTimestamp);
candidateSession = qtiService.updateAssessmentTestSession(candidateSession);
} else {
eventType = CandidateTestEventType.ADVANCE_TEST_PART;
}
}
boolean terminated = isTerminated();
/* Record current result state */
computeAndRecordTestAssessmentResult(currentTimestamp, testSessionState, terminated);
/* Record and log event */
final CandidateEvent candidateTestEvent = qtiService.recordCandidateTestEvent(candidateSession, testEntry, entry, eventType, testSessionState, notificationRecorder);
candidateAuditLogger.logCandidateEvent(candidateTestEvent);
this.lastEvent = candidateTestEvent;
if (terminated) {
qtiWorksCtrl.updateStatusAndResults(ureq);
doExitTest(ureq);
}
}
Aggregations