Search in sources :

Example 6 with ReminderRule

use of org.olat.modules.reminder.ReminderRule 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 7 with ReminderRule

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

the class ReminderRuleEngine method filterIdentitiesByProperty.

/**
 * Remove identities of the list which not match the user properties rules if any.
 *
 * @param identities
 * @param ruleList
 */
protected void filterIdentitiesByProperty(List<Identity> identities, List<ReminderRule> ruleList) {
    List<ReminderRule> userPropRules = new ArrayList<>(3);
    for (Iterator<ReminderRule> ruleIt = ruleList.iterator(); ruleIt.hasNext(); ) {
        ReminderRule rule = ruleIt.next();
        if (USER_PROP_RULE_TYPE.equals(rule.getType())) {
            userPropRules.add(rule);
            ruleIt.remove();
        }
    }
    if (userPropRules.size() > 0) {
        int numOfRules = userPropRules.size();
        ReminderRule[] ruleArr = userPropRules.toArray(new ReminderRule[numOfRules]);
        for (Iterator<Identity> identityIt = identities.iterator(); identityIt.hasNext(); ) {
            Identity identity = identityIt.next();
            boolean accept = true;
            for (int i = numOfRules; i-- > 0; ) {
                accept &= userPropertyRuleSpi.accept(ruleArr[i], identity);
            }
            if (!accept) {
                identityIt.remove();
            }
        }
    }
}
Also used : ReminderRule(org.olat.modules.reminder.ReminderRule) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity)

Example 8 with ReminderRule

use of org.olat.modules.reminder.ReminderRule 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 9 with ReminderRule

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

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)

Example 10 with ReminderRule

use of org.olat.modules.reminder.ReminderRule 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

ReminderRule (org.olat.modules.reminder.ReminderRule)46 ArrayList (java.util.ArrayList)32 ReminderRuleImpl (org.olat.modules.reminder.model.ReminderRuleImpl)26 RuleSPI (org.olat.modules.reminder.RuleSPI)12 ReminderRules (org.olat.modules.reminder.model.ReminderRules)12 DateRuleSPI (org.olat.modules.reminder.rule.DateRuleSPI)10 RepositoryEntryRoleRuleSPI (org.olat.modules.reminder.rule.RepositoryEntryRoleRuleSPI)8 UserPropertyRuleSPI (org.olat.modules.reminder.rule.UserPropertyRuleSPI)8 Identity (org.olat.core.id.Identity)6 FilterRuleSPI (org.olat.modules.reminder.FilterRuleSPI)6 IdentitiesProviderRuleSPI (org.olat.modules.reminder.IdentitiesProviderRuleSPI)6 RepositoryEntryRuleSPI (org.olat.modules.reminder.RepositoryEntryRuleSPI)6 BusinessGroupRoleRuleSPI (org.olat.modules.reminder.rule.BusinessGroupRoleRuleSPI)6 InitialAttemptsRuleSPI (org.olat.course.reminder.rule.InitialAttemptsRuleSPI)4 Reminder (org.olat.modules.reminder.Reminder)4 ReminderModule (org.olat.modules.reminder.ReminderModule)4 ReminderService (org.olat.modules.reminder.ReminderService)4 CourseEnrollmentDateRuleSPI (org.olat.modules.reminder.rule.CourseEnrollmentDateRuleSPI)4 ParseException (java.text.ParseException)2 Calendar (java.util.Calendar)2