Search in sources :

Example 1 with ReportSubscription

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);
}
Also used : ReportSubscription(org.activityinfo.server.database.hibernate.entity.ReportSubscription) Date(java.util.Date)

Example 2 with ReportSubscription

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));
}
Also used : ReportSubscription(org.activityinfo.server.database.hibernate.entity.ReportSubscription) Calendar(java.util.Calendar) Test(org.junit.Test)

Example 3 with ReportSubscription

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"));
}
Also used : User(org.activityinfo.server.database.hibernate.entity.User) Report(org.activityinfo.legacy.shared.reports.model.Report) ReportSubscription(org.activityinfo.server.database.hibernate.entity.ReportSubscription) ReportDefinition(org.activityinfo.server.database.hibernate.entity.ReportDefinition)

Example 4 with ReportSubscription

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);
}
Also used : ReportSubscription(org.activityinfo.server.database.hibernate.entity.ReportSubscription) Calendar(java.util.Calendar) Test(org.junit.Test)

Example 5 with ReportSubscription

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);
        }
    }
}
Also used : Report(org.activityinfo.legacy.shared.reports.model.Report) ReportSubscription(org.activityinfo.server.database.hibernate.entity.ReportSubscription) MessagingException(javax.mail.MessagingException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Aggregations

ReportSubscription (org.activityinfo.server.database.hibernate.entity.ReportSubscription)6 Calendar (java.util.Calendar)3 Test (org.junit.Test)3 Report (org.activityinfo.legacy.shared.reports.model.Report)2 IOException (java.io.IOException)1 Date (java.util.Date)1 MessagingException (javax.mail.MessagingException)1 ReportDefinition (org.activityinfo.server.database.hibernate.entity.ReportDefinition)1 User (org.activityinfo.server.database.hibernate.entity.User)1 SAXException (org.xml.sax.SAXException)1