use of org.olat.modules.reminder.model.ReminderImpl in project OpenOLAT by OpenOLAT.
the class ReminderDAO method delete.
public int delete(Reminder reminder) {
ReminderImpl ref = dbInstance.getCurrentEntityManager().getReference(ReminderImpl.class, reminder.getKey());
String del = "delete from sentreminder sent where sent.reminder.key=:reminderKey";
int numOfDeletedRows = dbInstance.getCurrentEntityManager().createQuery(del).setParameter("reminderKey", reminder.getKey()).executeUpdate();
dbInstance.getCurrentEntityManager().remove(ref);
numOfDeletedRows++;
return numOfDeletedRows;
}
use of org.olat.modules.reminder.model.ReminderImpl in project OpenOLAT by OpenOLAT.
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);
}
use of org.olat.modules.reminder.model.ReminderImpl 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());
}
use of org.olat.modules.reminder.model.ReminderImpl in project openolat by klemens.
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;
}
use of org.olat.modules.reminder.model.ReminderImpl in project openolat by klemens.
the class ReminderDAO method delete.
public int delete(Reminder reminder) {
ReminderImpl ref = dbInstance.getCurrentEntityManager().getReference(ReminderImpl.class, reminder.getKey());
String del = "delete from sentreminder sent where sent.reminder.key=:reminderKey";
int numOfDeletedRows = dbInstance.getCurrentEntityManager().createQuery(del).setParameter("reminderKey", reminder.getKey()).executeUpdate();
dbInstance.getCurrentEntityManager().remove(ref);
numOfDeletedRows++;
return numOfDeletedRows;
}
Aggregations