Search in sources :

Example 11 with SentReminder

use of org.olat.modules.reminder.SentReminder 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));
}
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 12 with SentReminder

use of org.olat.modules.reminder.SentReminder in project OpenOLAT by OpenOLAT.

the class ReminderDAOTest method createAndPersistSendReminder.

@Test
public void createAndPersistSendReminder() {
    // create and reminder and an identity
    Identity creator = JunitTestHelper.createAndPersistIdentityAsRndUser("creator-rem-2");
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("mind-1");
    RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
    Reminder reminder = reminderDao.createReminder(entry, creator);
    reminder.setConfiguration("<rules></rules>");
    reminder.setDescription("Reminder - 2");
    reminder.setEmailSubject("This is a subject");
    reminder.setEmailBody("Hello world");
    Reminder savedReminder = reminderDao.save(reminder);
    Assert.assertNotNull(savedReminder);
    dbInstance.commitAndCloseSession();
    // mark as sent
    reminderDao.markAsSend(reminder, id, "ok");
    dbInstance.commitAndCloseSession();
    // reload
    List<SentReminder> sentReminders = reminderDao.getSendReminders(savedReminder);
    Assert.assertNotNull(sentReminders);
    Assert.assertEquals(1, sentReminders.size());
    SentReminder sentReminder = sentReminders.get(0);
    Assert.assertNotNull(sentReminder);
    Assert.assertNotNull(sentReminder.getCreationDate());
    Assert.assertEquals(id, sentReminder.getIdentity());
    Assert.assertEquals(savedReminder, sentReminder.getReminder());
}
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 13 with SentReminder

use of org.olat.modules.reminder.SentReminder in project OpenOLAT by OpenOLAT.

the class ReminderDAOTest method markAsSend.

@Test
public void markAsSend() {
    // create and reminder and an identity
    Identity creator = JunitTestHelper.createAndPersistIdentityAsRndUser("creator-rem-5");
    Identity recepient = JunitTestHelper.createAndPersistIdentityAsRndUser("recepient-rem-5");
    RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
    Reminder savedReminder = createAndSaveReminder(entry, creator, 5);
    Assert.assertNotNull(savedReminder);
    dbInstance.commitAndCloseSession();
    SentReminderImpl sentReminder = reminderDao.markAsSend(savedReminder, recepient, "ok");
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(sentReminder);
    Assert.assertNotNull(sentReminder.getKey());
    Assert.assertEquals("ok", sentReminder.getStatus());
    Assert.assertEquals(savedReminder, sentReminder.getReminder());
    Assert.assertEquals(recepient, sentReminder.getIdentity());
}
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) Test(org.junit.Test)

Example 14 with SentReminder

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

the class ReminderDAOTest method deleteReminder.

@Test
public void deleteReminder() {
    // 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 reminderToDelete = createAndSaveReminder(entry, creator, 8);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(reminderToDelete);
    // send 4 reminders
    reminderDao.markAsSend(reminderToDelete, recepient1, "ok");
    reminderDao.markAsSend(reminderToDelete, recepient2, "error");
    reminderDao.markAsSend(reminderToDelete, recepient3, "error");
    reminderDao.markAsSend(reminderToDelete, recepient2, "error");
    dbInstance.commitAndCloseSession();
    // check
    List<SentReminder> sentReminders = reminderDao.getSendReminders(reminderToDelete);
    Assert.assertNotNull(sentReminders);
    Assert.assertEquals(4, sentReminders.size());
    reminderDao.delete(reminderToDelete);
    dbInstance.commit();
    // check that the reminder is missing
    List<Reminder> deletedReminders = reminderDao.getReminders(entry);
    Assert.assertNotNull(deletedReminders);
    Assert.assertEquals(0, deletedReminders.size());
}
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 15 with SentReminder

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

the class CourseSendReminderListController method updateModel.

private void updateModel() {
    List<SentReminder> sentReminders = reminderService.getSentReminders(reminder);
    List<SentReminderRow> rows = new ArrayList<>(sentReminders.size());
    for (SentReminder sentReminder : sentReminders) {
        Identity identity = sentReminder.getIdentity();
        SentReminderRow row = new SentReminderRow(reminder, sentReminder, identity, userPropertyHandlers, getLocale());
        rows.add(row);
    }
    tableModel.setObjects(rows);
    tableEl.reset();
}
Also used : ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) SentReminder(org.olat.modules.reminder.SentReminder) SentReminderRow(org.olat.course.reminder.model.SentReminderRow)

Aggregations

Identity (org.olat.core.id.Identity)16 SentReminder (org.olat.modules.reminder.SentReminder)16 Reminder (org.olat.modules.reminder.Reminder)14 Test (org.junit.Test)12 RepositoryEntry (org.olat.repository.RepositoryEntry)12 SentReminderImpl (org.olat.modules.reminder.model.SentReminderImpl)6 ArrayList (java.util.ArrayList)4 SentReminderRow (org.olat.course.reminder.model.SentReminderRow)4