package report; import dao.MarkingProperties; import dao.ResultDAO; import java.util.Collection; import java.util.concurrent.TimeUnit; import model.Student; import org.slf4j.LoggerFactory; /** * * @author mark */ public class Batcher { private static final org.slf4j.Logger logger = LoggerFactory.getLogger(Batcher.class); public void batch() { Collection<Student> students = new ResultDAO().getStudents(); for (Student student : students) { if (!student.getSendFeedback() || student.getEmailSent()) { continue; } String title = MarkingProperties.reportTitle(); String footer = MarkingProperties.reportFooter(); new FeedbackReportGenerator(new ResultDAO().getResult(student.getId()), MarkingProperties.reportPath(), MarkingProperties.attachmentFilePrefix(), title, footer).generate(student); String report = MarkingProperties.reportPath() + "/" + MarkingProperties.attachmentFilePrefix() + "-" + student.getId() + ".pdf"; if (MarkingProperties.isEmailEnabled()) { new SendReport().sendReport(student, report); try { int delay = MarkingProperties.emailDelay(); TimeUnit.SECONDS.sleep(delay); // delay to avoid triggering rate limiting } catch (InterruptedException e) { logger.error(e.getLocalizedMessage(), e); } } } } }