use of uk.ac.ed.ph.jqtiplus.state.TestSessionState in project openolat by klemens.
the class AssessmentTestDisplayController method processEndTestPart.
// public CandidateSession endCurrentTestPart(final CandidateSessionContext candidateSessionContext)
private void processEndTestPart(UserRequest ureq) {
/* Update state */
final Date requestTimestamp = ureq.getRequestTimestamp();
testSessionController.endCurrentTestPart(requestTimestamp);
TestSessionState testSessionState = testSessionController.getTestSessionState();
TestPlanNode nextTestPart = testSessionController.findNextEnterableTestPart();
// Record current result state
final AssessmentResult assessmentResult = computeAndRecordTestAssessmentResult(requestTimestamp, testSessionState, nextTestPart == null);
if (nextTestPart == null) {
candidateSession = qtiService.finishTestSession(candidateSession, testSessionState, assessmentResult, requestTimestamp, getDigitalSignatureOptions(), getIdentity());
if (!qtiWorksCtrl.willShowSomeAssessmentTestFeedbacks()) {
// need feedback, no more parts, quickly exit
try {
// end current test part
testSessionController.enterNextAvailableTestPart(requestTimestamp);
} 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;
}
// exit the test
NotificationRecorder notificationRecorder = new NotificationRecorder(NotificationLevel.INFO);
CandidateTestEventType eventType = CandidateTestEventType.EXIT_TEST;
testSessionController.exitTest(requestTimestamp);
candidateSession.setTerminationTime(requestTimestamp);
candidateSession = qtiService.updateAssessmentTestSession(candidateSession);
/* Record and log event */
final CandidateEvent candidateTestEvent = qtiService.recordCandidateTestEvent(candidateSession, testEntry, entry, eventType, testSessionState, notificationRecorder);
candidateAuditLogger.logCandidateEvent(candidateTestEvent);
this.lastEvent = candidateTestEvent;
qtiWorksCtrl.updateStatusAndResults(ureq);
doExitTest(ureq);
}
} else if (!qtiWorksCtrl.willShowSomeTestPartFeedbacks()) {
// no feedback, go to the next part
processAdvanceTestPart(ureq);
}
}
use of uk.ac.ed.ph.jqtiplus.state.TestSessionState in project openolat by klemens.
the class AssessmentTestDisplayController method handleResponse.
// public CandidateSession handleResponses(final CandidateSessionContext candidateSessionContext,
// final Map<Identifier, StringResponseData> stringResponseMap,
// final Map<Identifier, MultipartFile> fileResponseMap,
// final String candidateComment)
private void handleResponse(UserRequest ureq, Map<Identifier, ResponseInput> stringResponseMap, Map<Identifier, ResponseInput> fileResponseMap, String candidateComment) {
NotificationRecorder notificationRecorder = new NotificationRecorder(NotificationLevel.INFO);
TestSessionState testSessionState = testSessionController.getTestSessionState();
TestPlanNodeKey currentItemKey = testSessionState.getCurrentItemKey();
if (currentItemKey == null && getLastEvent() != null && getLastEvent().getTestEventType() == CandidateTestEventType.REVIEW_ITEM) {
// someone try to send the form in review with tab / return
return;
}
if (!qtiWorksCtrl.validatePresentedItem(currentItemKey)) {
logError("Response send by browser doesn't match current item key", null);
ServletUtil.printOutRequestParameters(ureq.getHttpReq());
if (candidateSession != null && candidateSession.getFinishTime() != null) {
showWarning("error.test.closed");
} else {
showWarning("error.reload.question");
}
// this is not the right node in the plan
return;
}
final Map<Identifier, File> fileSubmissionMap = new HashMap<>();
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()));
} else if (responseData instanceof Base64Input) {
// only used from drawing interaction
Base64Input fileInput = (Base64Input) responseData;
String filename = "submitted_image.png";
File storedFile = qtiService.importFileSubmission(candidateSession, filename, fileInput.getResponseData());
responseDataMap.put(identifier, new FileResponseData(storedFile, fileInput.getContentType(), storedFile.getName()));
fileSubmissionMap.put(identifier, storedFile);
} else if (responseData instanceof FileInput) {
FileInput fileInput = (FileInput) responseData;
File storedFile = qtiService.importFileSubmission(candidateSession, fileInput.getMultipartFileInfos());
responseDataMap.put(identifier, new FileResponseData(storedFile, fileInput.getContentType(), storedFile.getName()));
fileSubmissionMap.put(identifier, storedFile);
}
}
}
ParentPartItemRefs parentParts = getParentSection(currentItemKey);
String assessmentItemIdentifier = currentItemKey.getIdentifier().toString();
AssessmentItemSession itemSession = qtiService.getOrCreateAssessmentItemSession(candidateSession, parentParts, assessmentItemIdentifier);
if (fileResponseMap != null) {
for (Entry<Identifier, ResponseInput> fileResponseEntry : fileResponseMap.entrySet()) {
Identifier identifier = fileResponseEntry.getKey();
FileInput multipartFile = (FileInput) fileResponseEntry.getValue();
if (!multipartFile.isEmpty()) {
File storedFile = qtiService.importFileSubmission(candidateSession, multipartFile.getMultipartFileInfos());
responseDataMap.put(identifier, new FileResponseData(storedFile, multipartFile.getContentType(), storedFile.getName()));
fileSubmissionMap.put(identifier, storedFile);
}
}
}
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;
}
case FILE:
{
if (fileSubmissionMap.get(responseIdentifier) != null) {
File storedFile = fileSubmissionMap.get(responseIdentifier);
candidateItemResponse.setStringuifiedResponse(storedFile.getName());
}
break;
}
default:
throw new OLATRuntimeException("Unexpected switch case: " + responseData.getType());
}
candidateResponseMap.put(responseIdentifier, candidateItemResponse);
}
boolean allResponsesValid = true;
boolean allResponsesBound = true;
final Date timestamp = ureq.getRequestTimestamp();
if (candidateComment != null) {
testSessionController.setCandidateCommentForCurrentItem(timestamp, candidateComment);
}
/* Attempt to bind responses (and maybe perform RP & OP) */
testSessionController.handleResponsesToCurrentItem(timestamp, responseDataMap);
/* Classify this event */
final SubmissionMode submissionMode = testSessionController.getCurrentTestPart().getSubmissionMode();
final CandidateItemEventType candidateItemEventType;
if (allResponsesValid) {
candidateItemEventType = submissionMode == SubmissionMode.INDIVIDUAL ? CandidateItemEventType.ATTEMPT_VALID : CandidateItemEventType.RESPONSE_VALID;
} else {
candidateItemEventType = allResponsesBound ? CandidateItemEventType.RESPONSE_INVALID : CandidateItemEventType.RESPONSE_BAD;
}
/* Record resulting event */
final CandidateEvent candidateEvent = qtiService.recordCandidateTestEvent(candidateSession, testEntry, entry, CandidateTestEventType.ITEM_EVENT, candidateItemEventType, currentItemKey, testSessionState, notificationRecorder);
candidateAuditLogger.logCandidateEvent(candidateEvent, candidateResponseMap);
this.lastEvent = candidateEvent;
/* Record current result state */
AssessmentResult assessmentResult = computeAndRecordTestAssessmentResult(timestamp, testSessionState, false);
ItemSessionState itemSessionState = testSessionState.getCurrentItemSessionState();
long itemDuration = itemSessionState.getDurationAccumulated();
itemSession.setDuration(itemDuration);
ItemResult itemResult = assessmentResult.getItemResult(assessmentItemIdentifier);
collectOutcomeVariablesForItemSession(itemResult, itemSession);
/* Persist CandidateResponse entities */
qtiService.recordTestAssessmentResponses(itemSession, candidateResponseMap.values());
/* Save any change to session state */
candidateSession = qtiService.updateAssessmentTestSession(candidateSession);
addToHistory(ureq, this);
checkConcurrentExit(ureq);
}
use of uk.ac.ed.ph.jqtiplus.state.TestSessionState in project openolat by klemens.
the class AssessmentTestDisplayController method suspendAssessmentTest.
/**
* It suspend the current item
* @return
*/
private boolean suspendAssessmentTest(Date requestTimestamp) {
if (!deliveryOptions.isEnableSuspend() || testSessionController == null || testSessionController.getTestSessionState() == null || testSessionController.getTestSessionState().isEnded() || testSessionController.getTestSessionState().isExited() || testSessionController.getTestSessionState().isSuspended()) {
return false;
}
testSessionController.touchDurations(currentRequestTimestamp);
testSessionController.suspendTestSession(requestTimestamp);
TestSessionState testSessionState = testSessionController.getTestSessionState();
TestPlanNodeKey currentItemKey = testSessionState.getCurrentItemKey();
if (currentItemKey == null) {
return false;
}
TestPlanNode currentItemNode = testSessionState.getTestPlan().getNode(currentItemKey);
ItemProcessingContext itemProcessingContext = testSessionController.getItemProcessingContext(currentItemNode);
ItemSessionState itemSessionState = itemProcessingContext.getItemSessionState();
if (itemProcessingContext instanceof ItemSessionController && !itemSessionState.isEnded() && !itemSessionState.isExited() && itemSessionState.isOpen() && !itemSessionState.isSuspended()) {
ItemSessionController itemSessionController = (ItemSessionController) itemProcessingContext;
itemSessionController.suspendItemSession(requestTimestamp);
computeAndRecordTestAssessmentResult(requestTimestamp, testSessionState, false);
NotificationRecorder notificationRecorder = new NotificationRecorder(NotificationLevel.INFO);
final CandidateEvent candidateEvent = qtiService.recordCandidateTestEvent(candidateSession, testEntry, entry, CandidateTestEventType.SUSPEND, null, null, testSessionState, notificationRecorder);
candidateAuditLogger.logCandidateEvent(candidateEvent);
this.lastEvent = candidateEvent;
return true;
}
return false;
}
use of uk.ac.ed.ph.jqtiplus.state.TestSessionState in project openolat by klemens.
the class AssessmentTestDisplayController method processNextItem.
private void processNextItem(UserRequest ureq) {
if (checkConcurrentExit(ureq)) {
return;
}
Date requestTimestamp = ureq.getRequestTimestamp();
if (testSessionController.hasFollowingNonLinearItem()) {
TestPlanNode selectedNode = testSessionController.selectFollowingItemNonLinear(requestTimestamp);
TestPlanNodeKey selectedNodeKey = (selectedNode == null ? null : selectedNode.getKey());
NotificationRecorder notificationRecorder = new NotificationRecorder(NotificationLevel.INFO);
TestSessionState testSessionState = testSessionController.getTestSessionState();
CandidateEvent candidateEvent = qtiService.recordCandidateTestEvent(candidateSession, testEntry, entry, CandidateTestEventType.NEXT_ITEM, null, selectedNodeKey, testSessionState, notificationRecorder);
candidateAuditLogger.logCandidateEvent(candidateEvent);
}
}
use of uk.ac.ed.ph.jqtiplus.state.TestSessionState in project openolat by klemens.
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;
}
Aggregations