Search in sources :

Example 31 with CoursePropertyManager

use of org.olat.course.properties.CoursePropertyManager in project openolat by klemens.

the class NewCachePersistingAssessmentManager method saveScoreEvaluation.

/**
 * @see org.olat.course.assessment.AssessmentManager#saveScoreEvaluation(org.olat.course.nodes.CourseNode, org.olat.core.id.Identity, org.olat.core.id.Identity, org.olat.course.run.scoring.ScoreEvaluation)
 */
public void saveScoreEvaluation(final CourseNode courseNode, final Identity identity, final Identity assessedIdentity, final ScoreEvaluation scoreEvaluation, final UserCourseEnvironment userCourseEnv, final boolean incrementUserAttempts) {
    final ICourse course = CourseFactory.loadCourse(ores);
    final CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
    final RepositoryEntry courseEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    // o_clusterREVIEW we could sync on a element finer than course, e.g. the composite course+assessIdentity.
    // +: concurrency would be higher
    // -: many entries (num of courses * visitors of given course) in the locktable.
    // we could also sync on the assessedIdentity.
    Long attempts = CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(createOLATResourceableForLocking(assessedIdentity), new SyncerCallback<Long>() {

        public Long execute() {
            Long attempts = null;
            Float score = scoreEvaluation.getScore();
            Boolean passed = scoreEvaluation.getPassed();
            saveNodeScore(courseNode, assessedIdentity, score, cpm);
            saveNodePassed(courseNode, assessedIdentity, passed, cpm);
            saveAssessmentID(courseNode, assessedIdentity, scoreEvaluation.getAssessmentID(), cpm);
            if (incrementUserAttempts) {
                attempts = incrementNodeAttemptsProperty(courseNode, assessedIdentity, cpm);
            }
            if (courseNode instanceof AssessableCourseNode) {
                userCourseEnv.getScoreAccounting().evaluateAll();
                // Update users efficiency statement
                EfficiencyStatementManager esm = CoreSpringFactory.getImpl(EfficiencyStatementManager.class);
                esm.updateUserEfficiencyStatement(userCourseEnv);
            }
            if (passed != null && passed.booleanValue() && course.getCourseConfig().isAutomaticCertificationEnabled()) {
                CertificatesManager certificatesManager = CoreSpringFactory.getImpl(CertificatesManager.class);
                if (certificatesManager.isCertificationAllowed(assessedIdentity, courseEntry)) {
                    CertificateTemplate template = null;
                    Long templateId = course.getCourseConfig().getCertificateTemplate();
                    if (templateId != null) {
                        template = certificatesManager.getTemplateById(templateId);
                    }
                    CertificateInfos certificateInfos = new CertificateInfos(assessedIdentity, score, passed);
                    certificatesManager.generateCertificate(certificateInfos, courseEntry, template, true);
                }
            }
            return attempts;
        }
    });
    // node log
    UserNodeAuditManager am = course.getCourseEnvironment().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, ASSESSMENT_ID + " 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)));
    }
}
Also used : CertificateTemplate(org.olat.course.certificate.CertificateTemplate) EfficiencyStatementManager(org.olat.course.assessment.manager.EfficiencyStatementManager) CertificateInfos(org.olat.course.certificate.model.CertificateInfos) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) UserNodeAuditManager(org.olat.course.auditing.UserNodeAuditManager) AssessmentChangedEvent(org.olat.course.assessment.AssessmentChangedEvent) CertificatesManager(org.olat.course.certificate.CertificatesManager) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager)

Example 32 with CoursePropertyManager

use of org.olat.course.properties.CoursePropertyManager in project openolat by klemens.

the class NewCachePersistingAssessmentManager method saveNodeCoachComment.

/**
 * @see org.olat.course.assessment.AssessmentManager#saveNodeCoachComment(org.olat.course.nodes.CourseNode,
 *      org.olat.core.id.Identity, java.lang.String)
 */
public void saveNodeCoachComment(final CourseNode courseNode, final Identity assessedIdentity, final String comment) {
    ICourse course = CourseFactory.loadCourse(ores);
    final CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
    CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(createOLATResourceableForLocking(assessedIdentity), new SyncerExecutor() {

        public void execute() {
            Property commentProperty = cpm.findCourseNodeProperty(courseNode, assessedIdentity, null, COACH_COMMENT);
            if (commentProperty == null) {
                commentProperty = cpm.createCourseNodePropertyInstance(courseNode, assessedIdentity, null, COACH_COMMENT, null, null, null, comment);
                cpm.saveProperty(commentProperty);
            } else {
                commentProperty.setTextValue(comment);
                cpm.updateProperty(commentProperty);
            }
            // add to cache
            putPropertyIntoCache(assessedIdentity, commentProperty);
        }
    });
    // olat::: no node log here? (because what we did above is a node log with custom text AND by a coach)?
    // 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) SyncerExecutor(org.olat.core.util.coordinate.SyncerExecutor) Property(org.olat.properties.Property) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager)

Example 33 with CoursePropertyManager

use of org.olat.course.properties.CoursePropertyManager in project openolat by klemens.

the class EnrollmentManagerConcurrentTest method testEnroll.

// Test for WaitingList
// /////////////////////
/**
 * Enroll 3 identities (group with max-size=2 and waiting-list).
 * Cancel enrollment. Check size after each step.
 */
@Test
public void testEnroll() throws Exception {
    log.info("testEnroll: start...");
    ENCourseNode enNode = new ENCourseNode();
    OLATResource resource = resourceManager.createOLATResourceInstance(CourseModule.class);
    RepositoryEntry addedEntry = repositoryService.create("Ayanami", "-", "Enrollment test course 1", "A JUnit course", resource);
    CourseEnvironment cenv = CourseFactory.createCourse(addedEntry, "Test", "Test", "learningObjectives").getCourseEnvironment();
    // 1. enroll wg1 user
    IdentityEnvironment ienv = new IdentityEnvironment();
    ienv.setIdentity(wg1);
    UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(ienv, cenv);
    CoursePropertyManager coursePropertyManager = userCourseEnv.getCourseEnvironment().getCoursePropertyManager();
    log.info("enrollmentManager=" + enrollmentManager);
    log.info("bgWithWaitingList=" + bgWithWaitingList);
    assertTrue("bgWithWaitingList is null", bgWithWaitingList != null);
    log.info("userCourseEnv=" + userCourseEnv);
    log.info("userCourseEnv.getCourseEnvironment()=" + userCourseEnv.getCourseEnvironment());
    enrollmentManager.doEnroll(wg1, wg1Roles, bgWithWaitingList, enNode, coursePropertyManager, this, /*WindowControl mock*/
    testTranslator, new ArrayList<Long>(), /*enrollableGroupNames*/
    new ArrayList<Long>(), /*enrollableAreaNames*/
    userCourseEnv.getCourseEnvironment().getCourseGroupManager());
    assertTrue("Enrollment failed, user='wg1'", businessGroupService.isIdentityInBusinessGroup(wg1, bgWithWaitingList));
    int participantsCounter = businessGroupService.countMembers(bgWithWaitingList, GroupRoles.participant.name());
    assertTrue("Wrong number of participants," + participantsCounter, participantsCounter == 1);
    // 2. enroll wg2 user
    ienv = new IdentityEnvironment();
    ienv.setIdentity(wg2);
    userCourseEnv = new UserCourseEnvironmentImpl(ienv, cenv);
    coursePropertyManager = userCourseEnv.getCourseEnvironment().getCoursePropertyManager();
    enrollmentManager.doEnroll(wg2, wg2Roles, bgWithWaitingList, enNode, coursePropertyManager, this, /*WindowControl mock*/
    testTranslator, new ArrayList<Long>(), /*enrollableGroupNames*/
    new ArrayList<Long>(), /*enrollableAreaNames*/
    userCourseEnv.getCourseEnvironment().getCourseGroupManager());
    assertTrue("Enrollment failed, user='wg2'", businessGroupService.isIdentityInBusinessGroup(wg2, bgWithWaitingList));
    assertTrue("Enrollment failed, user='wg1'", businessGroupService.isIdentityInBusinessGroup(wg1, bgWithWaitingList));
    participantsCounter = businessGroupService.countMembers(bgWithWaitingList, GroupRoles.participant.name());
    assertTrue("Wrong number of participants," + participantsCounter, participantsCounter == 2);
    // 3. enroll wg3 user => list is full => waiting-list
    ienv = new IdentityEnvironment();
    ienv.setIdentity(wg3);
    userCourseEnv = new UserCourseEnvironmentImpl(ienv, cenv);
    coursePropertyManager = userCourseEnv.getCourseEnvironment().getCoursePropertyManager();
    enrollmentManager.doEnroll(wg3, wg3Roles, bgWithWaitingList, enNode, coursePropertyManager, this, /*WindowControl mock*/
    testTranslator, new ArrayList<Long>(), /*enrollableGroupNames*/
    new ArrayList<Long>(), /*enrollableAreaNames*/
    userCourseEnv.getCourseEnvironment().getCourseGroupManager());
    assertFalse("Wrong enrollment, user='wg3' is in PartipiciantGroup, must be on waiting-list", businessGroupService.isIdentityInBusinessGroup(wg3, bgWithWaitingList));
    assertFalse("Wrong enrollment, user='wg3' is in PartipiciantGroup, must be on waiting-list", businessGroupService.hasRoles(wg3, bgWithWaitingList, GroupRoles.participant.name()));
    assertTrue("Wrong enrollment, user='wg3' must be on waiting-list", businessGroupService.hasRoles(wg3, bgWithWaitingList, GroupRoles.waiting.name()));
    assertTrue("Enrollment failed, user='wg2'", businessGroupService.isIdentityInBusinessGroup(wg2, bgWithWaitingList));
    assertTrue("Enrollment failed, user='wg1'", businessGroupService.isIdentityInBusinessGroup(wg1, bgWithWaitingList));
    participantsCounter = businessGroupService.countMembers(bgWithWaitingList, GroupRoles.participant.name());
    assertTrue("Wrong number of participants," + participantsCounter, participantsCounter == 2);
    int waitingListCounter = businessGroupService.countMembers(bgWithWaitingList, GroupRoles.waiting.name());
    assertTrue("Wrong number of waiting-list, must be 1, is " + waitingListCounter, waitingListCounter == 1);
    // cancel enrollment for wg2 => transfer wg3 from waiting-list to participants
    ienv = new IdentityEnvironment();
    ienv.setIdentity(wg2);
    userCourseEnv = new UserCourseEnvironmentImpl(ienv, cenv);
    coursePropertyManager = userCourseEnv.getCourseEnvironment().getCoursePropertyManager();
    enrollmentManager.doCancelEnrollment(wg2, bgWithWaitingList, enNode, coursePropertyManager, this, /*WindowControl mock*/
    testTranslator);
    assertFalse("Cancel enrollment failed, user='wg2' is still participants.", businessGroupService.isIdentityInBusinessGroup(wg2, bgWithWaitingList));
    assertTrue("Enrollment failed, user='wg3'", businessGroupService.isIdentityInBusinessGroup(wg3, bgWithWaitingList));
    assertTrue("Enrollment failed, user='wg1'", businessGroupService.isIdentityInBusinessGroup(wg1, bgWithWaitingList));
    participantsCounter = businessGroupService.countMembers(bgWithWaitingList, GroupRoles.participant.name());
    assertTrue("Wrong number of participants, must be 2, is " + participantsCounter, participantsCounter == 2);
    waitingListCounter = businessGroupService.countMembers(bgWithWaitingList, GroupRoles.waiting.name());
    assertTrue("Wrong number of waiting-list, must be 0, is " + waitingListCounter, waitingListCounter == 0);
    // cancel enrollment for wg1
    ienv = new IdentityEnvironment();
    ienv.setIdentity(wg1);
    userCourseEnv = new UserCourseEnvironmentImpl(ienv, cenv);
    coursePropertyManager = userCourseEnv.getCourseEnvironment().getCoursePropertyManager();
    enrollmentManager.doCancelEnrollment(wg1, bgWithWaitingList, enNode, coursePropertyManager, this, /*WindowControl mock*/
    testTranslator);
    assertFalse("Cancel enrollment failed, user='wg2' is still participants.", businessGroupService.isIdentityInBusinessGroup(wg2, bgWithWaitingList));
    assertFalse("Cancel enrollment failed, user='wg1' is still participants.", businessGroupService.isIdentityInBusinessGroup(wg1, bgWithWaitingList));
    assertTrue("Enrollment failed, user='wg3'", businessGroupService.isIdentityInBusinessGroup(wg3, bgWithWaitingList));
    participantsCounter = businessGroupService.countMembers(bgWithWaitingList, GroupRoles.participant.name());
    assertTrue("Wrong number of participants, must be 1, is " + participantsCounter, participantsCounter == 1);
    waitingListCounter = businessGroupService.countMembers(bgWithWaitingList, GroupRoles.waiting.name());
    assertTrue("Wrong number of waiting-list, must be 0, is " + waitingListCounter, waitingListCounter == 0);
    // cancel enrollment for wg3
    ienv = new IdentityEnvironment();
    ienv.setIdentity(wg3);
    userCourseEnv = new UserCourseEnvironmentImpl(ienv, cenv);
    coursePropertyManager = userCourseEnv.getCourseEnvironment().getCoursePropertyManager();
    enrollmentManager.doCancelEnrollment(wg3, bgWithWaitingList, enNode, coursePropertyManager, this, /*WindowControl mock*/
    testTranslator);
    assertFalse("Cancel enrollment failed, user='wg3' is still participants.", businessGroupService.isIdentityInBusinessGroup(wg3, bgWithWaitingList));
    assertFalse("Cancel enrollment failed, user='wg2' is still participants.", businessGroupService.isIdentityInBusinessGroup(wg2, bgWithWaitingList));
    assertFalse("Cancel enrollment failed, user='wg1' is still participants.", businessGroupService.isIdentityInBusinessGroup(wg1, bgWithWaitingList));
    participantsCounter = businessGroupService.countMembers(bgWithWaitingList, GroupRoles.participant.name());
    assertTrue("Wrong number of participants, must be 0, is " + participantsCounter, participantsCounter == 0);
    waitingListCounter = businessGroupService.countMembers(bgWithWaitingList, GroupRoles.waiting.name());
    assertTrue("Wrong number of waiting-list, must be 0, is " + waitingListCounter, waitingListCounter == 0);
    log.info("testEnroll: done...");
}
Also used : ENCourseNode(org.olat.course.nodes.ENCourseNode) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) CourseEnvironment(org.olat.course.run.environment.CourseEnvironment) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager) Test(org.junit.Test)

Example 34 with CoursePropertyManager

use of org.olat.course.properties.CoursePropertyManager in project openolat by klemens.

the class IQSURVCourseNode method cleanupOnDelete.

/**
 * @see org.olat.course.nodes.CourseNode#cleanupOnDelete(org.olat.course.ICourse)
 */
@Override
public void cleanupOnDelete(ICourse course) {
    super.cleanupOnDelete(course);
    CoursePropertyManager pm = course.getCourseEnvironment().getCoursePropertyManager();
    // 1) Delete all properties: attempts
    pm.deleteNodeProperties(this, null);
    // 2) Delete all qtiresults for this node
    String repositorySoftKey = (String) getModuleConfiguration().get(IQEditController.CONFIG_KEY_REPOSITORY_SOFTKEY);
    RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntryBySoftkey(repositorySoftKey, false);
    if (re != null) {
        QTIResultManager.getInstance().deleteAllResults(course.getResourceableId(), getIdent(), re.getKey());
    }
}
Also used : RepositoryEntry(org.olat.repository.RepositoryEntry) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager)

Example 35 with CoursePropertyManager

use of org.olat.course.properties.CoursePropertyManager in project openolat by klemens.

the class MSCourseNode method cleanupOnDelete.

/**
 * @see org.olat.course.nodes.CourseNode#cleanupOnDelete(
 *      org.olat.course.ICourse)
 */
@Override
public void cleanupOnDelete(ICourse course) {
    super.cleanupOnDelete(course);
    CoursePropertyManager pm = course.getCourseEnvironment().getCoursePropertyManager();
    // Delete all properties: score, passed, log, comment, coach_comment
    pm.deleteNodeProperties(this, null);
    OLATResource resource = course.getCourseEnvironment().getCourseGroupManager().getCourseResource();
    CoreSpringFactory.getImpl(TaskExecutorManager.class).delete(resource, getIdent());
}
Also used : TaskExecutorManager(org.olat.core.commons.services.taskexecutor.TaskExecutorManager) OLATResource(org.olat.resource.OLATResource) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager) PersistingCoursePropertyManager(org.olat.course.properties.PersistingCoursePropertyManager)

Aggregations

CoursePropertyManager (org.olat.course.properties.CoursePropertyManager)108 Property (org.olat.properties.Property)62 PersistingCoursePropertyManager (org.olat.course.properties.PersistingCoursePropertyManager)44 Identity (org.olat.core.id.Identity)28 File (java.io.File)18 ICourse (org.olat.course.ICourse)18 ProjectBrokerManager (org.olat.course.nodes.projectbroker.service.ProjectBrokerManager)14 CourseNode (org.olat.course.nodes.CourseNode)12 Project (org.olat.course.nodes.projectbroker.datamodel.Project)12 RepositoryEntry (org.olat.repository.RepositoryEntry)12 AssessmentChangedEvent (org.olat.course.assessment.AssessmentChangedEvent)10 UserNodeAuditManager (org.olat.course.auditing.UserNodeAuditManager)10 ProjectGroupManager (org.olat.course.nodes.projectbroker.service.ProjectGroupManager)10 BusinessGroup (org.olat.group.BusinessGroup)10 XStream (com.thoughtworks.xstream.XStream)8 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)8 TaskExecutorManager (org.olat.core.commons.services.taskexecutor.TaskExecutorManager)8 PackageTranslator (org.olat.core.gui.translator.PackageTranslator)8 Translator (org.olat.core.gui.translator.Translator)8 SyncerExecutor (org.olat.core.util.coordinate.SyncerExecutor)8