use of uk.ac.ed.ph.jqtiplus.state.ItemSessionState in project openolat by klemens.
the class AssessmentResultController method initFormItemResult.
private Results initFormItemResult(FormLayoutContainer layoutCont, TestPlanNode node, Map<Identifier, AssessmentItemRef> identifierToRefs, Map<TestPlanNode, Results> resultsMap) {
TestPlanNodeKey testPlanNodeKey = node.getKey();
Identifier identifier = testPlanNodeKey.getIdentifier();
AssessmentItemRef itemRef = identifierToRefs.get(identifier);
ResolvedAssessmentItem resolvedAssessmentItem = resolvedAssessmentTest.getResolvedAssessmentItem(itemRef);
AssessmentItem assessmentItem = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
QTI21QuestionType type = QTI21QuestionType.getType(assessmentItem);
AssessmentItemSession itemSession = identifierToItemSession.get(identifier.toString());
Results r = new Results(false, node.getSectionPartTitle(), type.getCssClass(), options.isQuestionSummary());
// init
r.setSessionStatus(null);
r.setItemIdentifier(node.getIdentifier().toString());
ItemSessionState sessionState = testSessionState.getItemSessionStates().get(testPlanNodeKey);
if (sessionState != null) {
r.setSessionState(sessionState);
SessionStatus sessionStatus = sessionState.getSessionStatus();
if (sessionState != null) {
r.setSessionStatus(sessionStatus);
}
}
ItemResult itemResult = assessmentResult.getItemResult(identifier.toString());
if (itemResult != null) {
extractOutcomeVariable(itemResult.getItemVariables(), r);
}
if (itemSession != null) {
if (itemSession.getManualScore() != null) {
r.setScore(itemSession.getManualScore());
r.setManualScore(itemSession.getManualScore());
}
r.setComment(itemSession.getCoachComment());
}
// update max score of section
if (options.isUserSolutions() || options.isCorrectSolutions()) {
InteractionResults interactionResults = initFormItemInteractions(layoutCont, sessionState, resolvedAssessmentItem);
r.setInteractionResults(interactionResults);
if (options.isCorrectSolutions()) {
String correctSolutionId = "correctSolutionItem" + count++;
FeedbackResultFormItem correctSolutionItem = new FeedbackResultFormItem(correctSolutionId, resolvedAssessmentItem);
initInteractionResultFormItem(correctSolutionItem, sessionState);
layoutCont.add(correctSolutionId, correctSolutionItem);
r.setCorrectSolutionItem(correctSolutionItem);
}
}
updateSectionScoreInformations(node, r, resultsMap);
return r;
}
use of uk.ac.ed.ph.jqtiplus.state.ItemSessionState in project openolat by klemens.
the class AssessmentTestDisplayController method resumeSession.
private TestSessionController resumeSession(UserRequest ureq) {
Date requestTimestamp = ureq.getRequestTimestamp();
final NotificationRecorder notificationRecorder = new NotificationRecorder(NotificationLevel.INFO);
TestSessionController controller = createTestSessionController(notificationRecorder);
if (!controller.getTestSessionState().isEnded() && !controller.getTestSessionState().isExited()) {
controller.unsuspendTestSession(requestTimestamp);
TestSessionState testSessionState = controller.getTestSessionState();
TestPlanNodeKey currentItemKey = testSessionState.getCurrentItemKey();
if (currentItemKey != null) {
TestPlanNode currentItemNode = testSessionState.getTestPlan().getNode(currentItemKey);
ItemProcessingContext itemProcessingContext = controller.getItemProcessingContext(currentItemNode);
ItemSessionState itemSessionState = itemProcessingContext.getItemSessionState();
if (itemProcessingContext instanceof ItemSessionController && itemSessionState.isSuspended()) {
ItemSessionController itemSessionController = (ItemSessionController) itemProcessingContext;
itemSessionController.unsuspendItemSession(requestTimestamp);
}
}
}
return controller;
}
use of uk.ac.ed.ph.jqtiplus.state.ItemSessionState in project openolat by klemens.
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);
}
}
use of uk.ac.ed.ph.jqtiplus.state.ItemSessionState 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.ItemSessionState 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;
}
Aggregations