use of org.olat.repository.model.RepositoryEntryLifecycle in project OpenOLAT by OpenOLAT.
the class ReminderRuleEngineTest method afterEndDate.
@Test
public void afterEndDate() {
// create a course with 3 members
Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("after-end-1");
Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("after-end-2");
Identity id3 = JunitTestHelper.createAndPersistIdentityAsRndUser("after-end-3");
ICourse course = CoursesWebService.createEmptyCourse(null, "initial-launch-dates", "course long name", null);
RepositoryEntry re = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
Calendar cal = Calendar.getInstance();
// now
cal.setTime(new Date());
cal.add(Calendar.DATE, -25);
Date validFrom = cal.getTime();
// - 3weeks
cal.add(Calendar.DATE, 4);
Date validTo = cal.getTime();
RepositoryEntryLifecycle cycle = lifecycleDao.create("Cycle 2", "Cycle soft 2", false, validFrom, validTo);
re = repositoryManager.setDescriptionAndName(re, null, null, null, null, null, null, null, cycle);
repositoryEntryRelationDao.addRole(id1, re, GroupRoles.owner.name());
repositoryEntryRelationDao.addRole(id2, re, GroupRoles.coach.name());
repositoryEntryRelationDao.addRole(id3, re, GroupRoles.participant.name());
dbInstance.commit();
{
// check after 2 days
List<ReminderRule> rules = getRepositoryEntryLifecycleRuleValidToRule(2, LaunchUnit.day);
boolean match = ruleEngine.evaluateRepositoryEntryRule(re, rules);
Assert.assertTrue(match);
}
{
// check after 7 days (between begin and and date)
List<ReminderRule> rules = getRepositoryEntryLifecycleRuleValidToRule(7, LaunchUnit.day);
boolean match = ruleEngine.evaluateRepositoryEntryRule(re, rules);
Assert.assertTrue(match);
}
{
// check after 2 week s
List<ReminderRule> rules = getRepositoryEntryLifecycleRuleValidToRule(1, LaunchUnit.week);
boolean match = ruleEngine.evaluateRepositoryEntryRule(re, rules);
Assert.assertTrue(match);
}
{
// check after 21 days
List<ReminderRule> rules = getRepositoryEntryLifecycleRuleValidToRule(21, LaunchUnit.day);
boolean match = ruleEngine.evaluateRepositoryEntryRule(re, rules);
Assert.assertTrue(match);
}
{
// check after 3 weeks
List<ReminderRule> rules = getRepositoryEntryLifecycleRuleValidToRule(3, LaunchUnit.week);
boolean match = ruleEngine.evaluateRepositoryEntryRule(re, rules);
Assert.assertTrue(match);
}
{
// check after 22 days
List<ReminderRule> rules = getRepositoryEntryLifecycleRuleValidToRule(22, LaunchUnit.day);
boolean match = ruleEngine.evaluateRepositoryEntryRule(re, rules);
Assert.assertFalse(match);
}
{
// check after 4 weeks
List<ReminderRule> rules = getRepositoryEntryLifecycleRuleValidToRule(4, LaunchUnit.week);
boolean match = ruleEngine.evaluateRepositoryEntryRule(re, rules);
Assert.assertFalse(match);
}
{
// check after 1 month
List<ReminderRule> rules = getRepositoryEntryLifecycleRuleValidToRule(1, LaunchUnit.month);
boolean match = ruleEngine.evaluateRepositoryEntryRule(re, rules);
Assert.assertFalse(match);
}
}
use of org.olat.repository.model.RepositoryEntryLifecycle in project OpenOLAT by OpenOLAT.
the class RepositoryManagerTest method lazyLoadingCheck.
/**
* This is a simulation of OO-2667 to make sure that the LazyInitializationException don't
* set the transaction on rollback.
*/
@Test
public void lazyLoadingCheck() {
RepositoryEntry re = repositoryService.create("Rei Ayanami", "-", "Repository entry DAO Test 5", "", null);
dbInstance.commitAndCloseSession();
RepositoryEntryLifecycle cycle = lifecycleDao.create("New cycle 1", "New cycle soft 1", false, new Date(), new Date());
re = repositoryManager.setDescriptionAndName(re, "Updated repo entry", null, null, "", null, null, null, null, null, null, cycle);
dbInstance.commitAndCloseSession();
RepositoryEntry lazyRe = repositoryManager.setAccess(re, 2, false);
dbInstance.commitAndCloseSession();
try {
// produce the exception
lazyRe.getLifecycle().getValidFrom();
Assert.fail();
} catch (LazyInitializationException e) {
//
}
// load a fresh entry
RepositoryEntry entry = repositoryManager.lookupRepositoryEntry(lazyRe.getKey());
Date validFrom = entry.getLifecycle().getValidFrom();
Assert.assertNotNull(validFrom);
dbInstance.commitAndCloseSession();
}
use of org.olat.repository.model.RepositoryEntryLifecycle in project OpenOLAT by OpenOLAT.
the class RepositoryManagerTest method setDescriptionAndName.
@Test
public void setDescriptionAndName() {
RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
dbInstance.commitAndCloseSession();
Assert.assertNotNull(re);
String newName = "Brand new name";
String newDesc = "Brand new description";
String newAuthors = "Me and only me";
String newLocation = "Far away";
String newExternalId = "Brand - ext";
String newExternalRef = "Brand - ref";
String newManagedFlags = RepositoryEntryManagedFlag.access.name();
RepositoryEntryLifecycle newCycle = lifecycleDao.create("New cycle 1", "New cycle soft 1", false, new Date(), new Date());
re = repositoryManager.setDescriptionAndName(re, newName, newDesc, newLocation, newAuthors, newExternalId, newExternalRef, newManagedFlags, newCycle);
Assert.assertNotNull(re);
dbInstance.commitAndCloseSession();
RepositoryEntry reloaded = repositoryManager.lookupRepositoryEntry(re.getKey());
Assert.assertNotNull(reloaded);
Assert.assertEquals("Me and only me", reloaded.getAuthors());
Assert.assertEquals("Far away", reloaded.getLocation());
Assert.assertEquals("Brand new name", reloaded.getDisplayname());
Assert.assertEquals("Brand new description", reloaded.getDescription());
Assert.assertEquals("Brand - ext", reloaded.getExternalId());
Assert.assertEquals("Brand - ref", reloaded.getExternalRef());
Assert.assertEquals(RepositoryEntryManagedFlag.access.name(), reloaded.getManagedFlagsString());
Assert.assertNotNull(reloaded.getLifecycle());
Assert.assertEquals(newCycle, reloaded.getLifecycle());
}
use of org.olat.repository.model.RepositoryEntryLifecycle in project OpenOLAT by OpenOLAT.
the class RepositoryEntryLifecycleWebService method getPublicLifeCycles.
/**
* List all public lifecycles
* @response.representation.200.qname {http://www.example.com}repositoryEntryVO
* @response.representation.200.mediaType text/plain, text/html, application/xml, application/json
* @response.representation.200.doc List all entries in the repository
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_REPOENTRYVOes}
* @param uriInfo The URI information
* @param httpRequest The HTTP request
* @return
*/
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getPublicLifeCycles(@Context HttpServletRequest httpRequest) {
Roles roles = getRoles(httpRequest);
if (!roles.isInstitutionalResourceManager() && !roles.isOLATAdmin()) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
RepositoryEntryLifecycleDAO lifeCycleDao = CoreSpringFactory.getImpl(RepositoryEntryLifecycleDAO.class);
List<RepositoryEntryLifecycle> publicLifeCycles = lifeCycleDao.loadPublicLifecycle();
List<RepositoryEntryLifecycleVO> voList = new ArrayList<RepositoryEntryLifecycleVO>(publicLifeCycles.size());
for (RepositoryEntryLifecycle lifeCycle : publicLifeCycles) {
voList.add(new RepositoryEntryLifecycleVO(lifeCycle));
}
RepositoryEntryLifecycleVO[] voes = voList.toArray(new RepositoryEntryLifecycleVO[voList.size()]);
return Response.ok(voes).build();
}
use of org.olat.repository.model.RepositoryEntryLifecycle in project OpenOLAT by OpenOLAT.
the class LecturesSearchFormController method getSearchParameters.
public LectureStatisticsSearchParameters getSearchParameters() {
LectureStatisticsSearchParameters params = new LectureStatisticsSearchParameters();
String type = dateTypesEl.getSelectedKey();
if ("none".equals(type)) {
params.setStartDate(null);
params.setEndDate(null);
params.setLifecycle(null);
} else if ("public".equals(type)) {
params.setStartDate(null);
params.setEndDate(null);
if (publicDatesEl.isOneSelected() && StringHelper.isLong(publicDatesEl.getSelectedKey())) {
RepositoryEntryLifecycle lifecycle = lifecycleDao.loadById(new Long(publicDatesEl.getSelectedKey()));
params.setLifecycle(lifecycle);
} else {
params.setLifecycle(null);
}
} else if ("private".equals(type)) {
params.setStartDate(startDateEl.getDate());
params.setEndDate(endDateEl.getDate());
params.setLifecycle(null);
}
params.setLogin(getLogin());
params.setBulkIdentifiers(getBulkIdentifiers());
params.setUserProperties(getSearchProperties());
return params;
}
Aggregations