Search in sources :

Example 51 with Reminder

use of org.olat.modules.reminder.Reminder 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 52 with Reminder

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

the class ReminderServiceImpl method exportReminders.

@Override
public void exportReminders(RepositoryEntry entry, File fExportedDataDir) {
    List<Reminder> reminders = reminderDao.getReminders(entry);
    if (reminders.size() > 0) {
        try (OutputStream fOut = new FileOutputStream(new File(fExportedDataDir, REMINDERS_XML))) {
            ImportExportReminders exportReminders = new ImportExportReminders();
            for (Reminder reminder : reminders) {
                ImportExportReminder exportReminder = new ImportExportReminder(reminder);
                exportReminders.getReminders().add(exportReminder);
            }
            ruleXStream.toXML(exportReminders, fOut);
        } catch (Exception e) {
            log.error("", e);
        }
    }
}
Also used : ImportExportReminder(org.olat.modules.reminder.model.ImportExportReminder) SentReminder(org.olat.modules.reminder.SentReminder) Reminder(org.olat.modules.reminder.Reminder) ImportExportReminder(org.olat.modules.reminder.model.ImportExportReminder) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) ImportExportReminders(org.olat.modules.reminder.model.ImportExportReminders) ParseException(java.text.ParseException)

Example 53 with Reminder

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

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

Example 54 with Reminder

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

the class ReminderServiceImpl method importRawReminders.

@Override
public List<Reminder> importRawReminders(Identity creator, RepositoryEntry newEntry, File fExportedDataDir) {
    File reminderFile = new File(fExportedDataDir, REMINDERS_XML);
    List<Reminder> reminders = new ArrayList<>();
    if (reminderFile.exists()) {
        try (InputStream in = new FileInputStream(reminderFile)) {
            ImportExportReminders importReminders = (ImportExportReminders) ruleXStream.fromXML(in);
            List<ImportExportReminder> importReminderList = importReminders.getReminders();
            for (ImportExportReminder importReminder : importReminderList) {
                Reminder reminder = reminderDao.createReminder(newEntry, creator);
                reminder.setDescription(importReminder.getDescription());
                reminder.setEmailBody(importReminder.getEmailBody());
                reminder.setEmailSubject(importReminder.getEmailSubject() == null ? importReminder.getDescription() : importReminder.getEmailSubject());
                reminder.setConfiguration(importReminder.getConfiguration());
                reminders.add(reminder);
            }
        } catch (Exception e) {
            log.error("", e);
        }
    }
    return reminders;
}
Also used : ImportExportReminder(org.olat.modules.reminder.model.ImportExportReminder) SentReminder(org.olat.modules.reminder.SentReminder) Reminder(org.olat.modules.reminder.Reminder) ImportExportReminder(org.olat.modules.reminder.model.ImportExportReminder) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) File(java.io.File) ImportExportReminders(org.olat.modules.reminder.model.ImportExportReminders) FileInputStream(java.io.FileInputStream) ParseException(java.text.ParseException)

Example 55 with Reminder

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

the class ReminderDAO method save.

public Reminder save(Reminder reminder) {
    Reminder mergedReminder;
    if (reminder.getKey() != null) {
        reminder.setLastModified(new Date());
        mergedReminder = dbInstance.getCurrentEntityManager().merge(reminder);
    } else {
        dbInstance.getCurrentEntityManager().persist(reminder);
        mergedReminder = reminder;
    }
    return mergedReminder;
}
Also used : Reminder(org.olat.modules.reminder.Reminder) SentReminder(org.olat.modules.reminder.SentReminder) Date(java.util.Date)

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