1
2
3
4
5 package hu.elte.tribus.action;
6
7 import hu.elte.tribus.interfaces.UserDao;
8 import hu.elte.tribus.interfaces.UserTracker;
9 import hu.elte.tribus.model.Conversation;
10 import hu.elte.tribus.model.User;
11
12 import java.util.Iterator;
13 import java.util.List;
14 import java.util.Set;
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
26 * Creation date: 11-10-2006
27 *
28 * XDoclet definition:
29 * @struts.action validate="true"
30 */
31 public class ListOnlineUsersAction extends ActionSupport {
32
33
34
35
36 /***
37 * Method execute
38 * @param mapping
39 * @param form
40 * @param request
41 * @param response
42 * @return ActionForward
43 */
44 public ActionForward execute(ActionMapping mapping, ActionForm form,
45 HttpServletRequest request, HttpServletResponse response) {
46 if(request.getParameter("username") == null)
47 {
48 UserTracker tracker = (UserTracker) getWebApplicationContext().getBean("userTracker");
49 List onlineUsers = tracker.listOfOnlineUsers();
50 request.setAttribute("users", onlineUsers);
51 return mapping.findForward("ok");
52 }
53 else
54 {
55 UserDao userDao = (UserDao) getWebApplicationContext().getBean("userDao");
56 User user = userDao.getUser(request.getParameter("username"));
57 request.setAttribute("user", user);
58 Set conversations = user.getConversations();
59 if(conversations.size() > 0)
60 {
61 Iterator i = conversations.iterator();
62 Conversation lastConversation = (Conversation)i.next();
63 while(i.hasNext())
64 {
65 Conversation conversation = (Conversation)i.next();
66 if(conversation.getStartdate().after(lastConversation.getStartdate()))
67 {
68 lastConversation = conversation;
69 }
70 }
71
72 request.setAttribute("lastConversation", lastConversation);
73 }
74 return mapping.findForward("conversation");
75 }
76 }
77 }