Search in sources :

Example 31 with RepositoryEntryLifecycle

use of org.olat.repository.model.RepositoryEntryLifecycle in project openolat by klemens.

the class RepositoryEntryResource method updateEntry.

@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response updateEntry(@PathParam("repoEntryKey") String repoEntryKey, RepositoryEntryVO vo, @Context HttpServletRequest request) {
    if (!RestSecurityHelper.isAuthor(request)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    final RepositoryEntry re = lookupRepositoryEntry(repoEntryKey);
    if (re == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    RepositoryEntryLifecycle lifecycle = null;
    RepositoryEntryLifecycleVO lifecycleVo = vo.getLifecycle();
    if (lifecycleVo != null) {
        RepositoryEntryLifecycleDAO lifecycleDao = CoreSpringFactory.getImpl(RepositoryEntryLifecycleDAO.class);
        if (lifecycleVo.getKey() != null) {
            lifecycle = lifecycleDao.loadById(lifecycleVo.getKey());
            if (lifecycle.isPrivateCycle()) {
                // check date
                String fromStr = lifecycleVo.getValidFrom();
                String toStr = lifecycleVo.getValidTo();
                String label = lifecycleVo.getLabel();
                String softKey = lifecycleVo.getSoftkey();
                Date from = ObjectFactory.parseDate(fromStr);
                Date to = ObjectFactory.parseDate(toStr);
                lifecycle.setLabel(label);
                lifecycle.setSoftKey(softKey);
                lifecycle.setValidFrom(from);
                lifecycle.setValidTo(to);
            }
        } else {
            String fromStr = lifecycleVo.getValidFrom();
            String toStr = lifecycleVo.getValidTo();
            String label = lifecycleVo.getLabel();
            String softKey = lifecycleVo.getSoftkey();
            Date from = ObjectFactory.parseDate(fromStr);
            Date to = ObjectFactory.parseDate(toStr);
            lifecycle = lifecycleDao.create(label, softKey, true, from, to);
        }
    }
    RepositoryEntry reloaded = repositoryManager.setDescriptionAndName(re, vo.getDisplayname(), vo.getDescription(), vo.getLocation(), vo.getAuthors(), vo.getExternalId(), vo.getExternalRef(), vo.getManagedFlags(), lifecycle);
    RepositoryEntryVO rvo = ObjectFactory.get(reloaded);
    return Response.ok(rvo).build();
}
Also used : RepositoryEntryVO(org.olat.restapi.support.vo.RepositoryEntryVO) RepositoryEntryLifecycle(org.olat.repository.model.RepositoryEntryLifecycle) RepositoryEntry(org.olat.repository.RepositoryEntry) RepositoryEntryLifecycleVO(org.olat.restapi.support.vo.RepositoryEntryLifecycleVO) RepositoryEntryLifecycleDAO(org.olat.repository.manager.RepositoryEntryLifecycleDAO) Date(java.util.Date) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

Example 32 with RepositoryEntryLifecycle

use of org.olat.repository.model.RepositoryEntryLifecycle in project openolat by klemens.

the class GTAManagerImpl method getReferenceDate.

@Override
public DueDate getReferenceDate(int numOfDays, String relativeTo, TaskRef assignedTask, IdentityRef assessedIdentity, BusinessGroup assessedGroup, RepositoryEntry courseEntry) {
    DueDate dueDate = null;
    if (numOfDays >= 0 && StringHelper.containsNonWhitespace(relativeTo)) {
        GTARelativeToDates rel = GTARelativeToDates.valueOf(relativeTo);
        Date referenceDate = null;
        String messageKey = null;
        String messageArg = null;
        switch(rel) {
            case courseStart:
                {
                    RepositoryEntryLifecycle lifecycle = getRepositoryEntryLifecycle(courseEntry);
                    if (lifecycle != null && lifecycle.getValidFrom() != null) {
                        referenceDate = lifecycle.getValidFrom();
                    }
                    break;
                }
            case courseLaunch:
                {
                    if (assessedIdentity != null) {
                        referenceDate = userCourseInformationsManager.getInitialLaunchDate(courseEntry, assessedIdentity);
                    } else {
                        referenceDate = userCourseInformationsManager.getInitialParticipantLaunchDate(courseEntry, assessedGroup);
                    }
                    break;
                }
            case enrollment:
                {
                    if (assessedIdentity != null) {
                        referenceDate = repositoryService.getEnrollmentDate(courseEntry, assessedIdentity);
                    } else {
                        referenceDate = getEnrollmentDate(assessedGroup);
                    }
                    break;
                }
            case assignment:
                {
                    if (assignedTask != null) {
                        referenceDate = assignedTask.getAssignmentDate();
                    } else {
                        messageKey = "relative.to.assignment.message";
                        messageArg = Integer.toString(numOfDays);
                    }
                    break;
                }
        }
        if (referenceDate != null) {
            Calendar cal = Calendar.getInstance();
            cal.setTime(referenceDate);
            cal.add(Calendar.DATE, numOfDays);
            dueDate = new DueDate(true, cal.getTime());
        } else if (messageKey != null) {
            dueDate = new DueDate(true, messageKey, messageArg);
        }
    }
    return dueDate;
}
Also used : GTARelativeToDates(org.olat.course.nodes.gta.GTARelativeToDates) RepositoryEntryLifecycle(org.olat.repository.model.RepositoryEntryLifecycle) Calendar(java.util.Calendar) TaskDueDate(org.olat.course.nodes.gta.TaskDueDate) DueDate(org.olat.course.nodes.gta.model.DueDate) Date(java.util.Date) TaskDueDate(org.olat.course.nodes.gta.TaskDueDate) TaskRevisionDate(org.olat.course.nodes.gta.TaskRevisionDate) DueDate(org.olat.course.nodes.gta.model.DueDate)

Example 33 with RepositoryEntryLifecycle

use of org.olat.repository.model.RepositoryEntryLifecycle in project openolat by klemens.

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 34 with RepositoryEntryLifecycle

use of org.olat.repository.model.RepositoryEntryLifecycle in project openolat by klemens.

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 35 with RepositoryEntryLifecycle

use of org.olat.repository.model.RepositoryEntryLifecycle in project openolat by klemens.

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