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