use of org.olat.modules.reminder.Reminder in project OpenOLAT by OpenOLAT.
the class ReminderServiceImpl method remindAll.
@Override
public void remindAll() {
Date now = new Date();
List<Reminder> reminders = reminderDao.getReminders(now);
for (Reminder reminder : reminders) {
sendReminder(reminder);
}
}
use of org.olat.modules.reminder.Reminder in project OpenOLAT by OpenOLAT.
the class ReminderDAOTest method getReminderInfos.
@Test
public void getReminderInfos() {
// create and reminder and an identity
Identity creator = JunitTestHelper.createAndPersistIdentityAsRndUser("creator-rem-6");
Identity recepient1 = JunitTestHelper.createAndPersistIdentityAsRndUser("recepient-rem-6a");
Identity recepient2 = JunitTestHelper.createAndPersistIdentityAsRndUser("recepient-rem-6b");
RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
Reminder savedReminder = createAndSaveReminder(entry, creator, 6);
dbInstance.commitAndCloseSession();
Assert.assertNotNull(savedReminder);
// send 2 reminders
SentReminderImpl sentReminder1 = reminderDao.markAsSend(savedReminder, recepient1, "ok");
SentReminderImpl sentReminder2 = reminderDao.markAsSend(savedReminder, recepient2, "error");
dbInstance.commitAndCloseSession();
Assert.assertNotNull(sentReminder1);
Assert.assertNotNull(sentReminder2);
// check reminder infos
List<ReminderInfos> reminderInfos = reminderDao.getReminderInfos(entry);
Assert.assertNotNull(reminderInfos);
Assert.assertEquals(1, reminderInfos.size());
ReminderInfos reminderInfo = reminderInfos.get(0);
Assert.assertNotNull(reminderInfo);
Assert.assertEquals(savedReminder.getKey(), reminderInfo.getKey());
Assert.assertEquals(2, reminderInfo.getNumOfRemindersSent());
Assert.assertEquals(creator.getKey(), reminderInfo.getCreatorKey());
Assert.assertEquals("Reminder - 6", reminderInfo.getDescription());
}
use of org.olat.modules.reminder.Reminder in project OpenOLAT by OpenOLAT.
the class ReminderDAOTest method deleteReminder_paranoia.
/**
* Check that not all reminders are deleted from the database.
*/
@Test
public void deleteReminder_paranoia() {
// create and reminder and an identity
Identity creator = JunitTestHelper.createAndPersistIdentityAsRndUser("creator-rem-10");
Identity recepient1 = JunitTestHelper.createAndPersistIdentityAsRndUser("recepient-rem-10a");
Identity recepient2 = JunitTestHelper.createAndPersistIdentityAsRndUser("recepient-rem-10b");
Identity recepient3 = JunitTestHelper.createAndPersistIdentityAsRndUser("recepient-rem-10c");
RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
Reminder reminderToDelete = createAndSaveReminder(entry, creator, 10);
Reminder survivingReminder = createAndSaveReminder(entry, creator, 10);
dbInstance.commitAndCloseSession();
Assert.assertNotNull(reminderToDelete);
// send 4 reminders
reminderDao.markAsSend(reminderToDelete, recepient1, "ok");
reminderDao.markAsSend(reminderToDelete, recepient2, "error");
SentReminder sentReminder1 = reminderDao.markAsSend(survivingReminder, recepient3, "error");
SentReminder sentReminder2 = reminderDao.markAsSend(survivingReminder, recepient2, "error");
dbInstance.commitAndCloseSession();
// check
List<SentReminder> sentRemindersToDelete = reminderDao.getSendReminders(reminderToDelete);
Assert.assertNotNull(sentRemindersToDelete);
Assert.assertEquals(2, sentRemindersToDelete.size());
List<SentReminder> survivingSentReminders = reminderDao.getSendReminders(survivingReminder);
Assert.assertNotNull(survivingSentReminders);
Assert.assertEquals(2, survivingSentReminders.size());
reminderDao.delete(reminderToDelete);
dbInstance.commit();
// check that the reminder is missing
List<Reminder> deletedReminders = reminderDao.getReminders(entry);
Assert.assertNotNull(deletedReminders);
Assert.assertEquals(1, deletedReminders.size());
Assert.assertEquals(survivingReminder, deletedReminders.get(0));
// check that the send reminders are deleted but not all
List<SentReminder> reloadedSurvivingSentReminders = reminderDao.getSendReminders(survivingReminder);
Assert.assertNotNull(reloadedSurvivingSentReminders);
Assert.assertEquals(2, reloadedSurvivingSentReminders.size());
List<SentReminder> allSurvivingSentReminders = reminderDao.getSendReminders(entry);
Assert.assertNotNull(allSurvivingSentReminders);
Assert.assertEquals(2, allSurvivingSentReminders.size());
Assert.assertTrue(allSurvivingSentReminders.contains(sentReminder1));
Assert.assertTrue(allSurvivingSentReminders.contains(sentReminder2));
}
use of org.olat.modules.reminder.Reminder in project OpenOLAT by OpenOLAT.
the class ReminderDAOTest method createAndPersistReminder.
@Test
public void createAndPersistReminder() {
Identity creator = JunitTestHelper.createAndPersistIdentityAsRndUser("creator-rem-1");
RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
Reminder reminder = reminderDao.createReminder(entry, creator);
Assert.assertNotNull(reminder);
reminder.setConfiguration("<rules></rules>");
reminder.setDescription("Reminder - 1");
reminder.setEmailSubject("This is a subject");
reminder.setEmailBody("Hello world");
// save and check
Reminder savedReminder = reminderDao.save(reminder);
dbInstance.commitAndCloseSession();
Assert.assertNotNull(savedReminder);
Assert.assertNotNull(savedReminder.getKey());
Assert.assertNotNull(savedReminder.getCreationDate());
Assert.assertNotNull(savedReminder.getLastModified());
Assert.assertNotNull(savedReminder.getEntry());
Assert.assertEquals(entry, savedReminder.getEntry());
Assert.assertEquals("Reminder - 1", savedReminder.getDescription());
Assert.assertEquals("<rules></rules>", savedReminder.getConfiguration());
Assert.assertEquals("This is a subject", savedReminder.getEmailSubject());
Assert.assertEquals("Hello world", savedReminder.getEmailBody());
// reload and double check
Reminder reloadedReminder = reminderDao.loadByKey(savedReminder.getKey());
dbInstance.commitAndCloseSession();
Assert.assertNotNull(reloadedReminder);
Assert.assertEquals(savedReminder.getKey(), reloadedReminder.getKey());
Assert.assertNotNull(reloadedReminder.getCreationDate());
Assert.assertNotNull(reloadedReminder.getLastModified());
Assert.assertEquals(entry, reloadedReminder.getEntry());
Assert.assertEquals(savedReminder, reloadedReminder);
Assert.assertEquals("Reminder - 1", reloadedReminder.getDescription());
Assert.assertEquals("<rules></rules>", reloadedReminder.getConfiguration());
Assert.assertEquals("This is a subject", reloadedReminder.getEmailSubject());
Assert.assertEquals("Hello world", reloadedReminder.getEmailBody());
}
use of org.olat.modules.reminder.Reminder in project OpenOLAT by OpenOLAT.
the class ReminderDAOTest method getReminderRecipientKeys.
@Test
public void getReminderRecipientKeys() {
// create and reminder and an identity
Identity creator = JunitTestHelper.createAndPersistIdentityAsRndUser("creator-rem-9");
Identity recepient1 = JunitTestHelper.createAndPersistIdentityAsRndUser("recepient-rem-9a");
Identity recepient2 = JunitTestHelper.createAndPersistIdentityAsRndUser("recepient-rem-9b");
Identity recepient3 = JunitTestHelper.createAndPersistIdentityAsRndUser("recepient-rem-9c");
RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
Reminder savedReminder = createAndSaveReminder(entry, creator, 8);
dbInstance.commitAndCloseSession();
Assert.assertNotNull(savedReminder);
// send 3 reminders
reminderDao.markAsSend(savedReminder, recepient1, "ok");
reminderDao.markAsSend(savedReminder, recepient2, "error");
reminderDao.markAsSend(savedReminder, recepient3, "error");
dbInstance.commitAndCloseSession();
// load the sent reminder log
List<Long> recipientKeys = reminderDao.getReminderRecipientKeys(savedReminder);
Assert.assertNotNull(recipientKeys);
Assert.assertEquals(3, recipientKeys.size());
Assert.assertTrue(recipientKeys.contains(recepient1.getKey()));
Assert.assertTrue(recipientKeys.contains(recepient2.getKey()));
Assert.assertTrue(recipientKeys.contains(recepient3.getKey()));
}
Aggregations