Search in sources :

Example 61 with ReminderRuleImpl

use of org.olat.modules.reminder.model.ReminderRuleImpl in project OpenOLAT by OpenOLAT.

the class GTAReminderRuleTest method getAssignedTaskRules.

private ReminderRuleImpl getAssignedTaskRules(int amount, LaunchUnit unit) {
    ReminderRuleImpl rule = new ReminderRuleImpl();
    rule.setType(AssignTaskRuleSPI.class.getSimpleName());
    rule.setOperator("<");
    rule.setRightOperand(Integer.toString(amount));
    rule.setRightUnit(unit.name());
    return rule;
}
Also used : ReminderRuleImpl(org.olat.modules.reminder.model.ReminderRuleImpl)

Example 62 with ReminderRuleImpl

use of org.olat.modules.reminder.model.ReminderRuleImpl in project OpenOLAT by OpenOLAT.

the class GTAReminderRuleTest method assignTask_relativeToDateEnrollment.

@Test
public void assignTask_relativeToDateEnrollment() {
    // 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);
    addEnrollmentDate(re, participant1, GroupRoles.participant, -12, Calendar.DATE);
    addEnrollmentDate(re, participant2, GroupRoles.participant, -5, Calendar.DATE);
    dbInstance.commit();
    // create a fake node
    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_ASSIGNMENT_DEADLINE_RELATIVE, 15);
    node.getModuleConfiguration().setStringValue(GTACourseNode.GTASK_ASSIGNMENT_DEADLINE_RELATIVE_TO, GTARelativeToDates.enrollment.name());
    // need the task list
    TaskList tasks = gtaManager.createIfNotExists(re, node);
    Assert.assertNotNull(tasks);
    dbInstance.commit();
    // participant 1 has still 3 days to choose a task
    // participant 2 has still 10 days to choose a task
    {
        // check before 1 day
        ReminderRuleImpl rule = getAssignedTaskRules(1, LaunchUnit.day);
        List<Identity> all = assignTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(0, all.size());
    }
    {
        // check before 5 days
        ReminderRuleImpl rule = getAssignedTaskRules(5, LaunchUnit.day);
        List<Identity> all = assignTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(1, all.size());
        Assert.assertTrue(all.contains(participant1));
    }
    {
        // check before 1 week
        ReminderRuleImpl rule = getAssignedTaskRules(1, LaunchUnit.week);
        List<Identity> all = assignTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(1, all.size());
        Assert.assertTrue(all.contains(participant1));
    }
    {
        // check before 1 month
        ReminderRuleImpl rule = getAssignedTaskRules(1, LaunchUnit.month);
        List<Identity> all = assignTaskRuleSPI.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) 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) Test(org.junit.Test)

Example 63 with ReminderRuleImpl

use of org.olat.modules.reminder.model.ReminderRuleImpl in project OpenOLAT by OpenOLAT.

the class GTAReminderRuleTest method submitTask_individual.

@Test
public void submitTask_individual() {
    // prepare a course with a volatile task
    Identity participant1 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-1");
    Identity participant2 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-2");
    RepositoryEntry re = deployGTACourse();
    repositoryEntryRelationDao.addRole(participant1, re, GroupRoles.participant.name());
    repositoryEntryRelationDao.addRole(participant2, re, GroupRoles.participant.name());
    dbInstance.commit();
    GTACourseNode node = getGTACourseNode(re);
    node.getModuleConfiguration().setStringValue(GTACourseNode.GTASK_TYPE, GTAType.individual.name());
    Calendar cal = Calendar.getInstance();
    cal.add(2, Calendar.MONTH);
    node.getModuleConfiguration().setDateValue(GTACourseNode.GTASK_SUBMIT_DEADLINE, cal.getTime());
    TaskList tasks = gtaManager.createIfNotExists(re, node);
    File taskFile = new File("solo.txt");
    Assert.assertNotNull(tasks);
    dbInstance.commit();
    // select a task
    AssignmentResponse response = gtaManager.selectTask(participant1, tasks, node, taskFile);
    dbInstance.commitAndCloseSession();
    Assert.assertEquals(AssignmentResponse.Status.ok, response.getStatus());
    // only remind participant 2
    List<Identity> toRemind = submissionTaskRuleSPI.getPeopleToRemind(re, node);
    Assert.assertEquals(1, toRemind.size());
    Assert.assertTrue(toRemind.contains(participant2));
    {
        // check before 30 days
        ReminderRuleImpl rule = getSubmitTaskRules(30, LaunchUnit.day);
        List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(0, all.size());
    }
    {
        // check before 5 weeks
        ReminderRuleImpl rule = getSubmitTaskRules(5, LaunchUnit.week);
        List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(0, all.size());
    }
    {
        // check before 1 month
        ReminderRuleImpl rule = getSubmitTaskRules(1, LaunchUnit.month);
        List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(0, all.size());
    }
    {
        // check before  90 days
        ReminderRuleImpl rule = getSubmitTaskRules(90, LaunchUnit.day);
        List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(1, all.size());
        Assert.assertTrue(toRemind.contains(participant2));
    }
    {
        // check before  12 weeks
        ReminderRuleImpl rule = getSubmitTaskRules(12, LaunchUnit.week);
        List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(1, all.size());
        Assert.assertTrue(toRemind.contains(participant2));
    }
    {
        // check before  3 month
        ReminderRuleImpl rule = getSubmitTaskRules(3, LaunchUnit.month);
        List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(1, all.size());
        Assert.assertTrue(toRemind.contains(participant2));
    }
    {
        // check before 1 year
        ReminderRuleImpl rule = getSubmitTaskRules(1, LaunchUnit.year);
        List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(1, all.size());
        Assert.assertTrue(toRemind.contains(participant2));
    }
}
Also used : ReminderRuleImpl(org.olat.modules.reminder.model.ReminderRuleImpl) Calendar(java.util.Calendar) TaskList(org.olat.course.nodes.gta.TaskList) GTACourseNode(org.olat.course.nodes.GTACourseNode) AssignmentResponse(org.olat.course.nodes.gta.AssignmentResponse) 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) File(java.io.File) Test(org.junit.Test)

Example 64 with ReminderRuleImpl

use of org.olat.modules.reminder.model.ReminderRuleImpl in project OpenOLAT by OpenOLAT.

the class ReminderRuleEngineTest method getRepositoryEntryLifecycleRuleValidFromRule.

private List<ReminderRule> getRepositoryEntryLifecycleRuleValidFromRule(int amount, LaunchUnit unit) {
    ReminderRuleImpl rule = new ReminderRuleImpl();
    rule.setType(RepositoryEntryLifecycleAfterValidFromRuleSPI.class.getSimpleName());
    rule.setOperator(">");
    rule.setRightOperand(Integer.toString(amount));
    rule.setRightUnit(unit.name());
    List<ReminderRule> rules = new ArrayList<>(1);
    rules.add(rule);
    return rules;
}
Also used : ReminderRule(org.olat.modules.reminder.ReminderRule) ReminderRuleImpl(org.olat.modules.reminder.model.ReminderRuleImpl) ArrayList(java.util.ArrayList) RepositoryEntryLifecycleAfterValidFromRuleSPI(org.olat.modules.reminder.rule.RepositoryEntryLifecycleAfterValidFromRuleSPI)

Example 65 with ReminderRuleImpl

use of org.olat.modules.reminder.model.ReminderRuleImpl in project OpenOLAT by OpenOLAT.

the class ReminderRuleEngineTest method dateRule.

@Test
public void dateRule() {
    Calendar cal = Calendar.getInstance();
    // check rule with date in the past
    List<ReminderRule> rulePastList = new ArrayList<>();
    ReminderRuleImpl pastRule = new ReminderRuleImpl();
    pastRule.setType(DateRuleSPI.class.getSimpleName());
    pastRule.setOperator(DateRuleSPI.AFTER);
    cal.add(Calendar.HOUR_OF_DAY, -4);
    pastRule.setRightOperand(Formatter.formatDatetime(cal.getTime()));
    rulePastList.add(pastRule);
    boolean pastEval = ruleEngine.evaluateDateRule(rulePastList);
    Assert.assertTrue(pastEval);
    // check rule with date in the future
    List<ReminderRule> ruleFutureList = new ArrayList<>();
    ReminderRuleImpl futureRule = new ReminderRuleImpl();
    futureRule.setType(DateRuleSPI.class.getSimpleName());
    futureRule.setOperator(DateRuleSPI.AFTER);
    cal.add(Calendar.DATE, 4);
    futureRule.setRightOperand(Formatter.formatDatetime(cal.getTime()));
    ruleFutureList.add(futureRule);
    boolean futureEval = ruleEngine.evaluateDateRule(ruleFutureList);
    Assert.assertFalse(futureEval);
}
Also used : ReminderRule(org.olat.modules.reminder.ReminderRule) CourseEnrollmentDateRuleSPI(org.olat.modules.reminder.rule.CourseEnrollmentDateRuleSPI) DateRuleSPI(org.olat.modules.reminder.rule.DateRuleSPI) ReminderRuleImpl(org.olat.modules.reminder.model.ReminderRuleImpl) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

ReminderRuleImpl (org.olat.modules.reminder.model.ReminderRuleImpl)114 ArrayList (java.util.ArrayList)46 Identity (org.olat.core.id.Identity)26 ReminderRule (org.olat.modules.reminder.ReminderRule)26 ICourse (org.olat.course.ICourse)22 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)20 CourseNode (org.olat.course.nodes.CourseNode)20 Test (org.junit.Test)16 Date (java.util.Date)14 Translator (org.olat.core.gui.translator.Translator)14 GTACourseNode (org.olat.course.nodes.GTACourseNode)14 List (java.util.List)12 RepositoryEntry (org.olat.repository.RepositoryEntry)12 TaskList (org.olat.course.nodes.gta.TaskList)10 Calendar (java.util.Calendar)8 AssessableCourseNode (org.olat.course.nodes.AssessableCourseNode)8 ParseException (java.text.ParseException)6 InitialAttemptsRuleSPI (org.olat.course.reminder.rule.InitialAttemptsRuleSPI)6 ScoreRuleSPI (org.olat.course.reminder.rule.ScoreRuleSPI)6 File (java.io.File)4