Search in sources :

Example 6 with RepositoryEntryLifecycle

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);
    }
}
Also used : RepositoryEntryLifecycle(org.olat.repository.model.RepositoryEntryLifecycle) Calendar(java.util.Calendar) ICourse(org.olat.course.ICourse) List(java.util.List) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) Date(java.util.Date) Test(org.junit.Test)

Example 7 with RepositoryEntryLifecycle

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();
}
Also used : RepositoryEntryLifecycle(org.olat.repository.model.RepositoryEntryLifecycle) LazyInitializationException(org.hibernate.LazyInitializationException) Date(java.util.Date) Test(org.junit.Test)

Example 8 with RepositoryEntryLifecycle

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());
}
Also used : RepositoryEntryLifecycle(org.olat.repository.model.RepositoryEntryLifecycle) Date(java.util.Date) Test(org.junit.Test)

Example 9 with RepositoryEntryLifecycle

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();
}
Also used : RepositoryEntryLifecycle(org.olat.repository.model.RepositoryEntryLifecycle) ArrayList(java.util.ArrayList) RestSecurityHelper.getRoles(org.olat.restapi.security.RestSecurityHelper.getRoles) Roles(org.olat.core.id.Roles) RepositoryEntryLifecycleVO(org.olat.restapi.support.vo.RepositoryEntryLifecycleVO) RepositoryEntryLifecycleDAO(org.olat.repository.manager.RepositoryEntryLifecycleDAO) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 10 with RepositoryEntryLifecycle

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;
}
Also used : RepositoryEntryLifecycle(org.olat.repository.model.RepositoryEntryLifecycle) LectureStatisticsSearchParameters(org.olat.modules.lecture.model.LectureStatisticsSearchParameters)

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