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;
}
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;
}
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();
}
}
}
}
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;
}
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;
}
Aggregations