Search in sources :

Example 6 with ReminderRules

use of org.olat.modules.reminder.model.ReminderRules in project openolat by klemens.

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)

Example 7 with ReminderRules

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

the class CourseReminderEditController method formOK.

@Override
protected void formOK(UserRequest ureq) {
    String description = descriptionEl.getValue();
    reminder.setDescription(description);
    ReminderRules rules = new ReminderRules();
    for (RuleElement ruleEl : ruleEls) {
        ReminderRule rule = ruleEl.getEditor().getConfiguration();
        if (rule != null) {
            rules.getRules().add(rule);
        }
    }
    String configuration = reminderManager.toXML(rules);
    reminder.setConfiguration(configuration);
    String emailSubject = subjectEl.getValue();
    reminder.setEmailSubject(emailSubject);
    String emailBody = emailEl.getValue();
    reminder.setEmailBody(emailBody);
    reminder = reminderManager.save(reminder);
    fireEvent(ureq, Event.DONE_EVENT);
}
Also used : ReminderRule(org.olat.modules.reminder.ReminderRule) ReminderRules(org.olat.modules.reminder.model.ReminderRules)

Example 8 with ReminderRules

use of org.olat.modules.reminder.model.ReminderRules in project openolat by klemens.

the class CourseHandler method cloneReminders.

private void cloneReminders(Identity author, CourseEnvironmentMapper envMapper, RepositoryEntry source, RepositoryEntry target) {
    ReminderModule reminderModule = CoreSpringFactory.getImpl(ReminderModule.class);
    ReminderService reminderService = CoreSpringFactory.getImpl(ReminderService.class);
    List<Reminder> reminders = reminderService.getReminders(source);
    for (Reminder reminder : reminders) {
        String configuration = reminder.getConfiguration();
        ReminderRules rules = reminderService.toRules(configuration);
        ReminderRules clonedRules = new ReminderRules();
        for (ReminderRule rule : rules.getRules()) {
            RuleSPI ruleSpi = reminderModule.getRuleSPIByType(rule.getType());
            if (ruleSpi != null) {
                ReminderRule clonedRule = ruleSpi.clone(rule, envMapper);
                if (clonedRule != null)
                    clonedRules.getRules().add(clonedRule);
            }
        }
        Reminder clonedReminder = reminderService.createReminder(target, author);
        clonedReminder.setDescription(reminder.getDescription());
        clonedReminder.setEmailSubject(reminder.getEmailSubject());
        clonedReminder.setEmailBody(reminder.getEmailBody());
        clonedReminder.setConfiguration(reminderService.toXML(clonedRules));
        reminderService.save(clonedReminder);
    }
}
Also used : ReminderRule(org.olat.modules.reminder.ReminderRule) Reminder(org.olat.modules.reminder.Reminder) ReminderService(org.olat.modules.reminder.ReminderService) ReminderRules(org.olat.modules.reminder.model.ReminderRules) RuleSPI(org.olat.modules.reminder.RuleSPI) ReminderModule(org.olat.modules.reminder.ReminderModule)

Example 9 with ReminderRules

use of org.olat.modules.reminder.model.ReminderRules in project openolat by klemens.

the class CourseHandler method importReminders.

private void importReminders(RepositoryEntry re, File fImportBaseDirectory, CourseEnvironmentMapper envMapper, Identity initialAuthor) {
    ReminderModule reminderModule = CoreSpringFactory.getImpl(ReminderModule.class);
    ReminderService reminderService = CoreSpringFactory.getImpl(ReminderService.class);
    List<Reminder> reminders = reminderService.importRawReminders(initialAuthor, re, fImportBaseDirectory);
    if (reminders.size() > 0) {
        for (Reminder reminder : reminders) {
            ReminderRules clonedRules = new ReminderRules();
            String configuration = reminder.getConfiguration();
            ReminderRules rules = reminderService.toRules(configuration);
            for (ReminderRule rule : rules.getRules()) {
                RuleSPI ruleSpi = reminderModule.getRuleSPIByType(rule.getType());
                if (ruleSpi != null) {
                    ReminderRule clonedRule = ruleSpi.clone(rule, envMapper);
                    clonedRules.getRules().add(clonedRule);
                }
            }
            String convertedConfiguration = reminderService.toXML(clonedRules);
            reminder.setConfiguration(convertedConfiguration);
            reminderService.save(reminder);
        }
    }
}
Also used : ReminderRule(org.olat.modules.reminder.ReminderRule) Reminder(org.olat.modules.reminder.Reminder) ReminderService(org.olat.modules.reminder.ReminderService) ReminderRules(org.olat.modules.reminder.model.ReminderRules) RuleSPI(org.olat.modules.reminder.RuleSPI) ReminderModule(org.olat.modules.reminder.ReminderModule)

Example 10 with ReminderRules

use of org.olat.modules.reminder.model.ReminderRules in project openolat by klemens.

the class ReminderRuleEngine method evaluate.

public List<Identity> evaluate(Reminder reminder, boolean resend) {
    String config = reminder.getConfiguration();
    ReminderRules rules = reminderManager.toRules(config);
    if (rules == null || rules.getRules() == null || rules.getRules().isEmpty()) {
        return Collections.emptyList();
    }
    List<ReminderRule> ruleList = new ArrayList<>(rules.getRules());
    boolean allOk = evaluate(reminder, ruleList);
    List<Identity> identities;
    if (allOk) {
        identities = getIdentities(reminder.getEntry(), reminder, ruleList, resend);
        if (identities.size() > 0 && ruleList.size() > 0) {
            filterByRules(reminder.getEntry(), identities, ruleList);
        }
    } else {
        identities = Collections.emptyList();
    }
    return identities;
}
Also used : ReminderRule(org.olat.modules.reminder.ReminderRule) ReminderRules(org.olat.modules.reminder.model.ReminderRules) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity)

Aggregations

ReminderRule (org.olat.modules.reminder.ReminderRule)12 ReminderRules (org.olat.modules.reminder.model.ReminderRules)12 RuleSPI (org.olat.modules.reminder.RuleSPI)6 Reminder (org.olat.modules.reminder.Reminder)4 ReminderModule (org.olat.modules.reminder.ReminderModule)4 ReminderService (org.olat.modules.reminder.ReminderService)4 ParseException (java.text.ParseException)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)2 Identity (org.olat.core.id.Identity)2 ReminderImpl (org.olat.modules.reminder.model.ReminderImpl)2 ReminderRuleImpl (org.olat.modules.reminder.model.ReminderRuleImpl)2 DateRuleSPI (org.olat.modules.reminder.rule.DateRuleSPI)2