use of org.olat.modules.reminder.model.ReminderRuleImpl in project OpenOLAT by OpenOLAT.
the class RepositoryEntryLifecycleAfterValidToRuleSPI method evaluate.
public boolean evaluate(RepositoryEntryLifecycle lifecycle, ReminderRule rule) {
Date now = cleanNow();
ReminderRuleImpl r = (ReminderRuleImpl) rule;
int distance = Integer.parseInt(r.getRightOperand());
LaunchUnit unit = LaunchUnit.valueOf(r.getRightUnit());
Date referenceDate = getDate(lifecycle.getValidTo(), distance, unit);
return now.compareTo(referenceDate) >= 0;
}
use of org.olat.modules.reminder.model.ReminderRuleImpl in project OpenOLAT by OpenOLAT.
the class PassedRuleEditor method initForm.
@Override
public FormItem initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
String page = Util.getPackageVelocityRoot(this.getClass()) + "/passed.html";
String id = Long.toString(CodeHelper.getRAMUniqueID());
FormLayoutContainer ruleCont = FormLayoutContainer.createCustomFormLayout("attempts.".concat(id), formLayout.getTranslator(), page);
ruleCont.setRootForm(formLayout.getRootForm());
formLayout.add(ruleCont);
ruleCont.getFormItemComponent().contextPut("id", id);
ICourse course = CourseFactory.loadCourse(entry);
String currentStatus = null;
String currentCourseNode = null;
if (rule instanceof ReminderRuleImpl) {
ReminderRuleImpl r = (ReminderRuleImpl) rule;
currentStatus = r.getRightOperand();
currentCourseNode = r.getLeftOperand();
}
List<CourseNode> attemptableNodes = new ArrayList<>();
searchPassedNodes(course.getRunStructure().getRootNode(), attemptableNodes);
String[] nodeKeys = new String[attemptableNodes.size()];
String[] nodeValues = new String[attemptableNodes.size()];
for (int i = 0; i < attemptableNodes.size(); i++) {
CourseNode attemptableNode = attemptableNodes.get(i);
nodeKeys[i] = attemptableNode.getIdent();
nodeValues[i] = attemptableNode.getShortTitle() + " ( " + attemptableNode.getIdent() + " )";
}
courseNodeEl = uifactory.addDropdownSingleselect("coursenodes.".concat(id), null, ruleCont, nodeKeys, nodeValues, null);
courseNodeEl.setDomReplacementWrapperRequired(false);
boolean nodeSelected = false;
if (currentCourseNode != null) {
for (String nodeKey : nodeKeys) {
if (currentCourseNode.equals(nodeKey)) {
courseNodeEl.select(nodeKey, true);
nodeSelected = true;
}
}
}
if (!nodeSelected && nodeKeys.length > 0) {
courseNodeEl.select(nodeKeys[0], true);
}
if (StringHelper.containsNonWhitespace(currentCourseNode) && !nodeSelected) {
courseNodeEl.setErrorKey("error.course.node.found", null);
}
Translator trans = formLayout.getTranslator();
String[] statusValues = new String[] { trans.translate("passed"), trans.translate("failed") };
statusEl = uifactory.addDropdownSingleselect("status.".concat(id), null, ruleCont, statusKeys, statusValues, null);
statusEl.setDomReplacementWrapperRequired(false);
boolean statusSelected = false;
if (currentStatus != null) {
for (String statusKey : statusKeys) {
if (currentStatus.equals(statusKey)) {
statusEl.select(statusKey, true);
statusSelected = true;
}
}
}
if (!statusSelected) {
statusEl.select(statusKeys[1], true);
}
return ruleCont;
}
use of org.olat.modules.reminder.model.ReminderRuleImpl in project OpenOLAT by OpenOLAT.
the class PassedRuleEditor method getConfiguration.
@Override
public ReminderRule getConfiguration() {
ReminderRuleImpl configuredRule = null;
if (courseNodeEl.isOneSelected() && statusEl.isOneSelected()) {
configuredRule = new ReminderRuleImpl();
configuredRule.setType(PassedRuleSPI.class.getSimpleName());
configuredRule.setLeftOperand(courseNodeEl.getSelectedKey());
configuredRule.setOperator("=");
configuredRule.setRightOperand(statusEl.getSelectedKey());
}
return configuredRule;
}
use of org.olat.modules.reminder.model.ReminderRuleImpl in project OpenOLAT by OpenOLAT.
the class BeforeDateTaskRuleEditor method getConfiguration.
@Override
public ReminderRule getConfiguration() {
ReminderRuleImpl configuredRule = null;
if (courseNodeEl.isOneSelected() && unitEl.isOneSelected() && StringHelper.containsNonWhitespace(valueEl.getValue())) {
configuredRule = new ReminderRuleImpl();
configuredRule.setType(ruleType);
configuredRule.setLeftOperand(courseNodeEl.getSelectedKey());
configuredRule.setOperator("<");
configuredRule.setRightOperand(valueEl.getValue());
configuredRule.setRightUnit(unitEl.getSelectedKey());
}
return configuredRule;
}
use of org.olat.modules.reminder.model.ReminderRuleImpl in project openolat by klemens.
the class ReminderRuleEngineTest method dateRule.
@Test
public void dateRule() {
Calendar cal = Calendar.getInstance();
// check rule with date in the past
List<ReminderRule> rulePastList = new ArrayList<>();
ReminderRuleImpl pastRule = new ReminderRuleImpl();
pastRule.setType(DateRuleSPI.class.getSimpleName());
pastRule.setOperator(DateRuleSPI.AFTER);
cal.add(Calendar.HOUR_OF_DAY, -4);
pastRule.setRightOperand(Formatter.formatDatetime(cal.getTime()));
rulePastList.add(pastRule);
boolean pastEval = ruleEngine.evaluateDateRule(rulePastList);
Assert.assertTrue(pastEval);
// check rule with date in the future
List<ReminderRule> ruleFutureList = new ArrayList<>();
ReminderRuleImpl futureRule = new ReminderRuleImpl();
futureRule.setType(DateRuleSPI.class.getSimpleName());
futureRule.setOperator(DateRuleSPI.AFTER);
cal.add(Calendar.DATE, 4);
futureRule.setRightOperand(Formatter.formatDatetime(cal.getTime()));
ruleFutureList.add(futureRule);
boolean futureEval = ruleEngine.evaluateDateRule(ruleFutureList);
Assert.assertFalse(futureEval);
}
Aggregations