Search in sources :

Example 1 with AssessmentChangedEvent

use of org.olat.course.assessment.AssessmentChangedEvent in project OpenOLAT by OpenOLAT.

the class CourseAssessmentManagerImpl method saveScoreEvaluation.

@Override
public void saveScoreEvaluation(AssessableCourseNode courseNode, Identity identity, Identity assessedIdentity, ScoreEvaluation scoreEvaluation, UserCourseEnvironment userCourseEnv, boolean incrementUserAttempts, Role by) {
    final ICourse course = CourseFactory.loadCourse(cgm.getCourseEntry());
    final CourseEnvironment courseEnv = userCourseEnv.getCourseEnvironment();
    Float score = scoreEvaluation.getScore();
    Boolean passed = scoreEvaluation.getPassed();
    Long assessmentId = scoreEvaluation.getAssessmentID();
    String subIdent = courseNode.getIdent();
    RepositoryEntry referenceEntry = courseNode.getReferencedRepositoryEntry();
    AssessmentEntry assessmentEntry = getOrCreate(assessedIdentity, subIdent, referenceEntry);
    if (referenceEntry != null && !referenceEntry.equals(assessmentEntry.getReferenceEntry())) {
        assessmentEntry.setReferenceEntry(referenceEntry);
    }
    if (by == Role.coach) {
        assessmentEntry.setLastCoachModified(new Date());
    } else if (by == Role.user) {
        assessmentEntry.setLastUserModified(new Date());
    }
    if (score == null) {
        assessmentEntry.setScore(null);
    } else {
        assessmentEntry.setScore(new BigDecimal(Float.toString(score)));
    }
    assessmentEntry.setPassed(passed);
    assessmentEntry.setFullyAssessed(scoreEvaluation.getFullyAssessed());
    if (assessmentId != null) {
        assessmentEntry.setAssessmentId(assessmentId);
    }
    if (scoreEvaluation.getAssessmentStatus() != null) {
        assessmentEntry.setAssessmentStatus(scoreEvaluation.getAssessmentStatus());
    }
    if (scoreEvaluation.getUserVisible() != null) {
        assessmentEntry.setUserVisibility(scoreEvaluation.getUserVisible());
    }
    if (scoreEvaluation.getCurrentRunCompletion() != null) {
        assessmentEntry.setCurrentRunCompletion(scoreEvaluation.getCurrentRunCompletion());
    }
    if (scoreEvaluation.getCurrentRunStatus() != null) {
        assessmentEntry.setCurrentRunStatus(scoreEvaluation.getCurrentRunStatus());
    }
    Integer attempts = null;
    if (incrementUserAttempts) {
        attempts = assessmentEntry.getAttempts() == null ? 1 : assessmentEntry.getAttempts().intValue() + 1;
        assessmentEntry.setAttempts(attempts);
    }
    assessmentEntry = assessmentService.updateAssessmentEntry(assessmentEntry);
    // commit before sending events
    DBFactory.getInstance().commit();
    // reevalute the tree
    ScoreAccounting scoreAccounting = userCourseEnv.getScoreAccounting();
    scoreAccounting.evaluateAll(true);
    // commit before sending events
    DBFactory.getInstance().commit();
    // node log
    UserNodeAuditManager am = courseEnv.getAuditManager();
    am.appendToUserNodeLog(courseNode, identity, assessedIdentity, "score set to: " + String.valueOf(scoreEvaluation.getScore()));
    if (scoreEvaluation.getPassed() != null) {
        am.appendToUserNodeLog(courseNode, identity, assessedIdentity, "passed set to: " + scoreEvaluation.getPassed().toString());
    } else {
        am.appendToUserNodeLog(courseNode, identity, assessedIdentity, "passed set to \"undefined\"");
    }
    if (scoreEvaluation.getAssessmentID() != null) {
        am.appendToUserNodeLog(courseNode, assessedIdentity, assessedIdentity, "assessmentId set to: " + scoreEvaluation.getAssessmentID().toString());
    }
    // notify about changes
    AssessmentChangedEvent ace = new AssessmentChangedEvent(AssessmentChangedEvent.TYPE_SCORE_EVAL_CHANGED, assessedIdentity);
    CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(ace, course);
    // user activity logging
    if (scoreEvaluation.getScore() != null) {
        ThreadLocalUserActivityLogger.log(AssessmentLoggingAction.ASSESSMENT_SCORE_UPDATED, getClass(), LoggingResourceable.wrap(assessedIdentity), LoggingResourceable.wrapNonOlatResource(StringResourceableType.qtiScore, "", String.valueOf(scoreEvaluation.getScore())));
    }
    if (scoreEvaluation.getPassed() != null) {
        ThreadLocalUserActivityLogger.log(AssessmentLoggingAction.ASSESSMENT_PASSED_UPDATED, getClass(), LoggingResourceable.wrap(assessedIdentity), LoggingResourceable.wrapNonOlatResource(StringResourceableType.qtiPassed, "", String.valueOf(scoreEvaluation.getPassed())));
    } else {
        ThreadLocalUserActivityLogger.log(AssessmentLoggingAction.ASSESSMENT_PASSED_UPDATED, getClass(), LoggingResourceable.wrap(assessedIdentity), LoggingResourceable.wrapNonOlatResource(StringResourceableType.qtiPassed, "", "undefined"));
    }
    if (incrementUserAttempts && attempts != null) {
        ThreadLocalUserActivityLogger.log(AssessmentLoggingAction.ASSESSMENT_ATTEMPTS_UPDATED, getClass(), LoggingResourceable.wrap(identity), LoggingResourceable.wrapNonOlatResource(StringResourceableType.qtiAttempts, "", String.valueOf(attempts)));
    }
    // write only when enabled for this course
    if (courseEnv.getCourseConfig().isEfficencyStatementEnabled()) {
        List<AssessmentNodeData> data = new ArrayList<AssessmentNodeData>(50);
        AssessmentNodesLastModified lastModifications = new AssessmentNodesLastModified();
        AssessmentHelper.getAssessmentNodeDataList(0, courseEnv.getRunStructure().getRootNode(), scoreAccounting, userCourseEnv, true, true, true, data, lastModifications);
        efficiencyStatementManager.updateUserEfficiencyStatement(assessedIdentity, courseEnv, data, lastModifications, cgm.getCourseEntry());
    }
    if (course.getCourseConfig().isAutomaticCertificationEnabled()) {
        CourseNode rootNode = courseEnv.getRunStructure().getRootNode();
        ScoreEvaluation rootEval = scoreAccounting.evalCourseNode((AssessableCourseNode) rootNode);
        if (rootEval != null && rootEval.getPassed() != null && rootEval.getPassed().booleanValue() && certificatesManager.isCertificationAllowed(assessedIdentity, cgm.getCourseEntry())) {
            CertificateTemplate template = null;
            Long templateId = course.getCourseConfig().getCertificateTemplate();
            if (templateId != null) {
                template = certificatesManager.getTemplateById(templateId);
            }
            CertificateInfos certificateInfos = new CertificateInfos(assessedIdentity, rootEval.getScore(), rootEval.getPassed());
            certificatesManager.generateCertificate(certificateInfos, cgm.getCourseEntry(), template, true);
        }
    }
}
Also used : AssessmentNodesLastModified(org.olat.course.assessment.model.AssessmentNodesLastModified) ScoreEvaluation(org.olat.course.run.scoring.ScoreEvaluation) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) CourseEnvironment(org.olat.course.run.environment.CourseEnvironment) CertificateTemplate(org.olat.course.certificate.CertificateTemplate) CertificateInfos(org.olat.course.certificate.model.CertificateInfos) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry) Date(java.util.Date) BigDecimal(java.math.BigDecimal) AssessmentNodeData(org.olat.course.assessment.model.AssessmentNodeData) UserNodeAuditManager(org.olat.course.auditing.UserNodeAuditManager) AssessmentChangedEvent(org.olat.course.assessment.AssessmentChangedEvent) ScoreAccounting(org.olat.course.run.scoring.ScoreAccounting) CourseNode(org.olat.course.nodes.CourseNode) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode)

Example 2 with AssessmentChangedEvent

use of org.olat.course.assessment.AssessmentChangedEvent in project OpenOLAT by OpenOLAT.

the class CourseAssessmentManagerImpl method saveNodeCoachComment.

@Override
public void saveNodeCoachComment(CourseNode courseNode, Identity assessedIdentity, String comment) {
    ICourse course = CourseFactory.loadCourse(cgm.getCourseEntry());
    AssessmentEntry nodeAssessment = getOrCreate(assessedIdentity, courseNode);
    nodeAssessment.setCoachComment(comment);
    assessmentService.updateAssessmentEntry(nodeAssessment);
    // notify about changes
    AssessmentChangedEvent ace = new AssessmentChangedEvent(AssessmentChangedEvent.TYPE_COACH_COMMENT_CHANGED, assessedIdentity);
    CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(ace, course);
    // user activity logging
    ThreadLocalUserActivityLogger.log(AssessmentLoggingAction.ASSESSMENT_COACHCOMMENT_UPDATED, getClass(), LoggingResourceable.wrap(assessedIdentity), LoggingResourceable.wrapNonOlatResource(StringResourceableType.qtiCoachComment, "", StringHelper.stripLineBreaks(comment)));
}
Also used : AssessmentChangedEvent(org.olat.course.assessment.AssessmentChangedEvent) ICourse(org.olat.course.ICourse) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry)

Example 3 with AssessmentChangedEvent

use of org.olat.course.assessment.AssessmentChangedEvent in project OpenOLAT by OpenOLAT.

the class CourseAssessmentManagerImpl method incrementNodeAttempts.

@Override
public void incrementNodeAttempts(CourseNode courseNode, Identity assessedIdentity, UserCourseEnvironment userCourseEnv, Role by) {
    ICourse course = CourseFactory.loadCourse(cgm.getCourseEntry());
    AssessmentEntry nodeAssessment = getOrCreate(assessedIdentity, courseNode);
    int attempts = nodeAssessment.getAttempts() == null ? 1 : nodeAssessment.getAttempts().intValue() + 1;
    nodeAssessment.setAttempts(attempts);
    if (by == Role.coach) {
        nodeAssessment.setLastCoachModified(new Date());
    } else if (by == Role.user) {
        nodeAssessment.setLastUserModified(new Date());
    }
    assessmentService.updateAssessmentEntry(nodeAssessment);
    DBFactory.getInstance().commit();
    userCourseEnv.getScoreAccounting().evaluateAll(true);
    DBFactory.getInstance().commit();
    if (courseNode instanceof AssessableCourseNode) {
        // Update users efficiency statement
        efficiencyStatementManager.updateUserEfficiencyStatement(userCourseEnv);
    }
    // notify about changes
    AssessmentChangedEvent ace = new AssessmentChangedEvent(AssessmentChangedEvent.TYPE_ATTEMPTS_CHANGED, assessedIdentity);
    CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(ace, course);
    // user activity logging
    ThreadLocalUserActivityLogger.log(AssessmentLoggingAction.ASSESSMENT_ATTEMPTS_UPDATED, getClass(), LoggingResourceable.wrap(assessedIdentity), LoggingResourceable.wrapNonOlatResource(StringResourceableType.qtiAttempts, "", String.valueOf(attempts)));
}
Also used : AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) AssessmentChangedEvent(org.olat.course.assessment.AssessmentChangedEvent) ICourse(org.olat.course.ICourse) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry) Date(java.util.Date)

Example 4 with AssessmentChangedEvent

use of org.olat.course.assessment.AssessmentChangedEvent in project OpenOLAT by OpenOLAT.

the class CourseAssessmentManagerImpl method incrementNodeAttemptsInBackground.

@Override
public void incrementNodeAttemptsInBackground(CourseNode courseNode, Identity assessedIdentity, UserCourseEnvironment userCourseEnv) {
    ICourse course = CourseFactory.loadCourse(cgm.getCourseEntry());
    AssessmentEntry nodeAssessment = getOrCreate(assessedIdentity, courseNode);
    int attempts = nodeAssessment.getAttempts() == null ? 1 : nodeAssessment.getAttempts().intValue() + 1;
    nodeAssessment.setAttempts(attempts);
    assessmentService.updateAssessmentEntry(nodeAssessment);
    if (courseNode instanceof AssessableCourseNode) {
        // Update users efficiency statement
        efficiencyStatementManager.updateUserEfficiencyStatement(userCourseEnv);
    }
    // notify about changes
    AssessmentChangedEvent ace = new AssessmentChangedEvent(AssessmentChangedEvent.TYPE_ATTEMPTS_CHANGED, assessedIdentity);
    CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(ace, course);
}
Also used : AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) AssessmentChangedEvent(org.olat.course.assessment.AssessmentChangedEvent) ICourse(org.olat.course.ICourse) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry)

Example 5 with AssessmentChangedEvent

use of org.olat.course.assessment.AssessmentChangedEvent in project OpenOLAT by OpenOLAT.

the class NewCachePersistingAssessmentManager method incrementNodeAttempts.

private void incrementNodeAttempts(final CourseNode courseNode, final Identity identity, final UserCourseEnvironment userCourseEnv, boolean logActivity) {
    ICourse course = CourseFactory.loadCourse(ores);
    final CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
    long attempts = CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(createOLATResourceableForLocking(identity), new SyncerCallback<Long>() {

        public Long execute() {
            long attempts = incrementNodeAttemptsProperty(courseNode, identity, cpm);
            if (courseNode instanceof AssessableCourseNode) {
                // Update users efficiency statement
                EfficiencyStatementManager esm = CoreSpringFactory.getImpl(EfficiencyStatementManager.class);
                esm.updateUserEfficiencyStatement(userCourseEnv);
            }
            return attempts;
        }
    });
    // notify about changes
    AssessmentChangedEvent ace = new AssessmentChangedEvent(AssessmentChangedEvent.TYPE_ATTEMPTS_CHANGED, identity);
    CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(ace, course);
    if (logActivity) {
        // user activity logging
        ThreadLocalUserActivityLogger.log(AssessmentLoggingAction.ASSESSMENT_ATTEMPTS_UPDATED, getClass(), LoggingResourceable.wrap(identity), LoggingResourceable.wrapNonOlatResource(StringResourceableType.qtiAttempts, "", String.valueOf(attempts)));
    }
}
Also used : AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) EfficiencyStatementManager(org.olat.course.assessment.manager.EfficiencyStatementManager) AssessmentChangedEvent(org.olat.course.assessment.AssessmentChangedEvent) ICourse(org.olat.course.ICourse) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager)

Aggregations

AssessmentChangedEvent (org.olat.course.assessment.AssessmentChangedEvent)26 ICourse (org.olat.course.ICourse)22 UserNodeAuditManager (org.olat.course.auditing.UserNodeAuditManager)12 AssessmentEntry (org.olat.modules.assessment.AssessmentEntry)12 AssessableCourseNode (org.olat.course.nodes.AssessableCourseNode)10 CoursePropertyManager (org.olat.course.properties.CoursePropertyManager)10 Date (java.util.Date)6 SyncerExecutor (org.olat.core.util.coordinate.SyncerExecutor)6 Property (org.olat.properties.Property)6 EfficiencyStatementManager (org.olat.course.assessment.manager.EfficiencyStatementManager)4 CertificateTemplate (org.olat.course.certificate.CertificateTemplate)4 CertificateInfos (org.olat.course.certificate.model.CertificateInfos)4 RepositoryEntry (org.olat.repository.RepositoryEntry)4 BigDecimal (java.math.BigDecimal)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Identity (org.olat.core.id.Identity)2 OLATResourceable (org.olat.core.id.OLATResourceable)2 OLATResourceableJustBeforeDeletedEvent (org.olat.core.util.resource.OLATResourceableJustBeforeDeletedEvent)2 EfficiencyStatement (org.olat.course.assessment.EfficiencyStatement)2