Search in sources :

Example 16 with AssessmentTestSession

use of org.olat.ims.qti21.AssessmentTestSession in project OpenOLAT by OpenOLAT.

the class QTI21ServiceImpl method getAssessmentSessionAuditLogger.

@Override
public AssessmentSessionAuditLogger getAssessmentSessionAuditLogger(AssessmentTestSession session, boolean authorMode) {
    if (authorMode) {
        return new AssessmentSessionAuditOLog();
    }
    if (session.getIdentity() == null && StringHelper.containsNonWhitespace(session.getAnonymousIdentifier())) {
        return new AssessmentSessionAuditOLog();
    }
    try {
        File auditLog = getAssessmentSessionAuditLogFile(session);
        FileOutputStream outputStream = new FileOutputStream(auditLog, true);
        return new AssessmentSessionAuditFileLog(outputStream);
    } catch (IOException e) {
        log.error("Cannot open the user specific log audit, fall back to OLog", e);
        return new AssessmentSessionAuditOLog();
    }
}
Also used : AssessmentSessionAuditFileLog(org.olat.ims.qti21.manager.audit.AssessmentSessionAuditFileLog) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) AssessmentSessionAuditOLog(org.olat.ims.qti21.manager.audit.AssessmentSessionAuditOLog)

Example 17 with AssessmentTestSession

use of org.olat.ims.qti21.AssessmentTestSession in project OpenOLAT by OpenOLAT.

the class QTI21ServiceImpl method recordCandidateTestEvent.

@Override
public CandidateEvent recordCandidateTestEvent(AssessmentTestSession candidateSession, RepositoryEntryRef testEntry, RepositoryEntryRef entry, CandidateTestEventType textEventType, CandidateItemEventType itemEventType, TestPlanNodeKey itemKey, TestSessionState testSessionState, NotificationRecorder notificationRecorder) {
    CandidateEvent event = new CandidateEvent(candidateSession, testEntry, entry);
    event.setTestEventType(textEventType);
    event.setItemEventType(itemEventType);
    if (itemKey != null) {
        event.setTestItemKey(itemKey.toString());
    }
    storeTestSessionState(event, testSessionState);
    return event;
}
Also used : CandidateEvent(org.olat.ims.qti21.model.audit.CandidateEvent)

Example 18 with AssessmentTestSession

use of org.olat.ims.qti21.AssessmentTestSession 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;
}
Also used : TestPlanNode(uk.ac.ed.ph.jqtiplus.state.TestPlanNode) AssessmentTestSession(org.olat.ims.qti21.AssessmentTestSession) InMemoryAssessmentTestSession(org.olat.ims.qti21.model.InMemoryAssessmentTestSession) TestSessionState(uk.ac.ed.ph.jqtiplus.state.TestSessionState) TestPlan(uk.ac.ed.ph.jqtiplus.state.TestPlan) OLATResourceable(org.olat.core.id.OLATResourceable) ItemSessionState(uk.ac.ed.ph.jqtiplus.state.ItemSessionState) AssessmentSessionAuditLogger(org.olat.ims.qti21.AssessmentSessionAuditLogger) RetrieveAssessmentTestSessionEvent(org.olat.ims.qti21.ui.event.RetrieveAssessmentTestSessionEvent) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) TestPlanNodeKey(uk.ac.ed.ph.jqtiplus.state.TestPlanNodeKey)

Example 19 with AssessmentTestSession

use of org.olat.ims.qti21.AssessmentTestSession in project OpenOLAT by OpenOLAT.

the class AuditLogFormatter method log.

protected static void log(CandidateEvent candidateEvent, Map<Identifier, AssessmentResponse> candidateResponseMap, Writer writer) throws IOException {
    writer.append("QTI21 audit [");
    AssessmentTestSession testSession = candidateEvent.getCandidateSession();
    if (testSession != null) {
        RepositoryEntryRef testEntry = candidateEvent.getTestEntry();
        RepositoryEntryRef courseEntry = candidateEvent.getRepositoryEntry();
        if (courseEntry != null && !testEntry.getKey().equals(courseEntry.getKey())) {
            writer.write(courseEntry.getKey().toString());
            writer.write(":");
            if (testSession.getSubIdent() == null) {
                writer.write("NULL:");
            } else {
                writer.write(testSession.getSubIdent());
                writer.write(":");
            }
        }
        if (testEntry != null) {
            writer.write(testEntry.getKey().toString());
        }
    }
    writer.write("] ");
    if (candidateEvent.getTestEventType() != null) {
        writer.append("TestEvent:");
        writer.append(candidateEvent.getTestEventType().toString());
        writer.write(" ");
    }
    if (candidateEvent.getItemEventType() != null) {
        writer.append("ItemEvent:");
        writer.append(candidateEvent.getItemEventType().toString());
        writer.write(" ");
    }
    if (candidateEvent.getTestItemKey() != null) {
        writer.append("TestItemKey[");
        writer.append(candidateEvent.getTestItemKey());
        writer.write("] ");
    }
    if (candidateResponseMap != null) {
        writer.write("params=");
        for (Map.Entry<Identifier, AssessmentResponse> responseEntry : candidateResponseMap.entrySet()) {
            Identifier identifier = responseEntry.getKey();
            AssessmentResponse response = responseEntry.getValue();
            writer.append("|");
            writer.append(identifier.toString());
            writer.append("=");
            String stringuifiedResponse = response.getStringuifiedResponse();
            if (stringuifiedResponse == null) {
                writer.append("NULL");
            } else {
                writer.append(stringuifiedResponse);
            }
        }
    }
}
Also used : AssessmentTestSession(org.olat.ims.qti21.AssessmentTestSession) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) RepositoryEntryRef(org.olat.repository.RepositoryEntryRef) Map(java.util.Map) AssessmentResponse(org.olat.ims.qti21.AssessmentResponse)

Example 20 with AssessmentTestSession

use of org.olat.ims.qti21.AssessmentTestSession in project OpenOLAT by OpenOLAT.

the class QTI21ResultsExportMediaResource method createResultDetail.

private List<ResultDetail> createResultDetail(Identity identity, ZipOutputStream zout, String idDir) throws IOException {
    List<ResultDetail> assessments = new ArrayList<>();
    List<AssessmentTestSession> sessions = qtiService.getAssessmentTestSessions(entry, courseNode.getIdent(), identity);
    for (AssessmentTestSession session : sessions) {
        Long assessmentID = session.getKey();
        String idPath = idDir + translator.translate("table.user.attempt") + (sessions.indexOf(session) + 1) + SEP;
        createZipDirectory(zout, idPath);
        // content of result table
        ResultDetail resultDetail = new ResultDetail(assessmentID.toString(), assessmentDateFormat.format(session.getCreationDate()), displayDateFormat.format(new Date(session.getDuration())), session.getScore(), session.getManualScore(), createPassedIcons(session.getPassed() == null ? true : session.getPassed()), idPath.replace(idDir, "") + assessmentID + ".html");
        assessments.add(resultDetail);
        // WindowControlMocker needed because this is not a controller
        WindowControl mockwControl = new WindowControlMocker();
        FileResourceManager frm = FileResourceManager.getInstance();
        RepositoryEntry testEntry = session.getTestEntry();
        testEntries.add(testEntry);
        File fUnzippedDirRoot = frm.unzipFileResource(testEntry.getOlatResource());
        // add test repo key
        String mapperUri = "../../../test" + testEntry.getKey() + "/";
        String submissionMapperUri = ".";
        String exportUri = "../" + translator.translate("table.user.attempt") + (sessions.indexOf(session) + 1);
        Controller assessmentResultController = new AssessmentResultController(ureq, mockwControl, identity, false, session, fUnzippedDirRoot, mapperUri, submissionMapperUri, QTI21AssessmentResultsOptions.allOptions(), false, true, false, exportUri);
        Component component = assessmentResultController.getInitialComponent();
        String componentHTML = createResultHTML(component);
        convertToZipEntry(zout, idPath + assessmentID + ".html", componentHTML);
        File resultXML = qtiService.getAssessmentResultFile(session);
        convertToZipEntry(zout, idPath + assessmentID + ".xml", resultXML);
        File signatureXML = qtiService.getAssessmentResultSignature(session);
        if (signatureXML != null) {
            convertToZipEntry(zout, idPath + "assessmentResultSignature.xml", signatureXML);
        }
        File submissionDir = qtiService.getSubmissionDirectory(session);
        String baseDir = idPath + "submissions";
        ZipUtil.addDirectoryToZip(submissionDir.toPath(), baseDir, zout);
    }
    return assessments;
}
Also used : AssessmentTestSession(org.olat.ims.qti21.AssessmentTestSession) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) WindowControl(org.olat.core.gui.control.WindowControl) AssessmentResultController(org.olat.ims.qti21.ui.AssessmentResultController) Controller(org.olat.core.gui.control.Controller) Date(java.util.Date) FileResourceManager(org.olat.fileresource.FileResourceManager) AssessmentResultController(org.olat.ims.qti21.ui.AssessmentResultController) Component(org.olat.core.gui.components.Component) File(java.io.File) WindowControlMocker(org.olat.core.gui.util.WindowControlMocker)

Aggregations

AssessmentTestSession (org.olat.ims.qti21.AssessmentTestSession)107 Identity (org.olat.core.id.Identity)45 RepositoryEntry (org.olat.repository.RepositoryEntry)36 AssessmentEntry (org.olat.modules.assessment.AssessmentEntry)32 File (java.io.File)30 ArrayList (java.util.ArrayList)24 AssessmentItemSession (org.olat.ims.qti21.AssessmentItemSession)24 Date (java.util.Date)22 Test (org.junit.Test)20 TestSessionState (uk.ac.ed.ph.jqtiplus.state.TestSessionState)20 HashMap (java.util.HashMap)17 InMemoryAssessmentTestSession (org.olat.ims.qti21.model.InMemoryAssessmentTestSession)14 ItemSessionState (uk.ac.ed.ph.jqtiplus.state.ItemSessionState)14 AssessmentResponse (org.olat.ims.qti21.AssessmentResponse)12 TestPlanNodeKey (uk.ac.ed.ph.jqtiplus.state.TestPlanNodeKey)12 IOException (java.io.IOException)10 BigDecimal (java.math.BigDecimal)10 CandidateEvent (org.olat.ims.qti21.model.audit.CandidateEvent)10 AssessmentItemRef (uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef)10 ResolvedAssessmentTest (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest)10