Search in sources :

Example 21 with Reminder

use of org.olat.modules.reminder.Reminder in project openolat by klemens.

the class ReminderDAOTest method getSendReminders_byRepositoryEntry.

@Test
public void getSendReminders_byRepositoryEntry() {
    // create and reminder and an identity
    Identity creator = JunitTestHelper.createAndPersistIdentityAsRndUser("creator-rem-8");
    Identity recepient1 = JunitTestHelper.createAndPersistIdentityAsRndUser("recepient-rem-8a");
    Identity recepient2 = JunitTestHelper.createAndPersistIdentityAsRndUser("recepient-rem-8b");
    RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
    Reminder savedReminder = createAndSaveReminder(entry, creator, 8);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(savedReminder);
    // send 3 reminders
    SentReminderImpl sentReminder1 = reminderDao.markAsSend(savedReminder, recepient1, "ok");
    SentReminderImpl sentReminder2 = reminderDao.markAsSend(savedReminder, recepient2, "error");
    SentReminderImpl sentReminder3 = reminderDao.markAsSend(savedReminder, recepient2, "error");
    dbInstance.commitAndCloseSession();
    // load the sent reminder log
    List<SentReminder> sentReminders = reminderDao.getSendReminders(entry);
    Assert.assertNotNull(sentReminders);
    Assert.assertEquals(3, sentReminders.size());
    Assert.assertTrue(sentReminders.contains(sentReminder1));
    Assert.assertTrue(sentReminders.contains(sentReminder2));
    Assert.assertTrue(sentReminders.contains(sentReminder3));
}
Also used : Reminder(org.olat.modules.reminder.Reminder) SentReminder(org.olat.modules.reminder.SentReminder) SentReminderImpl(org.olat.modules.reminder.model.SentReminderImpl) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) SentReminder(org.olat.modules.reminder.SentReminder) Test(org.junit.Test)

Example 22 with Reminder

use of org.olat.modules.reminder.Reminder in project openolat by klemens.

the class ReminderDAOTest method duplicateReminder.

@Test
public void duplicateReminder() {
    Identity creator = JunitTestHelper.createAndPersistIdentityAsRndUser("creator-rem-12");
    RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
    Reminder reminderToCopy = createAndSaveReminder(entry, creator, 12);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(reminderToCopy);
    Reminder duplicate = reminderDao.duplicate(reminderToCopy, creator);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(duplicate);
    Assert.assertNotNull(duplicate.getKey());
    ReminderImpl reloadedDuplicate = (ReminderImpl) reminderDao.loadByKey(duplicate.getKey());
    Assert.assertNotNull(reloadedDuplicate);
    Assert.assertEquals(creator, reloadedDuplicate.getCreator());
    Assert.assertEquals(entry, reloadedDuplicate.getEntry());
    Assert.assertEquals(reminderToCopy.getEmailBody(), reloadedDuplicate.getEmailBody());
    Assert.assertEquals(reminderToCopy.getEmailSubject(), reloadedDuplicate.getEmailSubject());
    Assert.assertTrue(reloadedDuplicate.getDescription().startsWith(reminderToCopy.getDescription()));
    Assert.assertEquals(reminderToCopy.getConfiguration(), reloadedDuplicate.getConfiguration());
}
Also used : Reminder(org.olat.modules.reminder.Reminder) SentReminder(org.olat.modules.reminder.SentReminder) ReminderImpl(org.olat.modules.reminder.model.ReminderImpl) SentReminderImpl(org.olat.modules.reminder.model.SentReminderImpl) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 23 with Reminder

use of org.olat.modules.reminder.Reminder in project openolat by klemens.

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()));
}
Also used : Reminder(org.olat.modules.reminder.Reminder) SentReminder(org.olat.modules.reminder.SentReminder) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 24 with Reminder

use of org.olat.modules.reminder.Reminder in project openolat by klemens.

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));
}
Also used : Reminder(org.olat.modules.reminder.Reminder) SentReminder(org.olat.modules.reminder.SentReminder) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) SentReminder(org.olat.modules.reminder.SentReminder) Test(org.junit.Test)

Example 25 with Reminder

use of org.olat.modules.reminder.Reminder in project openolat by klemens.

the class ReminderDAO method delete.

public int delete(RepositoryEntry entry) {
    int rowsDeleted = 0;
    List<Reminder> reminders = getReminders(entry);
    for (Reminder reminder : reminders) {
        rowsDeleted += delete(reminder);
    }
    return rowsDeleted;
}
Also used : Reminder(org.olat.modules.reminder.Reminder) SentReminder(org.olat.modules.reminder.SentReminder)

Aggregations

Reminder (org.olat.modules.reminder.Reminder)62 SentReminder (org.olat.modules.reminder.SentReminder)46 Identity (org.olat.core.id.Identity)32 Test (org.junit.Test)26 RepositoryEntry (org.olat.repository.RepositoryEntry)26 SentReminderImpl (org.olat.modules.reminder.model.SentReminderImpl)10 Date (java.util.Date)8 ImportExportReminder (org.olat.modules.reminder.model.ImportExportReminder)6 File (java.io.File)4 ParseException (java.text.ParseException)4 ArrayList (java.util.ArrayList)4 MailerResult (org.olat.core.util.mail.MailerResult)4 ReminderModule (org.olat.modules.reminder.ReminderModule)4 ReminderRule (org.olat.modules.reminder.ReminderRule)4 ReminderService (org.olat.modules.reminder.ReminderService)4 RuleSPI (org.olat.modules.reminder.RuleSPI)4 ImportExportReminders (org.olat.modules.reminder.model.ImportExportReminders)4 ReminderRules (org.olat.modules.reminder.model.ReminderRules)4 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2