use of org.olat.modules.reminder.model.ReminderRuleImpl in project openolat by klemens.
the class DateRuleSPI method evaluate.
public boolean evaluate(ReminderRule rule) {
boolean allOk = true;
if (rule instanceof ReminderRuleImpl) {
ReminderRuleImpl r = (ReminderRuleImpl) rule;
String operator = r.getOperator();
if (AFTER.equals(operator) && StringHelper.containsNonWhitespace(r.getRightOperand())) {
try {
Date date = Formatter.parseDatetime(r.getRightOperand());
Date now = new Date();
allOk &= now.compareTo(date) >= 0;
} catch (ParseException e) {
log.error("", e);
}
}
}
return allOk;
}
use of org.olat.modules.reminder.model.ReminderRuleImpl in project openolat by klemens.
the class RepositoryEntryLifecycleAfterValidFromRuleSPI method evaluate.
public boolean evaluate(RepositoryEntryLifecycle lifecycle, ReminderRule rule) {
Date now = cleanNow();
Date validTo = lifecycle.getValidTo();
if (validTo != null && now.compareTo(validTo) >= 0) {
// the course is at the end
return false;
}
ReminderRuleImpl r = (ReminderRuleImpl) rule;
int distance = Integer.parseInt(r.getRightOperand());
LaunchUnit unit = LaunchUnit.valueOf(r.getRightUnit());
Date referenceDate = getDate(lifecycle.getValidFrom(), distance, unit);
return now.compareTo(referenceDate) >= 0;
}
use of org.olat.modules.reminder.model.ReminderRuleImpl in project openolat by klemens.
the class AbstractDueDateTaskRuleSPI method evaluate.
@Override
public List<Identity> evaluate(RepositoryEntry entry, ReminderRule rule) {
List<Identity> identities = null;
if (rule instanceof ReminderRuleImpl) {
ReminderRuleImpl r = (ReminderRuleImpl) rule;
String nodeIdent = r.getLeftOperand();
ICourse course = CourseFactory.loadCourse(entry);
CourseNode courseNode = course.getRunStructure().getNode(nodeIdent);
if (courseNode instanceof GTACourseNode) {
identities = evaluateRule(entry, (GTACourseNode) courseNode, r);
}
}
return identities == null ? Collections.<Identity>emptyList() : identities;
}
use of org.olat.modules.reminder.model.ReminderRuleImpl in project openolat by klemens.
the class BeforeDateTaskRuleEditor method getConfiguration.
@Override
public ReminderRule getConfiguration() {
ReminderRuleImpl configuredRule = null;
if (courseNodeEl.isOneSelected() && unitEl.isOneSelected() && StringHelper.containsNonWhitespace(valueEl.getValue())) {
configuredRule = new ReminderRuleImpl();
configuredRule.setType(ruleType);
configuredRule.setLeftOperand(courseNodeEl.getSelectedKey());
configuredRule.setOperator("<");
configuredRule.setRightOperand(valueEl.getValue());
configuredRule.setRightUnit(unitEl.getSelectedKey());
}
return configuredRule;
}
use of org.olat.modules.reminder.model.ReminderRuleImpl 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));
}
}
Aggregations