1
2
3
4
5 package hu.elte.tribus.action;
6
7 import hu.elte.tribus.interfaces.AnsverFinder;
8 import hu.elte.tribus.interfaces.ConversationDao;
9 import hu.elte.tribus.model.Conversation;
10 import hu.elte.tribus.model.Item;
11 import hu.elte.tribus.model.QA;
12 import hu.elte.tribus.services.QueryException;
13
14 import java.util.Date;
15
16 import javax.servlet.http.HttpServletRequest;
17 import javax.servlet.http.HttpServletResponse;
18
19 import org.apache.struts.action.ActionForm;
20 import org.apache.struts.action.ActionForward;
21 import org.apache.struts.action.ActionMapping;
22 import org.springframework.web.struts.ActionSupport;
23
24 /***
25 * MyEclipse Struts Creation date: 11-10-2006
26 *
27 * XDoclet definition:
28 *
29 * @struts.action validate="true"
30 */
31 public class AskQuestionAction extends ActionSupport {
32
33
34
35
36 /***
37 * Method execute
38 *
39 * @param mapping
40 * @param form
41 * @param request
42 * @param response
43 * @return ActionForward
44 */
45 public ActionForward execute(ActionMapping mapping, ActionForm form,
46 HttpServletRequest request, HttpServletResponse response) {
47 AnsverFinder ansverFinder = (AnsverFinder) getWebApplicationContext()
48 .getBean("ansverFinder");
49 ConversationDao conversationDao = (ConversationDao) getWebApplicationContext()
50 .getBean("conversationDao");
51
52 if (request.getParameter("question") != null) {
53 Integer conversationId = (Integer) request.getSession(true)
54 .getAttribute("conversation-id");
55 Conversation conversation = conversationDao
56 .getConversationbyId(conversationId);
57 String question = (String) request.getParameter("question");
58 QA qa = null;
59 try {
60 qa = ansverFinder.getQuestionAndAnsver(question, conversation);
61 } catch (QueryException e) {
62 qa = null;
63
64 }
65 Item item = new Item();
66 item.setConversation(conversation);
67 item.setQuestion(question);
68 item.setQa(qa);
69 item.setDate(new Date());
70 conversationDao.saveConversationItem(item);
71 String answer = qa == null ? "I cannot answer this question." : qa
72 .getAnswer();
73 request.setAttribute("answer", answer);
74 return mapping.findForward("answer");
75 } else {
76 return mapping.findForward("ok");
77 }
78 }
79 }