this.jizzEmailServices = jizzEmailServices;
this.jizzTaskQueue = jizzTaskQueue;
}
private JizzBroadcast createNewBroadcast(JizzStation station) {
JizzBroadcast broadcast = new JizzBroadcast();
broadcast.setStation(station);
// The most important part of a new broadcast is its end date which is
// calculated based on the Cron expression of the station
try {
Predictor cron = new Predictor(station.getBroadcastSchedule());
cron.setTimeZone(station.getTimeZone());
broadcast.setFinale(cron.nextMatchingDate());
} catch (InvalidPatternException pEx) {
logger.error("Cron trigger " + station.getBroadcastSchedule()
+ " is invalid", pEx);
// Send error to the admins
String msg = JizzServicesErrors.getString(station.getLocale(),
MSG_ERR_INVALID_BROADCAST_SCHEDULE);
msg = MessageFormat.format(msg, station.getBroadcastSchedule());
jizzErrorServices.reportErrorToAdmins(station, msg, pEx);
throw new RuntimeException("The cron trigger '"
+ station.getBroadcastSchedule()
+ "' is not valid, can't make a new broadcast", pEx);
}
// The estimated start date for now is 2 hours before the end. In the
// future might try and inspect past broadcasts and guess an average,
// but not now!
long millis = broadcast.getFinale().getTime();
broadcast.setEstimatedStart(new Date(millis
- GUESSED_BROADCAST_LENGTH_IN_MILLIS));
broadcast = jizzBroadcastDao.createOrUpdateBroadcast(broadcast);
try {