Search in sources :

Example 1 with RepositoryEntryLifecycle

use of org.olat.repository.model.RepositoryEntryLifecycle in project OpenOLAT by OpenOLAT.

the class CoursefolderWebDAVMergeSource method appendCourses.

private void appendCourses(List<RepositoryEntry> courseEntries, boolean editor, List<VFSContainer> containers, boolean useTerms, Map<String, VFSContainer> terms, VirtualContainer noTermContainer, VirtualContainer finishedContainer, boolean prependReference, UniqueNames container) {
    // Add all found repo entries to merge source
    int count = 0;
    for (RepositoryEntry re : courseEntries) {
        if (container.isDuplicate(re)) {
            continue;
        }
        String displayName = re.getDisplayname();
        if (prependReference && StringHelper.containsNonWhitespace(re.getExternalRef())) {
            displayName = re.getExternalRef() + " " + displayName;
        }
        String courseTitle = RequestUtil.normalizeFilename(displayName);
        if (finishedContainer != null && re.getRepositoryEntryStatus().isClosed()) {
            String name = container.getFinishedUniqueName(courseTitle);
            NamedContainerImpl cfContainer = new CoursefolderWebDAVNamedContainer(name, re, editor ? null : identityEnv);
            finishedContainer.getItems().add(cfContainer);
        } else if (useTerms) {
            RepositoryEntryLifecycle lc = re.getLifecycle();
            if (lc != null && !lc.isPrivateCycle()) {
                // when a semester term info is found, add it to corresponding term folder
                String termSoftKey = lc.getSoftKey();
                VFSContainer termContainer = terms.get(termSoftKey);
                if (termContainer == null) {
                    // folder for this semester term does not yet exist, create one and add to map
                    String normalizedKey = RequestUtil.normalizeFilename(termSoftKey);
                    termContainer = new VirtualContainer(normalizedKey);
                    terms.put(termSoftKey, termContainer);
                    addContainerToList(termContainer, containers);
                }
                String name = container.getTermUniqueName(termSoftKey, courseTitle);
                NamedContainerImpl cfContainer = new CoursefolderWebDAVNamedContainer(name, re, editor ? null : identityEnv);
                termContainer.getItems().add(cfContainer);
            } else {
                // no semester term found, add to no-term folder
                String name = container.getNoTermUniqueName(courseTitle);
                NamedContainerImpl cfContainer = new CoursefolderWebDAVNamedContainer(name, re, editor ? null : identityEnv);
                noTermContainer.getItems().add(cfContainer);
            }
        } else {
            String name = container.getContainersUniqueName(courseTitle);
            NamedContainerImpl cfContainer = new CoursefolderWebDAVNamedContainer(name, re, editor ? null : identityEnv);
            addContainerToList(cfContainer, containers);
        }
        if (++count % 5 == 0) {
            DBFactory.getInstance().commitAndCloseSession();
        }
    }
}
Also used : RepositoryEntryLifecycle(org.olat.repository.model.RepositoryEntryLifecycle) VFSContainer(org.olat.core.util.vfs.VFSContainer) RepositoryEntry(org.olat.repository.RepositoryEntry) NamedContainerImpl(org.olat.core.util.vfs.NamedContainerImpl) VirtualContainer(org.olat.core.util.vfs.VirtualContainer)

Example 2 with RepositoryEntryLifecycle

use of org.olat.repository.model.RepositoryEntryLifecycle in project OpenOLAT by OpenOLAT.

the class GTAReminderRuleTest method submitTask_relativeLifecycle.

@Test
public void submitTask_relativeLifecycle() {
    // prepare a course with a volatile task
    Identity participant1 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-1");
    Identity participant2 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-2");
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry("", false);
    repositoryEntryRelationDao.addRole(participant1, re, GroupRoles.participant.name());
    repositoryEntryRelationDao.addRole(participant2, re, GroupRoles.participant.name());
    dbInstance.commit();
    String label = "Life cycle for relative date";
    String softKey = UUID.randomUUID().toString();
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date());
    cal.add(Calendar.DATE, -5);
    Date from = cal.getTime();
    cal.add(Calendar.DATE, 20);
    Date to = cal.getTime();
    RepositoryEntryLifecycle lifecycle = reLifeCycleDao.create(label, softKey, true, from, to);
    re.setLifecycle(lifecycle);
    re = dbInstance.getCurrentEntityManager().merge(re);
    dbInstance.commit();
    // create a fake node with a relative submit deadline 15 days after the start of the course
    GTACourseNode node = new GTACourseNode();
    node.getModuleConfiguration().setStringValue(GTACourseNode.GTASK_TYPE, GTAType.individual.name());
    node.getModuleConfiguration().setBooleanEntry(GTACourseNode.GTASK_RELATIVE_DATES, true);
    node.getModuleConfiguration().setIntValue(GTACourseNode.GTASK_SUBMIT_DEADLINE_RELATIVE, 15);
    node.getModuleConfiguration().setStringValue(GTACourseNode.GTASK_SUBMIT_DEADLINE_RELATIVE_TO, GTARelativeToDates.courseStart.name());
    TaskList tasks = gtaManager.createIfNotExists(re, node);
    Assert.assertNotNull(tasks);
    dbInstance.commitAndCloseSession();
    // the course has start 5 days before, deadline is 15 days after it
    // conclusion the deadline is 10 days from now
    {
        // check before 5 days
        ReminderRuleImpl rule = getSubmitTaskRules(5, LaunchUnit.day);
        List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(0, all.size());
    }
    {
        // check before 1 week
        ReminderRuleImpl rule = getSubmitTaskRules(1, LaunchUnit.week);
        List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(0, all.size());
    }
    {
        // check before 10 days
        ReminderRuleImpl rule = getSubmitTaskRules(10, LaunchUnit.day);
        List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(2, all.size());
        Assert.assertTrue(all.contains(participant1));
        Assert.assertTrue(all.contains(participant2));
    }
    {
        // check before 2 days
        ReminderRuleImpl rule = getSubmitTaskRules(10, LaunchUnit.week);
        List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(2, all.size());
        Assert.assertTrue(all.contains(participant1));
        Assert.assertTrue(all.contains(participant2));
    }
    {
        // check before 30 days
        ReminderRuleImpl rule = getSubmitTaskRules(30, LaunchUnit.day);
        List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(2, all.size());
        Assert.assertTrue(all.contains(participant1));
        Assert.assertTrue(all.contains(participant2));
    }
    {
        // check before 1 months
        ReminderRuleImpl rule = getSubmitTaskRules(1, LaunchUnit.month);
        List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(2, all.size());
        Assert.assertTrue(all.contains(participant1));
        Assert.assertTrue(all.contains(participant2));
    }
    {
        // check before 5 months
        ReminderRuleImpl rule = getSubmitTaskRules(5, LaunchUnit.month);
        List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(2, all.size());
        Assert.assertTrue(all.contains(participant1));
        Assert.assertTrue(all.contains(participant2));
    }
    {
        // check before 1 year
        ReminderRuleImpl rule = getSubmitTaskRules(1, LaunchUnit.year);
        List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(2, all.size());
        Assert.assertTrue(all.contains(participant1));
        Assert.assertTrue(all.contains(participant2));
    }
}
Also used : ReminderRuleImpl(org.olat.modules.reminder.model.ReminderRuleImpl) RepositoryEntryLifecycle(org.olat.repository.model.RepositoryEntryLifecycle) Calendar(java.util.Calendar) TaskList(org.olat.course.nodes.gta.TaskList) GTACourseNode(org.olat.course.nodes.GTACourseNode) ArrayList(java.util.ArrayList) TaskList(org.olat.course.nodes.gta.TaskList) List(java.util.List) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) Date(java.util.Date) Test(org.junit.Test)

Example 3 with RepositoryEntryLifecycle

use of org.olat.repository.model.RepositoryEntryLifecycle in project OpenOLAT by OpenOLAT.

the class RepositoryEntryLifecycleDAOTest method loadPublicLifeCycles.

@Test
public void loadPublicLifeCycles() {
    // create a public life cycle object
    String label = "A public life cycle";
    RepositoryEntryLifecycle publicRelf = reLifeCycleDao.create(label, null, false, null, null);
    dbInstance.commitAndCloseSession();
    // load public life cycle
    List<RepositoryEntryLifecycle> publicLifeCycles = reLifeCycleDao.loadPublicLifecycle();
    Assert.assertNotNull(publicLifeCycles);
    Assert.assertFalse(publicLifeCycles.isEmpty());
    Assert.assertTrue(publicLifeCycles.contains(publicRelf));
}
Also used : RepositoryEntryLifecycle(org.olat.repository.model.RepositoryEntryLifecycle) Test(org.junit.Test)

Example 4 with RepositoryEntryLifecycle

use of org.olat.repository.model.RepositoryEntryLifecycle in project OpenOLAT by OpenOLAT.

the class RepositoryEntryLifecycleDAOTest method getLifeCycle.

@Test
public void getLifeCycle() {
    String label = "My second life cycle";
    String softKey = UUID.randomUUID().toString();
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date());
    cal.add(Calendar.DATE, -1);
    Date from = cal.getTime();
    cal.add(Calendar.DATE, +2);
    Date to = cal.getTime();
    RepositoryEntryLifecycle relf = reLifeCycleDao.create(label, softKey, true, from, to);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(relf);
    Assert.assertNotNull(relf.getKey());
    // check
    RepositoryEntryLifecycle loadedLifeCycle = reLifeCycleDao.loadById(relf.getKey());
    Assert.assertNotNull(loadedLifeCycle);
    Assert.assertNotNull(loadedLifeCycle.getCreationDate());
    Assert.assertNotNull(loadedLifeCycle.getLastModified());
    Assert.assertEquals(relf.getKey(), loadedLifeCycle.getKey());
    Assert.assertEquals("My second life cycle", loadedLifeCycle.getLabel());
    Assert.assertEquals(softKey, loadedLifeCycle.getSoftKey());
    Assert.assertTrue(loadedLifeCycle.isPrivateCycle());
    Assert.assertNotNull(loadedLifeCycle.getValidFrom());
    Assert.assertNotNull(loadedLifeCycle.getValidTo());
}
Also used : RepositoryEntryLifecycle(org.olat.repository.model.RepositoryEntryLifecycle) Calendar(java.util.Calendar) Date(java.util.Date) Test(org.junit.Test)

Example 5 with RepositoryEntryLifecycle

use of org.olat.repository.model.RepositoryEntryLifecycle in project OpenOLAT by OpenOLAT.

the class CoursesTest method setUp.

/**
 * SetUp is called before each test.
 */
@Before
public void setUp() throws Exception {
    super.setUp();
    conn = new RestConnection();
    try {
        // create course and persist as OLATResourceImpl
        admin = BaseSecurityManager.getInstance().findIdentityByName("administrator");
        course1 = CoursesWebService.createEmptyCourse(admin, "courses1", "courses1 long name", null, null, null, RepositoryEntry.ACC_OWNERS, false, null, null, null, null, null, null);
        externalId = UUID.randomUUID().toString();
        externalRef = UUID.randomUUID().toString();
        course2 = CoursesWebService.createEmptyCourse(admin, "courses2", "courses2 long name", null, null, null, RepositoryEntry.ACC_OWNERS, false, null, null, externalId, externalRef, "all", null);
        dbInstance.commitAndCloseSession();
        re1 = repositoryManager.lookupRepositoryEntry(course1, false);
        re2 = repositoryManager.lookupRepositoryEntry(course2, false);
        externalId3 = UUID.randomUUID().toString();
        course3 = CoursesWebService.createEmptyCourse(admin, "courses3", "courses3 long name", null, null, null, RepositoryEntry.ACC_OWNERS, false, null, null, externalId3, null, "all", null);
        re3 = repositoryManager.lookupRepositoryEntry(course3, false);
        RepositoryEntryLifecycle lifecycle3 = reLifecycleDao.create("course3 lifecycle", UUID.randomUUID().toString(), true, new Date(), new Date());
        dbInstance.commit();
        re3.setLifecycle(lifecycle3);
        re3 = dbInstance.getCurrentEntityManager().merge(re3);
        dbInstance.commitAndCloseSession();
    } catch (Exception e) {
        log.error("Exception in setUp(): " + e);
    }
}
Also used : RepositoryEntryLifecycle(org.olat.repository.model.RepositoryEntryLifecycle) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) Before(org.junit.Before)

Aggregations

RepositoryEntryLifecycle (org.olat.repository.model.RepositoryEntryLifecycle)54 Date (java.util.Date)34 Test (org.junit.Test)22 Calendar (java.util.Calendar)18 ArrayList (java.util.ArrayList)12 RepositoryEntry (org.olat.repository.RepositoryEntry)12 List (java.util.List)6 Identity (org.olat.core.id.Identity)6 RepositoryEntryLifecycleVO (org.olat.restapi.support.vo.RepositoryEntryLifecycleVO)6 Produces (javax.ws.rs.Produces)4 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)4 VFSContainer (org.olat.core.util.vfs.VFSContainer)4 ICourse (org.olat.course.ICourse)4 CourseEditorEnv (org.olat.course.editor.CourseEditorEnv)4 RepositoryEntryLifecycleDAO (org.olat.repository.manager.RepositoryEntryLifecycleDAO)4 LocalFileImpl (org.olat.core.util.vfs.LocalFileImpl)3 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)3 File (java.io.File)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2