Search in sources :

Example 21 with ReminderRuleImpl

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;
}
Also used : ReminderRuleImpl(org.olat.modules.reminder.model.ReminderRuleImpl) Date(java.util.Date)

Example 22 with ReminderRuleImpl

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;
}
Also used : ReminderRuleImpl(org.olat.modules.reminder.model.ReminderRuleImpl) Translator(org.olat.core.gui.translator.Translator) ArrayList(java.util.ArrayList) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) ICourse(org.olat.course.ICourse) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) CourseNode(org.olat.course.nodes.CourseNode)

Example 23 with ReminderRuleImpl

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;
}
Also used : ReminderRuleImpl(org.olat.modules.reminder.model.ReminderRuleImpl) PassedRuleSPI(org.olat.course.reminder.rule.PassedRuleSPI)

Example 24 with ReminderRuleImpl

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;
}
Also used : ReminderRuleImpl(org.olat.modules.reminder.model.ReminderRuleImpl)

Example 25 with ReminderRuleImpl

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);
}
Also used : ReminderRule(org.olat.modules.reminder.ReminderRule) CourseEnrollmentDateRuleSPI(org.olat.modules.reminder.rule.CourseEnrollmentDateRuleSPI) DateRuleSPI(org.olat.modules.reminder.rule.DateRuleSPI) ReminderRuleImpl(org.olat.modules.reminder.model.ReminderRuleImpl) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

ReminderRuleImpl (org.olat.modules.reminder.model.ReminderRuleImpl)114 ArrayList (java.util.ArrayList)46 Identity (org.olat.core.id.Identity)26 ReminderRule (org.olat.modules.reminder.ReminderRule)26 ICourse (org.olat.course.ICourse)22 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)20 CourseNode (org.olat.course.nodes.CourseNode)20 Test (org.junit.Test)16 Date (java.util.Date)14 Translator (org.olat.core.gui.translator.Translator)14 GTACourseNode (org.olat.course.nodes.GTACourseNode)14 List (java.util.List)12 RepositoryEntry (org.olat.repository.RepositoryEntry)12 TaskList (org.olat.course.nodes.gta.TaskList)10 Calendar (java.util.Calendar)8 AssessableCourseNode (org.olat.course.nodes.AssessableCourseNode)8 ParseException (java.text.ParseException)6 InitialAttemptsRuleSPI (org.olat.course.reminder.rule.InitialAttemptsRuleSPI)6 ScoreRuleSPI (org.olat.course.reminder.rule.ScoreRuleSPI)6 File (java.io.File)4