use of uk.ac.ed.ph.jqtiplus.state.ItemSessionState in project OpenOLAT by OpenOLAT.
the class RunningItemHelper method run.
public static ItemSessionController run(URI inputUri, Map<Identifier, ResponseData> responseMap, ResourceLocator inputResourceLocator) {
SimpleJqtiFacade simpleJqtiFacade = new SimpleJqtiFacade();
ResolvedAssessmentItem resolvedAssessmentItem = simpleJqtiFacade.loadAndResolveAssessmentItem(inputResourceLocator, inputUri);
ItemProcessingMap itemProcessingMap = new ItemProcessingInitializer(resolvedAssessmentItem, false).initialize();
ItemSessionState itemSessionState = new ItemSessionState();
ItemSessionControllerSettings itemSessionControllerSettings = new ItemSessionControllerSettings();
ItemSessionController itemSessionController = simpleJqtiFacade.createItemSessionController(itemSessionControllerSettings, itemProcessingMap, itemSessionState);
itemSessionController.initialize(new Date());
itemSessionController.performTemplateProcessing(new Date());
itemSessionController.enterItem(new Date());
itemSessionController.bindResponses(new Date(), responseMap);
itemSessionController.commitResponses(new Date());
itemSessionController.performResponseProcessing(new Date());
AssessmentItem assessmentItem = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
assessmentItem.getItemBody().willShowFeedback(itemSessionController);
itemSessionController.endItem(new Date());
itemSessionController.exitItem(new Date());
return itemSessionController;
}
use of uk.ac.ed.ph.jqtiplus.state.ItemSessionState in project OpenOLAT by OpenOLAT.
the class QTI21ServiceImpl method resumeItem.
private void resumeItem(TestPlanNodeKey lastEntryItemKey, TestSessionState testSessionState) {
TestPlan plan = testSessionState.getTestPlan();
Date now = new Date();
for (TestPlanNode currentNode = plan.getNode(lastEntryItemKey); currentNode != null; currentNode = currentNode.getParent()) {
TestNodeType type = currentNode.getTestNodeType();
TestPlanNodeKey currentNodeKey = currentNode.getKey();
switch(type) {
case TEST_PART:
{
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;
}
}
}
}
use of uk.ac.ed.ph.jqtiplus.state.ItemSessionState in project OpenOLAT by OpenOLAT.
the class AssessmentItemDisplayController method handleResponses.
public void handleResponses(UserRequest ureq, Map<Identifier, ResponseInput> stringResponseMap, Map<Identifier, ResponseInput> fileResponseMap, String candidateComment) {
/* Retrieve current JQTI state and set up JQTI controller */
NotificationRecorder notificationRecorder = new NotificationRecorder(NotificationLevel.INFO);
ItemSessionState itemSessionState = itemSessionController.getItemSessionState();
/* Make sure an attempt is allowed */
if (itemSessionState.isEnded()) {
candidateAuditLogger.logAndThrowCandidateException(candidateSession, CandidateExceptionReason.RESPONSES_NOT_EXPECTED, null);
logError("RESPONSES_NOT_EXPECTED", null);
return;
}
/* Build response map in required format for JQTI+.
* NB: The following doesn't test for duplicate keys in the two maps. I'm not sure
* it's worth the effort.
*/
final Map<Identifier, ResponseData> responseDataMap = new HashMap<>();
// final Map<Identifier, CandidateFileSubmission> fileSubmissionMap = new HashMap<>();
final Map<Identifier, AssessmentResponse> assessmentResponseDataMap = new HashMap<>();
if (stringResponseMap != null) {
for (final Entry<Identifier, ResponseInput> stringResponseEntry : stringResponseMap.entrySet()) {
Identifier identifier = stringResponseEntry.getKey();
ResponseInput responseData = stringResponseEntry.getValue();
if (responseData instanceof StringInput) {
responseDataMap.put(identifier, new StringResponseData(((StringInput) responseData).getResponseData()));
} else if (responseData instanceof Base64Input) {
// TODO
} else if (responseData instanceof FileInput) {
}
}
}
if (fileResponseMap != null) {
for (final Entry<Identifier, ResponseInput> fileResponseEntry : fileResponseMap.entrySet()) {
final Identifier identifier = fileResponseEntry.getKey();
final FileInput multipartFile = (FileInput) fileResponseEntry.getValue();
if (!multipartFile.isEmpty()) {
// final CandidateFileSubmission fileSubmission = candidateUploadService.importFileSubmission(candidateSession, multipartFile);
File storedFile = qtiService.importFileSubmission(candidateSession, multipartFile.getMultipartFileInfos());
final FileResponseData fileResponseData = new FileResponseData(storedFile, multipartFile.getContentType(), multipartFile.getFileName());
responseDataMap.put(identifier, fileResponseData);
assessmentResponseDataMap.put(identifier, new AssessmentResponseData(identifier, fileResponseData));
// fileSubmissionMap.put(identifier, fileSubmission);
}
}
}
/* Submit comment (if provided)
* NB: Do this first in case next actions end the item session.
*/
final Date timestamp = ureq.getRequestTimestamp();
if (candidateComment != null) {
try {
itemSessionController.setCandidateComment(timestamp, candidateComment);
} catch (final QtiCandidateStateException e) {
candidateAuditLogger.logAndThrowCandidateException(candidateSession, CandidateExceptionReason.CANDIDATE_COMMENT_FORBIDDEN, e);
logError("CANDIDATE_COMMENT_FORBIDDEN", null);
return;
} catch (final RuntimeException e) {
logError("", e);
// handleExplosion(e, candidateSession);
return;
}
}
/* Attempt to bind responses */
boolean allResponsesValid = false, allResponsesBound = false;
try {
itemSessionController.bindResponses(timestamp, responseDataMap);
/* Note any responses that failed to bind */
final Set<Identifier> badResponseIdentifiers = itemSessionState.getUnboundResponseIdentifiers();
allResponsesBound = badResponseIdentifiers.isEmpty();
/* Now validate the responses according to any constraints specified by the interactions */
if (allResponsesBound) {
final Set<Identifier> invalidResponseIdentifiers = itemSessionState.getInvalidResponseIdentifiers();
allResponsesValid = invalidResponseIdentifiers.isEmpty();
}
/* (We commit responses immediately here) */
itemSessionController.commitResponses(timestamp);
/* Invoke response processing (only if responses are valid) */
if (allResponsesValid) {
itemSessionController.performResponseProcessing(timestamp);
}
} catch (final QtiCandidateStateException e) {
candidateAuditLogger.logAndThrowCandidateException(candidateSession, CandidateExceptionReason.RESPONSES_NOT_EXPECTED, null);
logError("RESPONSES_NOT_EXPECTED", e);
return;
} catch (final RuntimeException e) {
logError("", e);
// handleExplosion(e, candidateSession);
return;
}
/* Record resulting attempt and event */
final CandidateItemEventType eventType = allResponsesBound ? (allResponsesValid ? CandidateItemEventType.ATTEMPT_VALID : CandidateItemEventType.RESPONSE_INVALID) : CandidateItemEventType.RESPONSE_BAD;
final CandidateEvent candidateEvent = qtiService.recordCandidateItemEvent(candidateSession, null, entry, eventType, itemSessionState, notificationRecorder);
candidateAuditLogger.logCandidateEvent(candidateEvent, assessmentResponseDataMap);
lastEvent = candidateEvent;
/* Record current result state, or finish session */
updateSessionFinishedStatus(ureq);
}
use of uk.ac.ed.ph.jqtiplus.state.ItemSessionState in project OpenOLAT by OpenOLAT.
the class AssessmentItemDisplayController method createNewItemSessionStateAndController.
public ItemSessionController createNewItemSessionStateAndController(NotificationRecorder notificationRecorder) {
/* Resolve the underlying JQTI+ object */
final ItemProcessingMap itemProcessingMap = getItemProcessingMap();
if (itemProcessingMap == null) {
return null;
}
/* Create fresh state for session */
final ItemSessionState itemSessionState = new ItemSessionState();
/* Create config for ItemSessionController */
final ItemSessionControllerSettings itemSessionControllerSettings = new ItemSessionControllerSettings();
itemSessionControllerSettings.setTemplateProcessingLimit(computeTemplateProcessingLimit());
itemSessionControllerSettings.setMaxAttempts(10);
/* Create controller and wire up notification recorder */
final ItemSessionController result = new ItemSessionController(qtiService.jqtiExtensionManager(), itemSessionControllerSettings, itemProcessingMap, itemSessionState);
if (notificationRecorder != null) {
result.addNotificationListener(notificationRecorder);
}
return result;
}
use of uk.ac.ed.ph.jqtiplus.state.ItemSessionState in project OpenOLAT by OpenOLAT.
the class AssessmentItemDisplayController method requestSolution.
public void requestSolution(UserRequest ureq) {
ItemSessionState itemSessionState = itemSessionController.getItemSessionState();
/* Make sure caller may do this */
// itemDeliverySettings.isAllowSolutionWhenOpen()
boolean allowSolutionWhenOpen = true;
if (!itemSessionState.isEnded() && !allowSolutionWhenOpen) {
candidateAuditLogger.logAndThrowCandidateException(candidateSession, CandidateExceptionReason.SOLUTION_WHEN_INTERACTING_FORBIDDEN, null);
logError("SOLUTION_WHEN_INTERACTING_FORBIDDEN", null);
return;
} else if (itemSessionState.isEnded()) /* && !itemDeliverySettings.isAllowSoftResetWhenEnded() */
{
candidateAuditLogger.logAndThrowCandidateException(candidateSession, CandidateExceptionReason.SOLUTION_WHEN_ENDED_FORBIDDEN, null);
logError("SOLUTION_WHEN_ENDED_FORBIDDEN", null);
return;
}
/* End session if still open */
final Date timestamp = ureq.getRequestTimestamp();
boolean isClosingSession = false;
if (!itemSessionState.isEnded()) {
isClosingSession = true;
try {
itemSessionController.endItem(timestamp);
} catch (final QtiCandidateStateException e) {
candidateAuditLogger.logAndThrowCandidateException(candidateSession, CandidateExceptionReason.SOLUTION_WHEN_ENDED_FORBIDDEN, null);
logError("SOLUTION_WHEN_ENDED_FORBIDDEN", e);
return;
} catch (final RuntimeException e) {
logError("", e);
// handleExplosion(e, candidateSession);
return;
}
}
/* Record current result state, and maybe close session */
final AssessmentResult assessmentResult = computeAndRecordItemAssessmentResult(ureq);
if (isClosingSession) {
qtiService.finishItemSession(candidateSession, assessmentResult, timestamp);
}
/* Record and log event */
final CandidateEvent candidateEvent = qtiService.recordCandidateItemEvent(candidateSession, null, entry, CandidateItemEventType.SOLUTION, itemSessionState);
candidateAuditLogger.logCandidateEvent(candidateEvent);
lastEvent = candidateEvent;
}
Aggregations