Search in sources :

Example 6 with ReminderImpl

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

the class ReminderServiceImpl method optimizeStartDate.

private void optimizeStartDate(Reminder reminder) {
    Date startDate = null;
    String configuration = reminder.getConfiguration();
    if (StringHelper.containsNonWhitespace(configuration)) {
        ReminderRules rules = toRules(configuration);
        for (ReminderRule rule : rules.getRules()) {
            if (rule instanceof ReminderRuleImpl && ReminderRuleEngine.DATE_RULE_TYPE.equals(rule.getType())) {
                ReminderRuleImpl r = (ReminderRuleImpl) rule;
                if (DateRuleSPI.AFTER.equals(r.getOperator()) && StringHelper.containsNonWhitespace(r.getRightOperand())) {
                    try {
                        Date date = Formatter.parseDatetime(r.getRightOperand());
                        if (startDate == null) {
                            startDate = date;
                        } else if (startDate.compareTo(date) > 0) {
                            startDate = date;
                        }
                    } catch (ParseException e) {
                        log.error("", e);
                    }
                }
            }
        }
    }
    ((ReminderImpl) reminder).setStartDate(startDate);
}
Also used : ReminderRule(org.olat.modules.reminder.ReminderRule) ReminderRuleImpl(org.olat.modules.reminder.model.ReminderRuleImpl) ReminderRules(org.olat.modules.reminder.model.ReminderRules) ReminderImpl(org.olat.modules.reminder.model.ReminderImpl) ParseException(java.text.ParseException) Date(java.util.Date)

Example 7 with ReminderImpl

use of org.olat.modules.reminder.model.ReminderImpl in project OpenOLAT by OpenOLAT.

the class ReminderDAO method duplicate.

public Reminder duplicate(Reminder toCopy, Identity creator) {
    ReminderImpl reminder = new ReminderImpl();
    Date now = new Date();
    reminder.setCreationDate(now);
    reminder.setLastModified(now);
    if (toCopy.getEntry() != null) {
        RepositoryEntry entryRef = dbInstance.getCurrentEntityManager().getReference(RepositoryEntry.class, toCopy.getEntry().getKey());
        reminder.setEntry(entryRef);
    }
    reminder.setCreator(creator);
    reminder.setDescription(toCopy.getDescription() + " (Copy)");
    reminder.setConfiguration(toCopy.getConfiguration());
    reminder.setEmailSubject(toCopy.getEmailSubject());
    reminder.setEmailBody(toCopy.getEmailBody());
    dbInstance.getCurrentEntityManager().persist(reminder);
    return reminder;
}
Also used : ReminderImpl(org.olat.modules.reminder.model.ReminderImpl) SentReminderImpl(org.olat.modules.reminder.model.SentReminderImpl) RepositoryEntry(org.olat.repository.RepositoryEntry) Date(java.util.Date)

Example 8 with ReminderImpl

use of org.olat.modules.reminder.model.ReminderImpl in project OpenOLAT by OpenOLAT.

the class ReminderDAO method createReminder.

public Reminder createReminder(RepositoryEntry entry, Identity creator) {
    ReminderImpl reminder = new ReminderImpl();
    Date now = new Date();
    reminder.setCreationDate(now);
    reminder.setLastModified(now);
    reminder.setEntry(entry);
    reminder.setCreator(creator);
    return reminder;
}
Also used : ReminderImpl(org.olat.modules.reminder.model.ReminderImpl) SentReminderImpl(org.olat.modules.reminder.model.SentReminderImpl) Date(java.util.Date)

Example 9 with ReminderImpl

use of org.olat.modules.reminder.model.ReminderImpl in project OpenOLAT by OpenOLAT.

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 10 with ReminderImpl

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

the class ReminderDAO method createReminder.

public Reminder createReminder(RepositoryEntry entry, Identity creator) {
    ReminderImpl reminder = new ReminderImpl();
    Date now = new Date();
    reminder.setCreationDate(now);
    reminder.setLastModified(now);
    reminder.setEntry(entry);
    reminder.setCreator(creator);
    return reminder;
}
Also used : ReminderImpl(org.olat.modules.reminder.model.ReminderImpl) SentReminderImpl(org.olat.modules.reminder.model.SentReminderImpl) Date(java.util.Date)

Aggregations

ReminderImpl (org.olat.modules.reminder.model.ReminderImpl)10 SentReminderImpl (org.olat.modules.reminder.model.SentReminderImpl)8 Date (java.util.Date)6 RepositoryEntry (org.olat.repository.RepositoryEntry)4 ParseException (java.text.ParseException)2 Test (org.junit.Test)2 Identity (org.olat.core.id.Identity)2 Reminder (org.olat.modules.reminder.Reminder)2 ReminderRule (org.olat.modules.reminder.ReminderRule)2 SentReminder (org.olat.modules.reminder.SentReminder)2 ReminderRuleImpl (org.olat.modules.reminder.model.ReminderRuleImpl)2 ReminderRules (org.olat.modules.reminder.model.ReminderRules)2