use of uk.ac.ed.ph.jqtiplus.state.TestSessionState in project OpenOLAT by OpenOLAT.
the class AssessmentTestDisplayController method processExitTestAfterTimeLimit.
private void processExitTestAfterTimeLimit(UserRequest ureq) {
synchronized (testSessionController) {
// make sure the ajax call and a user click don't close both the session
NotificationRecorder notificationRecorder = new NotificationRecorder(NotificationLevel.INFO);
TestSessionState testSessionState = testSessionController.getTestSessionState();
if (testSessionState.isEnded() || testSessionState.isExited())
return;
// close duration
testSessionController.touchDurations(currentRequestTimestamp);
final Date requestTimestamp = ureq.getRequestTimestamp();
testSessionController.exitTestIncomplete(requestTimestamp);
candidateSession.setTerminationTime(requestTimestamp);
// Record current result state
final AssessmentResult assessmentResult = computeAndRecordTestAssessmentResult(requestTimestamp, testSessionState, true);
candidateSession = qtiService.finishTestSession(candidateSession, testSessionState, assessmentResult, requestTimestamp, getDigitalSignatureOptions(), getIdentity());
qtiWorksCtrl.updateStatusAndResults(ureq);
/* Record and log event */
final CandidateEvent candidateTestEvent = qtiService.recordCandidateTestEvent(candidateSession, testEntry, entry, CandidateTestEventType.EXIT_DUE_TIME_LIMIT, testSessionState, notificationRecorder);
candidateAuditLogger.logCandidateEvent(candidateTestEvent);
this.lastEvent = candidateTestEvent;
}
doExitTest(ureq);
}
use of uk.ac.ed.ph.jqtiplus.state.TestSessionState in project OpenOLAT by OpenOLAT.
the class AssessmentTestDisplayController method processItemSolution.
private void processItemSolution(UserRequest ureq, String key) {
TestPlanNodeKey itemKey = TestPlanNodeKey.fromString(key);
NotificationRecorder notificationRecorder = new NotificationRecorder(NotificationLevel.INFO);
TestSessionState testSessionState = testSessionController.getTestSessionState();
// assertSessionNotTerminated(candidateSession);
try {
if (!testSessionController.mayAccessItemSolution(itemKey)) {
candidateAuditLogger.logAndThrowCandidateException(candidateSession, CandidateExceptionReason.CANNOT_SOLUTION_TEST_ITEM, null);
logError("CANNOT_SOLUTION_TEST_ITEM", null);
return;
}
} catch (final QtiCandidateStateException e) {
candidateAuditLogger.logAndThrowCandidateException(candidateSession, CandidateExceptionReason.CANNOT_SOLUTION_TEST_ITEM, e);
logError("CANNOT_SOLUTION_TEST_ITEM", e);
return;
} catch (final RuntimeException e) {
candidateAuditLogger.logAndThrowCandidateException(candidateSession, CandidateExceptionReason.CANNOT_SOLUTION_TEST_ITEM, e);
logError("Exploded", e);
// handleExplosion(e, candidateSession);
return;
}
/* Record current result state */
computeAndRecordTestAssessmentResult(ureq.getRequestTimestamp(), testSessionState, false);
/* Record and log event */
CandidateEvent candidateTestEvent = qtiService.recordCandidateTestEvent(candidateSession, testEntry, entry, CandidateTestEventType.SOLUTION_ITEM, null, itemKey, testSessionState, notificationRecorder);
this.lastEvent = candidateTestEvent;
candidateAuditLogger.logCandidateEvent(candidateTestEvent);
}
use of uk.ac.ed.ph.jqtiplus.state.TestSessionState in project OpenOLAT by OpenOLAT.
the class AssessmentTestDisplayController method processReviewItem.
private void processReviewItem(UserRequest ureq, String key) {
TestPlanNodeKey itemKey = TestPlanNodeKey.fromString(key);
// Assert.notNull(itemKey, "itemKey");
NotificationRecorder notificationRecorder = new NotificationRecorder(NotificationLevel.INFO);
TestSessionState testSessionState = testSessionController.getTestSessionState();
// assertSessionNotTerminated(candidateSession);
try {
if (!testSessionController.mayReviewItem(itemKey)) {
logError("CANNOT_REVIEW_TEST_ITEM", null);
candidateAuditLogger.logAndThrowCandidateException(candidateSession, CandidateExceptionReason.CANNOT_REVIEW_TEST_ITEM, null);
return;
}
} catch (final QtiCandidateStateException e) {
logError("CANNOT_REVIEW_TEST_ITEM", e);
candidateAuditLogger.logAndThrowCandidateException(candidateSession, CandidateExceptionReason.CANNOT_REVIEW_TEST_ITEM, e);
return;
} catch (final RuntimeException e) {
candidateAuditLogger.logAndThrowCandidateException(candidateSession, CandidateExceptionReason.CANNOT_REVIEW_TEST_ITEM, e);
logError("CANNOT_REVIEW_TEST_ITEM", e);
// handleExplosion(e, candidateSession);
return;
}
/* Record current result state */
computeAndRecordTestAssessmentResult(ureq.getRequestTimestamp(), testSessionState, false);
/* Record and log event */
final CandidateEvent candidateTestEvent = qtiService.recordCandidateTestEvent(candidateSession, testEntry, entry, CandidateTestEventType.REVIEW_ITEM, null, itemKey, testSessionState, notificationRecorder);
this.lastEvent = candidateTestEvent;
candidateAuditLogger.logCandidateEvent(candidateTestEvent);
}
use of uk.ac.ed.ph.jqtiplus.state.TestSessionState in project OpenOLAT by OpenOLAT.
the class AssessmentTestDisplayController method processExitTest.
/**
* Exit multi-part tests
*/
private void processExitTest(UserRequest ureq) {
NotificationRecorder notificationRecorder = new NotificationRecorder(NotificationLevel.INFO);
TestSessionState testSessionState = testSessionController.getTestSessionState();
/* Perform action */
final Date currentTimestamp = ureq.getRequestTimestamp();
try {
testSessionController.exitTest(currentTimestamp);
} catch (final QtiCandidateStateException e) {
candidateAuditLogger.logAndThrowCandidateException(candidateSession, CandidateExceptionReason.CANNOT_EXIT_TEST, e);
logError("CANNOT_EXIT_TEST", null);
return;
} catch (final RuntimeException e) {
candidateAuditLogger.logAndThrowCandidateException(candidateSession, CandidateExceptionReason.CANNOT_EXIT_TEST, e);
logError("Exploded", null);
// handleExplosion(e, candidateSession);
return;
}
/* Update CandidateSession as appropriate */
candidateSession.setTerminationTime(currentTimestamp);
candidateSession = qtiService.updateAssessmentTestSession(candidateSession);
/* Record current result state (final) */
computeAndRecordTestAssessmentResult(currentTimestamp, testSessionState, true);
/* Record and log event */
final CandidateEvent candidateTestEvent = qtiService.recordCandidateTestEvent(candidateSession, testEntry, entry, CandidateTestEventType.EXIT_TEST, testSessionState, notificationRecorder);
candidateAuditLogger.logCandidateEvent(candidateTestEvent);
this.lastEvent = candidateTestEvent;
doExitTest(ureq);
}
use of uk.ac.ed.ph.jqtiplus.state.TestSessionState in project OpenOLAT by OpenOLAT.
the class AssessmentTestDisplayController method handleTemporaryResponse.
private void handleTemporaryResponse(UserRequest ureq, Map<Identifier, ResponseInput> stringResponseMap) {
NotificationRecorder notificationRecorder = new NotificationRecorder(NotificationLevel.INFO);
TestSessionState testSessionState = testSessionController.getTestSessionState();
TestPlanNodeKey currentItemKey = testSessionState.getCurrentItemKey();
if (currentItemKey == null) {
//
return;
}
String cmd = ureq.getParameter("tmpResponse");
if (!qtiWorksCtrl.validateResponseIdentifierCommand(cmd, currentItemKey)) {
// this is not the right node in the plan
return;
}
final Date timestamp = ureq.getRequestTimestamp();
final Map<Identifier, ResponseData> responseDataMap = new HashMap<>();
if (stringResponseMap != null) {
for (final Entry<Identifier, ResponseInput> responseEntry : stringResponseMap.entrySet()) {
final Identifier identifier = responseEntry.getKey();
final ResponseInput responseData = responseEntry.getValue();
if (responseData instanceof StringInput) {
responseDataMap.put(identifier, new StringResponseData(((StringInput) responseData).getResponseData()));
}
}
}
ParentPartItemRefs parentParts = getParentSection(currentItemKey);
String assessmentItemIdentifier = currentItemKey.getIdentifier().toString();
AssessmentItemSession itemSession = qtiService.getOrCreateAssessmentItemSession(candidateSession, parentParts, assessmentItemIdentifier);
TestPlanNode currentItemRefNode = testSessionState.getTestPlan().getNode(currentItemKey);
ItemSessionController itemSessionController = (ItemSessionController) testSessionController.getItemProcessingContext(currentItemRefNode);
ItemSessionState itemSessionState = itemSessionController.getItemSessionState();
List<Interaction> interactions = itemSessionController.getInteractions();
Map<Identifier, Interaction> interactionMap = new HashMap<>();
for (Interaction interaction : interactions) {
interactionMap.put(interaction.getResponseIdentifier(), interaction);
}
Map<Identifier, AssessmentResponse> candidateResponseMap = qtiService.getAssessmentResponses(itemSession);
for (Entry<Identifier, ResponseData> responseEntry : responseDataMap.entrySet()) {
Identifier responseIdentifier = responseEntry.getKey();
ResponseData responseData = responseEntry.getValue();
AssessmentResponse candidateItemResponse;
if (candidateResponseMap.containsKey(responseIdentifier)) {
candidateItemResponse = candidateResponseMap.get(responseIdentifier);
} else {
candidateItemResponse = qtiService.createAssessmentResponse(candidateSession, itemSession, responseIdentifier.toString(), ResponseLegality.VALID, responseData.getType());
}
switch(responseData.getType()) {
case STRING:
{
List<String> data = ((StringResponseData) responseData).getResponseData();
String stringuifiedResponse = ResponseFormater.format(data);
candidateItemResponse.setStringuifiedResponse(stringuifiedResponse);
break;
}
default:
throw new OLATRuntimeException("Unexpected switch case: " + responseData.getType());
}
candidateResponseMap.put(responseIdentifier, candidateItemResponse);
itemSessionState.setRawResponseData(responseIdentifier, responseData);
try {
Interaction interaction = interactionMap.get(responseIdentifier);
interaction.bindResponse(itemSessionController, responseData);
} catch (final ResponseBindingException e) {
//
}
}
/* Copy uncommitted responses over */
for (final Entry<Identifier, Value> uncommittedResponseEntry : itemSessionState.getUncommittedResponseValues().entrySet()) {
final Identifier identifier = uncommittedResponseEntry.getKey();
final Value value = uncommittedResponseEntry.getValue();
itemSessionState.setResponseValue(identifier, value);
}
/* Persist CandidateResponse entities */
qtiService.recordTestAssessmentResponses(itemSession, candidateResponseMap.values());
/* Record resulting event */
final CandidateEvent candidateEvent = qtiService.recordCandidateTestEvent(candidateSession, testEntry, entry, CandidateTestEventType.ITEM_EVENT, null, currentItemKey, testSessionState, notificationRecorder);
candidateAuditLogger.logCandidateEvent(candidateEvent, candidateResponseMap);
/* Record current result state */
AssessmentResult assessmentResult = computeTestAssessmentResult(timestamp, candidateSession);
synchronized (this) {
qtiService.recordTestAssessmentResult(candidateSession, testSessionState, assessmentResult, candidateAuditLogger);
}
}
Aggregations