Search in sources :

Example 1 with RuleSPI

use of org.olat.modules.reminder.RuleSPI in project OpenOLAT by OpenOLAT.

the class ReminderRuleEngine method getMembers.

public List<Identity> getMembers(RepositoryEntry entry, ReminderRule rule) {
    List<Identity> members = new ArrayList<>();
    try {
        RuleSPI ruleSpi = reminderModule.getRuleSPIByType(rule.getType());
        IdentitiesProviderRuleSPI identitiesProviderRuleSpi = (IdentitiesProviderRuleSPI) ruleSpi;
        members = identitiesProviderRuleSpi.evaluate(entry, rule);
    } catch (Exception e) {
        log.error("", e);
    }
    return members;
}
Also used : IdentitiesProviderRuleSPI(org.olat.modules.reminder.IdentitiesProviderRuleSPI) FilterRuleSPI(org.olat.modules.reminder.FilterRuleSPI) RepositoryEntryRoleRuleSPI(org.olat.modules.reminder.rule.RepositoryEntryRoleRuleSPI) UserPropertyRuleSPI(org.olat.modules.reminder.rule.UserPropertyRuleSPI) IdentitiesProviderRuleSPI(org.olat.modules.reminder.IdentitiesProviderRuleSPI) RuleSPI(org.olat.modules.reminder.RuleSPI) RepositoryEntryRuleSPI(org.olat.modules.reminder.RepositoryEntryRuleSPI) BusinessGroupRoleRuleSPI(org.olat.modules.reminder.rule.BusinessGroupRoleRuleSPI) DateRuleSPI(org.olat.modules.reminder.rule.DateRuleSPI) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity)

Example 2 with RuleSPI

use of org.olat.modules.reminder.RuleSPI in project OpenOLAT by OpenOLAT.

the class ReminderRuleEngine method getIdentities.

protected List<Identity> getIdentities(RepositoryEntry entry, Reminder reminder, List<ReminderRule> ruleList, boolean resend) {
    List<ReminderRule> identitiesProviderRules = new ArrayList<>();
    for (Iterator<ReminderRule> ruleIt = ruleList.iterator(); ruleIt.hasNext(); ) {
        ReminderRule rule = ruleIt.next();
        RuleSPI ruleSpi = reminderModule.getRuleSPIByType(rule.getType());
        if (ruleSpi instanceof IdentitiesProviderRuleSPI) {
            identitiesProviderRules.add(rule);
            ruleIt.remove();
        }
    }
    List<Identity> identities;
    if (identitiesProviderRules.isEmpty()) {
        // all members of repository entry
        List<Identity> duplicatedIdentities = repositoryEntryRelationDao.getMembers(entry, RepositoryEntryRelationType.both, GroupRoles.owner.name(), GroupRoles.coach.name(), GroupRoles.participant.name());
        identities = new ArrayList<>(new HashSet<>(duplicatedIdentities));
    } else {
        identities = null;
        for (ReminderRule rule : identitiesProviderRules) {
            List<Identity> members = getMembers(entry, rule);
            if (identities == null) {
                identities = members;
            } else {
                identities.retainAll(members);
            }
        }
    }
    // filter by user property
    filterIdentitiesByProperty(identities, ruleList);
    // deduplicated the list
    identities = new ArrayList<>(new HashSet<>(identities));
    if (!resend) {
        List<Long> alreadySendKeys = reminderDao.getReminderRecipientKeys(reminder);
        Set<Long> alreadySendKeySet = new HashSet<>(alreadySendKeys);
        for (Iterator<Identity> identityIt = identities.iterator(); identityIt.hasNext(); ) {
            if (alreadySendKeySet.contains(identityIt.next().getKey())) {
                identityIt.remove();
            }
        }
    }
    return identities;
}
Also used : ReminderRule(org.olat.modules.reminder.ReminderRule) IdentitiesProviderRuleSPI(org.olat.modules.reminder.IdentitiesProviderRuleSPI) ArrayList(java.util.ArrayList) FilterRuleSPI(org.olat.modules.reminder.FilterRuleSPI) RepositoryEntryRoleRuleSPI(org.olat.modules.reminder.rule.RepositoryEntryRoleRuleSPI) UserPropertyRuleSPI(org.olat.modules.reminder.rule.UserPropertyRuleSPI) IdentitiesProviderRuleSPI(org.olat.modules.reminder.IdentitiesProviderRuleSPI) RuleSPI(org.olat.modules.reminder.RuleSPI) RepositoryEntryRuleSPI(org.olat.modules.reminder.RepositoryEntryRuleSPI) BusinessGroupRoleRuleSPI(org.olat.modules.reminder.rule.BusinessGroupRoleRuleSPI) DateRuleSPI(org.olat.modules.reminder.rule.DateRuleSPI) Identity(org.olat.core.id.Identity) HashSet(java.util.HashSet)

Example 3 with RuleSPI

use of org.olat.modules.reminder.RuleSPI in project OpenOLAT by OpenOLAT.

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 4 with RuleSPI

use of org.olat.modules.reminder.RuleSPI in project OpenOLAT by OpenOLAT.

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 5 with RuleSPI

use of org.olat.modules.reminder.RuleSPI in project OpenOLAT by OpenOLAT.

the class CourseReminderEditController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    FormLayoutContainer generalCont = FormLayoutContainer.createVerticalFormLayout("general", getTranslator());
    generalCont.setRootForm(mainForm);
    generalCont.setFormContextHelp("Course Reminders");
    formLayout.add(generalCont);
    String key = reminder.getKey() == null ? "" : reminder.getKey().toString();
    uifactory.addStaticTextElement("reminder.id", key, generalCont);
    String desc = reminder.getDescription();
    descriptionEl = uifactory.addTextElement("reminder.description", "reminder.description", 128, desc, generalCont);
    descriptionEl.setMandatory(true);
    descriptionEl.setElementCssClass("o_sel_course_reminder_desc");
    String sendTime = getSendTimeDescription();
    uifactory.addStaticTextElement("send.time.description.label", sendTime, generalCont);
    // rules
    String rulePage = velocity_root + "/edit_rules.html";
    rulesCont = FormLayoutContainer.createCustomFormLayout("rules", getTranslator(), rulePage);
    rulesCont.setRootForm(mainForm);
    formLayout.add(rulesCont);
    rulesCont.contextPut("rules", ruleEls);
    String configuration = reminder.getConfiguration();
    if (StringHelper.containsNonWhitespace(configuration)) {
        ReminderRules rules = reminderManager.toRules(configuration);
        if (rules.getRules() != null) {
            for (ReminderRule rule : rules.getRules()) {
                if (rule != null) {
                    RuleSPI ruleSpy = reminderModule.getRuleSPIByType(rule.getType());
                    RuleElement ruleEl = initRuleForm(ureq, ruleSpy, rule);
                    ruleEls.add(ruleEl);
                }
            }
        }
    }
    if (ruleEls.isEmpty()) {
        doInitDefaultRule(ureq);
    }
    // email content
    FormLayoutContainer contentCont = FormLayoutContainer.createVerticalFormLayout("contents", getTranslator());
    contentCont.setRootForm(mainForm);
    formLayout.add(contentCont);
    // email subject
    String subject = reminder.getEmailSubject();
    subjectEl = uifactory.addTextElement("reminder.subject", "reminder.subject", 128, subject, contentCont);
    subjectEl.setMandatory(true);
    subjectEl.setElementCssClass("o_sel_course_reminder_subject");
    String emailContent = reminder == null ? null : reminder.getEmailBody();
    if (!StringHelper.containsNonWhitespace(emailContent)) {
        emailContent = translate("reminder.def.body");
    }
    emailEl = uifactory.addRichTextElementForStringDataMinimalistic("email.content", "email.content", emailContent, 10, 60, contentCont, getWindowControl());
    emailEl.setMandatory(true);
    String buttonPage = velocity_root + "/edit_rules_buttons.html";
    FormLayoutContainer buttonLayout = FormLayoutContainer.createCustomFormLayout("buttons", getTranslator(), buttonPage);
    buttonLayout.setRootForm(mainForm);
    formLayout.add(buttonLayout);
    uifactory.addFormSubmitButton("save", buttonLayout);
    uifactory.addFormCancelButton("cancel", buttonLayout, ureq, getWindowControl());
}
Also used : ReminderRule(org.olat.modules.reminder.ReminderRule) ReminderRules(org.olat.modules.reminder.model.ReminderRules) RuleSPI(org.olat.modules.reminder.RuleSPI) DateRuleSPI(org.olat.modules.reminder.rule.DateRuleSPI) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)

Aggregations

RuleSPI (org.olat.modules.reminder.RuleSPI)22 DateRuleSPI (org.olat.modules.reminder.rule.DateRuleSPI)18 ReminderRule (org.olat.modules.reminder.ReminderRule)12 FilterRuleSPI (org.olat.modules.reminder.FilterRuleSPI)10 IdentitiesProviderRuleSPI (org.olat.modules.reminder.IdentitiesProviderRuleSPI)10 RepositoryEntryRuleSPI (org.olat.modules.reminder.RepositoryEntryRuleSPI)10 BusinessGroupRoleRuleSPI (org.olat.modules.reminder.rule.BusinessGroupRoleRuleSPI)10 RepositoryEntryRoleRuleSPI (org.olat.modules.reminder.rule.RepositoryEntryRoleRuleSPI)10 UserPropertyRuleSPI (org.olat.modules.reminder.rule.UserPropertyRuleSPI)10 ArrayList (java.util.ArrayList)6 ReminderRules (org.olat.modules.reminder.model.ReminderRules)6 Identity (org.olat.core.id.Identity)4 Reminder (org.olat.modules.reminder.Reminder)4 ReminderModule (org.olat.modules.reminder.ReminderModule)4 ReminderService (org.olat.modules.reminder.ReminderService)4 HashSet (java.util.HashSet)2 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)2 SingleSelection (org.olat.core.gui.components.form.flexible.elements.SingleSelection)2 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)2