Search in sources :

Example 41 with ICourse

use of org.olat.course.ICourse in project OpenOLAT by OpenOLAT.

the class EfficiencyStatementManagerTest method deployTestcourse.

private RepositoryEntry deployTestcourse() throws URISyntaxException {
    // deploy a course
    URL courseWithForumsUrl = CoachingLargeTest.class.getResource("CoachingCourse.zip");
    File courseWithForums = new File(courseWithForumsUrl.toURI());
    String softKey = UUID.randomUUID().toString();
    RepositoryEntry re = CourseFactory.deployCourseFromZIP(courseWithForums, softKey, 4);
    Assert.assertNotNull(re);
    dbInstance.commitAndCloseSession();
    ICourse course = CourseFactory.loadCourse(re);
    Assert.assertTrue(course.getCourseEnvironment().getCourseConfig().isEfficencyStatementEnabled());
    return re;
}
Also used : ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) File(java.io.File) URL(java.net.URL)

Example 42 with ICourse

use of org.olat.course.ICourse in project OpenOLAT by OpenOLAT.

the class UserNodeAuditManagerTest method testCreateLimitedLogContent.

@Test
public void testCreateLimitedLogContent() {
    // import a course
    Identity author = JunitTestHelper.createAndPersistIdentityAsUser("Auth-" + UUID.randomUUID());
    RepositoryEntry repositoryEntry = JunitTestHelper.deployDemoCourse(author);
    Long resourceableId = repositoryEntry.getOlatResource().getResourceableId();
    log.info("Demo course imported - resourceableId: " + resourceableId);
    ICourse course = CourseFactory.loadCourse(resourceableId);
    DBFactory.getInstance().commitAndCloseSession();
    log.info("Start testCreateLimitedLogContent");
    assertNotNull(course);
    UserNodeAuditManagerImpl userNodeAuditManagerImpl = new UserNodeAuditManagerImpl(course);
    StringBuilder logContent = new StringBuilder();
    logContent.append(createTestLogContent(1));
    String limitedLogContent = userNodeAuditManagerImpl.createLimitedLogContent(logContent.toString(), 400);
    assertEquals("logContent should not be limited", logContent.toString(), limitedLogContent);
    log.info("limitedLogContent:\n" + limitedLogContent);
    log.info("limitedLogContent.length=" + limitedLogContent.length());
    logContent.append(createTestLogContent(2));
    limitedLogContent = userNodeAuditManagerImpl.createLimitedLogContent(logContent.toString(), 400);
    assertEquals("logContent should not be limited", logContent.toString(), limitedLogContent);
    log.info("limitedLogContent:\n" + limitedLogContent);
    log.info("limitedLogContent.length=" + limitedLogContent.length());
    logContent.append(createTestLogContent(3));
    limitedLogContent = userNodeAuditManagerImpl.createLimitedLogContent(logContent.toString(), 400);
    assertEquals("logContent should not be limited", logContent.toString(), limitedLogContent);
    log.info("limitedLogContent:\n" + limitedLogContent);
    log.info("limitedLogContent.length=" + limitedLogContent.length());
    logContent.append(createTestLogContent(4));
    log.info("logContent.length()=" + logContent.length());
    limitedLogContent = userNodeAuditManagerImpl.createLimitedLogContent(logContent.toString(), 400);
    assertTrue("limitedLogContent same size like input, probably not limited", logContent.length() != limitedLogContent.length());
    assertTrue("logContent should not be limited", limitedLogContent.startsWith(UserNodeAuditManagerImpl.LOG_PREFIX_REMOVED_OLD_LOG_ENTRIES));
    assertTrue("Missing Log entry2", limitedLogContent.contains("LogEntry #2"));
    assertTrue("Missing Log entry3", limitedLogContent.contains("LogEntry #3"));
    assertTrue("Missing Log entry4", limitedLogContent.contains("LogEntry #4"));
    log.info("limitedLogContent:\n" + limitedLogContent);
    log.info("limitedLogContent.length=" + limitedLogContent.length());
    logContent.append(createTestLogContent(5));
    limitedLogContent = userNodeAuditManagerImpl.createLimitedLogContent(logContent.toString(), 400);
    assertTrue("limitedLogContent same size like input, probably not limited", logContent.length() != limitedLogContent.length());
    assertTrue("logContent should not be limited", limitedLogContent.startsWith(UserNodeAuditManagerImpl.LOG_PREFIX_REMOVED_OLD_LOG_ENTRIES));
    assertTrue("Missing Log entry3", limitedLogContent.contains("LogEntry #3"));
    assertTrue("Missing Log entry4", limitedLogContent.contains("LogEntry #4"));
    assertTrue("Missing Log entry5", limitedLogContent.contains("LogEntry #5"));
    log.info("limitedLogContent:\n" + limitedLogContent);
    log.info("limitedLogContent.length=" + limitedLogContent.length());
}
Also used : ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 43 with ICourse

use of org.olat.course.ICourse in project OpenOLAT by OpenOLAT.

the class GTAReminderRuleTest method getGTACourseNode.

private GTACourseNode getGTACourseNode(RepositoryEntry courseEntry) {
    ICourse course = CourseFactory.loadCourse(courseEntry);
    CourseNode rootNode = course.getRunStructure().getRootNode();
    for (int i = rootNode.getChildCount(); i-- > 0; ) {
        INode child = rootNode.getChildAt(i);
        if (child instanceof GTACourseNode) {
            return ((GTACourseNode) child);
        }
    }
    return null;
}
Also used : INode(org.olat.core.util.nodes.INode) GTACourseNode(org.olat.course.nodes.GTACourseNode) ICourse(org.olat.course.ICourse) CourseNode(org.olat.course.nodes.CourseNode) GTACourseNode(org.olat.course.nodes.GTACourseNode)

Example 44 with ICourse

use of org.olat.course.ICourse in project OpenOLAT by OpenOLAT.

the class HourOfDayStatisticUpdateManagerTest method statistics_hourOfDay.

@Test
public void statistics_hourOfDay() {
    Assert.assertNotNull(statisticUpdateManager);
    statisticUpdateManager.setEnabled(true);
    Assert.assertTrue(statisticUpdateManager.isEnabled());
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("log-3");
    RepositoryEntry re1 = JunitTestHelper.deployBasicCourse(id);
    ICourse course1 = CourseFactory.loadCourse(re1);
    CourseNode rootNode1 = course1.getRunStructure().getRootNode();
    CourseNode firstNode1 = (CourseNode) course1.getRunStructure().getRootNode().getChildAt(0);
    RepositoryEntry re2 = JunitTestHelper.deployBasicCourse(id);
    ICourse course2 = CourseFactory.loadCourse(re2);
    CourseNode rootNode2 = course2.getRunStructure().getRootNode();
    CourseNode firstNode2 = (CourseNode) course2.getRunStructure().getRootNode().getChildAt(0);
    Calendar ref = Calendar.getInstance();
    String date1 = null;
    String date2 = null;
    cleanUpLog();
    for (int i = 0; i < 12; i++) {
        addLogEntry(re1, rootNode1, ref, 0, getSecuredNowRef(ref, 1, i + 1), 1, i + 1);
        addLogEntry(re2, firstNode2, ref, 0, getSecuredNowRef(ref, 1, i + 1), 1, i + 1);
    }
    for (int i = 0; i < 7; i++) {
        addLogEntry(re1, rootNode1, ref, 1, 3 + i, 1, 1);
        date2 = addLogEntry(re2, rootNode2, ref, 1, 3 + i, 1, 1);
    }
    for (int i = 0; i < 9; i++) {
        date1 = addLogEntry(re1, firstNode1, ref, 2, 3 + i, 13, 1);
    }
    setLastUpdate(ref, 12);
    dbInstance.commitAndCloseSession();
    updateStatistics();
    // first log analyze
    String date = getHourOfDay(ref);
    checkStatistics(course1, rootNode1, date);
    checkStatistics(course1, firstNode1, date1);
    checkStatistics(course2, rootNode2, date2);
    // add log the same day
    Calendar now = Calendar.getInstance();
    addLogEntry(re1, rootNode1, ref, 0, now.get(Calendar.HOUR_OF_DAY), now.get(Calendar.MINUTE), now.get(Calendar.SECOND) + 1);
    addLogEntry(re1, rootNode1, ref, 0, now.get(Calendar.HOUR_OF_DAY), now.get(Calendar.MINUTE), now.get(Calendar.SECOND) + 2);
    addLogEntry(re2, firstNode2, ref, 0, now.get(Calendar.HOUR_OF_DAY), now.get(Calendar.MINUTE), now.get(Calendar.SECOND) + 2);
    dbInstance.commitAndCloseSession();
    sleep(5000);
    // update stats incremental
    updateStatistics();
    checkStatistics(course1, rootNode1, date);
    checkStatistics(course1, firstNode1, date1);
    checkStatistics(course2, rootNode2, date2);
    checkStatistics(course2, firstNode2, date);
    // update all stats, must be the same results
    updateAllStatistics();
    checkStatistics(course1, rootNode1, date);
    checkStatistics(course1, firstNode1, date1);
    checkStatistics(course2, rootNode2, date2);
    checkStatistics(course2, firstNode2, date);
}
Also used : Calendar(java.util.Calendar) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) CourseNode(org.olat.course.nodes.CourseNode) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 45 with ICourse

use of org.olat.course.ICourse in project OpenOLAT by OpenOLAT.

the class UserCourseInformationsManagerTest method createUpdateCourseInfos_create.

@Test
public void createUpdateCourseInfos_create() {
    Identity user = JunitTestHelper.createAndPersistIdentityAsUser("user-launch-1-" + UUID.randomUUID().toString());
    ICourse course = CoursesWebService.createEmptyCourse(user, "course-launch-dates", "course long name", null);
    dbInstance.commitAndCloseSession();
    OLATResource courseResource = course.getCourseEnvironment().getCourseGroupManager().getCourseResource();
    userCourseInformationsManager.updateUserCourseInformations(courseResource, user);
    dbInstance.commitAndCloseSession();
    UserCourseInformations infos = userCourseInformationsManager.getUserCourseInformations(courseResource, user);
    Assert.assertNotNull(infos);
    Assert.assertNotNull(infos.getIdentity());
    Assert.assertNotNull(infos.getResource());
    Assert.assertNotNull(infos.getInitialLaunch());
    Assert.assertNotNull(infos.getRecentLaunch());
    Assert.assertEquals(1, infos.getVisit());
    Assert.assertEquals(infos.getIdentity(), user);
    Assert.assertEquals(course.getResourceableId(), infos.getResource().getResourceableId());
    Assert.assertEquals(course.getResourceableTypeName(), infos.getResource().getResourceableTypeName());
}
Also used : OLATResource(org.olat.resource.OLATResource) ICourse(org.olat.course.ICourse) Identity(org.olat.core.id.Identity) UserCourseInformations(org.olat.course.assessment.UserCourseInformations) Test(org.junit.Test)

Aggregations

ICourse (org.olat.course.ICourse)674 Identity (org.olat.core.id.Identity)262 RepositoryEntry (org.olat.repository.RepositoryEntry)246 CourseNode (org.olat.course.nodes.CourseNode)182 Test (org.junit.Test)158 ArrayList (java.util.ArrayList)102 UserCourseEnvironment (org.olat.course.run.userview.UserCourseEnvironment)90 Date (java.util.Date)84 URI (java.net.URI)76 HttpResponse (org.apache.http.HttpResponse)76 OLATResource (org.olat.resource.OLATResource)64 File (java.io.File)62 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)52 AssessableCourseNode (org.olat.course.nodes.AssessableCourseNode)52 Produces (javax.ws.rs.Produces)48 Roles (org.olat.core.id.Roles)44 Path (javax.ws.rs.Path)42 UserRequest (org.olat.core.gui.UserRequest)42 INode (org.olat.core.util.nodes.INode)40 ScoreEvaluation (org.olat.course.run.scoring.ScoreEvaluation)40