Newer
Older
marking / src / main / java / report / Batcher.java
package report;

import dao.MarkingProperties;
import dao.ResultDAO;
import java.util.Collection;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import model.Student;

/**
 *
 * @author mark
 */
public class Batcher {

	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 ex) {
					Logger.getLogger(Batcher.class.getName()).log(Level.SEVERE, null, ex);
				}
			}
		}
	}

}