01: // license-header java merge-point
02: package org.andromda.timetracker.web.timecardsearch;
03:
04: import java.util.ArrayList;
05: import java.util.Arrays;
06: import java.util.List;
07:
08: import javax.servlet.http.HttpServletRequest;
09: import javax.servlet.http.HttpServletResponse;
10:
11: import org.andromda.timetracker.domain.TimecardStatus;
12: import org.andromda.timetracker.vo.TimecardSearchCriteriaVO;
13: import org.andromda.timetracker.vo.TimecardSummaryVO;
14: import org.andromda.timetracker.vo.UserVO;
15: import org.andromda.timetracker.vo.UserVOComparator;
16: import org.apache.commons.logging.Log;
17: import org.apache.commons.logging.LogFactory;
18: import org.apache.struts.action.ActionMapping;
19:
20: /**
21: * @see org.andromda.timetracker.web.timecardsearch.SearchController
22: */
23: public class SearchControllerImpl extends SearchController {
24: private Log logger = LogFactory.getLog(SearchControllerImpl.class);
25: private static final String ALL_STRING = "-- All --";
26:
27: /**
28: * @see org.andromda.timetracker.web.timecardsearch.SearchController#populateSearchScreen(org.apache.struts.action.ActionMapping, org.andromda.timetracker.web.timecardsearch.PopulateSearchScreenForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
29: */
30: public final void populateSearchScreen(
31: ActionMapping mapping,
32: org.andromda.timetracker.web.timecardsearch.PopulateSearchScreenForm form,
33: HttpServletRequest request, HttpServletResponse response)
34: throws Exception {
35: if (logger.isDebugEnabled()) {
36: logger.debug("form: " + form);
37: }
38:
39: // Get list of users and add the "All" option at the top
40: UserVO[] users = getUserService().getAllUsers();
41: Arrays.sort(users, new UserVOComparator());
42: List userList = new ArrayList(Arrays.asList(users));
43: userList.add(0, new UserVO(null, ALL_STRING, null, null));
44:
45: // Populate submitter and approver dropdowns
46: form.setSubmitterBackingList(userList, "id", "username");
47: form.setApproverBackingList(userList, "id", "username");
48:
49: // Populate status dropdown
50: List statusLabels = new ArrayList(TimecardStatus.literals());
51: List statusValues = new ArrayList(TimecardStatus.literals());
52: statusLabels.add(0, ALL_STRING);
53: statusValues.add(0, "");
54: form.setStatusLabelList(statusLabels.toArray());
55: form.setStatusValueList(statusValues.toArray());
56:
57: // Populate timecard summaries
58: TimecardStatus status = null;
59: if (form.getStatus() != null && form.getStatus().length() > 0) {
60: status = TimecardStatus.fromString(form.getStatus());
61: }
62: TimecardSearchCriteriaVO criteria = new TimecardSearchCriteriaVO(
63: form.getSubmitter(), form.getApprover(), status, form
64: .getStartDateMinimumAsDate(), form
65: .getStartDateMaximumAsDate());
66:
67: TimecardSummaryVO[] timecards = getTimeTrackingService()
68: .findTimecards(criteria);
69: form.setTimecardSummaries(timecards);
70: }
71:
72: public final void initializeTimecardId(
73: ActionMapping mapping,
74: org.andromda.timetracker.web.timecardsearch.InitializeTimecardIdForm form,
75: HttpServletRequest request, HttpServletResponse response)
76: throws Exception {
77: form.setTimecardId(form.getId());
78: }
79: }
|