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();
}
}
}
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));
}
}
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));
}
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());
}
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);
}
}
Aggregations