Search in sources :

Example 36 with CourseEnvironment

use of org.olat.course.run.environment.CourseEnvironment in project openolat by klemens.

the class FinishCallback method execute.

@Override
public Step execute(UserRequest ureq, WindowControl wControl, StepsRunContext runContext) {
    FOCourseNode node = (FOCourseNode) runContext.get(SendMailStepForm.FORUM);
    ICourse course = (ICourse) runContext.get(SendMailStepForm.ICOURSE);
    CourseEnvironment courseEnv = course.getCourseEnvironment();
    Forum chosenforum = node.loadOrCreateForum(courseEnv);
    Message msg = (Message) runContext.get(SendMailStepForm.MESSAGE_TO_MOVE);
    msg = forumManager.getMessageById(msg.getKey());
    Message parentMessage = (Message) runContext.get(SendMailStepForm.PARENT_MESSAGE);
    if (parentMessage != null) {
        parentMessage = forumManager.getMessageById(parentMessage.getKey());
    }
    if (msg.getParentKey() == null && msg.getThreadtop() == null) {
        msg = forumManager.createOrAppendThreadInAnotherForum(msg, chosenforum, parentMessage);
    } else {
        msg = forumManager.moveMessageToAnotherForum(msg, chosenforum, parentMessage);
    }
    // commit before sending event
    DBFactory.getInstance().commit();
    if ((Boolean) runContext.get(SendMailStepForm.SENDMAIL)) {
        sendMail(ureq, wControl, runContext);
    }
    return StepsMainRunController.DONE_MODIFIED;
}
Also used : CourseEnvironment(org.olat.course.run.environment.CourseEnvironment) Message(org.olat.modules.fo.Message) FOCourseNode(org.olat.course.nodes.FOCourseNode) ICourse(org.olat.course.ICourse) Forum(org.olat.modules.fo.Forum)

Example 37 with CourseEnvironment

use of org.olat.course.run.environment.CourseEnvironment in project openolat by klemens.

the class ConvertToGTACourseNode method convertAssessmentDatas.

private void convertAssessmentDatas(TaskList taskList, TACourseNode sourceNode, GTACourseNode gtaNode, ICourse course) {
    CourseEnvironment courseEnv = course.getCourseEnvironment();
    CoursePropertyManager propertyMgr = courseEnv.getCoursePropertyManager();
    Map<Long, AssessmentEntry> datas = new HashMap<>();
    List<AssessmentEntry> properties = courseEnv.getAssessmentManager().getAssessmentEntries(sourceNode);
    for (AssessmentEntry property : properties) {
        Identity identity = property.getIdentity();
        datas.put(identity.getKey(), property);
    }
    properties = null;
    DBFactory.getInstance().getCurrentEntityManager().clear();
    AssessmentManager assessmentMgr = courseEnv.getAssessmentManager();
    for (AssessmentEntry assessmentData : datas.values()) {
        Identity assessedIdentity = securityManager.loadIdentityByKey(assessmentData.getIdentity().getKey());
        if (assessmentData.getPassed() != null || assessmentData.getScore() != null) {
            UserCourseEnvironment userCourseEnv = AssessmentHelper.createAndInitUserCourseEnvironment(assessedIdentity, course);
            Float score = assessmentData.getScore() == null ? null : assessmentData.getScore().floatValue();
            ScoreEvaluation scoreEval = new ScoreEvaluation(score, assessmentData.getPassed());
            assessmentMgr.saveScoreEvaluation(gtaNode, null, assessedIdentity, scoreEval, userCourseEnv, false, Role.auto);
            // set graded
            Task task = gtaManager.getTask(assessedIdentity, taskList);
            if (task == null) {
                gtaManager.createTask(null, taskList, TaskProcess.graded, null, assessedIdentity, gtaNode);
            } else {
                gtaManager.updateTask(task, TaskProcess.graded, gtaNode, Role.auto);
            }
        }
        if (assessmentData.getAttempts() != null) {
            assessmentMgr.saveNodeAttempts(gtaNode, null, assessedIdentity, assessmentData.getAttempts().intValue(), Role.auto);
        }
        if (StringHelper.containsNonWhitespace(assessmentData.getCoachComment())) {
            assessmentMgr.saveNodeCoachComment(gtaNode, assessedIdentity, assessmentData.getCoachComment());
        }
        if (StringHelper.containsNonWhitespace(assessmentData.getComment())) {
            assessmentMgr.saveNodeComment(gtaNode, null, assessedIdentity, assessmentData.getComment());
        }
    }
    DBFactory.getInstance().getCurrentEntityManager().clear();
    // copy log entries
    List<Property> logEntries = propertyMgr.listCourseNodeProperties(sourceNode, null, null, UserNodeAuditManager.LOG_IDENTIFYER);
    for (Property logEntry : logEntries) {
        String logText = logEntry.getTextValue();
        Identity identity = securityManager.loadIdentityByKey(logEntry.getIdentity().getKey());
        Property targetProp = propertyMgr.findCourseNodeProperty(gtaNode, identity, null, UserNodeAuditManager.LOG_IDENTIFYER);
        if (targetProp == null) {
            targetProp = propertyMgr.createCourseNodePropertyInstance(gtaNode, identity, null, UserNodeAuditManager.LOG_IDENTIFYER, null, null, null, logText);
        } else {
            targetProp.setTextValue(logText);
        }
        propertyMgr.saveProperty(targetProp);
    }
}
Also used : ScoreEvaluation(org.olat.course.run.scoring.ScoreEvaluation) Task(org.olat.course.nodes.gta.Task) CourseEnvironment(org.olat.course.run.environment.CourseEnvironment) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) HashMap(java.util.HashMap) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) AssessmentManager(org.olat.course.assessment.AssessmentManager) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry) Identity(org.olat.core.id.Identity) Property(org.olat.properties.Property) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager)

Example 38 with CourseEnvironment

use of org.olat.course.run.environment.CourseEnvironment in project openolat by klemens.

the class ConvertToGTACourseNode method convert.

public void convert(TACourseNode sourceNode, GTACourseNode gtaNode, ICourse course) {
    ModuleConfiguration modConfig = sourceNode.getModuleConfiguration();
    CourseEnvironment courseEnv = course.getCourseEnvironment();
    gtaNode.setShortTitle("New_ " + sourceNode.getShortTitle());
    gtaNode.setLongTitle("New_ " + sourceNode.getLongTitle());
    gtaNode.setDisplayOption(sourceNode.getDisplayOption());
    gtaNode.setLearningObjectives(sourceNode.getLearningObjectives());
    TaskList taskList = gtaManager.createIfNotExists(courseEnv.getCourseGroupManager().getCourseEntry(), gtaNode);
    DBFactory.getInstance().commit();
    convertConfiguration(sourceNode, gtaNode);
    if (modConfig.getBooleanSafe(TACourseNode.CONF_TASK_ENABLED)) {
        convertTasks(taskList, sourceNode, gtaNode, course);
        DBFactory.getInstance().commit();
    }
    if (modConfig.getBooleanSafe(TACourseNode.CONF_DROPBOX_ENABLED)) {
        convertDropbox(taskList, sourceNode, gtaNode, courseEnv);
        DBFactory.getInstance().commit();
    }
    if (modConfig.getBooleanSafe(TACourseNode.CONF_RETURNBOX_ENABLED)) {
        convertReturnbox(taskList, sourceNode, gtaNode, courseEnv);
        DBFactory.getInstance().commit();
    }
    if (modConfig.getBooleanSafe(TACourseNode.CONF_SCORING_ENABLED)) {
        // copy the scores
        convertAssessmentDatas(taskList, sourceNode, gtaNode, course);
        DBFactory.getInstance().commit();
    }
    // solutions
    if (modConfig.getBooleanSafe(TACourseNode.CONF_SOLUTION_ENABLED)) {
        copySolutions(sourceNode, gtaNode, courseEnv);
    }
}
Also used : ModuleConfiguration(org.olat.modules.ModuleConfiguration) CourseEnvironment(org.olat.course.run.environment.CourseEnvironment) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) TaskList(org.olat.course.nodes.gta.TaskList)

Example 39 with CourseEnvironment

use of org.olat.course.run.environment.CourseEnvironment in project OpenOLAT by OpenOLAT.

the class EnrollmentManagerConcurrentTest method testConcurrentEnrollmentWithWaitingList_big.

@Test
@Ignore
public void testConcurrentEnrollmentWithWaitingList_big() {
    List<Identity> ids = new ArrayList<Identity>(100);
    for (int i = 0; i < 100; i++) {
        Identity id = JunitTestHelper.createAndPersistIdentityAsUser("enroll-a-" + i + "-" + UUID.randomUUID().toString());
        ids.add(id);
    }
    Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("enroller");
    RepositoryEntry addedEntry = JunitTestHelper.deployBasicCourse(author);
    ENCourseNode enNode1 = new ENCourseNode();
    ENCourseNode enNode2 = new ENCourseNode();
    ENCourseNode enNode3 = new ENCourseNode();
    ENCourseNode enNode4 = new ENCourseNode();
    ENCourseNode enNode5 = new ENCourseNode();
    CourseEnvironment cenv = CourseFactory.loadCourse(addedEntry).getCourseEnvironment();
    BusinessGroup group1 = businessGroupService.createBusinessGroup(author, "Enrollment 1", "Enroll 1", new Integer(1), new Integer(8), true, true, addedEntry);
    BusinessGroup group2 = businessGroupService.createBusinessGroup(author, "Enrollment 2", "Enroll 2", new Integer(1), new Integer(10), true, true, addedEntry);
    BusinessGroup group3 = businessGroupService.createBusinessGroup(author, "Enrollment 3", "Enroll 3", new Integer(1), new Integer(4), true, true, addedEntry);
    BusinessGroup group4 = businessGroupService.createBusinessGroup(author, "Enrollment 4", "Enroll 4", new Integer(1), new Integer(10), true, true, addedEntry);
    BusinessGroup group5 = businessGroupService.createBusinessGroup(author, "Enrollment 5", "Enroll 5", new Integer(1), new Integer(9), true, true, addedEntry);
    dbInstance.commitAndCloseSession();
    EnrollThread[] threads = new EnrollThread[100];
    final CountDownLatch doneSignal = new CountDownLatch(ids.size());
    int t = 0;
    for (int i = 0; i < 30; i++) {
        threads[t++] = new EnrollThread(ids.get(i), addedEntry, group1, enNode1, cenv, doneSignal);
    }
    for (int i = 30; i < 50; i++) {
        threads[t++] = new EnrollThread(ids.get(i), addedEntry, group2, enNode2, cenv, doneSignal);
    }
    for (int i = 50; i < 70; i++) {
        threads[t++] = new EnrollThread(ids.get(i), addedEntry, group3, enNode3, cenv, doneSignal);
    }
    for (int i = 70; i < 90; i++) {
        threads[t++] = new EnrollThread(ids.get(i), addedEntry, group4, enNode4, cenv, doneSignal);
    }
    for (int i = 90; i < 100; i++) {
        threads[t++] = new EnrollThread(ids.get(i), addedEntry, group5, enNode5, cenv, doneSignal);
    }
    for (EnrollThread thread : threads) {
        thread.start();
    }
    try {
        boolean interrupt = doneSignal.await(360, TimeUnit.SECONDS);
        assertTrue("Test takes too long (more than 10s)", interrupt);
    } catch (InterruptedException e) {
        fail("" + e.getMessage());
    }
    dbInstance.commitAndCloseSession();
    List<Identity> enrolled_1_Ids = businessGroupService.getMembers(group1, GroupRoles.participant.name());
    Assert.assertEquals(8, enrolled_1_Ids.size());
    List<Identity> enrolled_2_Ids = businessGroupService.getMembers(group2, GroupRoles.participant.name());
    Assert.assertEquals(10, enrolled_2_Ids.size());
    List<Identity> enrolled_3_Ids = businessGroupService.getMembers(group3, GroupRoles.participant.name());
    Assert.assertEquals(4, enrolled_3_Ids.size());
    List<Identity> enrolled_4_Ids = businessGroupService.getMembers(group4, GroupRoles.participant.name());
    Assert.assertEquals(10, enrolled_4_Ids.size());
    List<Identity> enrolled_5_Ids = businessGroupService.getMembers(group5, GroupRoles.participant.name());
    Assert.assertEquals(9, enrolled_5_Ids.size());
}
Also used : UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) CourseEnvironment(org.olat.course.run.environment.CourseEnvironment) BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) CountDownLatch(java.util.concurrent.CountDownLatch) ENCourseNode(org.olat.course.nodes.ENCourseNode) Identity(org.olat.core.id.Identity) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 40 with CourseEnvironment

use of org.olat.course.run.environment.CourseEnvironment in project OpenOLAT by OpenOLAT.

the class EnrollmentManagerConcurrentTest method testConcurrentEnrollmentWithWaitingList.

@Test
public void testConcurrentEnrollmentWithWaitingList() {
    int NUM_OF_USERS = 30;
    List<Identity> ids = new ArrayList<Identity>(NUM_OF_USERS);
    for (int i = 0; i < NUM_OF_USERS; i++) {
        Identity id = JunitTestHelper.createAndPersistIdentityAsUser("enroll-a-" + i + "-" + UUID.randomUUID().toString());
        ids.add(id);
    }
    ENCourseNode enNode = new ENCourseNode();
    Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("enroller");
    RepositoryEntry addedEntry = JunitTestHelper.deployBasicCourse(author);
    CourseEnvironment cenv = CourseFactory.createCourse(addedEntry, "Test-Enroll", "Test", "Test enrollment with concurrent users").getCourseEnvironment();
    BusinessGroup group = businessGroupService.createBusinessGroup(id1, "Enrollment", "Enroll", new Integer(1), new Integer(10), true, false, null);
    Assert.assertNotNull(group);
    dbInstance.commitAndCloseSession();
    final CountDownLatch doneSignal = new CountDownLatch(ids.size());
    EnrollThread[] threads = new EnrollThread[NUM_OF_USERS];
    int t = 0;
    for (Identity id : ids) {
        threads[t++] = new EnrollThread(id, addedEntry, group, enNode, cenv, doneSignal);
    }
    for (EnrollThread thread : threads) {
        thread.start();
    }
    try {
        boolean interrupt = doneSignal.await(360, TimeUnit.SECONDS);
        assertTrue("Test takes too long (more than 10s)", interrupt);
    } catch (InterruptedException e) {
        fail("" + e.getMessage());
    }
    dbInstance.commitAndCloseSession();
    List<Identity> enrolledIds = businessGroupService.getMembers(group, GroupRoles.participant.name());
    Assert.assertNotNull(enrolledIds);
    Assert.assertEquals(10, enrolledIds.size());
    List<Identity> waitingIds = businessGroupService.getMembers(group, GroupRoles.waiting.name());
    Assert.assertNotNull(waitingIds);
    Assert.assertEquals(ids.size() - 10, waitingIds.size());
}
Also used : UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) CourseEnvironment(org.olat.course.run.environment.CourseEnvironment) BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) CountDownLatch(java.util.concurrent.CountDownLatch) ENCourseNode(org.olat.course.nodes.ENCourseNode) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Aggregations

CourseEnvironment (org.olat.course.run.environment.CourseEnvironment)80 UserCourseEnvironment (org.olat.course.run.userview.UserCourseEnvironment)64 RepositoryEntry (org.olat.repository.RepositoryEntry)34 Identity (org.olat.core.id.Identity)28 ICourse (org.olat.course.ICourse)18 VFSContainer (org.olat.core.util.vfs.VFSContainer)16 File (java.io.File)14 Date (java.util.Date)14 CourseNode (org.olat.course.nodes.CourseNode)14 Test (org.junit.Test)12 AssessableCourseNode (org.olat.course.nodes.AssessableCourseNode)12 BusinessGroup (org.olat.group.BusinessGroup)12 ModuleConfiguration (org.olat.modules.ModuleConfiguration)12 ArrayList (java.util.ArrayList)10 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)10 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)10 IQTESTCourseNode (org.olat.course.nodes.IQTESTCourseNode)10 Path (java.nio.file.Path)8 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)8 OLATResourceable (org.olat.core.id.OLATResourceable)8