public ModelAndView detail(@PathVariable("questionId") long questionId, HttpServletRequest request, HttpServletResponse response)
throws Exception {
Person currentUser = accountService.getPerson(request);
notificationService.markAsRead(currentUser, questionId);
Question q = questionService.loadQuestion(questionId);
JsonObject question = jsonService.convertToJson(q);
JsonArray answers = new JsonArray();
for (Answer a : q.getAnswers()) {
JsonObject jo = jsonService.convertToJson(a);
answers.add(jo);
notificationService.markAsRead(currentUser, a.getId());
}
JsonArray tags = new JsonArray();
for (QuestionTag tag : q.getTags()) {
tags.add(jsonService.convertToJson(tag));
}
List<Activity> similarQuestions = searchService.searchQuestionsByTitle(q.getTitle());
JsonArray similar = new JsonArray();
for (Activity ques : similarQuestions) {
if (!ques.equals(q)) {
JsonObject obj = new JsonObject();
obj.addProperty("title", ques.getTitle());
obj.addProperty("id", ques.getId());
similar.add(obj);
}
}
Map<String, Object> model = Maps.newHashMap();
model.put("question", question);
model.put("answers", answers);
model.put("similar", similar);
model.put("tags", tags);
model.put("numAnswers", q.getAnswers().size());
jsonService.addUserInfoToModel(accountService.getAccount(request), model);
List<Contactable> contacts = contactService.loadAllContactables();
jsonService.addContactsToModel(contacts, model);
return new ModelAndView("questionDetail", model);
}