Search in sources :

Example 56 with ReminderRuleImpl

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

the class RepositoryEntryRoleEditor method initForm.

@Override
public FormItem initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    Translator translator = formLayout.getTranslator();
    String[] values = new String[] { translator.translate("course.role.owner"), translator.translate("course.role.coach"), translator.translate("course.role.participant"), translator.translate("course.role.participantAndCoach"), translator.translate("course.role.ownerAndCoach"), translator.translate("course.role.all") };
    roleEl = uifactory.addDropdownSingleselect("role." + CodeHelper.getRAMUniqueID(), null, formLayout, keys, values, null);
    boolean selected = false;
    if (rule instanceof ReminderRuleImpl) {
        ReminderRuleImpl roleRule = (ReminderRuleImpl) rule;
        String role = roleRule.getRightOperand();
        for (String key : keys) {
            if (key.equals(role)) {
                roleEl.select(key, true);
                selected = true;
            }
        }
    }
    if (!selected) {
        roleEl.select(keys[0], true);
    }
    return roleEl;
}
Also used : Translator(org.olat.core.gui.translator.Translator) ReminderRuleImpl(org.olat.modules.reminder.model.ReminderRuleImpl)

Example 57 with ReminderRuleImpl

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

the class RepositoryEntryRoleEditor method getConfiguration.

@Override
public ReminderRule getConfiguration() {
    ReminderRuleImpl configuredRule = null;
    if (roleEl.isOneSelected()) {
        configuredRule = new ReminderRuleImpl();
        configuredRule.setType(RepositoryEntryRoleRuleSPI.class.getSimpleName());
        configuredRule.setOperator("=");
        configuredRule.setRightOperand(roleEl.getSelectedKey());
    }
    return configuredRule;
}
Also used : ReminderRuleImpl(org.olat.modules.reminder.model.ReminderRuleImpl) RepositoryEntryRoleRuleSPI(org.olat.modules.reminder.rule.RepositoryEntryRoleRuleSPI)

Example 58 with ReminderRuleImpl

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

the class AbstractLaunchDateRuleSPI method filter.

@Override
public void filter(RepositoryEntry entry, List<Identity> identities, ReminderRule rule) {
    if (rule instanceof ReminderRuleImpl) {
        ReminderRuleImpl r = (ReminderRuleImpl) rule;
        Date now = new Date();
        int distance = Integer.parseInt(r.getRightOperand());
        LaunchUnit unit = LaunchUnit.valueOf(r.getRightUnit());
        Map<Long, Date> initialLaunchDates = getLaunchDates(rule, entry, identities);
        for (Iterator<Identity> identityIt = identities.iterator(); identityIt.hasNext(); ) {
            Identity identity = identityIt.next();
            Date initialLaunchDate = initialLaunchDates.get(identity.getKey());
            if (initialLaunchDate == null) {
                identityIt.remove();
            } else if (!after(initialLaunchDate, now, distance, unit)) {
                identityIt.remove();
            }
        }
    }
}
Also used : ReminderRuleImpl(org.olat.modules.reminder.model.ReminderRuleImpl) Identity(org.olat.core.id.Identity) Date(java.util.Date)

Example 59 with ReminderRuleImpl

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

the class UserPropertyRuleSPI method accept.

public boolean accept(ReminderRule rule, Identity identity) {
    boolean allOk = false;
    if (rule instanceof ReminderRuleImpl) {
        ReminderRuleImpl r = (ReminderRuleImpl) rule;
        String propertyName = r.getLeftOperand();
        String reference = r.getRightOperand();
        String value = identity.getUser().getProperty(propertyName, null);
        if (reference != null && reference.equalsIgnoreCase(value)) {
            allOk = true;
        }
    }
    return allOk;
}
Also used : ReminderRuleImpl(org.olat.modules.reminder.model.ReminderRuleImpl)

Example 60 with ReminderRuleImpl

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

the class GTAReminderRuleTest method assignTask_relativeToInitialLaunchDate.

@Test
public void assignTask_relativeToInitialLaunchDate() {
    // create a course with 3 members
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("initial-launch-1");
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("initial-launch-2");
    Identity id3 = JunitTestHelper.createAndPersistIdentityAsRndUser("initial-launch-3");
    ICourse course = CoursesWebService.createEmptyCourse(null, "initial-launch-dates", "course long name", null);
    RepositoryEntry re = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    repositoryEntryRelationDao.addRole(id1, re, GroupRoles.participant.name());
    repositoryEntryRelationDao.addRole(id2, re, GroupRoles.participant.name());
    repositoryEntryRelationDao.addRole(id3, re, GroupRoles.participant.name());
    dbInstance.commit();
    // create user course infos
    userCourseInformationsManager.updateUserCourseInformations(re.getOlatResource(), id1);
    userCourseInformationsManager.updateUserCourseInformations(re.getOlatResource(), id2);
    userCourseInformationsManager.updateUserCourseInformations(re.getOlatResource(), id3);
    dbInstance.commit();
    // fake the date
    updateInitialLaunchDate(re.getOlatResource(), id1, -5, Calendar.DATE);
    updateInitialLaunchDate(re.getOlatResource(), id2, -35, Calendar.DATE);
    updateInitialLaunchDate(re.getOlatResource(), id3, -75, Calendar.DATE);
    dbInstance.commitAndCloseSession();
    // 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, 40);
    node.getModuleConfiguration().setStringValue(GTACourseNode.GTASK_ASSIGNMENT_DEADLINE_RELATIVE_TO, GTARelativeToDates.courseLaunch.name());
    // need the task list
    TaskList tasks = gtaManager.createIfNotExists(re, node);
    Assert.assertNotNull(tasks);
    dbInstance.commit();
    {
        // check 3 days
        ReminderRuleImpl rule = getAssignedTaskRules(3, LaunchUnit.day);
        List<Identity> all = assignTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(1, all.size());
        Assert.assertTrue(all.contains(id3));
    }
    {
        // check 5 days
        ReminderRuleImpl rule = getAssignedTaskRules(5, LaunchUnit.day);
        List<Identity> all = assignTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(2, all.size());
        Assert.assertTrue(all.contains(id2));
        Assert.assertTrue(all.contains(id3));
    }
    {
        // check 1 week
        ReminderRuleImpl rule = getAssignedTaskRules(1, LaunchUnit.week);
        List<Identity> all = assignTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(2, all.size());
        Assert.assertTrue(all.contains(id2));
        Assert.assertTrue(all.contains(id3));
    }
    {
        // check 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(id2));
        Assert.assertTrue(all.contains(id3));
    }
    {
        // check 2 month
        ReminderRuleImpl rule = getAssignedTaskRules(2, LaunchUnit.month);
        List<Identity> all = assignTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(3, all.size());
        Assert.assertTrue(all.contains(id1));
        Assert.assertTrue(all.contains(id2));
        Assert.assertTrue(all.contains(id3));
    }
}
Also used : ReminderRuleImpl(org.olat.modules.reminder.model.ReminderRuleImpl) TaskList(org.olat.course.nodes.gta.TaskList) GTACourseNode(org.olat.course.nodes.GTACourseNode) ICourse(org.olat.course.ICourse) 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)

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