1
2
3
4 package org.flowfuse.base.frontend;
5
6 import org.apache.commons.logging.Log;
7 import org.apache.commons.logging.LogFactory;
8 import org.flowfuse.base.services.filter.FilterManagementService;
9 import org.springframework.beans.propertyeditors.CustomDateEditor;
10 import org.springframework.validation.BindException;
11 import org.springframework.web.bind.ServletRequestDataBinder;
12 import org.springframework.web.servlet.ModelAndView;
13 import org.springframework.web.servlet.view.RedirectView;
14
15 import javax.servlet.http.HttpServletRequest;
16 import javax.servlet.http.HttpServletResponse;
17 import java.text.SimpleDateFormat;
18 import java.util.Date;
19 import java.util.List;
20 import java.util.Map;
21
22 /***
23 * <p>The <code>WorkListController</code> is the controller for the work
24 * list view. It loads all work items for the current user and for the
25 * current filter.</p>
26 *
27 * @author <a href="stefan@flowfuse.org">Stefan Kleineikenscheidt</a>,
28 * Flowfuse.org
29 * @version $Id: WorkListController.java,v 1.3 2006/01/15 19:56:09 skleinei Exp $
30 */
31 public class WorkListController extends BaseFormController {
32
33 /***
34 * RCS ID
35 */
36 public final static String rcsid = "$Id: WorkListController.java,v 1.3 2006/01/15 19:56:09 skleinei Exp $";
37
38 /***
39 * Logger
40 */
41 protected final Log logger = LogFactory.getLog(this.getClass());
42
43 private FilterManagementService filterManagementService = null;
44
45 private static final String WORKLIST_FILTER_KEY = "ff.worklistfilter";
46 private static final String WORKITEMS_SESSION_KEY = "ff.workitems";
47
48
49 public static final String FILTER_ACTION_KEY = "filter.action";
50 public static final String FILTER_ACTION_RESET = "Reset";
51 public static final String FILTER_ACTION_FILTER = "Filter";
52
53 public WorkListController() {
54 setFormView("list");
55 setCommandClass(FrontendCommand.class);
56 }
57
58 protected boolean isFormSubmission(HttpServletRequest request) {
59 if (request.getParameter(FILTER_ACTION_KEY) != null) {
60 return true;
61 } else {
62 return false;
63 }
64 }
65
66 protected Object formBackingObject(HttpServletRequest request)
67 throws Exception {
68 if (logger.isDebugEnabled()) {
69 logger.debug("Forming backing object.");
70 }
71 FrontendCommand frontendCommand = (FrontendCommand) super.formBackingObject(
72 request);
73
74
75 Map filters = (Map) request.getSession().getAttribute(
76 WORKLIST_FILTER_KEY);
77 if (filters == null) {
78 filters = this.filterManagementService.getConfiguredFilters();
79 }
80
81 frontendCommand.setWorklistFilter(filters);
82
83
84 List workList = (List) request.getSession().getAttribute(
85 WORKITEMS_SESSION_KEY);
86
87
88 if (workList == null) {
89 workList = super.workItemManagementService.queryWorkItems(filters);
90 }
91 frontendCommand.setWorkList(workList);
92
93 return frontendCommand;
94 }
95
96 protected void initBinder(HttpServletRequest request,
97 ServletRequestDataBinder binder)
98 throws Exception {
99 SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
100 sdf.setLenient(true);
101 binder.registerCustomEditor(Date.class,
102 new CustomDateEditor(sdf, true));
103 }
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147 protected ModelAndView onSubmit(HttpServletRequest request,
148 HttpServletResponse response,
149 Object command,
150 BindException errors) throws Exception {
151
152 FrontendCommand frontendCommand = (FrontendCommand) command;
153 List workList = frontendCommand.getWorkList();
154 Map workListFilter = frontendCommand.getWorklistFilter();
155 String filterAction = request.getParameter(FILTER_ACTION_KEY);
156
157
158 if ((filterAction != null) &&
159 FILTER_ACTION_RESET.equals(filterAction)) {
160 logger.debug("Resetting worklist ilter.");
161 workListFilter = null;
162 }
163
164
165 if (workListFilter !=
166 request.getSession().getAttribute(WORKLIST_FILTER_KEY)) {
167 logger.debug("New worklist filter, therefore getting new worklist.");
168 }
169
170 workList = super.workItemManagementService.queryWorkItems(
171 workListFilter);
172
173
174 request.getSession().setAttribute(WORKITEMS_SESSION_KEY, workList);
175 request.getSession().setAttribute(WORKLIST_FILTER_KEY, workListFilter);
176
177 return new ModelAndView(new RedirectView("list"));
178 }
179
180 public FilterManagementService getFilterManagementService() {
181 return filterManagementService;
182 }
183
184 public void setFilterManagementService(
185 FilterManagementService filterManagementService) {
186 this.filterManagementService = filterManagementService;
187 }
188
189 }
190
191