Newer
Older
marking / src / 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;
			}

			new FeedbackReportGenerator(new ResultDAO().getResult(student.getUserName()), MarkingProperties.reportPath(), MarkingProperties.attachmentFilePrefix()).generate(student);

			String report = MarkingProperties.reportPath() + "/" + MarkingProperties.attachmentFilePrefix() + "-" + student.getId() + ".pdf";

			if (MarkingProperties.isEmailEnabled()) {
				new SendReport().sendReport(student, report);

				try {
					TimeUnit.SECONDS.sleep(1);  // short delay to avoid triggering rate limiting
				} catch (InterruptedException ex) {
					Logger.getLogger(Batcher.class.getName()).log(Level.SEVERE, null, ex);
				}
			}
		}
	}

}