Search in sources :

Example 16 with ReminderRuleImpl

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

the class ReminderRuleEngineTest method getAttemptsRules.

private List<ReminderRule> getAttemptsRules(String operator, int value, String nodeIdent) {
    ReminderRuleImpl rule = new ReminderRuleImpl();
    rule.setType(AttemptsRuleSPI.class.getSimpleName());
    rule.setLeftOperand(nodeIdent);
    rule.setOperator(operator);
    rule.setRightOperand(Integer.toString(value));
    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) AttemptsRuleSPI(org.olat.course.reminder.rule.AttemptsRuleSPI) InitialAttemptsRuleSPI(org.olat.course.reminder.rule.InitialAttemptsRuleSPI) ArrayList(java.util.ArrayList)

Example 17 with ReminderRuleImpl

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

the class BusinessGroupRoleRuleSPI method clone.

@Override
public ReminderRule clone(ReminderRule rule, CourseEnvironmentMapper envMapper) {
    ReminderRuleImpl clone = (ReminderRuleImpl) rule.clone();
    String groupKey = clone.getRightOperand();
    boolean found = false;
    if (StringHelper.isLong(groupKey)) {
        Long key = Long.parseLong(groupKey);
        for (BusinessGroupReference ref : envMapper.getGroups()) {
            if (key.equals(ref.getOriginalKey()) && ref.getKey() != null) {
                clone.setRightOperand(ref.getKey().toString());
                found = true;
            }
        }
    }
    return found ? clone : null;
}
Also used : ReminderRuleImpl(org.olat.modules.reminder.model.ReminderRuleImpl) BusinessGroupReference(org.olat.group.model.BusinessGroupReference)

Example 18 with ReminderRuleImpl

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

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;
}
Also used : ReminderRuleImpl(org.olat.modules.reminder.model.ReminderRuleImpl) Date(java.util.Date)

Example 19 with ReminderRuleImpl

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

the class CourseLaunchRuleEditor method getConfiguration.

@Override
public ReminderRule getConfiguration() {
    ReminderRuleImpl configuredRule = new ReminderRuleImpl();
    configuredRule.setType(ruleType);
    configuredRule.setOperator(">");
    configuredRule.setRightOperand(valueEl.getValue());
    configuredRule.setRightUnit(unitEl.getSelectedKey());
    return configuredRule;
}
Also used : ReminderRuleImpl(org.olat.modules.reminder.model.ReminderRuleImpl)

Example 20 with ReminderRuleImpl

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

the class ReminderServiceImpl method optimizeStartDate.

private void optimizeStartDate(Reminder reminder) {
    Date startDate = null;
    String configuration = reminder.getConfiguration();
    if (StringHelper.containsNonWhitespace(configuration)) {
        ReminderRules rules = toRules(configuration);
        for (ReminderRule rule : rules.getRules()) {
            if (rule instanceof ReminderRuleImpl && ReminderRuleEngine.DATE_RULE_TYPE.equals(rule.getType())) {
                ReminderRuleImpl r = (ReminderRuleImpl) rule;
                if (DateRuleSPI.AFTER.equals(r.getOperator()) && StringHelper.containsNonWhitespace(r.getRightOperand())) {
                    try {
                        Date date = Formatter.parseDatetime(r.getRightOperand());
                        if (startDate == null) {
                            startDate = date;
                        } else if (startDate.compareTo(date) > 0) {
                            startDate = date;
                        }
                    } catch (ParseException e) {
                        log.error("", e);
                    }
                }
            }
        }
    }
    ((ReminderImpl) reminder).setStartDate(startDate);
}
Also used : ReminderRule(org.olat.modules.reminder.ReminderRule) ReminderRuleImpl(org.olat.modules.reminder.model.ReminderRuleImpl) ReminderRules(org.olat.modules.reminder.model.ReminderRules) ReminderImpl(org.olat.modules.reminder.model.ReminderImpl) ParseException(java.text.ParseException) Date(java.util.Date)

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