Search in sources :

Example 16 with ReminderRule

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

the class ReminderRuleEngineTest method getInitialAttemptsRules.

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

Example 17 with ReminderRule

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

the class ReminderRuleEngineTest method getRules.

private List<ReminderRule> getRules(String propertyName, String value) {
    ReminderRuleImpl rule = new ReminderRuleImpl();
    rule.setType(UserPropertyRuleSPI.class.getSimpleName());
    rule.setLeftOperand(propertyName);
    rule.setOperator("=");
    rule.setRightOperand(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) UserPropertyRuleSPI(org.olat.modules.reminder.rule.UserPropertyRuleSPI) ArrayList(java.util.ArrayList)

Example 18 with ReminderRule

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

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 19 with ReminderRule

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

the class ReminderRuleEngine method evaluateDateRule.

/**
 * @param reminder
 */
protected boolean evaluateDateRule(List<ReminderRule> ruleList) {
    boolean allOk = true;
    for (Iterator<ReminderRule> ruleIt = ruleList.iterator(); ruleIt.hasNext(); ) {
        ReminderRule rule = ruleIt.next();
        if (DATE_RULE_TYPE.equals(rule.getType())) {
            allOk &= dateRuleSpi.evaluate(rule);
            ruleIt.remove();
        }
    }
    return allOk;
}
Also used : ReminderRule(org.olat.modules.reminder.ReminderRule)

Example 20 with ReminderRule

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

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)

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