01: package org.emforge.jbpm.web.bean;
02:
03: import java.util.List;
04:
05: import javax.servlet.http.HttpServletRequest;
06: import javax.servlet.http.HttpServletResponse;
07:
08: import org.apache.commons.logging.Log;
09: import org.apache.commons.logging.LogFactory;
10: import org.emforge.BpmService;
11: import org.emforge.jbpm.rss.TaskListRSSView;
12: import org.emforge.xfer.StepTO;
13: import org.emforge.xfer.TaskTO;
14: import org.springframework.web.servlet.ModelAndView;
15: import org.springframework.web.servlet.mvc.Controller;
16:
17: import ru.emdev.EmForge.security.EmForgeUserDetails;
18: import ru.emdev.EmForge.security.UserFactory;
19: import ru.emdev.EmForge.security.UserSettingsService;
20:
21: /** Controller for Main window
22: *
23: * This is implementation of Main Window Controller for Spring MVC
24: * It is based on JSF Controller
25: */
26: public class MainWindowController implements Controller {
27: /** Logger for this class and subclasses */
28: protected final Log logger = LogFactory.getLog(getClass());
29:
30: /** BPM Context */
31: BpmService m_bpmService;
32:
33: /** User Factory */
34: UserFactory m_userFactory;
35:
36: /** User Settings Service */
37: UserSettingsService m_userSettingsService;
38:
39: public void setBpmService(BpmService i_bpmContext) {
40: m_bpmService = i_bpmContext;
41: }
42:
43: public void setUserFactory(UserFactory i_userFactory) {
44: m_userFactory = i_userFactory;
45: }
46:
47: public void setUserSettingsService(
48: UserSettingsService i_userSettingsService) {
49: m_userSettingsService = i_userSettingsService;
50: }
51:
52: /**
53: * Creates model and view.
54: *
55: * @todo Localize messages
56: */
57: @SuppressWarnings("unchecked")
58: public ModelAndView handleRequest(HttpServletRequest i_request,
59: HttpServletResponse o_response) throws Exception {
60: String format = null;
61: if (i_request.getParameter("format") != null) {
62: format = i_request.getParameter("format").toString();
63: }
64:
65: if (format != null && format.equals("rss")) {
66: EmForgeUserDetails currentUser = m_userFactory
67: .getCurrentUser();
68: List<StepTO> stepList = m_bpmService
69: .getActiveSteps(m_userSettingsService
70: .getDefaultProject().getName());
71: String description = "List of Active Tasks for "
72: + currentUser.getDisplayName();
73: String title = "List of Active Tasks for "
74: + currentUser.getDisplayName();
75:
76: // create model
77: ModelAndView mv = new ModelAndView("taskListRSSView");
78: mv.addObject(TaskListRSSView.LIST_KEY, stepList);
79: mv.addObject(TaskListRSSView.DESCRIPTION_KEY, description);
80: mv.addObject(TaskListRSSView.TITLE_KEY, title);
81:
82: for (int i = 0; i < stepList.size(); i++) {
83: TaskTO task = m_bpmService.getTask(stepList.get(i)
84: .getTaskId());
85: mv.addObject(task.getId().toString(), task);
86: }
87:
88: return mv;
89: } else {
90: assert false;
91:
92: return null;
93: }
94: }
95:
96: }
|