1
2 package org.andromda.timetracker.web.timecardsearch;
3
4 import java.util.ArrayList;
5 import java.util.Arrays;
6 import java.util.List;
7
8 import org.andromda.timetracker.domain.TimecardStatus;
9 import org.andromda.timetracker.service.TimeTrackingServiceDelegate;
10 import org.andromda.timetracker.service.UserServiceDelegate;
11 import org.andromda.timetracker.vo.TimecardSearchCriteriaVO;
12 import org.andromda.timetracker.vo.TimecardSummaryVO;
13 import org.andromda.timetracker.vo.UserVO;
14 import org.andromda.timetracker.vo.UserVOComparator;
15 import org.apache.commons.logging.Log;
16 import org.apache.commons.logging.LogFactory;
17
18
19
20
21 public class SearchControllerImpl
22 extends SearchController
23 {
24 private static final long serialVersionUID = 1465722497189650491L;
25
26 private Log logger = LogFactory.getLog(SearchControllerImpl.class);
27 private static final String ALL_STRING = "-- All --";
28
29
30
31
32 public void populateSearchScreen(PopulateSearchScreenForm form)
33 {
34
35
36
37
38
39
40
41
42 if (logger.isDebugEnabled())
43 {
44 logger.debug("form: " + form);
45 }
46
47
48 UserVO[] users = null;
49 UserServiceDelegate usd = null;
50 try
51 {
52 usd = new UserServiceDelegate();
53 users = usd.getAllUsers();
54 }
55 finally
56 {
57 usd.close();
58 }
59
60 if (users != null)
61 {
62 Arrays.sort(users, new UserVOComparator());
63 List userList = new ArrayList(Arrays.asList(users));
64 userList.add(0, new UserVO(Long.valueOf(0), ALL_STRING, null, null));
65
66
67 form.setSubmitterBackingList(userList, "id", "username");
68 form.setApproverBackingList(userList, "id", "username");
69 }
70
71
72 List statusLabels = new ArrayList(TimecardStatus.literals());
73 List statusValues = new ArrayList(TimecardStatus.literals());
74 statusLabels.add(0, ALL_STRING);
75 statusValues.add(0, "");
76 form.setStatusLabelList(statusLabels.toArray());
77 form.setStatusValueList(statusValues.toArray());
78
79 TimecardStatus status = null;
80 if (form.getStatus() != null && form.getStatus().length() > 0)
81 {
82 status = TimecardStatus.fromString(form.getStatus());
83 }
84
85
86 TimecardSearchCriteriaVO criteria = new TimecardSearchCriteriaVO(
87 form.getSubmitter(),
88 form.getApprover(),
89 status,
90 form.getStartDateMinimum(),
91 form.getStartDateMaximum());
92
93 TimeTrackingServiceDelegate tsd = null;
94 try
95 {
96 tsd = new TimeTrackingServiceDelegate();
97 TimecardSummaryVO[] timecards = tsd.findTimecards(criteria);
98 form.setTimecardSummaries(timecards);
99 }
100 catch (Exception e)
101 {
102 logger.error("failed finding timecards", e);
103 }
104 finally
105 {
106 tsd.close();
107 }
108 }
109
110
111
112
113 public void initializeTimecardId(InitializeTimecardIdForm form)
114 {
115 form.setTimecardId(form.getId());
116 }
117
118 }