private EventManager eventManager;
@RequestMapping("/chapter")
public ModelAndView getChapter(@RequestParam("id")String id) throws ServletException, IOException {
Chapter chapter = retrieveChapter(id);
if (chapter == null) {
String errorText = "Failed to retrieve chapter with ID \"" + id +
"\" -- chapter not found.";
return new ModelAndView("error", "errorText", errorText);
}
chapter.setNumEvents(0);
List<Event> pastEvents = eventManager.getPastEvents(chapter.getId());
if (pastEvents != null) {
chapter.setNumEvents(pastEvents.size());
int totalAttendees = 0;
int totalEvents = 0;
for (Event event : pastEvents) {
if (event.getAttendeeCount() != null) {
totalAttendees += event.getAttendeeCount();
totalEvents++;
}
}
if (totalEvents > 0) {
chapter.setAverageAttendees(totalAttendees/totalEvents);
}
}
Map<String, Object> model = new HashMap<String, Object>();
model.put("chapter", chapter);
model.put("events", eventManager.getEventsForChapter(chapter.getId(), true));
model.put("pastevents", pastEvents);
return new ModelAndView("chapter", "model", model);
}