01: package org.bpmscript.web;
02:
03: import java.util.HashMap;
04: import java.util.Map;
05:
06: import javax.servlet.http.HttpServletRequest;
07: import javax.servlet.http.HttpServletResponse;
08:
09: import org.bpmscript.IPagedResult;
10: import org.bpmscript.IProcessInstance;
11: import org.bpmscript.Query;
12: import org.bpmscript.remote.IRemoteProcessManager;
13: import org.springframework.web.servlet.ModelAndView;
14: import org.springframework.web.servlet.mvc.ParameterizableViewController;
15:
16: public class ProcessInstancesController extends
17: ParameterizableViewController {
18:
19: private final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory
20: .getLog(ProcessInstancesController.class);
21:
22: private IRemoteProcessManager remoteProcessManager;
23: private int defaultPageSize = 20;
24:
25: @Override
26: protected ModelAndView handleRequestInternal(
27: HttpServletRequest request, HttpServletResponse response)
28: throws Exception {
29:
30: String sort = request.getParameter("sort");
31: String page = request.getParameter("page");
32: String dir = request.getParameter("dir");
33: String filter = request.getParameter("filter");
34: String pageSize = request.getParameter("pageSize");
35:
36: int pageNumber = 0;
37: if (page != null) {
38: try {
39: pageNumber = Integer.parseInt(page);
40: } catch (NumberFormatException e) {
41: log.warn(e, e);
42: }
43: }
44:
45: int pageSizeNumber = defaultPageSize;
46: if (pageSize != null) {
47: try {
48: pageSizeNumber = Integer.parseInt(pageSize);
49: } catch (NumberFormatException e) {
50: log.warn(e, e);
51: }
52: }
53:
54: Query query = new Query();
55:
56: query.setFirstResult(pageNumber * pageSizeNumber);
57: query.setMaxResults(pageSizeNumber);
58:
59: if (sort != null && sort.trim().length() > 0) {
60: query.addOrderBy(sort, "asc".equals(dir));
61: }
62:
63: if (filter != null && filter.trim().length() > 0) {
64: query.setFilter(filter);
65: }
66:
67: Map<String, Object> model = new HashMap<String, Object>();
68:
69: model.put("sort", sort);
70: model.put("page", pageNumber);
71: model.put("pageSize", pageSizeNumber);
72: model.put("dir", dir);
73: model.put("filter", filter);
74:
75: IPagedResult<IProcessInstance> processInstances = remoteProcessManager
76: .getProcessInstances(query);
77: model.put("processInstances", processInstances);
78:
79: return new ModelAndView(getViewName(), model);
80: }
81:
82: public void setRemoteProcessManager(
83: IRemoteProcessManager remoteProcessManager) {
84: this.remoteProcessManager = remoteProcessManager;
85: }
86:
87: }
|