use of org.activityinfo.server.database.hibernate.entity.ReportSubscription in project activityinfo by bedatadriven.
the class ReportMailerServlet method doGet.
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException {
Date today = parseDate(request);
Predicate<ReportSubscription> filter = parseFilter(request);
mailerJob.get().execute(today, filter);
}
use of org.activityinfo.server.database.hibernate.entity.ReportSubscription in project activityinfo by bedatadriven.
the class ReportMailerTest method testWeeklyCheck.
@Test
public void testWeeklyCheck() {
ReportSubscription report = new ReportSubscription();
report.setEmailDelivery(EmailDelivery.WEEKLY);
// Saturday
report.setEmailDay(7);
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, 2012);
cal.set(Calendar.MONTH, Calendar.AUGUST);
cal.set(Calendar.DATE, 11);
Assert.assertTrue("Saturday report goes out on Saturday", ReportMailerHelper.mailToday(cal.getTime(), report));
cal.set(Calendar.DATE, 5);
Assert.assertFalse("Sunday report does not out on Monday", ReportMailerHelper.mailToday(cal.getTime(), report));
report.setEmailDay(1);
Assert.assertTrue("Monday report goes out on Monday", ReportMailerHelper.mailToday(cal.getTime(), report));
}
use of org.activityinfo.server.database.hibernate.entity.ReportSubscription in project activityinfo by bedatadriven.
the class ReportMailerTest method testEmail.
private void testEmail(String locale) {
User user = new User();
user.setEmail("akbertram@gmail.com");
user.setName("alex");
user.setLocale(locale);
ReportSubscription sub = new ReportSubscription();
sub.setTemplate(new ReportDefinition());
sub.getTemplate().setId(5040);
sub.setUser(user);
sub.setEmailDelivery(EmailDelivery.WEEKLY);
sub.setEmailDay(1);
Report report = new Report();
report.setTitle("Rapport RRM Mensuelle");
String text = ReportMailerHelper.composeTextEmail(sub, report);
System.out.println(text);
Assert.assertTrue("user name is present", text.contains(user.getName()));
Assert.assertTrue("link is correct without comma", text.contains("#report/5040"));
}
use of org.activityinfo.server.database.hibernate.entity.ReportSubscription in project activityinfo by bedatadriven.
the class ReportMailerTest method testMonthly.
@Test
public void testMonthly() {
ReportSubscription report = new ReportSubscription();
report.setEmailDelivery(EmailDelivery.MONTHLY);
report.setEmailDay(11);
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, 2009);
cal.set(Calendar.MONTH, Calendar.DECEMBER);
cal.set(Calendar.DATE, 11);
Assert.assertTrue("Monthly report scheduled for each the 11th goes out on the 11th", ReportMailerHelper.mailToday(cal.getTime(), report));
cal.set(Calendar.DATE, 30);
}
use of org.activityinfo.server.database.hibernate.entity.ReportSubscription in project activityinfo by bedatadriven.
the class ReportMailer method execute.
public void execute(Date today, Predicate<ReportSubscription> filter) {
LOGGER.info("Starting nightly mailing job for " + today);
List<ReportSubscription> subscriptions = em.createQuery("select t from ReportSubscription t", ReportSubscription.class).getResultList();
for (ReportSubscription subscription : subscriptions) {
try {
if (ReportMailerHelper.mailToday(today, subscription) && filter.apply(subscription)) {
Report report = ReportParserJaxb.parseXml(subscription.getTemplate().getXml());
execute(today, subscription, report);
}
} catch (Exception caught) {
LOGGER.log(Level.SEVERE, "Exception thrown while processing report " + subscription.getId(), caught);
}
}
}
Aggregations