@Override
public HomeResult execute(HomeAction action, ExecutionContext context)
throws DispatchException {
logger.trace("Jizz Home execution underway");
HomeResult result = new HomeResult();
// Look for the station - if nothing there then this is a new install
JizzStation station = jizzStationDao.getPrimaryStation();
if (station == null) {
result.setNewInstall(true);
logger.info("New install detected by virtue of no primary "
+ "station. Returning result {}", result);
return result;
}
result.setStationName(station.getName());
// Look for the DJ based on their login name
JizzDj dj = jizzDjServices.getCurrentDj();
result.setName(dj.getName());
result.setEmail(dj.getEmail());
if (dj.getEmail() != null && dj.getEmail().length() > 0 && dj.getEmailConfirmation() != null) {
result.setEmailAwaitingConfirmation(true);
} else {
result.setEmailAwaitingConfirmation(false);
}
result.setLocale(dj.getLocale());
// Look up the next broadcast and set in its details
JizzBroadcast broadcast = jizzBroadcastServices
.getNextBroadcast(station);
if (broadcast.getActualStart() != null) {
logger.trace("Broadcast start date isn't estimated - it's "
+ "confirmed");
result.setNextBroadcastStartDateEstimated(false);
result.setNextBroadcastStartDate(broadcast.getActualStart());
} else {
logger.trace("Broadcast start date is still estimated");
result.setNextBroadcastStartDateEstimated(true);
result.setNextBroadcastStartDate(broadcast.getEstimatedStart());
}
result.setNextBroadcastEndDate(broadcast.getFinale());
// Find this DJ's history for this broadcast
List<JizzSong> songs = jizzSongServices.getSongsForBroadcast(dj,
broadcast);
List<HomeResultSong> resultSongs = new ArrayList<HomeResultSong>(
songs.size());
for (JizzSong song : songs) {
HomeResultSong resultSong = new HomeResultSong();
resultSong.setArtist(song.getArtist());
resultSong.setTitle(song.getTitle());
resultSongs.add(resultSong);
}
result.setSubmittedSongs(resultSongs);
// How many songs can this DJ submit?
result.setHowManySongsDjCanSubmit(jizzSongServices
.getHowManySongsDjCanSubmit(dj, broadcast, songs));
logger.trace("Jizz Home execution complete with result {}", result);
return result;
}