use of org.olat.modules.reminder.model.ReminderRuleImpl in project OpenOLAT by OpenOLAT.
the class InitialAttemptsRuleEditor method getConfiguration.
@Override
public ReminderRule getConfiguration() {
ReminderRuleImpl configuredRule = null;
if (courseNodeEl.isOneSelected() && unitEl.isOneSelected() && StringHelper.containsNonWhitespace(valueEl.getValue())) {
configuredRule = new ReminderRuleImpl();
configuredRule.setType(InitialAttemptsRuleSPI.class.getSimpleName());
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 OpenOLAT.
the class InitialAttemptsRuleEditor method initForm.
@Override
public FormItem initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
String page = Util.getPackageVelocityRoot(this.getClass()) + "/initial_attempts.html";
String id = Long.toString(CodeHelper.getRAMUniqueID());
Translator trans = formLayout.getTranslator();
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 currentValue = null;
String currentUnit = null;
String currentCourseNode = null;
if (rule instanceof ReminderRuleImpl) {
ReminderRuleImpl r = (ReminderRuleImpl) rule;
currentUnit = r.getRightUnit();
currentValue = r.getRightOperand();
currentCourseNode = r.getLeftOperand();
}
List<CourseNode> attemptableNodes = new ArrayList<>();
searchAttemptableNodes(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);
}
valueEl = uifactory.addTextElement("attemptvalue.".concat(id), null, 128, currentValue, ruleCont);
valueEl.setDomReplacementWrapperRequired(false);
valueEl.setDisplaySize(3);
String[] unitValues = new String[] { trans.translate(LaunchUnit.day.name()), trans.translate(LaunchUnit.week.name()), trans.translate(LaunchUnit.month.name()), trans.translate(LaunchUnit.year.name()) };
unitEl = uifactory.addDropdownSingleselect("attemptunit.".concat(id), null, ruleCont, unitKeys, unitValues, null);
unitEl.setDomReplacementWrapperRequired(false);
boolean selected = false;
if (currentUnit != null) {
for (String unitKey : unitKeys) {
if (currentUnit.equals(unitKey)) {
unitEl.select(unitKey, true);
selected = true;
}
}
}
if (!selected) {
unitEl.select(unitKeys[1], true);
}
return ruleCont;
}
use of org.olat.modules.reminder.model.ReminderRuleImpl in project OpenOLAT by OpenOLAT.
the class AttemptsRuleEditor method getConfiguration.
@Override
public ReminderRule getConfiguration() {
ReminderRuleImpl configuredRule = null;
if (courseNodeEl.isOneSelected() && operatorEl.isOneSelected() && StringHelper.containsNonWhitespace(valueEl.getValue())) {
configuredRule = new ReminderRuleImpl();
configuredRule.setType(AttemptsRuleSPI.class.getSimpleName());
configuredRule.setLeftOperand(courseNodeEl.getSelectedKey());
configuredRule.setOperator(operatorEl.getSelectedKey());
configuredRule.setRightOperand(valueEl.getValue());
}
return configuredRule;
}
use of org.olat.modules.reminder.model.ReminderRuleImpl in project OpenOLAT by OpenOLAT.
the class AttemptsRuleSPI method filter.
@Override
public void filter(RepositoryEntry entry, List<Identity> identities, ReminderRule rule) {
if (rule instanceof ReminderRuleImpl) {
ReminderRuleImpl r = (ReminderRuleImpl) rule;
String nodeIdent = r.getLeftOperand();
String operator = r.getOperator();
int value = Integer.parseInt(r.getRightOperand());
ICourse course = CourseFactory.loadCourse(entry);
CourseNode courseNode = course.getRunStructure().getNode(nodeIdent);
if (courseNode == null) {
identities.clear();
log.error("Attempts rule in course " + entry.getKey() + " (" + entry.getDisplayname() + ") is missing a course element");
return;
}
Map<Long, Integer> attempts = helperDao.getAttempts(entry, courseNode, identities);
for (Iterator<Identity> identityIt = identities.iterator(); identityIt.hasNext(); ) {
Identity identity = identityIt.next();
Integer attempt = attempts.get(identity.getKey());
if (attempt == null) {
attempt = 0;
}
if (!evaluateAttempt(attempt.intValue(), operator, value)) {
identityIt.remove();
}
}
}
}
use of org.olat.modules.reminder.model.ReminderRuleImpl in project OpenOLAT by OpenOLAT.
the class GTAReminderRuleTest method assignTask_individual.
@Test
public void assignTask_individual() {
// prepare a course with a volatile task
Identity participant1 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-1");
Identity participant2 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-2");
RepositoryEntry re = deployGTACourse();
repositoryEntryRelationDao.addRole(participant1, re, GroupRoles.participant.name());
repositoryEntryRelationDao.addRole(participant2, re, GroupRoles.participant.name());
dbInstance.commit();
GTACourseNode node = getGTACourseNode(re);
node.getModuleConfiguration().setStringValue(GTACourseNode.GTASK_TYPE, GTAType.individual.name());
Calendar cal = Calendar.getInstance();
cal.add(2, Calendar.MONTH);
node.getModuleConfiguration().setDateValue(GTACourseNode.GTASK_ASSIGNMENT_DEADLINE, cal.getTime());
TaskList tasks = gtaManager.createIfNotExists(re, node);
File taskFile = new File("solo.txt");
Assert.assertNotNull(tasks);
dbInstance.commit();
// select a task
AssignmentResponse response = gtaManager.selectTask(participant1, tasks, node, taskFile);
dbInstance.commitAndCloseSession();
Assert.assertEquals(AssignmentResponse.Status.ok, response.getStatus());
// only remind participant 2
List<Identity> toRemind = assignTaskRuleSPI.getPeopleToRemind(re, node);
Assert.assertEquals(1, toRemind.size());
Assert.assertTrue(toRemind.contains(participant2));
{
// check before 30 days
ReminderRuleImpl rule = getAssignedTaskRules(30, LaunchUnit.day);
List<Identity> all = assignTaskRuleSPI.evaluateRule(re, node, rule);
Assert.assertEquals(0, all.size());
}
{
// check before 5 weeks
ReminderRuleImpl rule = getAssignedTaskRules(5, LaunchUnit.week);
List<Identity> all = assignTaskRuleSPI.evaluateRule(re, node, rule);
Assert.assertEquals(0, all.size());
}
{
// check before 1 month
ReminderRuleImpl rule = getAssignedTaskRules(1, LaunchUnit.month);
List<Identity> all = assignTaskRuleSPI.evaluateRule(re, node, rule);
Assert.assertEquals(0, all.size());
}
{
// check before 90 days
ReminderRuleImpl rule = getAssignedTaskRules(90, LaunchUnit.day);
List<Identity> all = assignTaskRuleSPI.evaluateRule(re, node, rule);
Assert.assertEquals(1, all.size());
Assert.assertTrue(toRemind.contains(participant2));
}
{
// check before 12 weeks
ReminderRuleImpl rule = getAssignedTaskRules(12, LaunchUnit.week);
List<Identity> all = assignTaskRuleSPI.evaluateRule(re, node, rule);
Assert.assertEquals(1, all.size());
Assert.assertTrue(toRemind.contains(participant2));
}
{
// check before 3 month
ReminderRuleImpl rule = getAssignedTaskRules(3, LaunchUnit.month);
List<Identity> all = assignTaskRuleSPI.evaluateRule(re, node, rule);
Assert.assertEquals(1, all.size());
Assert.assertTrue(toRemind.contains(participant2));
}
{
// check before 1 year
ReminderRuleImpl rule = getAssignedTaskRules(1, LaunchUnit.year);
List<Identity> all = assignTaskRuleSPI.evaluateRule(re, node, rule);
Assert.assertEquals(1, all.size());
Assert.assertTrue(toRemind.contains(participant2));
}
}
Aggregations